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:

979fc436ab

* indents/spaces/formtting
pull/529/head
geogolem 6 years ago committed by Qstick
parent f8ce2334c6
commit 875e1aedcb

@ -202,6 +202,8 @@ class SignalRConnector extends Component {
if (body.action === 'updated') { if (body.action === 'updated') {
this.props.dispatchUpdateItem({ section, ...body.resource }); this.props.dispatchUpdateItem({ section, ...body.resource });
// Repopulate the page to handle recently imported file
repopulatePage('trackFileUpdated');
} else if (body.action === 'deleted') { } else if (body.action === 'deleted') {
this.props.dispatchRemoveItem({ section, id: body.resource.id }); this.props.dispatchRemoveItem({ section, id: body.resource.id });
} }

@ -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); 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;
} }

@ -1,17 +1,27 @@
let currentPopulator = null; let currentPopulator = null;
let currentReasons = [];
export function registerPagePopulator(populator) { export function registerPagePopulator(populator, reasons = []) {
currentPopulator = populator; currentPopulator = populator;
currentReasons = reasons;
} }
export function unregisterPagePopulator(populator) { export function unregisterPagePopulator(populator) {
if (currentPopulator === populator) { if (currentPopulator === populator) {
currentPopulator = null; currentPopulator = null;
currentReasons = [];
} }
} }
export function repopulatePage() { export function repopulatePage(reason) {
if (currentPopulator) { if (!currentPopulator) {
return;
}
if (!reason) {
currentPopulator();
}
if (reason && currentReasons.includes(reason)) {
currentPopulator(); currentPopulator();
} }
} }

@ -21,6 +21,14 @@ import FilterMenu from 'Components/Menu/FilterMenu';
import ConfirmModal from 'Components/Modal/ConfirmModal'; import ConfirmModal from 'Components/Modal/ConfirmModal';
import CutoffUnmetRowConnector from './CutoffUnmetRowConnector'; import CutoffUnmetRowConnector from './CutoffUnmetRowConnector';
function getMonitoredValue(props) {
const {
filters,
selectedFilterKey
} = props;
return getFilterValue(filters, selectedFilterKey, 'monitored', false);
}
class CutoffUnmet extends Component { class CutoffUnmet extends Component {
// //
@ -74,9 +82,12 @@ class CutoffUnmet extends Component {
} }
onToggleSelectedPress = () => { onToggleSelectedPress = () => {
const selected = this.getSelectedIds(); const albumIds = this.getSelectedIds();
this.props.onToggleSelectedPress(selected); this.props.batchToggleCutoffUnmetAlbums({
albumIds,
monitored: !getMonitoredValue(this.props)
});
} }
onSearchAllCutoffUnmetPress = () => { onSearchAllCutoffUnmetPress = () => {
@ -119,7 +130,7 @@ class CutoffUnmet extends Component {
} = this.state; } = this.state;
const itemsSelected = !!this.getSelectedIds().length; const itemsSelected = !!this.getSelectedIds().length;
const monitoredFilterValue = getFilterValue(filters, 'monitored'); const isShowingMonitored = getMonitoredValue(this.props);
return ( return (
<PageContent title="Cutoff Unmet"> <PageContent title="Cutoff Unmet">
@ -133,8 +144,8 @@ class CutoffUnmet extends Component {
/> />
<PageToolbarButton <PageToolbarButton
label={monitoredFilterValue ? 'Unmonitor Selected' : 'Monitor Selected'} label={isShowingMonitored ? 'Unmonitor Selected' : 'Monitor Selected'}
iconName={icons.MONITORED} iconName={isShowingMonitored ? icons.UNMONITORED : icons.MONITORED}
isDisabled={!itemsSelected} isDisabled={!itemsSelected}
isSpinning={isSaving} isSpinning={isSaving}
onPress={this.onToggleSelectedPress} onPress={this.onToggleSelectedPress}
@ -257,7 +268,7 @@ CutoffUnmet.propTypes = {
isSaving: PropTypes.bool.isRequired, isSaving: PropTypes.bool.isRequired,
onFilterSelect: PropTypes.func.isRequired, onFilterSelect: PropTypes.func.isRequired,
onSearchSelectedPress: PropTypes.func.isRequired, onSearchSelectedPress: PropTypes.func.isRequired,
onToggleSelectedPress: PropTypes.func.isRequired, batchToggleCutoffUnmetAlbums: PropTypes.func.isRequired,
onSearchAllCutoffUnmetPress: PropTypes.func.isRequired onSearchAllCutoffUnmetPress: PropTypes.func.isRequired
}; };

@ -4,7 +4,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator'; import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
import getFilterValue from 'Utilities/Filter/getFilterValue';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems'; import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import selectUniqueIds from 'Utilities/Object/selectUniqueIds'; import selectUniqueIds from 'Utilities/Object/selectUniqueIds';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector'; import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
@ -45,7 +44,7 @@ class CutoffUnmetConnector extends Component {
// Lifecycle // Lifecycle
componentDidMount() { componentDidMount() {
registerPagePopulator(this.repopulate); registerPagePopulator(this.repopulate, ['trackFileUpdated']);
this.props.gotoCutoffUnmetFirstPage(); this.props.gotoCutoffUnmetFirstPage();
} }
@ -122,19 +121,6 @@ class CutoffUnmetConnector extends Component {
}); });
} }
onToggleSelectedPress = (selected) => {
const {
filters
} = this.props;
const monitored = getFilterValue(filters, 'monitored');
this.props.batchToggleCutoffUnmetAlbums({
albumIds: selected,
monitored: monitored == null || !monitored
});
}
onSearchAllCutoffUnmetPress = () => { onSearchAllCutoffUnmetPress = () => {
this.props.executeCommand({ this.props.executeCommand({
name: commandNames.CUTOFF_UNMET_ALBUM_SEARCH name: commandNames.CUTOFF_UNMET_ALBUM_SEARCH
@ -166,7 +152,6 @@ class CutoffUnmetConnector extends Component {
CutoffUnmetConnector.propTypes = { CutoffUnmetConnector.propTypes = {
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
filters: PropTypes.arrayOf(PropTypes.object).isRequired,
fetchCutoffUnmet: PropTypes.func.isRequired, fetchCutoffUnmet: PropTypes.func.isRequired,
gotoCutoffUnmetFirstPage: PropTypes.func.isRequired, gotoCutoffUnmetFirstPage: PropTypes.func.isRequired,
gotoCutoffUnmetPreviousPage: PropTypes.func.isRequired, gotoCutoffUnmetPreviousPage: PropTypes.func.isRequired,
@ -176,7 +161,6 @@ CutoffUnmetConnector.propTypes = {
setCutoffUnmetSort: PropTypes.func.isRequired, setCutoffUnmetSort: PropTypes.func.isRequired,
setCutoffUnmetFilter: PropTypes.func.isRequired, setCutoffUnmetFilter: PropTypes.func.isRequired,
setCutoffUnmetTableOption: PropTypes.func.isRequired, setCutoffUnmetTableOption: PropTypes.func.isRequired,
batchToggleCutoffUnmetAlbums: PropTypes.func.isRequired,
clearCutoffUnmet: PropTypes.func.isRequired, clearCutoffUnmet: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired, executeCommand: PropTypes.func.isRequired,
fetchQueueDetails: PropTypes.func.isRequired, fetchQueueDetails: PropTypes.func.isRequired,

@ -22,6 +22,15 @@ import ConfirmModal from 'Components/Modal/ConfirmModal';
import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal'; import InteractiveImportModal from 'InteractiveImport/InteractiveImportModal';
import MissingRowConnector from './MissingRowConnector'; import MissingRowConnector from './MissingRowConnector';
function getMonitoredValue(props) {
const {
filters,
selectedFilterKey
} = props;
return getFilterValue(filters, selectedFilterKey, 'monitored', false);
}
class Missing extends Component { class Missing extends Component {
// //
@ -75,9 +84,12 @@ class Missing extends Component {
} }
onToggleSelectedPress = () => { onToggleSelectedPress = () => {
const selected = this.getSelectedIds(); const albumIds = this.getSelectedIds();
this.props.onToggleSelectedPress(selected); this.props.batchToggleMissingAlbums({
albumIds,
monitored: !getMonitoredValue(this.props)
});
} }
onSearchAllMissingPress = () => { onSearchAllMissingPress = () => {
@ -129,7 +141,7 @@ class Missing extends Component {
} = this.state; } = this.state;
const itemsSelected = !!this.getSelectedIds().length; const itemsSelected = !!this.getSelectedIds().length;
const monitoredFilterValue = getFilterValue(filters, 'monitored'); const isShowingMonitored = getMonitoredValue(this.props);
return ( return (
<PageContent title="Missing"> <PageContent title="Missing">
@ -143,8 +155,8 @@ class Missing extends Component {
/> />
<PageToolbarButton <PageToolbarButton
label={monitoredFilterValue ? 'Unmonitor Selected' : 'Monitor Selected'} label={isShowingMonitored ? 'Unmonitor Selected' : 'Monitor Selected'}
iconName={icons.MONITORED} iconName={isShowingMonitored ? icons.UNMONITORED : icons.MONITORED}
isDisabled={!itemsSelected} isDisabled={!itemsSelected}
isSpinning={isSaving} isSpinning={isSaving}
onPress={this.onToggleSelectedPress} onPress={this.onToggleSelectedPress}
@ -279,7 +291,7 @@ Missing.propTypes = {
isSaving: PropTypes.bool.isRequired, isSaving: PropTypes.bool.isRequired,
onFilterSelect: PropTypes.func.isRequired, onFilterSelect: PropTypes.func.isRequired,
onSearchSelectedPress: PropTypes.func.isRequired, onSearchSelectedPress: PropTypes.func.isRequired,
onToggleSelectedPress: PropTypes.func.isRequired, batchToggleMissingAlbums: PropTypes.func.isRequired,
onSearchAllMissingPress: PropTypes.func.isRequired onSearchAllMissingPress: PropTypes.func.isRequired
}; };

@ -4,7 +4,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator'; import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
import getFilterValue from 'Utilities/Filter/getFilterValue';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems'; import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import selectUniqueIds from 'Utilities/Object/selectUniqueIds'; import selectUniqueIds from 'Utilities/Object/selectUniqueIds';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector'; import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
@ -42,7 +41,7 @@ class MissingConnector extends Component {
// Lifecycle // Lifecycle
componentDidMount() { componentDidMount() {
registerPagePopulator(this.repopulate); registerPagePopulator(this.repopulate, ['trackFileUpdated']);
this.props.gotoMissingFirstPage(); this.props.gotoMissingFirstPage();
} }
@ -112,19 +111,6 @@ class MissingConnector extends Component {
}); });
} }
onToggleSelectedPress = (selected) => {
const {
filters
} = this.props;
const monitored = getFilterValue(filters, 'monitored');
this.props.batchToggleMissingAlbums({
albumIds: selected,
monitored: monitored == null || !monitored
});
}
onSearchAllMissingPress = () => { onSearchAllMissingPress = () => {
this.props.executeCommand({ this.props.executeCommand({
name: commandNames.MISSING_ALBUM_SEARCH name: commandNames.MISSING_ALBUM_SEARCH
@ -156,7 +142,6 @@ class MissingConnector extends Component {
MissingConnector.propTypes = { MissingConnector.propTypes = {
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
filters: PropTypes.arrayOf(PropTypes.object).isRequired,
fetchMissing: PropTypes.func.isRequired, fetchMissing: PropTypes.func.isRequired,
gotoMissingFirstPage: PropTypes.func.isRequired, gotoMissingFirstPage: PropTypes.func.isRequired,
gotoMissingPreviousPage: PropTypes.func.isRequired, gotoMissingPreviousPage: PropTypes.func.isRequired,
@ -167,7 +152,6 @@ MissingConnector.propTypes = {
setMissingFilter: PropTypes.func.isRequired, setMissingFilter: PropTypes.func.isRequired,
setMissingTableOption: PropTypes.func.isRequired, setMissingTableOption: PropTypes.func.isRequired,
clearMissing: PropTypes.func.isRequired, clearMissing: PropTypes.func.isRequired,
batchToggleMissingAlbums: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired, executeCommand: PropTypes.func.isRequired,
fetchQueueDetails: PropTypes.func.isRequired, fetchQueueDetails: PropTypes.func.isRequired,
clearQueueDetails: PropTypes.func.isRequired clearQueueDetails: PropTypes.func.isRequired

Loading…
Cancel
Save