feat: The order of the category operator form is messed up after refreshing 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):
This commit is contained in:
balibabu 2024-10-29 19:21:52 +08:00 committed by GitHub
parent c7dfb0193b
commit d868c283c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 12 deletions

View File

@ -29,7 +29,9 @@ export const useBuildCategorizeHandlePositions = ({
idx: number;
}> = [];
Object.keys(categoryData).forEach((x, idx) => {
Object.keys(categoryData)
.sort((a, b) => categoryData[a].index - categoryData[b].index)
.forEach((x, idx) => {
list.push({
text: x,
idx,

View File

@ -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 (
@ -178,6 +186,9 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
)}
/>
</Form.Item>
<Form.Item hidden name={[field.name, 'index']}>
<Input />
</Form.Item>
</Card>
))}

View File

@ -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);
};
/**

View File

@ -43,6 +43,7 @@ export interface ICategorizeItem {
description?: string;
examples?: string;
to?: string;
index: number;
}
export interface IGenerateParameter {