Skip to content

Commit

Permalink
fixup! v3 UI
Browse files Browse the repository at this point in the history
Missing/Cutoff Unmet monitoring
  • Loading branch information
markus101 committed Oct 6, 2018
1 parent 40d13c9 commit 979fc43
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 50 deletions.
3 changes: 3 additions & 0 deletions frontend/src/Components/SignalRConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class SignalRConnector extends Component {

if (body.action === 'updated') {
this.props.dispatchUpdateItem({ section, ...body.resource });

// Repopulate the page to handle recently imported file
repopulatePage('episodeFileUpdated');
} else if (body.action === 'deleted') {
this.props.dispatchRemoveItem({ section, id: body.resource.id });
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Store/Actions/wantedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const SET_MISSING_FILTER = 'wanted/missing/setMissingFilter';
export const SET_MISSING_TABLE_OPTION = 'wanted/missing/setMissingTableOption';
export const CLEAR_MISSING = 'wanted/missing/clearMissing';

export const BATCH_TOGGLE_MISSING_EPISODES = 'wanted/missing/';
export const BATCH_TOGGLE_MISSING_EPISODES = 'wanted/missing/batchToggleMissingEpisodes';

export const FETCH_CUTOFF_UNMET = 'wanted/cutoffUnmet/fetchCutoffUnmet';
export const GOTO_FIRST_CUTOFF_UNMET_PAGE = 'wanted/cutoffUnmet/gotoCutoffUnmetFirstPage';
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/Utilities/Filter/getFilterValue.js
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 14 additions & 3 deletions frontend/src/Utilities/pagePopulator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
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();
}
}
22 changes: 17 additions & 5 deletions frontend/src/Wanted/CutoffUnmet/CutoffUnmet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ 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 {

//
Expand Down Expand Up @@ -78,9 +87,12 @@ class CutoffUnmet extends Component {
}

onToggleSelectedPress = () => {
const selected = this.getSelectedIds();
const episodeIds = this.getSelectedIds();

this.props.onToggleSelectedPress(selected);
this.props.batchToggleCutoffUnmetEpisodes({
episodeIds,
monitored: !getMonitoredValue(this.props)
});
}

onSearchAllCutoffUnmetPress = () => {
Expand Down Expand Up @@ -123,7 +135,7 @@ class CutoffUnmet extends Component {
} = this.state;

const itemsSelected = !!this.getSelectedIds().length;
const monitoredFilterValue = getFilterValue(filters, 'monitored');
const isShowingMonitored = getMonitoredValue(this.props);

return (
<PageContent title="Cutoff Unmet">
Expand All @@ -137,7 +149,7 @@ class CutoffUnmet extends Component {
/>

<PageToolbarButton
label={monitoredFilterValue ? 'Unmonitor Selected' : 'Monitor Selected'}
label={isShowingMonitored ? 'Unmonitor Selected' : 'Monitor Selected'}
iconName={icons.MONITORED}
isDisabled={!itemsSelected}
isSpinning={isSaving}
Expand Down Expand Up @@ -261,7 +273,7 @@ CutoffUnmet.propTypes = {
isSaving: PropTypes.bool.isRequired,
onFilterSelect: PropTypes.func.isRequired,
onSearchSelectedPress: PropTypes.func.isRequired,
onToggleSelectedPress: PropTypes.func.isRequired,
batchToggleCutoffUnmetEpisodes: PropTypes.func.isRequired,
onSearchAllCutoffUnmetPress: PropTypes.func.isRequired
};

Expand Down
18 changes: 1 addition & 17 deletions frontend/src/Wanted/CutoffUnmet/CutoffUnmetConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
import getFilterValue from 'Utilities/Filter/getFilterValue';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import selectUniqueIds from 'Utilities/Object/selectUniqueIds';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
Expand Down Expand Up @@ -44,7 +43,7 @@ class CutoffUnmetConnector extends Component {
// Lifecycle

componentDidMount() {
registerPagePopulator(this.repopulate);
registerPagePopulator(this.repopulate, ['episodeFileUpdated']);
this.props.gotoCutoffUnmetFirstPage();
}

Expand Down Expand Up @@ -120,19 +119,6 @@ class CutoffUnmetConnector extends Component {
});
}

onToggleSelectedPress = (selected) => {
const {
filters
} = this.props;

const monitored = getFilterValue(filters, 'monitored');

this.props.batchToggleCutoffUnmetEpisodes({
episodeIds: selected,
monitored: monitored == null || !monitored
});
}

onSearchAllCutoffUnmetPress = () => {
this.props.executeCommand({
name: commandNames.CUTOFF_UNMET_EPISODE_SEARCH
Expand Down Expand Up @@ -164,7 +150,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,
Expand All @@ -174,7 +159,6 @@ CutoffUnmetConnector.propTypes = {
setCutoffUnmetSort: PropTypes.func.isRequired,
setCutoffUnmetFilter: PropTypes.func.isRequired,
setCutoffUnmetTableOption: PropTypes.func.isRequired,
batchToggleCutoffUnmetEpisodes: PropTypes.func.isRequired,
clearCutoffUnmet: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired,
fetchQueueDetails: PropTypes.func.isRequired,
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/Wanted/Missing/Missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

//
Expand Down Expand Up @@ -75,9 +84,12 @@ class Missing extends Component {
}

onToggleSelectedPress = () => {
const selected = this.getSelectedIds();
const episodeIds = this.getSelectedIds();

this.props.onToggleSelectedPress(selected);
this.props.batchToggleMissingEpisodes({
episodeIds,
monitored: !getMonitoredValue(this.props)
});
}

onSearchAllMissingPress = () => {
Expand Down Expand Up @@ -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 (
<PageContent title="Missing">
Expand All @@ -143,7 +155,7 @@ class Missing extends Component {
/>

<PageToolbarButton
label={monitoredFilterValue ? 'Unmonitor Selected' : 'Monitor Selected'}
label={isShowingMonitored ? 'Unmonitor Selected' : 'Monitor Selected'}
iconName={icons.MONITORED}
isDisabled={!itemsSelected}
isSpinning={isSaving}
Expand Down Expand Up @@ -279,7 +291,7 @@ Missing.propTypes = {
isSaving: PropTypes.bool.isRequired,
onFilterSelect: PropTypes.func.isRequired,
onSearchSelectedPress: PropTypes.func.isRequired,
onToggleSelectedPress: PropTypes.func.isRequired,
batchToggleMissingEpisodes: PropTypes.func.isRequired,
onSearchAllMissingPress: PropTypes.func.isRequired
};

Expand Down
18 changes: 1 addition & 17 deletions frontend/src/Wanted/Missing/MissingConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { registerPagePopulator, unregisterPagePopulator } from 'Utilities/pagePopulator';
import getFilterValue from 'Utilities/Filter/getFilterValue';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import selectUniqueIds from 'Utilities/Object/selectUniqueIds';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
Expand Down Expand Up @@ -41,7 +40,7 @@ class MissingConnector extends Component {
// Lifecycle

componentDidMount() {
registerPagePopulator(this.repopulate);
registerPagePopulator(this.repopulate, ['episodeFileUpdated']);
this.props.gotoMissingFirstPage();
}

Expand Down Expand Up @@ -111,19 +110,6 @@ class MissingConnector extends Component {
});
}

onToggleSelectedPress = (selected) => {
const {
filters
} = this.props;

const monitored = getFilterValue(filters, 'monitored');

this.props.batchToggleMissingEpisodes({
episodeIds: selected,
monitored: monitored == null || !monitored
});
}

onSearchAllMissingPress = () => {
this.props.executeCommand({
name: commandNames.MISSING_EPISODE_SEARCH
Expand Down Expand Up @@ -155,7 +141,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,
Expand All @@ -166,7 +151,6 @@ MissingConnector.propTypes = {
setMissingFilter: PropTypes.func.isRequired,
setMissingTableOption: PropTypes.func.isRequired,
clearMissing: PropTypes.func.isRequired,
batchToggleMissingEpisodes: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired,
fetchQueueDetails: PropTypes.func.isRequired,
clearQueueDetails: PropTypes.func.isRequired
Expand Down

0 comments on commit 979fc43

Please sign in to comment.