Respect alphabetical order

This commit is contained in:
Mark Kaylor 2022-09-23 15:36:44 +02:00
parent b6bbd3e534
commit 5e8cb0f63b

View File

@ -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;