From 875e1aedcb5b917465858632a5b105d6e2c96a48 Mon Sep 17 00:00:00 2001 From: geogolem Date: Tue, 6 Nov 2018 20:59:02 -0500 Subject: [PATCH] Wanted Monitor/Unmonitor Selected button fixed (#528) * the button was not changing based on the filter selection nor was it properly carrying out its function. It should now work. this code was ported from Sonarr: https://github.com/Sonarr/Sonarr/commit/979fc436ab88be6e0c9a3f1a721eb3b47d85c218 * indents/spaces/formtting --- frontend/src/Components/SignalRConnector.js | 2 ++ .../src/Utilities/Filter/getFilterValue.js | 10 ++++++-- frontend/src/Utilities/pagePopulator.js | 16 ++++++++++--- .../src/Wanted/CutoffUnmet/CutoffUnmet.js | 23 +++++++++++++----- .../CutoffUnmet/CutoffUnmetConnector.js | 18 +------------- frontend/src/Wanted/Missing/Missing.js | 24 ++++++++++++++----- .../src/Wanted/Missing/MissingConnector.js | 18 +------------- 7 files changed, 60 insertions(+), 51 deletions(-) diff --git a/frontend/src/Components/SignalRConnector.js b/frontend/src/Components/SignalRConnector.js index b652a7096..72bc1d893 100644 --- a/frontend/src/Components/SignalRConnector.js +++ b/frontend/src/Components/SignalRConnector.js @@ -202,6 +202,8 @@ class SignalRConnector extends Component { if (body.action === 'updated') { this.props.dispatchUpdateItem({ section, ...body.resource }); + // Repopulate the page to handle recently imported file + repopulatePage('trackFileUpdated'); } else if (body.action === 'deleted') { this.props.dispatchRemoveItem({ section, id: body.resource.id }); } diff --git a/frontend/src/Utilities/Filter/getFilterValue.js b/frontend/src/Utilities/Filter/getFilterValue.js index a8fc82183..70b0b51f1 100644 --- a/frontend/src/Utilities/Filter/getFilterValue.js +++ b/frontend/src/Utilities/Filter/getFilterValue.js @@ -1,5 +1,11 @@ -export default function getFilterValue(filters, filterKey) { +export default function getFilterValue(filters, filterKey, filterValueKey, defaultValue) { const filter = filters.find((f) => f.key === filterKey); - return filter && filter.value; + if (!filter) { + return defaultValue; + } + + const filterValue = filter.filters.find((f) => f.key === filterValueKey); + + return filterValue ? filterValue.value : defaultValue; } diff --git a/frontend/src/Utilities/pagePopulator.js b/frontend/src/Utilities/pagePopulator.js index 3fb26b1db..128a1d7a3 100644 --- a/frontend/src/Utilities/pagePopulator.js +++ b/frontend/src/Utilities/pagePopulator.js @@ -1,17 +1,27 @@ let currentPopulator = null; +let currentReasons = []; -export function registerPagePopulator(populator) { +export function registerPagePopulator(populator, reasons = []) { currentPopulator = populator; + currentReasons = reasons; } export function unregisterPagePopulator(populator) { if (currentPopulator === populator) { currentPopulator = null; + currentReasons = []; } } -export function repopulatePage() { - if (currentPopulator) { +export function repopulatePage(reason) { + if (!currentPopulator) { + return; + } + if (!reason) { + currentPopulator(); + } + + if (reason && currentReasons.includes(reason)) { currentPopulator(); } } diff --git a/frontend/src/Wanted/CutoffUnmet/CutoffUnmet.js b/frontend/src/Wanted/CutoffUnmet/CutoffUnmet.js index f328b73ac..af01ef7a5 100644 --- a/frontend/src/Wanted/CutoffUnmet/CutoffUnmet.js +++ b/frontend/src/Wanted/CutoffUnmet/CutoffUnmet.js @@ -21,6 +21,14 @@ import FilterMenu from 'Components/Menu/FilterMenu'; import ConfirmModal from 'Components/Modal/ConfirmModal'; import CutoffUnmetRowConnector from './CutoffUnmetRowConnector'; +function getMonitoredValue(props) { + const { + filters, + selectedFilterKey + } = props; + return getFilterValue(filters, selectedFilterKey, 'monitored', false); +} + class CutoffUnmet extends Component { // @@ -74,9 +82,12 @@ class CutoffUnmet extends Component { } onToggleSelectedPress = () => { - const selected = this.getSelectedIds(); + const albumIds = this.getSelectedIds(); - this.props.onToggleSelectedPress(selected); + this.props.batchToggleCutoffUnmetAlbums({ + albumIds, + monitored: !getMonitoredValue(this.props) + }); } onSearchAllCutoffUnmetPress = () => { @@ -119,7 +130,7 @@ class CutoffUnmet extends Component { } = this.state; const itemsSelected = !!this.getSelectedIds().length; - const monitoredFilterValue = getFilterValue(filters, 'monitored'); + const isShowingMonitored = getMonitoredValue(this.props); return ( @@ -133,8 +144,8 @@ class CutoffUnmet extends Component { /> { - const { - filters - } = this.props; - - const monitored = getFilterValue(filters, 'monitored'); - - this.props.batchToggleCutoffUnmetAlbums({ - albumIds: selected, - monitored: monitored == null || !monitored - }); - } - onSearchAllCutoffUnmetPress = () => { this.props.executeCommand({ name: commandNames.CUTOFF_UNMET_ALBUM_SEARCH @@ -166,7 +152,6 @@ class CutoffUnmetConnector extends Component { CutoffUnmetConnector.propTypes = { items: PropTypes.arrayOf(PropTypes.object).isRequired, - filters: PropTypes.arrayOf(PropTypes.object).isRequired, fetchCutoffUnmet: PropTypes.func.isRequired, gotoCutoffUnmetFirstPage: PropTypes.func.isRequired, gotoCutoffUnmetPreviousPage: PropTypes.func.isRequired, @@ -176,7 +161,6 @@ CutoffUnmetConnector.propTypes = { setCutoffUnmetSort: PropTypes.func.isRequired, setCutoffUnmetFilter: PropTypes.func.isRequired, setCutoffUnmetTableOption: PropTypes.func.isRequired, - batchToggleCutoffUnmetAlbums: PropTypes.func.isRequired, clearCutoffUnmet: PropTypes.func.isRequired, executeCommand: PropTypes.func.isRequired, fetchQueueDetails: PropTypes.func.isRequired, diff --git a/frontend/src/Wanted/Missing/Missing.js b/frontend/src/Wanted/Missing/Missing.js index 3eda2ed60..0f8e0a3fd 100644 --- a/frontend/src/Wanted/Missing/Missing.js +++ b/frontend/src/Wanted/Missing/Missing.js @@ -22,6 +22,15 @@ import ConfirmModal from 'Components/Modal/ConfirmModal'; import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal'; import MissingRowConnector from './MissingRowConnector'; +function getMonitoredValue(props) { + const { + filters, + selectedFilterKey + } = props; + + return getFilterValue(filters, selectedFilterKey, 'monitored', false); +} + class Missing extends Component { // @@ -75,9 +84,12 @@ class Missing extends Component { } onToggleSelectedPress = () => { - const selected = this.getSelectedIds(); + const albumIds = this.getSelectedIds(); - this.props.onToggleSelectedPress(selected); + this.props.batchToggleMissingAlbums({ + albumIds, + monitored: !getMonitoredValue(this.props) + }); } onSearchAllMissingPress = () => { @@ -129,7 +141,7 @@ class Missing extends Component { } = this.state; const itemsSelected = !!this.getSelectedIds().length; - const monitoredFilterValue = getFilterValue(filters, 'monitored'); + const isShowingMonitored = getMonitoredValue(this.props); return ( @@ -143,8 +155,8 @@ class Missing extends Component { /> { - const { - filters - } = this.props; - - const monitored = getFilterValue(filters, 'monitored'); - - this.props.batchToggleMissingAlbums({ - albumIds: selected, - monitored: monitored == null || !monitored - }); - } - onSearchAllMissingPress = () => { this.props.executeCommand({ name: commandNames.MISSING_ALBUM_SEARCH @@ -156,7 +142,6 @@ class MissingConnector extends Component { MissingConnector.propTypes = { items: PropTypes.arrayOf(PropTypes.object).isRequired, - filters: PropTypes.arrayOf(PropTypes.object).isRequired, fetchMissing: PropTypes.func.isRequired, gotoMissingFirstPage: PropTypes.func.isRequired, gotoMissingPreviousPage: PropTypes.func.isRequired, @@ -167,7 +152,6 @@ MissingConnector.propTypes = { setMissingFilter: PropTypes.func.isRequired, setMissingTableOption: PropTypes.func.isRequired, clearMissing: PropTypes.func.isRequired, - batchToggleMissingAlbums: PropTypes.func.isRequired, executeCommand: PropTypes.func.isRequired, fetchQueueDetails: PropTypes.func.isRequired, clearQueueDetails: PropTypes.func.isRequired