From d8a0aac9c396acdfd4ab2342889cbf6799466c6e Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 27 Sep 2020 22:33:21 -0400 Subject: [PATCH] Convert some instances (filter, find, pick) to native from lodash --- .../Details/HistoryDetailsConnector.js | 9 ++++--- .../Import/ImportMovieConnector.js | 3 +-- .../Import/ImportMovieRowConnector.js | 5 ++-- .../ImportMovie/Import/ImportMovieTable.js | 5 ++-- .../ImportMovieSelectMovieConnector.js | 3 +-- .../src/Calendar/Day/CalendarDayConnector.js | 2 +- .../Header/CalendarHeaderConnector.js | 24 ++++++++----------- frontend/src/Components/ImportListList.js | 3 +-- .../Table/Cells/RelativeDateCellConnector.js | 13 +++++----- frontend/src/Components/TagList.js | 3 +-- frontend/src/Movie/Details/MovieDetails.js | 3 +-- .../Details/MovieReleaseDatesConnector.js | 13 +++++----- .../src/Movie/Details/MovieTagsConnector.js | 2 +- .../Edit/EditMovieModalContentConnector.js | 15 ++++++------ .../src/Movie/MovieFileStatusConnector.js | 18 ++++++-------- .../AddDownloadClientModalContentConnector.js | 5 ++-- ...ditImportExclusionModalContentConnector.js | 3 +-- .../EditRestrictionModalContentConnector.js | 3 +-- .../EditMetadataModalContentConnector.js | 3 +-- .../src/Store/Actions/movieFileActions.js | 4 ++-- frontend/src/Utilities/String/parseUrl.js | 24 +++++++++---------- 21 files changed, 69 insertions(+), 94 deletions(-) diff --git a/frontend/src/Activity/History/Details/HistoryDetailsConnector.js b/frontend/src/Activity/History/Details/HistoryDetailsConnector.js index 0848c7905..65d95e557 100644 --- a/frontend/src/Activity/History/Details/HistoryDetailsConnector.js +++ b/frontend/src/Activity/History/Details/HistoryDetailsConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector'; @@ -8,10 +7,10 @@ function createMapStateToProps() { return createSelector( createUISettingsSelector(), (uiSettings) => { - return _.pick(uiSettings, [ - 'shortDateFormat', - 'timeFormat' - ]); + return { + shortDateFormat: uiSettings.shortDateFormat, + timeFormat: uiSettings.timeFormat + }; } ); } diff --git a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieConnector.js b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieConnector.js index f6f92aea4..702e1631e 100644 --- a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieConnector.js +++ b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -42,7 +41,7 @@ function createMapStateToProps() { }; if (items.length) { - const rootFolder = _.find(items, { id: rootFolderId }); + const rootFolder = items.find({ id: rootFolderId }); return { ...result, diff --git a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieRowConnector.js b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieRowConnector.js index b134b8ffd..d7a00e9c6 100644 --- a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieRowConnector.js +++ b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieRowConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -12,7 +11,7 @@ function createImportMovieItemSelector() { (state, { id }) => id, (state) => state.importMovie.items, (id, items) => { - return _.find(items, { id }) || {}; + return items.find({ id }) || {}; } ); } @@ -23,7 +22,7 @@ function createMapStateToProps() { createAllMoviesSelector(), (item, movies) => { const selectedMovie = item && item.selectedMovie; - const isExistingMovie = !!selectedMovie && _.some(movies, { tmdbId: selectedMovie.tmdbId }); + const isExistingMovie = !!selectedMovie && movies.some({ tmdbId: selectedMovie.tmdbId }); return { ...item, diff --git a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieTable.js b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieTable.js index 89665fb0a..ad3fa1c81 100644 --- a/frontend/src/AddMovie/ImportMovie/Import/ImportMovieTable.js +++ b/frontend/src/AddMovie/ImportMovie/Import/ImportMovieTable.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import VirtualTable from 'Components/Table/VirtualTable'; @@ -56,7 +55,7 @@ class ImportMovieTable extends Component { id } = prevItem; - const item = _.find(items, { id }); + const item = items.find({ id }); if (!item) { onRemoveSelectedStateItem(id); @@ -67,7 +66,7 @@ class ImportMovieTable extends Component { const isSelected = selectedState[id]; const isExistingMovie = !!selectedMovie && - _.some(prevProps.allMovies, { tmdbId: selectedMovie.tmdbId }); + prevProps.allMovies.some({ tmdbId: selectedMovie.tmdbId }); // Props doesn't have a selected movie or // the selected movie is an existing movie. diff --git a/frontend/src/AddMovie/ImportMovie/Import/SelectMovie/ImportMovieSelectMovieConnector.js b/frontend/src/AddMovie/ImportMovie/Import/SelectMovie/ImportMovieSelectMovieConnector.js index 31c94f294..29e43456c 100644 --- a/frontend/src/AddMovie/ImportMovie/Import/SelectMovie/ImportMovieSelectMovieConnector.js +++ b/frontend/src/AddMovie/ImportMovie/Import/SelectMovie/ImportMovieSelectMovieConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -46,7 +45,7 @@ class ImportMovieSelectMovieConnector extends Component { this.props.setImportMovieValue({ id, - selectedMovie: _.find(items, { tmdbId }) + selectedMovie: items.find({ tmdbId }) }); } diff --git a/frontend/src/Calendar/Day/CalendarDayConnector.js b/frontend/src/Calendar/Day/CalendarDayConnector.js index 33fa1baa4..9cff6c184 100644 --- a/frontend/src/Calendar/Day/CalendarDayConnector.js +++ b/frontend/src/Calendar/Day/CalendarDayConnector.js @@ -21,7 +21,7 @@ function createCalendarEventsConnector() { (state, { date }) => date, (state) => state.calendar.items, (date, items) => { - const filtered = _.filter(items, (item) => { + const filtered = items.filter((item) => { return (item.inCinemas && moment(date).isSame(moment(item.inCinemas), 'day')) || (item.physicalRelease && moment(date).isSame(moment(item.physicalRelease), 'day')) || (item.digitalRelease && moment(date).isSame(moment(item.digitalRelease), 'day')); diff --git a/frontend/src/Calendar/Header/CalendarHeaderConnector.js b/frontend/src/Calendar/Header/CalendarHeaderConnector.js index aec2d8e55..ba3941eab 100644 --- a/frontend/src/Calendar/Header/CalendarHeaderConnector.js +++ b/frontend/src/Calendar/Header/CalendarHeaderConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -14,19 +13,16 @@ function createMapStateToProps() { createDimensionsSelector(), createUISettingsSelector(), (calendar, dimensions, uiSettings) => { - const result = _.pick(calendar, [ - 'isFetching', - 'view', - 'time', - 'start', - 'end' - ]); - - result.isSmallScreen = dimensions.isSmallScreen; - result.collapseViewButtons = dimensions.isLargeScreen; - result.longDateFormat = uiSettings.longDateFormat; - - return result; + return { + isFetching: calendar.isFetching, + view: calendar.view, + time: calendar.time, + start: calendar.start, + end: calendar.end, + isSmallScreen: dimensions.isSmallScreen, + collapseViewButtons: dimensions.isLargeScreen, + longDateFormat: uiSettings.longDateFormat + }; } ); } diff --git a/frontend/src/Components/ImportListList.js b/frontend/src/Components/ImportListList.js index 7695b26d3..7949bc70a 100644 --- a/frontend/src/Components/ImportListList.js +++ b/frontend/src/Components/ImportListList.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; import { kinds, sizes } from 'Helpers/Props'; @@ -10,7 +9,7 @@ function ImportListList({ lists, importListList }) {
{ lists.map((t) => { - const list = _.find(importListList, { id: t }); + const list = importListList.find({ id: t }); if (!list) { return null; diff --git a/frontend/src/Components/Table/Cells/RelativeDateCellConnector.js b/frontend/src/Components/Table/Cells/RelativeDateCellConnector.js index ed996abbe..38783e7a5 100644 --- a/frontend/src/Components/Table/Cells/RelativeDateCellConnector.js +++ b/frontend/src/Components/Table/Cells/RelativeDateCellConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector'; @@ -8,12 +7,12 @@ function createMapStateToProps() { return createSelector( createUISettingsSelector(), (uiSettings) => { - return _.pick(uiSettings, [ - 'showRelativeDates', - 'shortDateFormat', - 'longDateFormat', - 'timeFormat' - ]); + return { + showRelativeDates: uiSettings.showRelativeDates, + shortDateFormat: uiSettings.shortDateFormat, + longDateFormat: uiSettings.longDateFormat, + timeFormat: uiSettings.timeFormat + }; } ); } diff --git a/frontend/src/Components/TagList.js b/frontend/src/Components/TagList.js index 485651bdc..4d1602583 100644 --- a/frontend/src/Components/TagList.js +++ b/frontend/src/Components/TagList.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; import { kinds } from 'Helpers/Props'; @@ -10,7 +9,7 @@ function TagList({ tags, tagList }) {
{ tags.map((t) => { - const tag = _.find(tagList, { id: t }); + const tag = tagList.find({ id: t }); if (!tag) { return null; diff --git a/frontend/src/Movie/Details/MovieDetails.js b/frontend/src/Movie/Details/MovieDetails.js index c505a25c1..e76d43d53 100644 --- a/frontend/src/Movie/Details/MovieDetails.js +++ b/frontend/src/Movie/Details/MovieDetails.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { Tab, TabList, TabPanel, Tabs } from 'react-tabs'; @@ -50,7 +49,7 @@ const defaultFontSize = parseInt(fonts.defaultFontSize); const lineHeight = parseFloat(fonts.lineHeight); function getFanartUrl(images) { - const fanartImage = _.find(images, { coverType: 'fanart' }); + const fanartImage = images.find({ coverType: 'fanart' }); if (fanartImage) { // Remove protocol return fanartImage.url.replace(/^https?:/, ''); diff --git a/frontend/src/Movie/Details/MovieReleaseDatesConnector.js b/frontend/src/Movie/Details/MovieReleaseDatesConnector.js index efd6b29f7..9c60c374b 100644 --- a/frontend/src/Movie/Details/MovieReleaseDatesConnector.js +++ b/frontend/src/Movie/Details/MovieReleaseDatesConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector'; @@ -8,12 +7,12 @@ function createMapStateToProps() { return createSelector( createUISettingsSelector(), (uiSettings) => { - return _.pick(uiSettings, [ - 'showRelativeDates', - 'shortDateFormat', - 'longDateFormat', - 'timeFormat' - ]); + return { + showRelativeDates: uiSettings.showRelativeDates, + shortDateFormat: uiSettings.shortDateFormat, + longDateFormat: uiSettings.longDateFormat, + timeFormat: uiSettings.timeFormat + }; } ); } diff --git a/frontend/src/Movie/Details/MovieTagsConnector.js b/frontend/src/Movie/Details/MovieTagsConnector.js index ce03ff2c2..29ed5bb02 100644 --- a/frontend/src/Movie/Details/MovieTagsConnector.js +++ b/frontend/src/Movie/Details/MovieTagsConnector.js @@ -11,7 +11,7 @@ function createMapStateToProps() { createTagsSelector(), (movie, tagList) => { const tags = _.reduce(movie.tags, (acc, tag) => { - const matchingTag = _.find(tagList, { id: tag }); + const matchingTag = tagList.find({ id: tag }); if (matchingTag) { acc.push(matchingTag.label); diff --git a/frontend/src/Movie/Edit/EditMovieModalContentConnector.js b/frontend/src/Movie/Edit/EditMovieModalContentConnector.js index 298f934ad..49f5aa11e 100644 --- a/frontend/src/Movie/Edit/EditMovieModalContentConnector.js +++ b/frontend/src/Movie/Edit/EditMovieModalContentConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -36,13 +35,13 @@ function createMapStateToProps() { pendingChanges } = moviesState; - const movieSettings = _.pick(movie, [ - 'monitored', - 'qualityProfileId', - 'minimumAvailability', - 'path', - 'tags' - ]); + const movieSettings = { + monitored: movie.monitored, + qualityProfileId: movie.qualityProfileId, + minimumAvailability: movie.minimumAvailability, + path: movie.path, + tags: movie.tags + }; const settings = selectSettings(movieSettings, pendingChanges, saveError); diff --git a/frontend/src/Movie/MovieFileStatusConnector.js b/frontend/src/Movie/MovieFileStatusConnector.js index 3afaf555f..f015f59ec 100644 --- a/frontend/src/Movie/MovieFileStatusConnector.js +++ b/frontend/src/Movie/MovieFileStatusConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -10,16 +9,13 @@ function createMapStateToProps() { return createSelector( createMovieSelector(), (movie) => { - const result = _.pick(movie, [ - 'inCinemas', - 'isAvailable', - 'monitored', - 'grabbed' - ]); - - result.movieFile = movie.movieFile; - - return result; + return { + inCinemas: movie.inCinemas, + isAvailable: movie.isAvailable, + monitored: movie.monitored, + grabbed: movie.grabbed, + movieFile: movie.movieFile + }; } ); } diff --git a/frontend/src/Settings/DownloadClients/DownloadClients/AddDownloadClientModalContentConnector.js b/frontend/src/Settings/DownloadClients/DownloadClients/AddDownloadClientModalContentConnector.js index 99d5c4f19..d06b1305d 100644 --- a/frontend/src/Settings/DownloadClients/DownloadClients/AddDownloadClientModalContentConnector.js +++ b/frontend/src/Settings/DownloadClients/DownloadClients/AddDownloadClientModalContentConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -17,8 +16,8 @@ function createMapStateToProps() { schema } = downloadClients; - const usenetDownloadClients = _.filter(schema, { protocol: 'usenet' }); - const torrentDownloadClients = _.filter(schema, { protocol: 'torrent' }); + const usenetDownloadClients = schema.filter({ protocol: 'usenet' }); + const torrentDownloadClients = schema.filter({ protocol: 'torrent' }); return { isSchemaFetching, diff --git a/frontend/src/Settings/ImportLists/ImportExclusions/EditImportExclusionModalContentConnector.js b/frontend/src/Settings/ImportLists/ImportExclusions/EditImportExclusionModalContentConnector.js index 70ea1d873..fc88125f1 100644 --- a/frontend/src/Settings/ImportLists/ImportExclusions/EditImportExclusionModalContentConnector.js +++ b/frontend/src/Settings/ImportLists/ImportExclusions/EditImportExclusionModalContentConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -27,7 +26,7 @@ function createImportExclusionSelector() { items } = importExclusions; - const mapping = id ? _.find(items, { id }) : newImportExclusion; + const mapping = id ? items.find({ id }) : newImportExclusion; const settings = selectSettings(mapping, pendingChanges, saveError); return { diff --git a/frontend/src/Settings/Indexers/Restrictions/EditRestrictionModalContentConnector.js b/frontend/src/Settings/Indexers/Restrictions/EditRestrictionModalContentConnector.js index 5737826e6..48f8fa1c0 100644 --- a/frontend/src/Settings/Indexers/Restrictions/EditRestrictionModalContentConnector.js +++ b/frontend/src/Settings/Indexers/Restrictions/EditRestrictionModalContentConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -27,7 +26,7 @@ function createMapStateToProps() { items } = restrictions; - const profile = id ? _.find(items, { id }) : newRestriction; + const profile = id ? items.find({ id }) : newRestriction; const settings = selectSettings(profile, pendingChanges, saveError); return { diff --git a/frontend/src/Settings/Metadata/Metadata/EditMetadataModalContentConnector.js b/frontend/src/Settings/Metadata/Metadata/EditMetadataModalContentConnector.js index 6ebeb7907..6a6027be8 100644 --- a/frontend/src/Settings/Metadata/Metadata/EditMetadataModalContentConnector.js +++ b/frontend/src/Settings/Metadata/Metadata/EditMetadataModalContentConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -20,7 +19,7 @@ function createMapStateToProps() { items } = metadata; - const settings = selectSettings(_.find(items, { id }), pendingChanges, saveError); + const settings = selectSettings(items.find({ id }), pendingChanges, saveError); return { advancedSettings, diff --git a/frontend/src/Store/Actions/movieFileActions.js b/frontend/src/Store/Actions/movieFileActions.js index 2a7203f57..fe5b7a517 100644 --- a/frontend/src/Store/Actions/movieFileActions.js +++ b/frontend/src/Store/Actions/movieFileActions.js @@ -68,7 +68,7 @@ export const actionHandlers = handleThunks({ deletePromise.done(() => { const movies = getState().movies.items; - const moviesWithRemovedFiles = _.filter(movies, { movieFileId }); + const moviesWithRemovedFiles = movies.filter({ movieFileId }); dispatch(batchActions([ ...moviesWithRemovedFiles.map((movie) => { @@ -100,7 +100,7 @@ export const actionHandlers = handleThunks({ promise.done(() => { const movies = getState().movies.items; const moviesWithRemovedFiles = movieFileIds.reduce((acc, movieFileId) => { - acc.push(..._.filter(movies, { movieFileId })); + acc.push(...movies.filter({ movieFileId })); return acc; }, []); diff --git a/frontend/src/Utilities/String/parseUrl.js b/frontend/src/Utilities/String/parseUrl.js index 93341f85f..e9408e9a0 100644 --- a/frontend/src/Utilities/String/parseUrl.js +++ b/frontend/src/Utilities/String/parseUrl.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import qs from 'qs'; // See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils @@ -10,18 +9,17 @@ export default function parseUrl(url) { // The `origin`, `password`, and `username` properties are unavailable in // Opera Presto. We synthesize `origin` if it's not present. While `password` // and `username` are ignored intentionally. - const properties = _.pick( - anchor, - 'hash', - 'host', - 'hostname', - 'href', - 'origin', - 'pathname', - 'port', - 'protocol', - 'search' - ); + const properties = { + hash: anchor.hash, + host: anchor.host, + hostname: anchor.hostname, + href: anchor.href, + origin: anchor.origin, + pathname: anchor.pathname, + port: anchor.port, + protocol: anchor.protocol, + search: anchor.search + }; properties.isAbsolute = (/^[\w:]*\/\//).test(url);