mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Project Aphrodite
This commit is contained in:
42
frontend/src/Utilities/State/getProviderState.js
Normal file
42
frontend/src/Utilities/State/getProviderState.js
Normal file
@@ -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;
|
Reference in New Issue
Block a user