fix(menuItemSettings): enhance route moving logic to support nested i… (#6413)

* fix(menuItemSettings): enhance route moving logic to support nested insertion

* fix(menuItemSettings): update position method from 'prepend' to 'insertBefore'

* fix: insertBefore

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
Zeke Zhang 2025-03-11 11:11:30 +08:00 committed by GitHub
parent 1e3f988c48
commit 256b526800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 23 deletions

View File

@ -28,7 +28,6 @@ import {
useGlobalTheme,
useNavigateNoUpdate,
useNocoBaseRoutes,
useToken,
useURLAndHTMLSchema,
} from '../../..';
import { getPageMenuSchema } from '../../../';
@ -61,7 +60,7 @@ const toItems = (routes: NocoBaseDesktopRoute[], { t, compile }) => {
};
const insertPositionToMethod = {
beforeBegin: 'prepend',
beforeBegin: 'insertBefore',
afterEnd: 'insertAfter',
};
@ -490,28 +489,43 @@ const MoveToMenuItem = () => {
const { moveRoute } = useNocoBaseRoutes();
const currentRoute = useCurrentRoute();
const onMoveToSubmit: (values: any) => void = useCallback(async ({ target, position }) => {
const [targetId] = target?.split?.('||') || [];
if (!targetId) {
return;
}
const onMoveToSubmit: (values: any) => void = useCallback(
async ({ target, position }) => {
const [targetId] = target?.split?.('||') || [];
if (!targetId) {
return;
}
if (targetId === undefined || !currentRoute) {
return;
}
if (targetId === undefined || !currentRoute) {
return;
}
const positionToMethod = {
beforeBegin: 'prepend',
afterEnd: 'insertAfter',
};
const positionToMethod = {
beforeBegin: 'insertBefore',
afterEnd: 'insertAfter',
};
await moveRoute({
sourceId: currentRoute.id as any,
targetId: targetId,
sortField: 'sort',
method: positionToMethod[position],
});
}, []);
// 'beforeEnd' 表示的是插入到一个分组的里面
const options =
position === 'beforeEnd'
? {
targetScope: {
parentId: targetId,
},
}
: {
targetId: targetId,
};
await moveRoute({
sourceId: currentRoute.id as any,
sortField: 'sort',
method: positionToMethod[position],
...options,
});
},
[currentRoute, moveRoute],
);
return (
<SchemaSettingsModalItem

View File

@ -34,7 +34,7 @@ import { useInsertPageSchema } from '../../../modules/menu/PageMenuItem';
import { NocoBaseDesktopRouteType } from '../../../route-switch/antd/admin-layout/convertRoutesToSchema';
const insertPositionToMethod = {
beforeBegin: 'prepend',
beforeBegin: 'insertBefore',
afterEnd: 'insertAfter',
};
@ -453,7 +453,7 @@ export const MenuDesigner = () => {
});
const positionToMethod = {
beforeBegin: 'prepend',
beforeBegin: 'insertBefore',
afterEnd: 'insertAfter',
};