@nocobase/client-v2 2.2.53 → 2.2.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/client-v2",
3
- "version": "2.2.53",
3
+ "version": "2.2.55",
4
4
  "license": "Apache-2.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.mjs",
@@ -27,11 +27,11 @@
27
27
  "@formily/antd-v5": "1.2.3",
28
28
  "@formily/react": "^2.2.27",
29
29
  "@formily/shared": "^2.2.27",
30
- "@nocobase/evaluators": "2.2.53",
31
- "@nocobase/flow-engine": "2.2.53",
32
- "@nocobase/sdk": "2.2.53",
33
- "@nocobase/shared": "2.2.53",
34
- "@nocobase/utils": "2.2.53",
30
+ "@nocobase/evaluators": "2.2.55",
31
+ "@nocobase/flow-engine": "2.2.55",
32
+ "@nocobase/sdk": "2.2.55",
33
+ "@nocobase/shared": "2.2.55",
34
+ "@nocobase/utils": "2.2.55",
35
35
  "ahooks": "^3.7.2",
36
36
  "antd": "5.24.2",
37
37
  "antd-style": "3.7.1",
@@ -49,5 +49,5 @@
49
49
  "react-router-dom": "^6.30.1",
50
50
  "zxing-wasm": "^3.1.3"
51
51
  },
52
- "gitHead": "ce368f267e6e2d422a35ab108f7d79fc04065857"
52
+ "gitHead": "22236b7bbbb38eb97e4c489417e962601fccb5db"
53
53
  }
@@ -103,6 +103,7 @@ export interface BaseApplicationOptions<TPluginType> {
103
103
  scopes?: Record<string, any>;
104
104
  router?: RouterOptions;
105
105
  designable?: boolean;
106
+ initializeAuthFromUrl?: boolean;
106
107
  loadRemotePlugins?: boolean;
107
108
  devDynamicImport?: DevDynamicImport;
108
109
  disableAcl?: boolean;
@@ -161,6 +162,7 @@ export abstract class BaseApplication<
161
162
 
162
163
  model: ApplicationModel;
163
164
 
165
+ private appliedAuthCallback?: { token: string; authenticator: string | null };
164
166
  private wsAuthorized = false;
165
167
  apps: {
166
168
  Component?: AnyComponent | null;
@@ -235,6 +237,29 @@ export abstract class BaseApplication<
235
237
  });
236
238
  this.initListeners();
237
239
  this.afterManagersInitialized();
240
+ if (options.initializeAuthFromUrl && typeof window !== 'undefined') {
241
+ const params = new URLSearchParams(window.location.search);
242
+ if (params.get('authenticator')) {
243
+ this.applyAuthCallback(params);
244
+ }
245
+ }
246
+ }
247
+
248
+ // The router cleans the URL after mount. Do not replay a startup token that a
249
+ // request has since renewed or rejected while plugins were loading.
250
+ applyAuthCallback(params: URLSearchParams) {
251
+ const token = params.get('token');
252
+ if (!token) {
253
+ this.appliedAuthCallback = undefined;
254
+ return false;
255
+ }
256
+ const authenticator = params.get('authenticator');
257
+ if (this.appliedAuthCallback?.token !== token || this.appliedAuthCallback.authenticator !== authenticator) {
258
+ this.appliedAuthCallback = { token, authenticator };
259
+ this.apiClient.auth.setAuthenticator(authenticator);
260
+ this.apiClient.auth.setToken(token);
261
+ }
262
+ return true;
238
263
  }
239
264
 
240
265
  /**
@@ -29,6 +29,7 @@ import {
29
29
  resolveAdminLayoutMenuDragMoveOptionsFromEvent,
30
30
  } from './AdminLayoutMenuModels';
31
31
  import type { AdminLayoutModel } from './AdminLayoutModel';
32
+ import { observeAdminMenuRoutes } from './observeAdminMenuRoutes';
32
33
  import { AdminLayoutContent } from './AdminLayoutSlotModels';
33
34
  import { ADMIN_LAYOUT_MODEL_UID } from './constants';
34
35
  import { ResetThemeTokenAndKeepAlgorithm } from './ResetThemeTokenAndKeepAlgorithm';
@@ -120,7 +121,7 @@ const resetStyle = css`
120
121
  }
121
122
 
122
123
  .ant-menu-item:has([data-nb-hidden-menu-item='true']),
123
- .ant-menu-submenu:has([data-nb-hidden-menu-item='true']) {
124
+ .ant-menu-submenu:has(> .ant-menu-submenu-title [data-nb-hidden-menu-item='true']) {
124
125
  display: none !important;
125
126
  }
126
127
  `;
@@ -554,15 +555,12 @@ export const AdminLayoutComponent = observer((props: any) => {
554
555
 
555
556
  useLayoutEffect(() => {
556
557
  adminLayoutModel?.syncMenuRoutes(allAccessRoutes);
557
- const nextRoute = adminLayoutModel?.toProLayoutRoute({
558
+ return observeAdminMenuRoutes(
559
+ () =>
560
+ adminLayoutModel?.toProLayoutRoute({ designable, isMobile: isMobileSider, t }) || { path: '/', children: [] },
561
+ setRoute,
558
562
  designable,
559
- isMobile: isMobileSider,
560
- t,
561
- }) || {
562
- path: '/',
563
- children: [],
564
- };
565
- setRoute(nextRoute);
563
+ );
566
564
  }, [adminLayoutModel, allAccessRoutes, designable, isMobileSider, menuRouteRefreshVersion, t]);
567
565
 
568
566
  useEffect(() => {
@@ -15,7 +15,7 @@ import { describe, expect, it, vi } from 'vitest';
15
15
  import { NocoBaseDesktopRouteType } from '../../../flow-compat';
16
16
  import { RouteRepository } from '../../../RouteRepository';
17
17
  import { AdminLayoutEntryGuard } from './AdminLayoutEntryGuard';
18
- import type { AdminLayoutModel } from './AdminLayoutModel';
18
+ import { AdminLayoutModel } from './AdminLayoutModel';
19
19
 
20
20
  describe('AdminLayoutEntryGuard', () => {
21
21
  it('should ensure accessible routes for the active layout before resolving the landing route', async () => {
@@ -309,6 +309,53 @@ describe('AdminLayoutEntryGuard', () => {
309
309
  expect(activateLayout).toHaveBeenLastCalledWith(expect.objectContaining({ uid: 'admin-layout-next' }));
310
310
  });
311
311
 
312
+ it.each([false, true])(
313
+ 'should use the settled home destination only while still at the root (leave=%s)',
314
+ async (leave) => {
315
+ const engine = new FlowEngine();
316
+ const repository = new RouteRepository({});
317
+ const hidden = { type: NocoBaseDesktopRouteType.flowPage, schemaUid: 'hidden' };
318
+ const visible = { type: NocoBaseDesktopRouteType.flowPage, schemaUid: 'visible' };
319
+ repository.setRoutes([hidden, visible]);
320
+ engine.context.defineProperty('routeRepository', { value: repository });
321
+ engine.context.defineProperty('app', {
322
+ value: {
323
+ getPublicPath: () => '/v/',
324
+ router: { getBasename: () => '/v' },
325
+ },
326
+ });
327
+ const model = engine.createModel<AdminLayoutModel>({ uid: 'admin-layout-model', use: AdminLayoutModel });
328
+ let finish!: (page: typeof visible) => void;
329
+ const pending = new Promise<typeof visible>((resolve) => {
330
+ finish = resolve;
331
+ });
332
+ const resolvePage = vi.spyOn(model, 'resolveDefaultPage').mockReturnValue(pending);
333
+ const router = createMemoryRouter(
334
+ [
335
+ {
336
+ id: 'admin',
337
+ path: '/admin',
338
+ element: (
339
+ <FlowEngineProvider engine={engine}>
340
+ <AdminLayoutEntryGuard model={model}>
341
+ <Outlet />
342
+ </AdminLayoutEntryGuard>
343
+ </FlowEngineProvider>
344
+ ),
345
+ children: [{ id: 'admin.__page', path: ':name', element: <div>Page</div> }],
346
+ },
347
+ ],
348
+ { initialEntries: ['/admin'] },
349
+ );
350
+ render(<RouterProvider router={router} />);
351
+ await waitFor(() => expect(resolvePage).toHaveBeenCalled());
352
+ expect(router.state.location.pathname).toBe('/admin');
353
+ if (leave) await act(() => router.navigate('/admin/sibling'));
354
+ await act(async () => finish(visible));
355
+ expect(router.state.location.pathname).toBe(leave ? '/admin/sibling' : '/admin/visible');
356
+ },
357
+ );
358
+
312
359
  it('should redirect group id paths to the first v2 landing route', async () => {
313
360
  const modernWindow = window as Window & { __nocobase_modern_client_prefix__?: string };
314
361
  modernWindow.__nocobase_modern_client_prefix__ = 'v2';
@@ -158,7 +158,11 @@ export const AdminLayoutEntryGuard: FC<{ children: React.ReactNode; model?: Admi
158
158
  return;
159
159
  }
160
160
 
161
- const firstAccessibleRoute = findFirstV2LandingRoute(routeRepository?.listAccessible?.() || []);
161
+ const routes = routeRepository?.listAccessible?.() || [];
162
+ const firstAccessibleRoute = model?.resolveDefaultPage
163
+ ? await model.resolveDefaultPage(routes, findFirstV2LandingRoute)
164
+ : findFirstV2LandingRoute(routes);
165
+ if (!active) return;
162
166
  if (!firstAccessibleRoute) {
163
167
  if (active) {
164
168
  setReady(true);
@@ -203,6 +207,7 @@ export const AdminLayoutEntryGuard: FC<{ children: React.ReactNode; model?: Admi
203
207
  location.hash,
204
208
  location.pathname,
205
209
  location.search,
210
+ model,
206
211
  navigate,
207
212
  pageUid,
208
213
  routeRepository,
@@ -43,9 +43,6 @@ import {
43
43
  import { ADMIN_LAYOUT_MODEL_UID } from './constants';
44
44
  import {
45
45
  type AdminLayoutRoutePathLike,
46
- findFirstAccessiblePageRoute,
47
- findFirstV2LandingRoute,
48
- isV2AdminRuntime,
49
46
  joinAdminLayoutRoutePath,
50
47
  resolveAdminRouteRuntimeTarget,
51
48
  toRouterNavigationPath,
@@ -91,6 +88,10 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
91
88
  private persistedStateHydrated = false;
92
89
  private persistedStateHydrating?: Promise<void>;
93
90
 
91
+ get pendingMenuState() {
92
+ return this.persistedStateHydrating;
93
+ }
94
+
94
95
  onInit(options: any) {
95
96
  super.onInit(options);
96
97
  this.syncFromRoute(
@@ -98,7 +99,9 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
98
99
  this.props.parentRoute as NocoBaseDesktopRoute | undefined,
99
100
  );
100
101
  if (this.shouldHydratePersistedState()) {
101
- void this.hydratePersistedState();
102
+ void this.hydratePersistedState().catch((error) => {
103
+ console.error('[NocoBase] Failed to hydrate menu item', this.uid, error);
104
+ });
102
105
  }
103
106
  }
104
107
 
@@ -289,7 +292,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
289
292
  }
290
293
 
291
294
  if (shouldRerenderAfterHydrate) {
292
- void this.rerender();
295
+ await this.rerender();
293
296
  }
294
297
  })().finally(() => {
295
298
  this.persistedStateHydrated = true;
@@ -669,6 +672,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
669
672
  path,
670
673
  redirect: route.schemaUid ? joinAdminLayoutRoutePath(layout, route.schemaUid) : undefined,
671
674
  hideInMenu: route.hideInMenu,
675
+ _landingPage: runtimeTarget.runtimePath && !route.hideInMenu && !route.hidden ? route : undefined,
672
676
  disabled: !runtimeTarget.runtimePath,
673
677
  _runtimePath: runtimeTarget.runtimePath,
674
678
  _navigationMode: runtimeTarget.navigationMode,
@@ -681,27 +685,18 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
681
685
  }
682
686
 
683
687
  if (route.type === NocoBaseDesktopRouteType.group) {
684
- const itemChildren = Array.isArray(route.children) ? route.children : [];
685
- const children =
686
- (this.subModels.menuItems || [])
687
- .map((item: AdminLayoutMenuItemModel) =>
688
- item.toProLayoutRoute({
689
- ...options,
690
- depth: depth + 1,
691
- }),
692
- )
693
- .filter(Boolean) || [];
688
+ const children = (this.subModels.menuItems || [])
689
+ .map((item: AdminLayoutMenuItemModel) => item.toProLayoutRoute({ ...options, depth: depth + 1 }))
690
+ .filter((item): item is AdminLayoutMenuNode => item !== null);
691
+ const landingPage = children.find((item) => item._landingPage)?._landingPage;
694
692
 
695
693
  if (options.designable && depth === 0) {
696
694
  children.push(getAdminLayoutMenuInitializerButton('schema-initializer-Menu-side', this, route, layout));
697
695
  }
698
696
 
699
- const landingRoute = isV2AdminRuntime(this.context.app)
700
- ? findFirstV2LandingRoute(itemChildren)
701
- : findFirstAccessiblePageRoute(itemChildren);
702
697
  const runtimeTarget = resolveAdminRouteRuntimeTarget({
703
698
  app: this.context.app,
704
- route: isV2AdminRuntime(this.context.app) && landingRoute ? landingRoute : route,
699
+ route: landingPage,
705
700
  layout,
706
701
  });
707
702
 
@@ -712,8 +707,9 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
712
707
  redirect:
713
708
  children[0]?.key === 'x-designer-button'
714
709
  ? undefined
715
- : joinAdminLayoutRoutePath(layout, landingRoute?.schemaUid || route.id),
710
+ : joinAdminLayoutRoutePath(layout, landingPage?.schemaUid || route.id),
716
711
  hideInMenu: route.hideInMenu,
712
+ _landingPage: route.hideInMenu || route.hidden ? undefined : landingPage,
717
713
  _runtimePath: runtimeTarget.runtimePath,
718
714
  _navigationMode: runtimeTarget.navigationMode,
719
715
  _isLegacy: runtimeTarget.isLegacy,
@@ -724,7 +720,7 @@ export class AdminLayoutMenuItemModel extends FlowModel<AdminLayoutMenuItemStruc
724
720
  };
725
721
 
726
722
  if (children.length > 0) {
727
- groupRoute.routes = children as AdminLayoutMenuNode[];
723
+ groupRoute.routes = children;
728
724
  }
729
725
 
730
726
  return groupRoute;
@@ -58,6 +58,7 @@ export type AdminLayoutMenuNode = {
58
58
  icon?: React.ReactNode;
59
59
  path: string;
60
60
  redirect?: string;
61
+ _landingPage?: NocoBaseDesktopRoute;
61
62
  hideInMenu?: boolean;
62
63
  disabled?: boolean;
63
64
  _runtimePath?: string | null;
@@ -36,6 +36,35 @@ export type AdminLayoutStructure = BaseLayoutStructure & {
36
36
  };
37
37
  };
38
38
 
39
+ type FindFirstPage = (routes: NocoBaseDesktopRoute[]) => NocoBaseDesktopRoute | undefined;
40
+
41
+ async function findVisibleMenuPage(
42
+ items: AdminLayoutMenuItemModel[],
43
+ findFirstPage: FindFirstPage,
44
+ ): Promise<NocoBaseDesktopRoute | undefined> {
45
+ for (const item of items) {
46
+ const route = item.getRoute();
47
+ // Keep the runtime's existing rules for static visibility and supported page types.
48
+ if (!findFirstPage([route])) continue;
49
+
50
+ if (item.pendingMenuState) {
51
+ try {
52
+ await item.pendingMenuState;
53
+ } catch {
54
+ // A failed menu rule cannot establish a default destination for this branch.
55
+ continue;
56
+ }
57
+ }
58
+ if (item.hidden) continue;
59
+ if (route.type === 'group') {
60
+ const page = await findVisibleMenuPage(item.subModels.menuItems || [], findFirstPage);
61
+ if (page) return page;
62
+ } else if (route.schemaUid) {
63
+ return route;
64
+ }
65
+ }
66
+ }
67
+
39
68
  type GetAdminLayoutModelOptions<TModel extends FlowModel = AdminLayoutModel> = GetLayoutModelOptions<TModel>;
40
69
 
41
70
  /**
@@ -79,6 +108,11 @@ export class AdminLayoutModel extends BaseLayoutModel<AdminLayoutStructure> {
79
108
  reconcileAdminLayoutMenuItems(this, Array.isArray(routes) ? routes : []);
80
109
  }
81
110
 
111
+ resolveDefaultPage(routes: NocoBaseDesktopRoute[], findFirstPage: FindFirstPage) {
112
+ this.syncMenuRoutes(routes);
113
+ return findVisibleMenuPage(this.subModels.menuItems || [], findFirstPage);
114
+ }
115
+
82
116
  /**
83
117
  * 将菜单模型转换为 ProLayout 路由树。
84
118
  *
@@ -22,6 +22,8 @@ import {
22
22
  buildMenuTitleWithIcon,
23
23
  getAdminLayoutMenuMovePositionOptions,
24
24
  normalizeAdminLayoutMenuLegacyVariables,
25
+ observeAdminMenuRoutes,
26
+ findFirstV2LandingRoute,
25
27
  openAdminLayoutMenuLink,
26
28
  resolveAdminLayoutMenuLink,
27
29
  resolveAdminLayoutMenuDragMoveOptionsFromEvent,
@@ -1440,6 +1442,150 @@ describe('AdminLayoutModel menu items', () => {
1440
1442
  expect(defaultAdminLayoutModel.menuRouteRefreshVersion).toBe(defaultRefreshBefore);
1441
1443
  });
1442
1444
 
1445
+ it('should open the first visible page in a nested menu group', () => {
1446
+ const layout = engine.createModel<AdminLayoutModel>({
1447
+ uid: ADMIN_LAYOUT_MODEL_UID,
1448
+ use: AdminLayoutModel,
1449
+ });
1450
+ const { group, flowPage } = NocoBaseDesktopRouteType;
1451
+ layout.syncMenuRoutes([
1452
+ {
1453
+ id: 1,
1454
+ type: group,
1455
+ children: [
1456
+ {
1457
+ id: 2,
1458
+ type: group,
1459
+ children: [
1460
+ { id: 3, type: flowPage, schemaUid: 'first' },
1461
+ { id: 4, type: flowPage, schemaUid: 'second' },
1462
+ ],
1463
+ },
1464
+ ],
1465
+ },
1466
+ ]);
1467
+ const nested = layout.subModels.menuItems[0].subModels.menuItems[0];
1468
+ const [firstPage, secondPage] = nested.subModels.menuItems;
1469
+ const options = { designable: false, isMobile: false, t: (title: string) => title };
1470
+ const topGroup = () => layout.toProLayoutRoute(options).children[0];
1471
+
1472
+ firstPage.setHidden(true);
1473
+ expect(topGroup()).toMatchObject({
1474
+ redirect: '/admin/second',
1475
+ _runtimePath: '/apps/demo/v2/admin/second',
1476
+ routes: [{ redirect: '/admin/second', routes: [{ path: '/admin/second' }] }],
1477
+ });
1478
+ secondPage.setHidden(true);
1479
+ expect(topGroup()).toMatchObject({ redirect: '/admin/1', _runtimePath: null });
1480
+ firstPage.setHidden(false);
1481
+ expect(topGroup().redirect).toBe('/admin/first');
1482
+ });
1483
+
1484
+ it('should resolve the home page from settled menu rules in accessible route order', async () => {
1485
+ let finishRule!: () => void;
1486
+ const rule = new Promise<void>((resolve) => {
1487
+ finishRule = resolve;
1488
+ });
1489
+ const findOne = vi.fn(async ({ uid }) => ({
1490
+ uid,
1491
+ stepParams: { menuSettings: { linkageRules: { value: [{ enable: true }] } } },
1492
+ }));
1493
+ engine.setModelRepository({ findOne, save: vi.fn(), destroy: vi.fn(), move: vi.fn(), duplicate: vi.fn() });
1494
+ const layout = engine.createModel<AdminLayoutModel>({ uid: ADMIN_LAYOUT_MODEL_UID, use: AdminLayoutModel });
1495
+ const { group, page, flowPage } = NocoBaseDesktopRouteType;
1496
+ const routes = [
1497
+ { id: 1, type: page, schemaUid: 'classic' },
1498
+ {
1499
+ id: 2,
1500
+ type: group,
1501
+ children: [
1502
+ {
1503
+ id: 3,
1504
+ type: group,
1505
+ children: [
1506
+ { id: 4, type: flowPage, schemaUid: 'first', options: { hasPersistedMenuInstanceFlow: true } },
1507
+ { id: 5, type: flowPage, schemaUid: 'second' },
1508
+ ],
1509
+ },
1510
+ ],
1511
+ },
1512
+ { id: 6, type: flowPage, schemaUid: 'sibling' },
1513
+ ];
1514
+ const resolveHome = () => layout.resolveDefaultPage(routes, findFirstV2LandingRoute);
1515
+ const landed = vi.fn();
1516
+ const navigation = resolveHome().then(landed);
1517
+ const nested = layout.subModels.menuItems[1].subModels.menuItems[0];
1518
+ const first = nested.subModels.menuItems[0];
1519
+ const rerender = vi.spyOn(first, 'rerender').mockImplementation(async () => {
1520
+ await rule;
1521
+ first.setHidden(true);
1522
+ });
1523
+ await waitFor(() => expect(rerender).toHaveBeenCalled());
1524
+ expect(landed).not.toHaveBeenCalled();
1525
+ finishRule();
1526
+ await navigation;
1527
+ expect(landed).toHaveBeenCalledWith(expect.objectContaining({ schemaUid: 'second' }));
1528
+ first.setHidden(false);
1529
+ expect((await resolveHome())?.schemaUid).toBe('first');
1530
+ nested.setHidden(true);
1531
+ expect((await resolveHome())?.schemaUid).toBe('sibling');
1532
+ layout.subModels.menuItems[2].setHidden(true);
1533
+ expect(await resolveHome()).toBeUndefined();
1534
+ expect(findOne).toHaveBeenCalledTimes(1);
1535
+ });
1536
+
1537
+ it('should wait for the first nested page visibility before publishing a group link on refresh', async () => {
1538
+ const findOne = vi.fn(async ({ uid }) => ({
1539
+ uid,
1540
+ stepParams: { menuSettings: { linkageRules: { value: [{ enable: true }] } } },
1541
+ }));
1542
+ engine.setModelRepository({ findOne, save: vi.fn(), destroy: vi.fn(), move: vi.fn(), duplicate: vi.fn() });
1543
+ const layout = engine.createModel<AdminLayoutModel>({ uid: ADMIN_LAYOUT_MODEL_UID, use: AdminLayoutModel });
1544
+ const { group, flowPage } = NocoBaseDesktopRouteType;
1545
+ layout.syncMenuRoutes([
1546
+ { id: 1, type: flowPage, schemaUid: 'sibling' },
1547
+ {
1548
+ id: 2,
1549
+ type: group,
1550
+ children: [
1551
+ {
1552
+ id: 3,
1553
+ type: group,
1554
+ children: [
1555
+ { id: 4, type: flowPage, schemaUid: 'hidden', options: { hasPersistedMenuInstanceFlow: true } },
1556
+ { id: 5, type: flowPage, schemaUid: 'visible' },
1557
+ ],
1558
+ },
1559
+ ],
1560
+ },
1561
+ ]);
1562
+ const first = layout.subModels.menuItems[1].subModels.menuItems[0].subModels.menuItems[0];
1563
+ let finishRule!: () => void;
1564
+ const rule = new Promise<void>((resolve) => {
1565
+ finishRule = resolve;
1566
+ });
1567
+ const rerender = vi.spyOn(first, 'rerender').mockImplementation(async () => {
1568
+ await rule;
1569
+ first.setHidden(true);
1570
+ });
1571
+ const publish = vi.fn();
1572
+ const stop = observeAdminMenuRoutes(
1573
+ () => layout.toProLayoutRoute({ designable: false, isMobile: false, t: (title) => title }),
1574
+ publish,
1575
+ false,
1576
+ );
1577
+ await waitFor(() => expect(rerender).toHaveBeenCalled());
1578
+ expect(publish).toHaveBeenCalledTimes(1);
1579
+ expect(publish.mock.calls[0][0].children.map((item) => item.redirect)).toEqual(['/admin/sibling']);
1580
+ finishRule();
1581
+ await waitFor(() => expect(publish).toHaveBeenCalledTimes(2));
1582
+ expect(publish.mock.calls[1][0].children[1]).toMatchObject({
1583
+ redirect: '/admin/visible',
1584
+ routes: [{ redirect: '/admin/visible', routes: [{ path: '/admin/visible' }] }],
1585
+ });
1586
+ stop();
1587
+ });
1588
+
1443
1589
  it('should render hidden menu item with opacity and keep original title in config mode', () => {
1444
1590
  const model = engine.createModel<AdminLayoutMenuItemModel>({
1445
1591
  uid: 'menu-item-hidden-in-config',
@@ -9,6 +9,7 @@
9
9
 
10
10
  export * from './AdminLayoutComponent';
11
11
  export * from './AdminLayoutModel';
12
+ export * from './observeAdminMenuRoutes';
12
13
  export * from './AppSwitcherActionPanelModel';
13
14
  export * from '../BaseLayoutModel';
14
15
  export * from '../BaseLayoutRouteCoordinator';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ type MenuNode<T> = {
11
+ _route?: { type?: string };
12
+ _model?: { readonly pendingMenuState?: Promise<void> };
13
+ _landingPage?: unknown;
14
+ routes?: T[];
15
+ };
16
+
17
+ // Only the candidate page and its ancestor groups can change this group's first destination.
18
+ function pendingLanding<T extends MenuNode<T>>(group: T) {
19
+ let candidate: T | undefined = group;
20
+ while (candidate) {
21
+ const pending = candidate._model?.pendingMenuState;
22
+ if (pending) return pending;
23
+ candidate = candidate.routes?.find((child) => child._landingPage);
24
+ }
25
+ }
26
+
27
+ export function observeAdminMenuRoutes<T extends MenuNode<T>>(
28
+ project: () => { path: string; children: T[] },
29
+ publish: (route: { path: string; children: T[] }) => void,
30
+ designable: boolean,
31
+ ) {
32
+ let active = true;
33
+ const waiting = new Set<Promise<void>>();
34
+
35
+ const showReadyGroup = (node: T) => {
36
+ if (node._route?.type !== 'group') return true;
37
+ const pending = pendingLanding(node);
38
+ if (pending) {
39
+ if (!waiting.has(pending)) {
40
+ waiting.add(pending);
41
+ void pending.then(update, update);
42
+ }
43
+ return false;
44
+ }
45
+ if (node.routes) node.routes = node.routes.filter(showReadyGroup);
46
+ return true;
47
+ };
48
+
49
+ function update() {
50
+ if (!active) return;
51
+ const route = project();
52
+ if (!designable) route.children = route.children.filter(showReadyGroup);
53
+ publish(route);
54
+ }
55
+
56
+ update();
57
+ return () => {
58
+ active = false;
59
+ };
60
+ }
@@ -183,6 +183,7 @@ export class DetailsBlockModel extends CollectionBlockModel<{
183
183
  renderComponent() {
184
184
  const { colon, labelAlign, labelWidth, labelWrap, layout } = this.props;
185
185
  const isConfigMode = !!this.context.flowSettingsEnabled;
186
+ const showActionBar = isConfigMode || !!this.findSubModel('actions', (action) => !action.hidden);
186
187
  const disableRuntimeActions = !isConfigMode && !this.hasAvailableData();
187
188
  const { heightMode, height } = this.decoratorProps;
188
189
  return (
@@ -190,6 +191,7 @@ export class DetailsBlockModel extends CollectionBlockModel<{
190
191
  model={this}
191
192
  gridModel={this.subModels.grid}
192
193
  isConfigMode={isConfigMode}
194
+ showActionBar={showActionBar}
193
195
  heightMode={heightMode}
194
196
  height={height}
195
197
  layoutProps={{ colon, labelAlign, labelWidth, labelWrap, layout }}
@@ -233,6 +235,7 @@ const DetailsBlockContent = ({
233
235
  model,
234
236
  gridModel,
235
237
  isConfigMode,
238
+ showActionBar,
236
239
  heightMode,
237
240
  height,
238
241
  layoutProps,
@@ -241,6 +244,7 @@ const DetailsBlockContent = ({
241
244
  model: DetailsBlockModel;
242
245
  gridModel: DetailsGridModel;
243
246
  isConfigMode: boolean;
247
+ showActionBar: boolean;
244
248
  heightMode?: string;
245
249
  height?: number;
246
250
  layoutProps?: any;
@@ -290,7 +294,7 @@ const DetailsBlockContent = ({
290
294
  style={{
291
295
  textAlign: 'right',
292
296
  lineHeight: '0px',
293
- paddingBottom: isConfigMode && model.context.themeToken.padding,
297
+ paddingBottom: showActionBar ? model.context.themeToken.padding : undefined,
294
298
  }}
295
299
  >
296
300
  {actions}
@@ -7,7 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import { tExpr, FlowModelContext, type SubModelItem } from '@nocobase/flow-engine';
10
+ import { tExpr, type Collection, type FlowModelContext, type SubModelItem } from '@nocobase/flow-engine';
11
11
  import { TableAssociationFieldGroupModel } from './TableAssociationFieldGroupModel';
12
12
  import { TableCustomColumnModel } from './TableCustomColumnModel';
13
13
  import { buildJSFieldMenuChildren } from '../utils/transformChildrenToJS';
@@ -19,13 +19,21 @@ import { buildJSFieldMenuChildren } from '../utils/transformChildrenToJS';
19
19
  * - 点击后创建 TableColumnModel,并将其 subModels.field 固定为 JSFieldModel。
20
20
  */
21
21
  export class TableJSFieldItemModel extends TableCustomColumnModel {
22
- static defineChildren(ctx: FlowModelContext) {
23
- return buildJSFieldMenuChildren(ctx, {
22
+ static async defineChildren(ctx: FlowModelContext) {
23
+ const items = await buildJSFieldMenuChildren(ctx, {
24
24
  useModel: 'TableColumnModel',
25
25
  fieldUseModel: 'JSFieldModel',
26
26
  refreshTargets: ['TableColumnModel'],
27
27
  associationProvider: (inner) => TableAssociationFieldGroupModel.defineChildren(inner) as SubModelItem[],
28
28
  });
29
+ const collection: Collection = ctx.model['collection'] || ctx.collection;
30
+ const treeChildrenNames = new Set(
31
+ collection
32
+ .getFields()
33
+ .filter((field) => field.options?.treeChildren)
34
+ .map((field) => field.name),
35
+ );
36
+ return items.filter((item) => item.type === 'group' || !treeChildrenNames.has(item.key));
29
37
  }
30
38
  }
31
39