mirror of
https://github.com/Radarr/Radarr
synced 2025-03-15 00:19:49 +00:00
Convert some instances (filter, find, pick) to native from lodash
This commit is contained in:
parent
987ed357d5
commit
d8a0aac9c3
21 changed files with 69 additions and 94 deletions
|
@ -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
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 })
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 }) {
|
|||
<div className={styles.lists}>
|
||||
{
|
||||
lists.map((t) => {
|
||||
const list = _.find(importListList, { id: t });
|
||||
const list = importListList.find({ id: t });
|
||||
|
||||
if (!list) {
|
||||
return null;
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 }) {
|
|||
<div className={styles.tags}>
|
||||
{
|
||||
tags.map((t) => {
|
||||
const tag = _.find(tagList, { id: t });
|
||||
const tag = tagList.find({ id: t });
|
||||
|
||||
if (!tag) {
|
||||
return null;
|
||||
|
|
|
@ -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?:/, '');
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}, []);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue