Merge pull request #16441 from strapi/fix/nested-repeatable-components-can-be-reordered

This commit is contained in:
Josh 2023-04-21 12:19:56 +01:00 committed by GitHub
commit 2edcb60e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,11 +97,17 @@ const DraggedItem = ({
const accordionRef = useRef(null);
const { formatMessage } = useIntl();
const [parentFieldName] = componentFieldName.split('.');
/**
* The last item in the fieldName array will be the index of this component.
* Drag and drop should be isolated to the parent component so nested repeatable
* components are not affected by the drag and drop of the parent component in
* their own re-ordering context.
*/
const componentKey = componentFieldName.split('.').slice(0, -1).join('.');
const [{ handlerId, isDragging, handleKeyDown }, boxRef, dropRef, dragRef, dragPreviewRef] =
useDragAndDrop(!isReadOnly, {
type: `${ItemTypes.COMPONENT}_${parentFieldName}`,
type: `${ItemTypes.COMPONENT}_${componentKey}`,
index,
item: {
displayedValue,