@nocobase/client-v2 2.1.11 → 2.2.0-alpha.2
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/es/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +21 -6
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/TypedVariableInput.d.ts +22 -4
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/index.d.ts +2 -0
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
- package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.mjs +181 -131
- package/lib/index.js +186 -136
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +126 -24
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +216 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/collection-manager/field-configure.ts +1 -1
- package/src/collection-manager/interfaces/id.ts +1 -1
- package/src/collection-manager/interfaces/m2m.tsx +2 -2
- package/src/collection-manager/interfaces/m2o.tsx +2 -2
- package/src/collection-manager/interfaces/nanoid.ts +1 -1
- package/src/collection-manager/interfaces/o2m.tsx +2 -2
- package/src/collection-manager/interfaces/obo.tsx +2 -2
- package/src/collection-manager/interfaces/oho.tsx +2 -2
- package/src/collection-manager/interfaces/properties/index.ts +2 -2
- package/src/collection-manager/interfaces/uuid.ts +1 -1
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/TypedVariableInput.tsx +416 -93
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +266 -9
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/index.ts +2 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +443 -5
- package/src/flow/__tests__/getKey.test.ts +7 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
- package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/linkageRules.tsx +2 -7
- package/src/flow/actions/openView.tsx +38 -4
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +34 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +310 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +44 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +188 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +166 -2
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/FieldAssignValueInput.tsx +10 -5
- package/src/flow/components/FlowRoute.tsx +56 -11
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/index.ts +1 -0
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +12 -1
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +0 -4
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +36 -13
- package/src/flow/models/blocks/table/TableBlockModel.tsx +38 -17
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +111 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/topbar/TopbarActionModel.tsx +93 -10
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/index.ts +8 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +0 -2
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +1 -2
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/utils.tsx +0 -6
|
@@ -13,6 +13,7 @@ import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
|
|
13
13
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
14
14
|
import { FlowContextProvider, FlowEngine, FlowEngineProvider, type FlowModel } from '@nocobase/flow-engine';
|
|
15
15
|
import FlowRoute from '../components/FlowRoute';
|
|
16
|
+
import { RouteRepository } from '../../RouteRepository';
|
|
16
17
|
|
|
17
18
|
type MockAdminLayoutModel = FlowModel & {
|
|
18
19
|
registerRoutePage: ReturnType<typeof vi.fn>;
|
|
@@ -321,6 +322,94 @@ describe('FlowRoute', () => {
|
|
|
321
322
|
});
|
|
322
323
|
});
|
|
323
324
|
|
|
325
|
+
it('should ensure accessible routes for the current layout before bridging', async () => {
|
|
326
|
+
const engine = new FlowEngine();
|
|
327
|
+
const request = vi.fn().mockResolvedValue({
|
|
328
|
+
data: {
|
|
329
|
+
data: [
|
|
330
|
+
{
|
|
331
|
+
type: 'flowPage',
|
|
332
|
+
schemaUid: 'mobile-page',
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
const routeRepository = new RouteRepository({
|
|
338
|
+
api: {
|
|
339
|
+
request,
|
|
340
|
+
resource: vi.fn(),
|
|
341
|
+
},
|
|
342
|
+
} as never);
|
|
343
|
+
routeRepository.setRoutes([], 'admin-layout-model');
|
|
344
|
+
const deactivateLayout = routeRepository.activateLayout({
|
|
345
|
+
uid: 'mobile-layout-model',
|
|
346
|
+
});
|
|
347
|
+
engine.context.defineProperty('routeRepository', {
|
|
348
|
+
value: routeRepository,
|
|
349
|
+
});
|
|
350
|
+
engine.context.defineProperty('app', {
|
|
351
|
+
value: {
|
|
352
|
+
getPublicPath: () => '/v2/',
|
|
353
|
+
router: {
|
|
354
|
+
getBasename: () => '/v2',
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
const routeModel = engine.createModel({
|
|
359
|
+
uid: 'mobile-route-model',
|
|
360
|
+
use: 'FlowModel',
|
|
361
|
+
});
|
|
362
|
+
routeModel.context.defineProperty('layout', {
|
|
363
|
+
value: {
|
|
364
|
+
routeName: 'mobile',
|
|
365
|
+
routePath: '/mobile',
|
|
366
|
+
rootRouteName: 'mobile',
|
|
367
|
+
uid: 'mobile-layout-model',
|
|
368
|
+
layoutModelClass: 'MobileLayoutModel',
|
|
369
|
+
rootPageModelClass: 'MobileRootPageModel',
|
|
370
|
+
childPageModelClass: 'MobileChildPageModel',
|
|
371
|
+
authCheck: true,
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const mobileLayoutModel: MockAdminLayoutModel = Object.assign(
|
|
376
|
+
engine.createModel({
|
|
377
|
+
uid: 'mobile-layout-model',
|
|
378
|
+
use: 'FlowModel',
|
|
379
|
+
}),
|
|
380
|
+
{
|
|
381
|
+
registerRoutePage: vi.fn(),
|
|
382
|
+
updateRoutePage: vi.fn(),
|
|
383
|
+
unregisterRoutePage: vi.fn(),
|
|
384
|
+
},
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
render(
|
|
388
|
+
<FlowEngineProvider engine={engine}>
|
|
389
|
+
<FlowContextProvider context={routeModel.context}>
|
|
390
|
+
<MemoryRouter initialEntries={['/mobile/mobile-page']}>
|
|
391
|
+
<Routes>
|
|
392
|
+
<Route path="/mobile/:name" element={<FlowRoute />} />
|
|
393
|
+
</Routes>
|
|
394
|
+
</MemoryRouter>
|
|
395
|
+
</FlowContextProvider>
|
|
396
|
+
</FlowEngineProvider>,
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
await waitFor(() => {
|
|
400
|
+
expect(request).toHaveBeenCalledWith({
|
|
401
|
+
url: '/desktopRoutes:listAccessible',
|
|
402
|
+
params: {
|
|
403
|
+
tree: true,
|
|
404
|
+
sort: 'sort',
|
|
405
|
+
layout: 'mobile-layout-model',
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
expect(mobileLayoutModel.registerRoutePage).toHaveBeenCalledWith('mobile-page', expect.any(Object));
|
|
409
|
+
});
|
|
410
|
+
deactivateLayout();
|
|
411
|
+
});
|
|
412
|
+
|
|
324
413
|
it('should fail fast when admin-layout-model is missing', () => {
|
|
325
414
|
const engine = new FlowEngine();
|
|
326
415
|
engine.context.defineProperty('route', {
|
|
@@ -420,6 +509,75 @@ describe('FlowRoute', () => {
|
|
|
420
509
|
});
|
|
421
510
|
});
|
|
422
511
|
|
|
512
|
+
it('should not rerun accessible guard when layout reference changes but fields stay the same', async () => {
|
|
513
|
+
const engine = new FlowEngine();
|
|
514
|
+
const ensureAccessibleLoaded = vi.fn().mockResolvedValue([]);
|
|
515
|
+
const getRouteBySchemaUid = vi.fn(() => ({ type: 'flowPage', schemaUid: 'test-page' }));
|
|
516
|
+
engine.context.defineProperty('routeRepository', {
|
|
517
|
+
value: {
|
|
518
|
+
refreshAccessible: hookState.refresh,
|
|
519
|
+
isAccessibleLoaded: () => true,
|
|
520
|
+
ensureAccessibleLoaded,
|
|
521
|
+
getRouteBySchemaUid,
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
engine.context.defineProperty('app', {
|
|
525
|
+
value: {
|
|
526
|
+
getPublicPath: () => '/v2/',
|
|
527
|
+
router: {
|
|
528
|
+
getBasename: () => '/v2',
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const layoutModel: MockAdminLayoutModel = Object.assign(
|
|
534
|
+
engine.createModel({ uid: 'legacy-admin-layout-model', use: 'FlowModel' }),
|
|
535
|
+
{
|
|
536
|
+
registerRoutePage: vi.fn(),
|
|
537
|
+
updateRoutePage: vi.fn(),
|
|
538
|
+
unregisterRoutePage: vi.fn(),
|
|
539
|
+
},
|
|
540
|
+
);
|
|
541
|
+
let layoutReadCount = 0;
|
|
542
|
+
const stableLayout = {
|
|
543
|
+
uid: 'admin-layout-model',
|
|
544
|
+
routeName: 'admin',
|
|
545
|
+
routePath: '/admin',
|
|
546
|
+
authCheck: true,
|
|
547
|
+
};
|
|
548
|
+
Object.defineProperty(layoutModel, 'layout', {
|
|
549
|
+
get: () => {
|
|
550
|
+
layoutReadCount += 1;
|
|
551
|
+
return layoutReadCount <= 2 ? { ...stableLayout } : stableLayout;
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
const element = (
|
|
556
|
+
<FlowEngineProvider engine={engine}>
|
|
557
|
+
<MemoryRouter initialEntries={['/flow/test-page']}>
|
|
558
|
+
<Routes>
|
|
559
|
+
<Route path="/flow/:name" element={<FlowRoute getLayoutModel={() => layoutModel as any} />} />
|
|
560
|
+
</Routes>
|
|
561
|
+
</MemoryRouter>
|
|
562
|
+
</FlowEngineProvider>
|
|
563
|
+
);
|
|
564
|
+
const { rerender } = render(element);
|
|
565
|
+
|
|
566
|
+
await waitFor(() => {
|
|
567
|
+
expect(layoutModel.registerRoutePage).toHaveBeenCalledWith('test-page', expect.any(Object));
|
|
568
|
+
});
|
|
569
|
+
expect(ensureAccessibleLoaded).not.toHaveBeenCalled();
|
|
570
|
+
expect(getRouteBySchemaUid).toHaveBeenCalledTimes(1);
|
|
571
|
+
|
|
572
|
+
rerender(element);
|
|
573
|
+
|
|
574
|
+
await waitFor(() => {
|
|
575
|
+
expect(layoutModel.updateRoutePage).toHaveBeenCalled();
|
|
576
|
+
});
|
|
577
|
+
expect(ensureAccessibleLoaded).not.toHaveBeenCalled();
|
|
578
|
+
expect(getRouteBySchemaUid).toHaveBeenCalledTimes(1);
|
|
579
|
+
});
|
|
580
|
+
|
|
423
581
|
it('should show 404 when current route is a legacy page in v2 runtime', async () => {
|
|
424
582
|
const originalLocation = window.location;
|
|
425
583
|
const replace = vi.fn();
|
|
@@ -571,6 +729,22 @@ describe('FlowRoute', () => {
|
|
|
571
729
|
},
|
|
572
730
|
},
|
|
573
731
|
});
|
|
732
|
+
const routeModel = engine.createModel({
|
|
733
|
+
uid: 'public-form-route-model',
|
|
734
|
+
use: 'FlowModel',
|
|
735
|
+
});
|
|
736
|
+
routeModel.context.defineProperty('layout', {
|
|
737
|
+
value: {
|
|
738
|
+
routeName: 'public-forms',
|
|
739
|
+
routePath: '/public-forms',
|
|
740
|
+
rootRouteName: 'public-forms',
|
|
741
|
+
uid: 'public-form-layout-model',
|
|
742
|
+
layoutModelClass: 'PublicFormLayoutModel',
|
|
743
|
+
rootPageModelClass: 'PublicFormPageModel',
|
|
744
|
+
childPageModelClass: 'ChildPageModel',
|
|
745
|
+
authCheck: false,
|
|
746
|
+
},
|
|
747
|
+
});
|
|
574
748
|
|
|
575
749
|
const layoutModel: MockAdminLayoutModel = Object.assign(
|
|
576
750
|
engine.createModel({ uid: 'public-form-layout-model', use: 'FlowModel' }),
|
|
@@ -581,13 +755,82 @@ describe('FlowRoute', () => {
|
|
|
581
755
|
},
|
|
582
756
|
);
|
|
583
757
|
|
|
758
|
+
render(
|
|
759
|
+
<FlowEngineProvider engine={engine}>
|
|
760
|
+
<FlowContextProvider context={routeModel.context}>
|
|
761
|
+
<MemoryRouter initialEntries={['/public-forms/public-form-1']}>
|
|
762
|
+
<Routes>
|
|
763
|
+
<Route
|
|
764
|
+
path="/public-forms/:name"
|
|
765
|
+
element={<FlowRoute legacyPageBehavior="notFound" getLayoutModel={() => layoutModel} />}
|
|
766
|
+
/>
|
|
767
|
+
</Routes>
|
|
768
|
+
</MemoryRouter>
|
|
769
|
+
</FlowContextProvider>
|
|
770
|
+
</FlowEngineProvider>,
|
|
771
|
+
);
|
|
772
|
+
|
|
773
|
+
await waitFor(() => {
|
|
774
|
+
expect(layoutModel.registerRoutePage).toHaveBeenCalledWith('public-form-1', expect.any(Object));
|
|
775
|
+
});
|
|
776
|
+
expect(screen.queryByText('404')).not.toBeInTheDocument();
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it('should use getLayoutModel layout authCheck when FlowContext has no layout', async () => {
|
|
780
|
+
const engine = new FlowEngine();
|
|
781
|
+
engine.setModelRepository({
|
|
782
|
+
findOne: vi.fn().mockResolvedValue({
|
|
783
|
+
uid: 'public-form-1',
|
|
784
|
+
use: 'FlowModel',
|
|
785
|
+
}),
|
|
786
|
+
save: vi.fn(),
|
|
787
|
+
destroy: vi.fn(),
|
|
788
|
+
} as any);
|
|
789
|
+
engine.context.defineProperty('routeRepository', {
|
|
790
|
+
value: {
|
|
791
|
+
refreshAccessible: hookState.refresh,
|
|
792
|
+
isAccessibleLoaded: () => true,
|
|
793
|
+
ensureAccessibleLoaded: vi.fn().mockResolvedValue([]),
|
|
794
|
+
getRouteBySchemaUid: vi.fn(() => undefined),
|
|
795
|
+
},
|
|
796
|
+
});
|
|
797
|
+
engine.context.defineProperty('app', {
|
|
798
|
+
value: {
|
|
799
|
+
getPublicPath: () => '/v2/',
|
|
800
|
+
router: {
|
|
801
|
+
getBasename: () => '/v2',
|
|
802
|
+
},
|
|
803
|
+
},
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
const layoutModel: MockAdminLayoutModel = Object.assign(
|
|
807
|
+
engine.createModel({ uid: 'public-form-layout-model', use: 'FlowModel' }),
|
|
808
|
+
{
|
|
809
|
+
registerRoutePage: vi.fn(),
|
|
810
|
+
updateRoutePage: vi.fn(),
|
|
811
|
+
unregisterRoutePage: vi.fn(),
|
|
812
|
+
},
|
|
813
|
+
);
|
|
814
|
+
Object.defineProperty(layoutModel, 'layout', {
|
|
815
|
+
value: {
|
|
816
|
+
routeName: 'public-forms',
|
|
817
|
+
routePath: '/public-forms',
|
|
818
|
+
rootRouteName: 'public-forms',
|
|
819
|
+
uid: 'public-form-layout-model',
|
|
820
|
+
layoutModelClass: 'PublicFormLayoutModel',
|
|
821
|
+
rootPageModelClass: 'PublicFormPageModel',
|
|
822
|
+
childPageModelClass: 'ChildPageModel',
|
|
823
|
+
authCheck: false,
|
|
824
|
+
},
|
|
825
|
+
});
|
|
826
|
+
|
|
584
827
|
render(
|
|
585
828
|
<FlowEngineProvider engine={engine}>
|
|
586
829
|
<MemoryRouter initialEntries={['/public-forms/public-form-1']}>
|
|
587
830
|
<Routes>
|
|
588
831
|
<Route
|
|
589
832
|
path="/public-forms/:name"
|
|
590
|
-
element={<FlowRoute legacyPageBehavior="notFound" getLayoutModel={() => layoutModel} />}
|
|
833
|
+
element={<FlowRoute legacyPageBehavior="notFound" getLayoutModel={() => layoutModel as any} />}
|
|
591
834
|
/>
|
|
592
835
|
</Routes>
|
|
593
836
|
</MemoryRouter>
|
|
@@ -600,6 +843,202 @@ describe('FlowRoute', () => {
|
|
|
600
843
|
expect(screen.queryByText('404')).not.toBeInTheDocument();
|
|
601
844
|
});
|
|
602
845
|
|
|
846
|
+
it('should render not found when admin route is not accessible', async () => {
|
|
847
|
+
const engine = new FlowEngine();
|
|
848
|
+
engine.setModelRepository({
|
|
849
|
+
findOne: vi.fn().mockResolvedValue({
|
|
850
|
+
uid: 'admin-denied-page',
|
|
851
|
+
use: 'FlowModel',
|
|
852
|
+
}),
|
|
853
|
+
save: vi.fn(),
|
|
854
|
+
destroy: vi.fn(),
|
|
855
|
+
} as any);
|
|
856
|
+
engine.context.defineProperty('routeRepository', {
|
|
857
|
+
value: {
|
|
858
|
+
refreshAccessible: hookState.refresh,
|
|
859
|
+
isAccessibleLoaded: () => true,
|
|
860
|
+
ensureAccessibleLoaded: vi.fn().mockResolvedValue([]),
|
|
861
|
+
getRouteBySchemaUid: vi.fn(() => undefined),
|
|
862
|
+
},
|
|
863
|
+
});
|
|
864
|
+
engine.context.defineProperty('app', {
|
|
865
|
+
value: {
|
|
866
|
+
getPublicPath: () => '/v2/',
|
|
867
|
+
router: {
|
|
868
|
+
getBasename: () => '/v2',
|
|
869
|
+
},
|
|
870
|
+
},
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
const adminLayoutModel: MockAdminLayoutModel = Object.assign(
|
|
874
|
+
engine.createModel({ uid: 'admin-layout-model', use: 'FlowModel' }),
|
|
875
|
+
{
|
|
876
|
+
registerRoutePage: vi.fn(),
|
|
877
|
+
updateRoutePage: vi.fn(),
|
|
878
|
+
unregisterRoutePage: vi.fn(),
|
|
879
|
+
},
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
render(
|
|
883
|
+
<FlowEngineProvider engine={engine}>
|
|
884
|
+
<MemoryRouter initialEntries={['/admin/admin-denied-page']}>
|
|
885
|
+
<Routes>
|
|
886
|
+
<Route path="/admin/:name" element={<FlowRoute />} />
|
|
887
|
+
</Routes>
|
|
888
|
+
</MemoryRouter>
|
|
889
|
+
</FlowEngineProvider>,
|
|
890
|
+
);
|
|
891
|
+
|
|
892
|
+
expect(await screen.findByText('404')).toBeInTheDocument();
|
|
893
|
+
expect(adminLayoutModel.registerRoutePage).not.toHaveBeenCalled();
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
it('should not use flowModels:findOne to bridge a missing route for protected layouts', async () => {
|
|
897
|
+
const engine = new FlowEngine();
|
|
898
|
+
const findOne = vi.fn().mockResolvedValue({
|
|
899
|
+
uid: 'mobile-denied-page',
|
|
900
|
+
use: 'FlowModel',
|
|
901
|
+
});
|
|
902
|
+
engine.setModelRepository({
|
|
903
|
+
findOne,
|
|
904
|
+
save: vi.fn(),
|
|
905
|
+
destroy: vi.fn(),
|
|
906
|
+
} as any);
|
|
907
|
+
engine.context.defineProperty('routeRepository', {
|
|
908
|
+
value: {
|
|
909
|
+
refreshAccessible: hookState.refresh,
|
|
910
|
+
isAccessibleLoaded: () => true,
|
|
911
|
+
ensureAccessibleLoaded: vi.fn().mockResolvedValue([]),
|
|
912
|
+
getRouteBySchemaUid: vi.fn(() => undefined),
|
|
913
|
+
},
|
|
914
|
+
});
|
|
915
|
+
engine.context.defineProperty('app', {
|
|
916
|
+
value: {
|
|
917
|
+
getPublicPath: () => '/v2/',
|
|
918
|
+
router: {
|
|
919
|
+
getBasename: () => '/v2',
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
});
|
|
923
|
+
const routeModel = engine.createModel({
|
|
924
|
+
uid: 'mobile-route-model',
|
|
925
|
+
use: 'FlowModel',
|
|
926
|
+
});
|
|
927
|
+
routeModel.context.defineProperty('layout', {
|
|
928
|
+
value: {
|
|
929
|
+
routeName: 'mobile',
|
|
930
|
+
routePath: '/mobile',
|
|
931
|
+
rootRouteName: 'mobile',
|
|
932
|
+
uid: 'mobile-layout-model',
|
|
933
|
+
layoutModelClass: 'MobileLayoutModel',
|
|
934
|
+
rootPageModelClass: 'MobileRootPageModel',
|
|
935
|
+
childPageModelClass: 'MobileChildPageModel',
|
|
936
|
+
authCheck: true,
|
|
937
|
+
},
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
const layoutModel: MockAdminLayoutModel = Object.assign(
|
|
941
|
+
engine.createModel({ uid: 'mobile-layout-model', use: 'FlowModel' }),
|
|
942
|
+
{
|
|
943
|
+
registerRoutePage: vi.fn(),
|
|
944
|
+
updateRoutePage: vi.fn(),
|
|
945
|
+
unregisterRoutePage: vi.fn(),
|
|
946
|
+
},
|
|
947
|
+
);
|
|
948
|
+
|
|
949
|
+
render(
|
|
950
|
+
<FlowEngineProvider engine={engine}>
|
|
951
|
+
<FlowContextProvider context={routeModel.context}>
|
|
952
|
+
<MemoryRouter initialEntries={['/mobile/mobile-denied-page']}>
|
|
953
|
+
<Routes>
|
|
954
|
+
<Route
|
|
955
|
+
path="/mobile/:name"
|
|
956
|
+
element={<FlowRoute legacyPageBehavior="notFound" getLayoutModel={() => layoutModel} />}
|
|
957
|
+
/>
|
|
958
|
+
</Routes>
|
|
959
|
+
</MemoryRouter>
|
|
960
|
+
</FlowContextProvider>
|
|
961
|
+
</FlowEngineProvider>,
|
|
962
|
+
);
|
|
963
|
+
|
|
964
|
+
expect(await screen.findByText('404')).toBeInTheDocument();
|
|
965
|
+
expect(findOne).not.toHaveBeenCalled();
|
|
966
|
+
expect(layoutModel.registerRoutePage).not.toHaveBeenCalled();
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it('should not load a known page uid when a protected custom layout has no accessible route', async () => {
|
|
970
|
+
const engine = new FlowEngine();
|
|
971
|
+
const findOne = vi.fn().mockResolvedValue({
|
|
972
|
+
uid: 'known-denied-custom-page',
|
|
973
|
+
use: 'FlowModel',
|
|
974
|
+
});
|
|
975
|
+
engine.setModelRepository({
|
|
976
|
+
findOne,
|
|
977
|
+
save: vi.fn(),
|
|
978
|
+
destroy: vi.fn(),
|
|
979
|
+
} as any);
|
|
980
|
+
engine.context.defineProperty('routeRepository', {
|
|
981
|
+
value: {
|
|
982
|
+
refreshAccessible: hookState.refresh,
|
|
983
|
+
isAccessibleLoaded: () => true,
|
|
984
|
+
ensureAccessibleLoaded: vi.fn().mockResolvedValue([]),
|
|
985
|
+
getRouteBySchemaUid: vi.fn(() => undefined),
|
|
986
|
+
},
|
|
987
|
+
});
|
|
988
|
+
engine.context.defineProperty('app', {
|
|
989
|
+
value: {
|
|
990
|
+
getPublicPath: () => '/v2/',
|
|
991
|
+
router: {
|
|
992
|
+
getBasename: () => '/v2',
|
|
993
|
+
},
|
|
994
|
+
},
|
|
995
|
+
});
|
|
996
|
+
const routeModel = engine.createModel({
|
|
997
|
+
uid: 'custom-layout-route-model',
|
|
998
|
+
use: 'FlowModel',
|
|
999
|
+
});
|
|
1000
|
+
routeModel.context.defineProperty('layout', {
|
|
1001
|
+
value: {
|
|
1002
|
+
routeName: 'admin2',
|
|
1003
|
+
routePath: '/admin2',
|
|
1004
|
+
rootRouteName: 'admin2',
|
|
1005
|
+
uid: 'custom-protected-layout-model',
|
|
1006
|
+
layoutModelClass: 'AdminLayoutModel',
|
|
1007
|
+
rootPageModelClass: 'RootPageModel',
|
|
1008
|
+
childPageModelClass: 'ChildPageModel',
|
|
1009
|
+
authCheck: true,
|
|
1010
|
+
},
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
const layoutModel: MockAdminLayoutModel = Object.assign(
|
|
1014
|
+
engine.createModel({ uid: 'custom-protected-layout-model', use: 'FlowModel' }),
|
|
1015
|
+
{
|
|
1016
|
+
registerRoutePage: vi.fn(),
|
|
1017
|
+
updateRoutePage: vi.fn(),
|
|
1018
|
+
unregisterRoutePage: vi.fn(),
|
|
1019
|
+
},
|
|
1020
|
+
);
|
|
1021
|
+
|
|
1022
|
+
render(
|
|
1023
|
+
<FlowEngineProvider engine={engine}>
|
|
1024
|
+
<FlowContextProvider context={routeModel.context}>
|
|
1025
|
+
<MemoryRouter initialEntries={['/admin2/known-denied-custom-page']}>
|
|
1026
|
+
<Routes>
|
|
1027
|
+
<Route
|
|
1028
|
+
path="/admin2/:name"
|
|
1029
|
+
element={<FlowRoute legacyPageBehavior="notFound" getLayoutModel={() => layoutModel} />}
|
|
1030
|
+
/>
|
|
1031
|
+
</Routes>
|
|
1032
|
+
</MemoryRouter>
|
|
1033
|
+
</FlowContextProvider>
|
|
1034
|
+
</FlowEngineProvider>,
|
|
1035
|
+
);
|
|
1036
|
+
|
|
1037
|
+
expect(await screen.findByText('404')).toBeInTheDocument();
|
|
1038
|
+
expect(findOne).not.toHaveBeenCalled();
|
|
1039
|
+
expect(layoutModel.registerRoutePage).not.toHaveBeenCalled();
|
|
1040
|
+
});
|
|
1041
|
+
|
|
603
1042
|
it('should check model existence without occupying the route model uid', async () => {
|
|
604
1043
|
const engine = new FlowEngine();
|
|
605
1044
|
const findOne = vi.fn().mockResolvedValue({
|
|
@@ -817,7 +1256,7 @@ describe('FlowRoute', () => {
|
|
|
817
1256
|
}
|
|
818
1257
|
});
|
|
819
1258
|
|
|
820
|
-
it('should not
|
|
1259
|
+
it('should render not found without redirecting when admin route does not exist', async () => {
|
|
821
1260
|
const originalLocation = window.location;
|
|
822
1261
|
const replace = vi.fn();
|
|
823
1262
|
Object.defineProperty(window, 'location', {
|
|
@@ -866,9 +1305,8 @@ describe('FlowRoute', () => {
|
|
|
866
1305
|
</FlowEngineProvider>,
|
|
867
1306
|
);
|
|
868
1307
|
|
|
869
|
-
await
|
|
870
|
-
|
|
871
|
-
});
|
|
1308
|
+
expect(await screen.findByText('404')).toBeInTheDocument();
|
|
1309
|
+
expect(adminLayoutModel.registerRoutePage).not.toHaveBeenCalled();
|
|
872
1310
|
expect(replace).not.toHaveBeenCalled();
|
|
873
1311
|
} finally {
|
|
874
1312
|
Object.defineProperty(window, 'location', {
|
|
@@ -58,4 +58,11 @@ describe('getKey', () => {
|
|
|
58
58
|
|
|
59
59
|
expect(getKey(a)).not.toBe(getKey(b));
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
it('distinguishes RunJS openView route state overrides', () => {
|
|
63
|
+
const a = createViewItem({ viewUid: 'v', openViewRouteState: { mode: 'drawer' } }, 0);
|
|
64
|
+
const b = createViewItem({ viewUid: 'v', openViewRouteState: { mode: 'dialog' } }, 0);
|
|
65
|
+
|
|
66
|
+
expect(getKey(a)).not.toBe(getKey(b));
|
|
67
|
+
});
|
|
61
68
|
});
|
|
@@ -250,6 +250,40 @@ describe('resolveViewParamsToViewList', () => {
|
|
|
250
250
|
expect(result[0].hidden.value).toBe(false); // default drawer type
|
|
251
251
|
expect(result[1].hidden.value).toBe(false); // default drawer type
|
|
252
252
|
});
|
|
253
|
+
|
|
254
|
+
it('should let RunJS openView route state override persisted mode for hidden calculation', () => {
|
|
255
|
+
const model2 = createMockModel('view2', 'drawer');
|
|
256
|
+
mockFlowEngine.getModel = vi.fn().mockReturnValue(model2);
|
|
257
|
+
|
|
258
|
+
const viewParams: ViewParam[] = [
|
|
259
|
+
{ viewUid: 'view1' },
|
|
260
|
+
{ viewUid: 'view2', openViewRouteState: { mode: 'embed' } },
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
const result = resolveViewParamsToViewList(mockFlowEngine, viewParams, mockRouteModel);
|
|
264
|
+
updateViewListHidden(result);
|
|
265
|
+
|
|
266
|
+
expect(result[0].hidden.value).toBe(true);
|
|
267
|
+
expect(result[1].hidden.value).toBe(false);
|
|
268
|
+
expect(model2.getStepParams).not.toHaveBeenCalled();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should treat child views as embed in mobile hidden calculation', () => {
|
|
272
|
+
const model2 = createMockModel('view2', 'drawer');
|
|
273
|
+
mockFlowEngine.getModel = vi.fn().mockReturnValue(model2);
|
|
274
|
+
|
|
275
|
+
const viewParams: ViewParam[] = [
|
|
276
|
+
{ viewUid: 'view1' },
|
|
277
|
+
{ viewUid: 'view2', openViewRouteState: { mode: 'dialog' } },
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
const result = resolveViewParamsToViewList(mockFlowEngine, viewParams, mockRouteModel);
|
|
281
|
+
updateViewListHidden(result, true);
|
|
282
|
+
|
|
283
|
+
expect(result[0].hidden.value).toBe(true);
|
|
284
|
+
expect(result[1].hidden.value).toBe(false);
|
|
285
|
+
expect(model2.getStepParams).not.toHaveBeenCalled();
|
|
286
|
+
});
|
|
253
287
|
});
|
|
254
288
|
|
|
255
289
|
describe('edge cases', () => {
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
import {
|
|
11
|
+
FlowEngine,
|
|
12
|
+
FlowModel,
|
|
13
|
+
FlowRuntimeContext,
|
|
14
|
+
setupRuntimeContextSteps,
|
|
15
|
+
type Collection,
|
|
16
|
+
} from '@nocobase/flow-engine';
|
|
17
|
+
import { describe, expect, it } from 'vitest';
|
|
18
|
+
import { afterSuccess, getAfterSuccessResponseRecord, getMetaTreeWithResponseRecord } from '../afterSuccess';
|
|
19
|
+
|
|
20
|
+
describe('afterSuccess response record variable', () => {
|
|
21
|
+
it('reads the submit response record from the saveResource step', () => {
|
|
22
|
+
const record = { id: 1, title: 'Saved' };
|
|
23
|
+
|
|
24
|
+
expect(
|
|
25
|
+
getAfterSuccessResponseRecord({
|
|
26
|
+
steps: {
|
|
27
|
+
confirm: { params: {}, result: undefined },
|
|
28
|
+
saveResource: { params: {}, result: record },
|
|
29
|
+
afterSuccess: { params: {} },
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
).toBe(record);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('injects responseRecord into the afterSuccess runtime context', async () => {
|
|
36
|
+
const record = { id: 1, title: 'Saved' };
|
|
37
|
+
const sourceCtx = {
|
|
38
|
+
steps: {
|
|
39
|
+
saveResource: { params: {}, result: record },
|
|
40
|
+
},
|
|
41
|
+
t: (value: string) => value,
|
|
42
|
+
};
|
|
43
|
+
const properties = await afterSuccess.defineProperties(sourceCtx as FlowRuntimeContext);
|
|
44
|
+
|
|
45
|
+
expect(properties.responseRecord.get()).toBe(record);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('shows responseRecord in the variable picker for settings context', () => {
|
|
49
|
+
const engine = new FlowEngine();
|
|
50
|
+
class SubmitActionModel extends FlowModel {}
|
|
51
|
+
engine.registerModels({ SubmitActionModel });
|
|
52
|
+
const model = engine.createModel<SubmitActionModel>({ use: 'SubmitActionModel' });
|
|
53
|
+
const collection = {
|
|
54
|
+
name: 'users',
|
|
55
|
+
dataSourceKey: 'main',
|
|
56
|
+
getFilterByTK: (record: { id?: number }) => record.id,
|
|
57
|
+
} as unknown as Collection;
|
|
58
|
+
model.context.defineProperty('collection', { value: collection });
|
|
59
|
+
const flow = model.registerFlow({
|
|
60
|
+
key: 'submitSettings',
|
|
61
|
+
steps: {
|
|
62
|
+
saveResource: { title: 'Save record', handler: () => undefined },
|
|
63
|
+
afterSuccess: { use: 'afterSuccess' },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const ctx = new FlowRuntimeContext(model, 'submitSettings', 'settings');
|
|
67
|
+
setupRuntimeContextSteps(ctx, flow.steps, model, 'submitSettings');
|
|
68
|
+
|
|
69
|
+
const metaTree = getMetaTreeWithResponseRecord(ctx);
|
|
70
|
+
|
|
71
|
+
expect(metaTree.find((node) => node.name === 'responseRecord')?.title).toBe('Response record');
|
|
72
|
+
});
|
|
73
|
+
});
|