balibabu
commited on
Commit
·
2ace2a9
1
Parent(s):
6251e7e
feat: The order of the category operator form is messed up after refreshing the page #3088 (#3089)
Browse files### 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):
web/src/pages/flow/canvas/node/hooks.ts
CHANGED
|
@@ -29,13 +29,15 @@ export const useBuildCategorizeHandlePositions = ({
|
|
| 29 |
idx: number;
|
| 30 |
}> = [];
|
| 31 |
|
| 32 |
-
Object.keys(categoryData)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
});
|
| 38 |
-
});
|
| 39 |
|
| 40 |
return list;
|
| 41 |
}, [categoryData]);
|
|
|
|
| 29 |
idx: number;
|
| 30 |
}> = [];
|
| 31 |
|
| 32 |
+
Object.keys(categoryData)
|
| 33 |
+
.sort((a, b) => categoryData[a].index - categoryData[b].index)
|
| 34 |
+
.forEach((x, idx) => {
|
| 35 |
+
list.push({
|
| 36 |
+
text: x,
|
| 37 |
+
idx,
|
| 38 |
+
top: idx === 0 ? 98 : list[idx - 1].top + 8 + 26,
|
| 39 |
+
});
|
| 40 |
});
|
|
|
|
| 41 |
|
| 42 |
return list;
|
| 43 |
}, [categoryData]);
|
web/src/pages/flow/form/categorize-form/dynamic-categorize.tsx
CHANGED
|
@@ -111,7 +111,15 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
|
|
| 111 |
<Form.List name="items">
|
| 112 |
{(fields, { add, remove }) => {
|
| 113 |
const handleAdd = () => {
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
if (nodeId) updateNodeInternals(nodeId);
|
| 116 |
};
|
| 117 |
return (
|
|
@@ -178,6 +186,9 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
|
|
| 178 |
)}
|
| 179 |
/>
|
| 180 |
</Form.Item>
|
|
|
|
|
|
|
|
|
|
| 181 |
</Card>
|
| 182 |
))}
|
| 183 |
|
|
|
|
| 111 |
<Form.List name="items">
|
| 112 |
{(fields, { add, remove }) => {
|
| 113 |
const handleAdd = () => {
|
| 114 |
+
const idx = form.getFieldValue([
|
| 115 |
+
'items',
|
| 116 |
+
fields.at(-1)?.name,
|
| 117 |
+
'index',
|
| 118 |
+
]);
|
| 119 |
+
add({
|
| 120 |
+
name: humanId(),
|
| 121 |
+
index: fields.length === 0 ? 0 : idx + 1,
|
| 122 |
+
});
|
| 123 |
if (nodeId) updateNodeInternals(nodeId);
|
| 124 |
};
|
| 125 |
return (
|
|
|
|
| 186 |
)}
|
| 187 |
/>
|
| 188 |
</Form.Item>
|
| 189 |
+
<Form.Item hidden name={[field.name, 'index']}>
|
| 190 |
+
<Input />
|
| 191 |
+
</Form.Item>
|
| 192 |
</Card>
|
| 193 |
))}
|
| 194 |
|
web/src/pages/flow/form/categorize-form/hooks.ts
CHANGED
|
@@ -24,15 +24,14 @@ const buildCategorizeListFromObject = (
|
|
| 24 |
) => {
|
| 25 |
// Categorize's to field has two data sources, with edges as the data source.
|
| 26 |
// Changes in the edge or to field need to be synchronized to the form field.
|
| 27 |
-
return Object.keys(categorizeItem)
|
| 28 |
-
(pre, cur) => {
|
| 29 |
// synchronize edge data to the to field
|
| 30 |
|
| 31 |
pre.push({ name: cur, ...categorizeItem[cur] });
|
| 32 |
return pre;
|
| 33 |
-
},
|
| 34 |
-
|
| 35 |
-
);
|
| 36 |
};
|
| 37 |
|
| 38 |
/**
|
|
|
|
| 24 |
) => {
|
| 25 |
// Categorize's to field has two data sources, with edges as the data source.
|
| 26 |
// Changes in the edge or to field need to be synchronized to the form field.
|
| 27 |
+
return Object.keys(categorizeItem)
|
| 28 |
+
.reduce<Array<ICategorizeItem>>((pre, cur) => {
|
| 29 |
// synchronize edge data to the to field
|
| 30 |
|
| 31 |
pre.push({ name: cur, ...categorizeItem[cur] });
|
| 32 |
return pre;
|
| 33 |
+
}, [])
|
| 34 |
+
.sort((a, b) => a.index - b.index);
|
|
|
|
| 35 |
};
|
| 36 |
|
| 37 |
/**
|
web/src/pages/flow/interface.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface ICategorizeItem {
|
|
| 43 |
description?: string;
|
| 44 |
examples?: string;
|
| 45 |
to?: string;
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
export interface IGenerateParameter {
|
|
|
|
| 43 |
description?: string;
|
| 44 |
examples?: string;
|
| 45 |
to?: string;
|
| 46 |
+
index: number;
|
| 47 |
}
|
| 48 |
|
| 49 |
export interface IGenerateParameter {
|