Zeke Zhang 97333d0c06
refactor(Menu): optimize menu interface (#5955)
* feat: define desktopRoutes collection

* feat: convert routes to schema

* feat: support to add new route

* feat: support to delete routes

* feat: adaptor Hidden option

* feat: adaptor Edit option

* fix: fix incomplete menu display issue

* feat: support to insert

* feat: adjust permission configuration page interface

* feat: add listAccessible action

* feat: routes table

* feat: edit button

* style: optimize style

* chore: add confirm text

* fix: delete corresponding schema when removing routes to ensure data consistency

* chore: add field type

* feat: create a tab when creating a page

* fix: fix tabs issue

* fix: avoid undefined error

* fix: should hide menu when it's hideInMenu is true

* fix: should refresh menu when updating it

* chore: optimize params

* fix: fix tab when adding child

* chore: should display empty

* fix: fix subapp path

* fix: fix activeKey of tab

* chore: add translation

* chore: prevent menu collapse after adding new menu item

* refactor: rename useDesktopRoutes to useNocoBaseRoutes

* fix: fix tab path

* fix: fix draging issue

* feat: support to set Hidden for Tab

* feat: implement move

* fix: draging

* chore: add migration

* fix: fix migration

* chore: fix build

* chore: fix e2e test

* fix: fix menu creation position issue

* fix: migration

* chore: add translation

* fix: fix some bugs

* fix: fix 'Move to'

* fix: compile Route name in permission management page

* fix: fix table selection issue

* chore: add comment

* fix: hidden

* fix: fix mobile route path

* fix: do not select parent node when selecting child nodes

* fix(mobile): hide menu

* fix(mobile): path

* fix(mobile): fix schema

* fix(mobile): compile tab title

* fix: fix permission configuration page selection error

* fix: fix selection issues

* fix(migration): transform old permission configuration to new permission configuration

* chore: translate fields title

* feat: support localization

* fix: fix pagination

* chore: fix build

* fix: change aclSnippet

* chore: fix unit tests

* fix: fix error

* chore: fix unit tests of server

* chore(migration): update version of migration

* chore: fix e2e tests

* chore: fix build error

* chore: make e2e tests pass

* chore: fix migration error

* fix: show ellipsis when text overflows

* fix: show ellipsis when text overflows

* chore: change 'Access' to 'View'

* fix: should use sort field to sort

* fix: fix tab drag and drop issue

* refactor: rename unnamed tab label to 'Unnamed'

* fix: fix draging issue

* refactor: add 'enableTabs' field

* refactor: optimize route fields

* refactor: optimize migration

* fix: set enableTabs to false when creating page

* refactor: change empty tab name to 'Unnamed'

* fix: fix tab path

* fix: avoid undefined error

* chore(migration): update appVersion

* fix(migration): fix page issue

* chore: fix unit test

* fix(mobile): fix incorrect path

* fix(mobile): fix enableTabs issue

* fix: disable Add child route button when enableTabs is false

* fix: fix embed issue

* fix(migration): add migration for mobile

* chore: update migration

* fix: fix tab title not updating issue

* fix: fix untranslated text issue

* fix: fix routes table style

* fix: fix group issue

* fix(mobile): fix 404 issue

* fix: should hide tabs when creating page

* fix: should translate tabs title

* fix: fix translation issue

* fix(migration): fix appVersion

* fix: fix ACL

* fix: should set paginate to true and filter out hidden items

* fix(migration): fix bug

* refactor(desktopRoutes): add enableHeader and displayTitle

* fix: fix permission issue

* fix(mobile): fix error

* fix(mobile): fix migration error

* fix(migration): compatible with older versions

* fix: make unit tests pass

* chore: ignore some failing test cases

* chore: test

* fix: test
2025-01-24 13:02:38 +08:00

102 lines
2.8 KiB
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { lazy } from '@nocobase/client';
import { TabsProps } from 'antd/es/tabs/index';
import React from 'react';
import { TFunction } from 'react-i18next';
// import { GeneralPermissions } from './permissions/GeneralPermissions';
// import { MenuItemsProvider } from './permissions/MenuItemsProvider';
// import { MenuPermissions } from './permissions/MenuPermissions';
const { GeneralPermissions } = lazy(() => import('./permissions/GeneralPermissions'), 'GeneralPermissions');
// const { MenuItemsProvider } = lazy(() => import('./permissions/MenuItemsProvider'), 'MenuItemsProvider');
const { MenuPermissions } = lazy(() => import('./permissions/MenuPermissions'), 'MenuPermissions');
import { Role } from './RolesManagerProvider';
import { DesktopAllRoutesProvider } from './permissions/MenuPermissions';
interface PermissionsTabsProps {
/**
* the key of the currently active tab panel
*/
activeKey: string;
/**
* the currently selected role
*/
activeRole: null | Role;
/**
* the current user's role
*/
currentUserRole: null | Role;
/**
* translation function
*/
t: TFunction;
/**
* used to constrain the size of the container in the Tab
*/
TabLayout: React.FC;
}
type Tab = TabsProps['items'][0] & {
/**
* Used for sorting tabs - lower numbers appear first
* Default values: System (10), Desktop routes (20)
* @default 100
*/
sort?: number;
};
type TabCallback = (props: PermissionsTabsProps) => Tab;
/**
* the extension API for ACL settings page
*/
export class ACLSettingsUI {
private permissionsTabs: (Tab | TabCallback)[] = [
({ t, TabLayout }) => ({
key: 'general',
label: t('System'),
sort: 10,
children: (
<TabLayout>
<GeneralPermissions />
</TabLayout>
),
}),
({ activeKey, t, TabLayout }) => ({
key: 'menu',
label: t('Desktop routes'),
sort: 20,
children: (
<TabLayout>
<DesktopAllRoutesProvider active={activeKey === 'menu'}>
<MenuPermissions active={activeKey === 'menu'} />
</DesktopAllRoutesProvider>
</TabLayout>
),
}),
];
addPermissionsTab(tab: Tab | TabCallback): void {
this.permissionsTabs.push(tab);
}
getPermissionsTabs(props: PermissionsTabsProps): Tab[] {
return this.permissionsTabs
.map((tab) => {
if (typeof tab === 'function') {
return tab(props);
}
return tab;
})
.sort((a, b) => (a.sort ?? 100) - (b.sort ?? 100));
}
}