mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-23 22:25:14 -04:00
New: Project Aphrodite
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import _ from 'lodash';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
|
||||
function getProviderState(payload, getState, section) {
|
||||
const {
|
||||
id,
|
||||
...otherPayload
|
||||
} = payload;
|
||||
|
||||
const state = getSectionState(getState(), section, true);
|
||||
const pendingChanges = Object.assign({}, state.pendingChanges, otherPayload);
|
||||
const pendingFields = state.pendingChanges.fields || {};
|
||||
delete pendingChanges.fields;
|
||||
|
||||
const item = id ? _.find(state.items, { id }) : state.selectedSchema || state.schema || {};
|
||||
|
||||
if (item.fields) {
|
||||
pendingChanges.fields = _.reduce(item.fields, (result, field) => {
|
||||
const name = field.name;
|
||||
|
||||
const value = pendingFields.hasOwnProperty(name) ?
|
||||
pendingFields[name] :
|
||||
field.value;
|
||||
|
||||
// Only send the name and value to the server
|
||||
result.push({
|
||||
name,
|
||||
value
|
||||
});
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
|
||||
const result = Object.assign({}, item, pendingChanges);
|
||||
|
||||
delete result.presets;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export default getProviderState;
|
||||
@@ -0,0 +1,22 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
function getSectionState(state, section, isFullStateTree = false) {
|
||||
if (isFullStateTree) {
|
||||
return _.get(state, section);
|
||||
}
|
||||
|
||||
const [, subSection] = section.split('.');
|
||||
|
||||
if (subSection) {
|
||||
return Object.assign({}, state[subSection]);
|
||||
}
|
||||
|
||||
// TODO: Remove in favour of using subSection
|
||||
if (state.hasOwnProperty(section)) {
|
||||
return Object.assign({}, state[section]);
|
||||
}
|
||||
|
||||
return Object.assign({}, state);
|
||||
}
|
||||
|
||||
export default getSectionState;
|
||||
@@ -0,0 +1,34 @@
|
||||
import _ from 'lodash';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
|
||||
function applySchemaDefaults(selectedSchema, schemaDefaults) {
|
||||
if (!schemaDefaults) {
|
||||
return selectedSchema;
|
||||
} else if (_.isFunction(schemaDefaults)) {
|
||||
return schemaDefaults(selectedSchema);
|
||||
}
|
||||
|
||||
return Object.assign(selectedSchema, schemaDefaults);
|
||||
}
|
||||
|
||||
function selectProviderSchema(state, section, payload, schemaDefaults) {
|
||||
const newState = getSectionState(state, section);
|
||||
|
||||
const {
|
||||
implementation,
|
||||
presetName
|
||||
} = payload;
|
||||
|
||||
const selectedImplementation = _.find(newState.schema, { implementation });
|
||||
|
||||
const selectedSchema = presetName ?
|
||||
_.find(selectedImplementation.presets, { name: presetName }) :
|
||||
selectedImplementation;
|
||||
|
||||
newState.selectedSchema = applySchemaDefaults(_.cloneDeep(selectedSchema), schemaDefaults);
|
||||
|
||||
return updateSectionState(state, section, newState);
|
||||
}
|
||||
|
||||
export default selectProviderSchema;
|
||||
@@ -0,0 +1,16 @@
|
||||
function updateSectionState(state, section, newState) {
|
||||
const [, subSection] = section.split('.');
|
||||
|
||||
if (subSection) {
|
||||
return Object.assign({}, state, { [subSection]: newState });
|
||||
}
|
||||
|
||||
// TODO: Remove in favour of using subSection
|
||||
if (state.hasOwnProperty(section)) {
|
||||
return Object.assign({}, state, { [section]: newState });
|
||||
}
|
||||
|
||||
return Object.assign({}, state, newState);
|
||||
}
|
||||
|
||||
export default updateSectionState;
|
||||
Reference in New Issue
Block a user