Skip to content

Commit 5545b98

Browse files
fix(ui): workflow field sorting doesn't use unique identifier for fields
1 parent 0c9434c commit 5545b98

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/LinearViewField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const LinearViewFieldInternal = ({ fieldIdentifier }: Props) => {
5252
<Flex
5353
ref={ref}
5454
// This is used to trigger the post-move flash animation
55-
data-field-name={fieldIdentifier.fieldName}
55+
data-field-name={`${fieldIdentifier.nodeId}-${fieldIdentifier.fieldName}`}
5656
data-is-dragging={isDragging}
5757
onMouseEnter={handleMouseOver}
5858
onMouseLeave={handleMouseOut}

invokeai/frontend/web/src/features/nodes/components/sidePanel/workflow/WorkflowLinearTab.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
77
import { IAINoContentFallback } from 'common/components/IAIImageFallback';
88
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
99
import { colorTokenToCssVar } from 'common/util/colorTokenToCssVar';
10+
import { deepClone } from 'common/util/deepClone';
1011
import { singleWorkflowFieldDndSource } from 'features/dnd/dnd';
1112
import { triggerPostMoveFlash } from 'features/dnd/util';
1213
import LinearViewFieldInternal from 'features/nodes/components/flow/nodes/Invocation/fields/LinearViewField';
1314
import { selectWorkflowSlice, workflowExposedFieldsReordered } from 'features/nodes/store/workflowSlice';
1415
import type { FieldIdentifier } from 'features/nodes/types/field';
16+
import { isEqual } from 'lodash-es';
1517
import { memo, useEffect } from 'react';
1618
import { flushSync } from 'react-dom';
1719
import { useTranslation } from 'react-i18next';
@@ -78,11 +80,13 @@ const FieldListInnerContent = memo(({ fields }: { fields: FieldIdentifier[] }) =
7880
return;
7981
}
8082

81-
const indexOfSource = fields.findIndex(
82-
(fieldIdentifier) => fieldIdentifier.fieldName === sourceData.payload.fieldIdentifier.fieldName
83+
const fieldsClone = deepClone(fields);
84+
85+
const indexOfSource = fieldsClone.findIndex((fieldIdentifier) =>
86+
isEqual(fieldIdentifier, sourceData.payload.fieldIdentifier)
8387
);
84-
const indexOfTarget = fields.findIndex(
85-
(fieldIdentifier) => fieldIdentifier.fieldName === targetData.payload.fieldIdentifier.fieldName
88+
const indexOfTarget = fieldsClone.findIndex((fieldIdentifier) =>
89+
isEqual(fieldIdentifier, targetData.payload.fieldIdentifier)
8690
);
8791

8892
if (indexOfTarget < 0 || indexOfSource < 0) {
@@ -113,7 +117,7 @@ const FieldListInnerContent = memo(({ fields }: { fields: FieldIdentifier[] }) =
113117
}
114118

115119
const reorderedFields = reorderWithEdge({
116-
list: fields,
120+
list: fieldsClone,
117121
startIndex: indexOfSource,
118122
indexOfTarget,
119123
closestEdgeOfTarget,
@@ -126,7 +130,9 @@ const FieldListInnerContent = memo(({ fields }: { fields: FieldIdentifier[] }) =
126130
});
127131

128132
// Flash the element that was moved
129-
const element = document.querySelector(`[data-field-name="${sourceData.payload.fieldIdentifier.fieldName}"]`);
133+
const element = document.querySelector(
134+
`[data-field-name="${sourceData.payload.fieldIdentifier.nodeId}-${sourceData.payload.fieldIdentifier.fieldName}"]`
135+
);
130136
if (element instanceof HTMLElement) {
131137
triggerPostMoveFlash(element, colorTokenToCssVar('base.700'));
132138
}

0 commit comments

Comments
 (0)