diff --git a/packages/core/content-type-builder/admin/src/components/DataManagerProvider/reducer.js b/packages/core/content-type-builder/admin/src/components/DataManagerProvider/reducer.js index 5252d7ac1e..c979444c6f 100644 --- a/packages/core/content-type-builder/admin/src/components/DataManagerProvider/reducer.js +++ b/packages/core/content-type-builder/admin/src/components/DataManagerProvider/reducer.js @@ -40,34 +40,6 @@ const reducer = (state = initialState, action) => // eslint-disable-next-line consistent-return produce(state, (draftState) => { switch (action.type) { - case actions.ADD_CUSTOM_FIELD_ATTRIBUTE: { - const { - attributeToSet: { name, ...rest }, - forTarget, - targetUid, - } = action; - - const pathToDataToEdit = ['component', 'contentType'].includes(forTarget) - ? [forTarget] - : [forTarget, targetUid]; - - const currentAttributes = get( - state, - ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes'], - [] - ).slice(); - - // Add the createdAttribute - const updatedAttributes = [...currentAttributes, { ...rest, name }]; - - set( - draftState, - ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes'], - updatedAttributes - ); - - break; - } case actions.ADD_ATTRIBUTE: { const { attributeToSet: { name, ...rest }, @@ -189,6 +161,34 @@ const reducer = (state = initialState, action) => break; } + case actions.ADD_CUSTOM_FIELD_ATTRIBUTE: { + const { + attributeToSet: { name, ...rest }, + forTarget, + targetUid, + } = action; + + const pathToDataToEdit = ['component', 'contentType'].includes(forTarget) + ? [forTarget] + : [forTarget, targetUid]; + + const currentAttributes = get( + state, + ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes'], + [] + ).slice(); + + // Add the createdAttribute + const updatedAttributes = [...currentAttributes, { ...rest, name }]; + + set( + draftState, + ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes'], + updatedAttributes + ); + + break; + } case actions.CHANGE_DYNAMIC_ZONE_COMPONENTS: { const { dynamicZoneTarget, newComponents } = action; @@ -261,27 +261,6 @@ const reducer = (state = initialState, action) => break; } - case actions.EDIT_CUSTOM_FIELD_ATTRIBUTE: { - const { forTarget, targetUid, initialAttribute, attributeToSet } = action; - - const initialAttributeName = initialAttribute.name; - const pathToDataToEdit = ['component', 'contentType'].includes(forTarget) - ? [forTarget] - : [forTarget, targetUid]; - - const initialAttributeIndex = findAttributeIndex( - get(state, ['modifiedData', ...pathToDataToEdit]), - initialAttributeName - ); - - set( - draftState, - ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes', initialAttributeIndex], - attributeToSet - ); - - break; - } case actions.EDIT_ATTRIBUTE: { const { attributeToSet: { name, ...rest }, @@ -462,6 +441,27 @@ const reducer = (state = initialState, action) => break; } + case actions.EDIT_CUSTOM_FIELD_ATTRIBUTE: { + const { forTarget, targetUid, initialAttribute, attributeToSet } = action; + + const initialAttributeName = initialAttribute.name; + const pathToDataToEdit = ['component', 'contentType'].includes(forTarget) + ? [forTarget] + : [forTarget, targetUid]; + + const initialAttributeIndex = findAttributeIndex( + get(state, ['modifiedData', ...pathToDataToEdit]), + initialAttributeName + ); + + set( + draftState, + ['modifiedData', ...pathToDataToEdit, 'schema', 'attributes', initialAttributeIndex], + attributeToSet + ); + + break; + } case actions.GET_DATA_SUCCEEDED: { draftState.components = action.components; draftState.initialComponents = action.components;