Fix relation update order

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-10-20 09:47:06 +02:00
parent dc3de8fac7
commit 27668b1fb5

View File

@ -368,8 +368,16 @@ const reducer = (state = initialState, action) =>
oppositeAttributeToCreate.private = rest.private;
}
const indexOfInitialAttribute = updatedAttributes.findIndex(
({ name }) => name === initialAttribute.name
);
const indexOfUpdatedAttribute = updatedAttributes.findIndex(
({ name: attrName }) => name === attrName
);
const indexToInsert =
updatedAttributes.findIndex(({ name }) => name === initialAttribute.name) + 1;
(indexOfInitialAttribute === -1 ? indexOfUpdatedAttribute : indexOfInitialAttribute) +
1;
updatedAttributes.splice(indexToInsert, 0, oppositeAttributeToCreate);
}