From 8087996c8edbb103c5e931b9c76d49bbe430b611 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 4 Apr 2019 18:38:19 -0700 Subject: [PATCH] Better selection of executing commands in series list --- .../Series/Index/SeriesIndexItemConnector.js | 17 +++++++---------- .../createExecutingCommandsSelector.js | 13 +++++++++++++ .../src/Store/Selectors/createSeriesSelector.js | 5 ++--- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 frontend/src/Store/Selectors/createExecutingCommandsSelector.js diff --git a/frontend/src/Series/Index/SeriesIndexItemConnector.js b/frontend/src/Series/Index/SeriesIndexItemConnector.js index 633fa722b..86173ec7e 100644 --- a/frontend/src/Series/Index/SeriesIndexItemConnector.js +++ b/frontend/src/Series/Index/SeriesIndexItemConnector.js @@ -3,9 +3,8 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import { isCommandExecuting } from 'Utilities/Command'; import createSeriesSelector from 'Store/Selectors/createSeriesSelector'; -import createCommandsSelector from 'Store/Selectors/createCommandsSelector'; +import createExecutingCommandsSelector from 'Store/Selectors/createCommandsSelector'; import createQualityProfileSelector from 'Store/Selectors/createQualityProfileSelector'; import createLanguageProfileSelector from 'Store/Selectors/createLanguageProfileSelector'; import { executeCommand } from 'Store/Actions/commandActions'; @@ -35,27 +34,25 @@ function createMapStateToProps() { createQualityProfileSelector(), createLanguageProfileSelector(), selectShowSearchAction(), - createCommandsSelector(), + createExecutingCommandsSelector(), ( series, qualityProfile, languageProfile, showSearchAction, - commands + executingCommands ) => { - const isRefreshingSeries = commands.some((command) => { + const isRefreshingSeries = executingCommands.some((command) => { return ( command.name === commandNames.REFRESH_SERIES && - command.body.seriesId === series.id && - isCommandExecuting(command) + command.body.seriesId === series.id ); }); - const isSearchingSeries = commands.some((command) => { + const isSearchingSeries = executingCommands.some((command) => { return ( command.name === commandNames.SERIES_SEARCH && - command.body.seriesId === series.id && - isCommandExecuting(command) + command.body.seriesId === series.id ); }); diff --git a/frontend/src/Store/Selectors/createExecutingCommandsSelector.js b/frontend/src/Store/Selectors/createExecutingCommandsSelector.js new file mode 100644 index 000000000..266865a8a --- /dev/null +++ b/frontend/src/Store/Selectors/createExecutingCommandsSelector.js @@ -0,0 +1,13 @@ +import { createSelector } from 'reselect'; +import { isCommandExecuting } from 'Utilities/Command'; + +function createExecutingCommandsSelector() { + return createSelector( + (state) => state.commands.items, + (commands) => { + return commands.filter((command) => isCommandExecuting(command)); + } + ); +} + +export default createExecutingCommandsSelector; diff --git a/frontend/src/Store/Selectors/createSeriesSelector.js b/frontend/src/Store/Selectors/createSeriesSelector.js index 1c1ab5bb8..fc5057b95 100644 --- a/frontend/src/Store/Selectors/createSeriesSelector.js +++ b/frontend/src/Store/Selectors/createSeriesSelector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import { createSelector } from 'reselect'; import createAllSeriesSelector from './createAllSeriesSelector'; @@ -6,8 +5,8 @@ function createSeriesSelector() { return createSelector( (state, { seriesId }) => seriesId, createAllSeriesSelector(), - (seriesId, series) => { - return _.find(series, { id: seriesId }); + (seriesId, allSeries) => { + return allSeries.find((series) => series.id === seriesId); } ); }