1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-21 22:05:43 -04:00

New: Dynamic Select and UMask Fields

Fixes #5380
Fixes #5348
Fixes #5167
Fixes #5166

Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
This commit is contained in:
Qstick
2020-11-20 23:33:10 -05:00
parent 73ce77f1ca
commit 9c77399379
50 changed files with 1244 additions and 212 deletions
@@ -1,3 +1,4 @@
import _ from 'lodash';
import { createAction } from 'redux-actions';
import { createThunk, handleThunks } from 'Store/thunks';
import requestAction from 'Utilities/requestAction';
@@ -10,11 +11,14 @@ import createHandleActions from './Creators/createHandleActions';
export const section = 'providerOptions';
const lastActions = {};
let lastActionId = 0;
//
// State
export const defaultState = {
items: {},
items: [],
isFetching: false,
isPopulated: false,
error: false
@@ -23,8 +27,8 @@ export const defaultState = {
//
// Actions Types
export const FETCH_OPTIONS = 'devices/fetchOptions';
export const CLEAR_OPTIONS = 'devices/clearOptions';
export const FETCH_OPTIONS = 'providers/fetchOptions';
export const CLEAR_OPTIONS = 'providers/clearOptions';
//
// Action Creators
@@ -38,35 +42,55 @@ export const clearOptions = createAction(CLEAR_OPTIONS);
export const actionHandlers = handleThunks({
[FETCH_OPTIONS]: function(getState, payload, dispatch) {
const subsection = `${section}.${payload.section}`;
if (lastActions[payload.section] && _.isEqual(payload, lastActions[payload.section].payload)) {
return;
}
const actionId = ++lastActionId;
lastActions[payload.section] = {
actionId,
payload
};
dispatch(set({
section,
section: subsection,
isFetching: true
}));
const oldItems = getState().providerOptions.items;
const itemSection = payload.itemSection;
const promise = requestAction(payload);
promise.done((data) => {
oldItems[itemSection] = data.options || [];
if (lastActions[payload.section]) {
if (lastActions[payload.section].actionId === actionId) {
lastActions[payload.section] = null;
}
dispatch(set({
section,
isFetching: false,
isPopulated: true,
error: null,
items: oldItems
}));
dispatch(set({
section: subsection,
isFetching: false,
isPopulated: true,
error: null,
items: data.options || []
}));
}
});
promise.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhr
}));
if (lastActions[payload.section]) {
if (lastActions[payload.section].actionId === actionId) {
lastActions[payload.section] = null;
}
dispatch(set({
section: subsection,
isFetching: false,
isPopulated: false,
error: xhr
}));
}
});
}
});
@@ -76,8 +100,12 @@ export const actionHandlers = handleThunks({
export const reducers = createHandleActions({
[CLEAR_OPTIONS]: function(state) {
return updateSectionState(state, section, defaultState);
[CLEAR_OPTIONS]: function(state, { payload }) {
const subsection = `${section}.${payload.section}`;
lastActions[payload.section] = null;
return updateSectionState(state, subsection, defaultState);
}
}, defaultState, section);
}, {}, section);