Zeke Zhang 0d0c81cc90
refactor: make the menu responsive to screen width (#6331)
* chore: convert routes

* chore: stash

* chore: stash

* feat: support to add menu item

* feat: add MenuSchemaToolbar

* refactor: extract EditMenuItem component

* feat: add hidden option

* refactor: extract HiddenMenuItem

* feat: add 'Move to' option

* feat: add insert options

* feat: remove route

* fix: children

* fix: route

* feat: enhance menu item rendering and group handling in admin layout

* feat: add container support to MenuSchemaToolbar and fix display issue in Group

* fix: add conditional check before moving routes in menu item settings

* feat(navigation): add default page navigation for admin layout

* chore(versions): 😊 publish v1.6.0-alpha.24

* feat: export AppNotFound component and integrate 404 handling in AdminDynamicPage

* fix: update admin layout route path to use item options URL

* chore(versions): 😊 publish v1.6.0-alpha.25

* refactor: rename route node retrieval functions for clarity and add legacy route compatibility

* refactor: clean up layout component by removing unused styles and improving header rendering

* refactor: simplify menu item components by removing unused schema insertion logic and optimizing imports

* refactor: add 'x-async' property to tab schema and clean up server imports

* refactor: tabs

* feat: support extending frontend filter operators (#6085)

* feat: operator extension

* fix: bug

* refactor: code improve

* fix: jsonLogic

---------

Co-authored-by: chenos <chenlinxh@gmail.com>

* feat: add fake schema for routing in SortableItem and remove unused fieldSchema import

* feat: adjust content padding in InternalAdminLayout for improved layout

* refactor: remove registerOperators (#6224)

* refactor(plugin-workflow): trigger workflow action settings (#6143)

* refactor(plugin-workflow): move bind workflow settings to plugin

* refactor(plugin-block-workbench): move component to core

* refactor(plugin-block-workbench): adjust component api

* fix(plugin-workflow-action-trigger): fix test cases

* fix(plugin-workflow): fix component scope

* fix(plugin-workflow-action-trigger): fix test cases

* chore(versions): 😊 publish v1.6.0-alpha.26

* feat: support the extension of preset fields in collections (#6183)

* feat: support the extension of preset fields in collections

* fix: bug

* fix: bug

* fix: bug

* refactor: create collection

* fix: config

* fix: test case

* refactor: code improve

* refactor: code improve

* fix: bug

* fix: bug

---------

Co-authored-by: chenos <chenlinxh@gmail.com>

* feat: replace SchemaComponent with RemoteSchemaComponent and add AppNotFound for empty tabs

* refactor: rename useCurrentRoute to useCurrentRouteData for clarity

* fix: redirect to first tab by default

* feat: support for the extension of optional fields for Kanban, Calendar, and Formula Field plugins (#6076)

* feat: kanban field extention

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* feat: calender title fields

* feat: background color fields

* fix: bug

* fix: bug

* feat: formula field expression support field

* feat: preset fields

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* refactor: code improve

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* refactor: code improve

* revert: preset fields

* refactor: code improve

* refactor: code improve

* fix: bug

* fix: bug

* fix: bug

* refactor: code improve

* fix: bug

* refactor: code improve

* refactor: code improve

* fix: bug

* fix: locale

* refactor: code improve

* fix: bug

* refactor: code improve

* refactor: code improve

* refactor: code improve

* refactor: locale

* fix: test

* fix: bug

* fix: test

* fix: test

---------

Co-authored-by: chenos <chenlinxh@gmail.com>

* fix: enhance access permission check and clean up unused props in Page component

* fix: adjust Action.Page style to set top position to 0

* fix: update redirect logic to point to the first page route in admin layout

* chore(versions): 😊 publish v1.6.0-alpha.27

* fix: add link handling in MenuItem to open URLs in a new tab

* fix(data-source-main): update order

* fix: integrate drag-and-drop functionality in MenuItem and Page components

* fix: add drag-and-drop support in admin layout and improve loading behavior

* fix: header style

* fix: set sider width in admin layout

* fix: refactor InternalAdminLayout for improved readability and maintainability

* fix: optimize token management in InternalAdminLayout for better styling consistency

* fix: style

* fix: avoid error

* fix: update container reference in MenuSchemaToolbarWithContainer

* fix: add icon style to MenuSchemaToolbar

* fix: remove bottom border from header in admin layout

* fix: add collapsed button render function to InternalAdminLayout

* fix: update viewport meta tag for better responsiveness

* fix: add MenuItemIcon component for conditional icon rendering in admin layout

* fix: wrap SchemaToolbar in SiderContext.Provider to prevent style issues in collapsed state

* fix: update InternalAdminLayout styles for improved menu item appearance

* fix: adjust menu item spacing and height for compact mode in admin layout

* fix: add collapse handling and page change logic in InternalAdminLayout

* fix: add header context provider and update MenuItemIcon rendering logic in InternalAdminLayout

* fix: replace Modal with App.useApp().modal in HiddenMenuItem for improved modal handling

* fix: enhance click area for links in MenuItem and streamline group navigation logic

* fix: refresh routes after adding link menu

* fix: add mobile actions popover for improved user interaction in admin layout

* fix: adjust layout width and margin for improved alignment in admin layout

* style: fix the style of the top collapsed menu button dropdown

* fix: add active background color for selected menu items in collapsed menu

* fix: improve z-index management for modal, drawer, and page components to prevent overlap with collapsed menu button

* fix: adjust position of collapsed button to prevent overlap with subpages

* fix: update collapsed button rendering to handle mobile context and prevent overlap with subpages

* fix: prevent schema data request for group pages in admin layout

* fix: handle undefined menu titles by providing a default value

* fix: add refresh functionality for desktop routes in menu permissions

* fix: adjust page header padding based on route settings and token

* fix: center text

* fix: add tooltip support for menu items in collapsed state

* fix: tooltip

* fix: improve page tab routing and deletion handling

* fix: adjust admin layout height to account for header

* fix: improve route navigation and deletion handling in admin layout

* chore: update version

* fix(routing): Add Navigate import from react-router-dom

* fix(e2e): locator

* test: remove demo and useless test case for Page component

* fix: improve page creation and routing in e2e utils

* fix: improve z-index handling for embedded pages

* feat(admin-layout): Add aria-label to menu item links for improved accessibility

* fix(mobile-ui): Adjust toolbar and navigation bar styling

* test(acl): Simplify menu item visibility test setup

* test: update e2e test templates and route handling

* fix: fix compatibility issues

* fix(admin-layout): improve default page navigation handling

* fix(acl): add optional chaining to prevent potential null/undefined error in uiButtonSchemasBlacklist check

* fix: keep alive

* fix(desktop-routes): enhance route retrieval with automatic child route inclusion

* test: add test

* fix(page): update navigation logic to use location pathname for tab routing

* fix(route): export CurrentRouteProvider for better accessibility in routing context

* refactor(layout): remove unused styles for cleaner code

* fix(layout): integrate useGlobalTheme for consistent theming and clean up unused parameters

* fix(route): improve route redirection logic

---------

Co-authored-by: nocobase[bot] <179432756+nocobase[bot]@users.noreply.github.com>
Co-authored-by: Katherine <katherine_15995@163.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
Co-authored-by: Junyi <mytharcher@users.noreply.github.com>
2025-03-05 22:52:24 +08:00

362 lines
10 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 { DisconnectOutlined, LoadingOutlined } from '@ant-design/icons';
import { css } from '@emotion/css';
import { observer } from '@formily/reactive-react';
import { getSubAppName } from '@nocobase/sdk';
import { tval } from '@nocobase/utils/client';
import { Button, Modal, Result, Spin } from 'antd';
import React, { FC } from 'react';
import { Navigate, useNavigate } from 'react-router-dom';
import { ACLPlugin } from '../acl';
import { Application } from '../application';
import { Plugin } from '../application/Plugin';
import { BlockSchemaComponentPlugin } from '../block-provider';
import { CollectionPlugin } from '../collection-manager';
import { RemoteDocumentTitlePlugin } from '../document-title';
import { PinnedListPlugin } from '../plugin-manager';
import { PMPlugin } from '../pm';
import { AdminLayoutPlugin, RouteSchemaComponent } from '../route-switch';
import { AntdSchemaComponentPlugin, PageTabs, SchemaComponentPlugin } from '../schema-component';
import { ErrorFallback } from '../schema-component/antd/error-fallback';
import { PagePopups } from '../schema-component/antd/page/PagePopups';
import { AssociationFilterPlugin, SchemaInitializerPlugin } from '../schema-initializer';
import { SchemaSettingsPlugin } from '../schema-settings';
import { BlockTemplateDetails, BlockTemplatePage } from '../schema-templates';
import { SystemSettingsPlugin } from '../system-settings';
import { CurrentUserProvider, CurrentUserSettingsMenuProvider } from '../user';
import { LocalePlugin } from './plugins/LocalePlugin';
const AppSpin = () => {
return (
<Spin style={{ position: 'fixed', top: '50%', left: '50%', fontSize: 72, transform: 'translate(-50%, -50%)' }} />
);
};
const useErrorProps = (app: Application, error: any) => {
if (!error) {
return {};
}
const err = error?.response?.data?.errors?.[0] || error;
const subApp = getSubAppName(app.getPublicPath());
switch (err.code) {
case 'USER_HAS_NO_ROLES_ERR':
return {
title: app.i18n.t('Permission denied'),
subTitle: err.message,
extra: [
<Button
type="primary"
key="try"
onClick={() => {
app.apiClient.auth.setToken(null);
window.location.reload();
}}
>
{app.i18n.t('Sign in with another account')}
</Button>,
subApp ? (
<Button key="back" onClick={() => (window.location.href = '/admin')}>
{app.i18n.t('Return to the main application')}
</Button>
) : null,
],
};
default:
return {};
}
};
const AppError: FC<{ error: Error; app: Application }> = observer(
({ app, error }) => {
const props = useErrorProps(app, error);
return (
<div>
<Result
className={css`
top: 50%;
position: absolute;
width: 100%;
transform: translate(0, -50%);
`}
status="error"
title={app.i18n.t('App error')}
subTitle={app.i18n.t(error?.message)}
extra={[
<Button type="primary" key="try" onClick={() => window.location.reload()}>
{app.i18n.t('Try again')}
</Button>,
]}
{...props}
/>
</div>
);
},
{ displayName: 'AppError' },
);
const getProps = (app: Application) => {
if (app.ws.serverDown) {
return {
status: 'error',
icon: <DisconnectOutlined />,
title: "You're offline",
subTitle: 'Please check the server status or network connection status',
};
}
if (!app.error) {
return {};
}
if (app.error.code === 'APP_NOT_FOUND') {
return {
status: 'warning',
title: 'App not found',
subTitle: app.error?.message,
};
}
if (app.error.code === 'APP_INITIALIZING') {
return {
status: 'info',
icon: <LoadingOutlined />,
title: 'App initializing',
subTitle: app.error?.message,
};
}
if (app.error.code === 'APP_INITIALIZED') {
return {
status: 'warning',
title: 'App initialized',
subTitle: app.error?.message,
};
}
if (['ENOENT', 'APP_ERROR', 'LOAD_ERROR'].includes(app.error.code)) {
return {
status: 'error',
title: 'App error',
subTitle: app.error?.message,
};
}
if (app.error.code === 'APP_NOT_INSTALLED_ERROR') {
return {
status: 'warning',
title: 'App not installed',
subTitle: app.error?.message,
};
}
if (app.error.code === 'APP_STOPPED') {
return {
status: 'warning',
title: 'App stopped',
subTitle: app.error?.message,
};
}
if (app.error.code === 'APP_COMMANDING') {
const props = {
status: 'info',
icon: <LoadingOutlined />,
title: app.error?.command?.name,
subTitle: app.error?.message,
};
const commands = {
start: {
title: 'App starting',
},
restart: {
title: 'App restarting',
},
install: {
title: 'App installing',
},
upgrade: {
title: 'App upgrading',
},
'pm.add': {
title: 'Adding plugin',
},
'pm.update': {
title: 'Updating plugin',
},
'pm.enable': {
title: 'Enabling plugin',
},
'pm.disable': {
title: 'Disabling plugin',
},
'pm.remove': {
title: 'Removing plugin',
},
};
return { ...props, ...commands[app.error?.command?.name] };
}
return {
status: 'warning',
title: 'App warning',
subTitle: app.error?.message,
};
};
const AppMaintaining: FC<{ app: Application; error: Error }> = observer(
({ app }) => {
const { icon, status, title, subTitle } = getProps(app);
return (
<div>
<Result
className={css`
top: 50%;
position: absolute;
width: 100%;
transform: translate(0, -50%);
`}
icon={icon}
status={status}
title={app.i18n.t(title)}
subTitle={<div style={{ whiteSpace: 'pre-wrap' }}>{app.i18n.t(subTitle)}</div>}
// extra={[
// <Button type="primary" key="try" onClick={() => window.location.reload()}>
// {app.i18n.t('Try again')}
// </Button>,
// ]}
/>
</div>
);
},
{ displayName: 'AppMaintaining' },
);
const AppMaintainingDialog: FC<{ app: Application; error: Error }> = observer(
({ app }) => {
const { icon, status, title, subTitle } = getProps(app);
return (
<Modal open={true} footer={null} closable={false}>
<Result icon={icon} status={status} title={app.i18n.t(title)} subTitle={app.i18n.t(subTitle)} />
</Modal>
);
},
{ displayName: 'AppMaintainingDialog' },
);
export const AppNotFound = () => {
const navigate = useNavigate();
return (
<Result
status="404"
title="404"
subTitle="Sorry, the page you visited does not exist."
extra={
<Button onClick={() => navigate('/', { replace: true })} type="primary">
Back Home
</Button>
}
/>
);
};
export class NocoBaseBuildInPlugin extends Plugin {
async afterAdd() {
this.app.addComponents({
AppSpin,
AppError,
AppMaintaining,
AppMaintainingDialog,
AppNotFound,
});
await this.addPlugins();
}
async load() {
this.addComponents();
this.addRoutes();
this.app.use(CurrentUserProvider);
this.app.use(CurrentUserSettingsMenuProvider);
this.app.pluginSettingsManager.add('security', {
title: tval('Security'),
icon: 'SafetyOutlined',
});
}
addRoutes() {
this.router.add('root', {
path: '/',
element: <Navigate replace to="/admin" />,
});
this.router.add('not-found', {
path: '*',
Component: AppNotFound,
});
this.router.add('admin', {
path: '/admin',
Component: 'AdminLayout',
});
this.router.add('admin.page', {
path: '/admin/:name',
Component: 'AdminDynamicPage',
});
this.router.add('admin.page.tab', {
path: '/admin/:name/tabs/:tabUid',
Component: PageTabs as any,
});
this.router.add('admin.page.popup', {
path: '/admin/:name/popups/*',
Component: PagePopups,
});
this.router.add('admin.page.tab.popup', {
path: '/admin/:name/tabs/:tabUid/popups/*',
Component: PagePopups,
});
}
addComponents() {
this.app.addComponents({
ErrorFallback,
RouteSchemaComponent,
BlockTemplatePage,
BlockTemplateDetails,
});
}
async addPlugins() {
await this.app.pm.add(AssociationFilterPlugin);
await this.app.pm.add(LocalePlugin, { name: 'builtin-locale' });
await this.app.pm.add(AdminLayoutPlugin, { name: 'admin-layout' });
await this.app.pm.add(SystemSettingsPlugin, { name: 'system-setting' });
await this.app.pm.add(PinnedListPlugin, {
name: 'pinned-list',
config: {
items: {
ui: { order: 100, component: 'DesignableSwitch', pin: true, snippet: 'ui.*' },
pm: { order: 200, component: 'PluginManagerLink', pin: true, snippet: 'pm' },
sc: { order: 300, component: 'SettingsCenterDropdown', pin: true, snippet: 'pm.*' },
},
},
});
await this.app.pm.add(SchemaComponentPlugin, { name: 'schema-component' });
await this.app.pm.add(SchemaInitializerPlugin, { name: 'schema-initializer' });
await this.app.pm.add(SchemaSettingsPlugin, { name: 'schema-settings' });
await this.app.pm.add(BlockSchemaComponentPlugin, { name: 'block-schema-component' });
await this.app.pm.add(AntdSchemaComponentPlugin, { name: 'antd-schema-component' });
await this.app.pm.add(ACLPlugin, { name: 'builtin-acl' });
await this.app.pm.add(RemoteDocumentTitlePlugin, { name: 'remote-document-title' });
await this.app.pm.add(PMPlugin, { name: 'builtin-pm' });
await this.app.pm.add(CollectionPlugin, { name: 'builtin-collection' });
}
}