Skip to content

Commit

Permalink
feat: The order of the category operator form is messed up after refr…
Browse files Browse the repository at this point in the history
…eshing the page #3088 (#3089)

### What problem does this PR solve?

feat: The order of the category operator form is messed up after
refreshing the page #3088

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
  • Loading branch information
cike8899 authored Oct 29, 2024
1 parent c7dfb01 commit d868c28
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
14 changes: 8 additions & 6 deletions web/src/pages/flow/canvas/node/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ export const useBuildCategorizeHandlePositions = ({
idx: number;
}> = [];

Object.keys(categoryData).forEach((x, idx) => {
list.push({
text: x,
idx,
top: idx === 0 ? 98 : list[idx - 1].top + 8 + 26,
Object.keys(categoryData)
.sort((a, b) => categoryData[a].index - categoryData[b].index)
.forEach((x, idx) => {
list.push({
text: x,
idx,
top: idx === 0 ? 98 : list[idx - 1].top + 8 + 26,
});
});
});

return list;
}, [categoryData]);
Expand Down
13 changes: 12 additions & 1 deletion web/src/pages/flow/form/categorize-form/dynamic-categorize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
<Form.List name="items">
{(fields, { add, remove }) => {
const handleAdd = () => {
add({ name: humanId() });
const idx = form.getFieldValue([
'items',
fields.at(-1)?.name,
'index',
]);
add({
name: humanId(),
index: fields.length === 0 ? 0 : idx + 1,
});
if (nodeId) updateNodeInternals(nodeId);
};
return (
Expand Down Expand Up @@ -178,6 +186,9 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
)}
/>
</Form.Item>
<Form.Item hidden name={[field.name, 'index']}>
<Input />
</Form.Item>
</Card>
))}

Expand Down
9 changes: 4 additions & 5 deletions web/src/pages/flow/form/categorize-form/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ const buildCategorizeListFromObject = (
) => {
// Categorize's to field has two data sources, with edges as the data source.
// Changes in the edge or to field need to be synchronized to the form field.
return Object.keys(categorizeItem).reduce<Array<ICategorizeItem>>(
(pre, cur) => {
return Object.keys(categorizeItem)
.reduce<Array<ICategorizeItem>>((pre, cur) => {
// synchronize edge data to the to field

pre.push({ name: cur, ...categorizeItem[cur] });
return pre;
},
[],
);
}, [])
.sort((a, b) => a.index - b.index);
};

/**
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/flow/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ICategorizeItem {
description?: string;
examples?: string;
to?: string;
index: number;
}

export interface IGenerateParameter {
Expand Down

0 comments on commit d868c28

Please sign in to comment.