♻️ refactor(api): Sort and Announcement
This commit is contained in:
@@ -205,7 +205,7 @@ export default function NodeTable() {
|
||||
await createNode({
|
||||
...params,
|
||||
enable: false,
|
||||
});
|
||||
} as API.CreateNodeRequest);
|
||||
toast.success(t('copySuccess'));
|
||||
ref.current?.refresh();
|
||||
setLoading(false);
|
||||
@@ -258,26 +258,27 @@ export default function NodeTable() {
|
||||
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
||||
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
||||
|
||||
const originalSorts = items.map((item) => ({ id: item.id, sort: item.sort || item.id }));
|
||||
const originalSortMap = new Map(items.map((item) => [item.id, item.sort || item.id]));
|
||||
|
||||
const [movedItem] = items.splice(sourceIndex, 1);
|
||||
items.splice(targetIndex, 0, movedItem!);
|
||||
|
||||
const updatedItems = items.map((item) => {
|
||||
const originalSort = originalSorts.find((sortItem) => sortItem.id === item.id)?.sort;
|
||||
return {
|
||||
...item,
|
||||
sort: originalSort !== undefined ? originalSort : item.sort,
|
||||
};
|
||||
});
|
||||
nodeSort({
|
||||
sort: updatedItems.map((item) => {
|
||||
return {
|
||||
id: item.id,
|
||||
sort: item.sort,
|
||||
};
|
||||
}),
|
||||
const updatedItems = items.map((item, index) => {
|
||||
const originalSort = originalSortMap.get(item.id);
|
||||
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
||||
return { ...item, sort: newSort };
|
||||
});
|
||||
|
||||
const changedItems = updatedItems.filter(
|
||||
(item) => originalSortMap.get(item.id) !== item.sort,
|
||||
);
|
||||
|
||||
if (changedItems.length > 0) {
|
||||
nodeSort({
|
||||
sort: changedItems.map((item) => ({ id: item.id, sort: item.sort })),
|
||||
});
|
||||
}
|
||||
|
||||
return updatedItems;
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user