fix: use modifiedData if we have it

This commit is contained in:
Josh 2022-10-20 22:24:07 +01:00 committed by Gustav Hansen
parent 34f69999f9
commit c57f46f506

View File

@ -185,8 +185,6 @@ const reducer = (state, action) =>
*/ */
const data = cloneDeep(initialValues); const data = cloneDeep(initialValues);
console.log('data', data);
/** /**
* relationalFields won't be an array which is what we're expecting * relationalFields won't be an array which is what we're expecting
* Therefore we reset these bits of state to the correct data type * Therefore we reset these bits of state to the correct data type
@ -198,16 +196,13 @@ const reducer = (state, action) =>
.reduce((acc, currentPaths) => { .reduce((acc, currentPaths) => {
const [componentName] = currentPaths; const [componentName] = currentPaths;
// const initialRepeatableValue = if (state.modifiedData && Array.isArray(get(state.modifiedData, componentName))) {
// state.modifiedData && Array.isArray(get(state.modifiedData, componentName)) /**
// ? get(state.modifiedData, componentName) * this will be null on initial load, however subsequent calls
// : get(acc, componentName); * will have data in them correlating to the names of the relational fields.
*/
/** set(acc, componentName, get(state.modifiedData, componentName));
* This currently should only be ran on `repeatable` fields. } else if (repeatableFields.includes(componentName)) {
* You probably could make it work with any and all relational fields.
*/
if (repeatableFields.includes(componentName)) {
/** /**
* if the componentName is a repeatable field we collect the list of paths e.g. * if the componentName is a repeatable field we collect the list of paths e.g.
* ["repeatable_single_component_relation","categories"] and then reduce this * ["repeatable_single_component_relation","categories"] and then reduce this
@ -215,12 +210,6 @@ const reducer = (state, action) =>
*/ */
const findleaf = findLeafByPath(currentPaths.slice(-1)[0]); const findleaf = findLeafByPath(currentPaths.slice(-1)[0]);
currentPaths.reduce(findleaf, acc); currentPaths.reduce(findleaf, acc);
} else if (state.modifiedData && Array.isArray(get(state.modifiedData, currentPaths))) {
/**
* this will be null on initial load, however subsequent calls
* will have data in them correlating to the names of the relational fields.
*/
set(acc, currentPaths, get(state.modifiedData, currentPaths));
} else { } else {
set(acc, currentPaths, []); set(acc, currentPaths, []);
} }
@ -228,8 +217,6 @@ const reducer = (state, action) =>
return acc; return acc;
}, data); }, data);
console.log('mergeDataWithPreparedRelations', mergeDataWithPreparedRelations);
draftState.initialData = mergeDataWithPreparedRelations; draftState.initialData = mergeDataWithPreparedRelations;
draftState.modifiedData = mergeDataWithPreparedRelations; draftState.modifiedData = mergeDataWithPreparedRelations;