@nocobase/client-v2 2.1.31 → 2.2.0-alpha.10

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.
Files changed (170) hide show
  1. package/es/APIClient.d.ts +1 -3
  2. package/es/BaseApplication.d.ts +2 -0
  3. package/es/PluginSettingsManager.d.ts +33 -0
  4. package/es/RouteRepository.d.ts +29 -6
  5. package/es/RouterManager.d.ts +15 -0
  6. package/es/authRedirect.d.ts +1 -0
  7. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  8. package/es/components/category-tabs/index.d.ts +9 -0
  9. package/es/components/form/TypedVariableInput.d.ts +31 -5
  10. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  11. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  12. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  13. package/es/components/form/filter/index.d.ts +2 -0
  14. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  15. package/es/components/index.d.ts +2 -0
  16. package/es/entry-actions/EntryActionManager.d.ts +24 -0
  17. package/es/entry-actions/index.d.ts +9 -0
  18. package/es/flow/actions/index.d.ts +1 -1
  19. package/es/flow/actions/linkageRules.d.ts +2 -0
  20. package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
  21. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
  22. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +3 -0
  23. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
  24. package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
  25. package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
  26. package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
  27. package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
  28. package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
  29. package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
  30. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  31. package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
  32. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  33. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  34. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  35. package/es/flow/index.d.ts +1 -0
  36. package/es/flow/models/base/ActionModelCore.d.ts +2 -0
  37. package/es/flow/models/base/GridModel.d.ts +1 -1
  38. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  39. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  40. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  41. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
  42. package/es/flow-compat/routeTypes.d.ts +1 -0
  43. package/es/index.d.ts +7 -1
  44. package/es/index.mjs +223 -135
  45. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  46. package/es/utils/index.d.ts +1 -0
  47. package/lib/index.js +220 -132
  48. package/package.json +7 -7
  49. package/src/APIClient.ts +1 -10
  50. package/src/Application.tsx +4 -0
  51. package/src/BaseApplication.tsx +2 -0
  52. package/src/PluginSettingsManager.ts +53 -0
  53. package/src/RouteRepository.ts +151 -24
  54. package/src/RouterManager.tsx +142 -1
  55. package/src/__tests__/PluginSettingsManager.test.ts +13 -0
  56. package/src/__tests__/RouteRepository.test.ts +239 -0
  57. package/src/__tests__/RouterManager.test.ts +125 -0
  58. package/src/__tests__/app.test.tsx +18 -0
  59. package/src/__tests__/authRedirect.test.ts +17 -0
  60. package/src/__tests__/browserChecker.test.ts +61 -0
  61. package/src/__tests__/exports.test.ts +16 -0
  62. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  63. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
  64. package/src/__tests__/plugin-manager.test.tsx +44 -2
  65. package/src/__tests__/settings-center.test.tsx +40 -1
  66. package/src/authRedirect.ts +38 -0
  67. package/src/components/README.md +7 -1
  68. package/src/components/README.zh-CN.md +6 -1
  69. package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
  70. package/src/components/category-tabs/index.ts +10 -0
  71. package/src/components/form/JsonTextArea.tsx +4 -0
  72. package/src/components/form/TypedVariableInput.tsx +452 -101
  73. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  74. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  75. package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
  76. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  77. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
  78. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  79. package/src/components/form/filter/index.ts +2 -0
  80. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  81. package/src/components/index.ts +2 -0
  82. package/src/entry-actions/EntryActionManager.ts +76 -0
  83. package/src/entry-actions/index.ts +10 -0
  84. package/src/flow/__tests__/FlowRoute.test.tsx +1084 -145
  85. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  86. package/src/flow/actions/customVariable.tsx +1 -2
  87. package/src/flow/actions/index.ts +2 -0
  88. package/src/flow/actions/linkageRules.tsx +65 -8
  89. package/src/flow/actions/runjs.tsx +2 -14
  90. package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
  91. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +46 -13
  92. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +486 -0
  93. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +64 -8
  94. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
  95. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
  96. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
  97. package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
  98. package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
  99. package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
  100. package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
  101. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +435 -0
  102. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
  103. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
  104. package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +214 -2
  105. package/src/flow/admin-shell/admin-layout/index.ts +1 -0
  106. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
  107. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
  108. package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
  109. package/src/flow/components/DefaultValue.tsx +1 -2
  110. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  111. package/src/flow/components/FieldAssignValueInput.tsx +76 -9
  112. package/src/flow/components/FlowRoute.tsx +185 -28
  113. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  114. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
  115. package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
  116. package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
  117. package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
  118. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  119. package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
  120. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  121. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  122. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
  123. package/src/flow/index.ts +1 -0
  124. package/src/flow/models/actions/JSActionModel.tsx +2 -7
  125. package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
  126. package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
  127. package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
  128. package/src/flow/models/base/ActionModel.tsx +21 -8
  129. package/src/flow/models/base/ActionModelCore.tsx +5 -0
  130. package/src/flow/models/base/GridModel.tsx +38 -7
  131. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  132. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  133. package/src/flow/models/base/PageModel/PageTabModel.tsx +186 -3
  134. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -14
  135. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  136. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  137. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +586 -1
  138. package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
  139. package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
  140. package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
  141. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
  142. package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
  143. package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
  144. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
  145. package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
  146. package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
  147. package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
  148. package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
  149. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +1 -1
  150. package/src/flow/models/blocks/table/TableBlockModel.tsx +13 -3
  151. package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +54 -0
  152. package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
  153. package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
  154. package/src/flow/models/fields/JSFieldModel.tsx +2 -7
  155. package/src/flow/models/fields/JSItemModel.tsx +2 -14
  156. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  157. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  158. package/src/flow/models/topbar/TopbarActionModel.tsx +168 -10
  159. package/src/flow-compat/Popover.tsx +43 -4
  160. package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
  161. package/src/flow-compat/routeTypes.ts +1 -0
  162. package/src/index.ts +13 -1
  163. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
  164. package/src/nocobase-buildin-plugin/index.tsx +19 -3
  165. package/src/settings-center/AdminSettingsLayout.tsx +10 -2
  166. package/src/settings-center/SystemSettingsPage.tsx +0 -1
  167. package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
  168. package/src/settings-center/utils.tsx +0 -6
  169. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  170. package/src/utils/index.tsx +1 -0
@@ -18,24 +18,53 @@ vi.mock('@nocobase/flow-engine', async (importOriginal) => {
18
18
  return {
19
19
  ...actual,
20
20
  FlowModel: class {
21
+ uid: string;
22
+ parentId?: string;
21
23
  props: any;
22
24
  context: any;
23
25
  stepParams: any;
26
+ flowEngine?: {
27
+ modelRepository?: {
28
+ findOne?: (query: Record<string, unknown>) => Promise<unknown>;
29
+ };
30
+ flowSettings?: {
31
+ open?: (options: Record<string, unknown>) => Promise<unknown> | unknown;
32
+ };
33
+ };
34
+ flowRegistryData: Record<string, unknown>;
35
+ invalidateFlowCache = vi.fn();
36
+ rerender = vi.fn(async () => undefined);
24
37
 
25
38
  constructor(options: any = {}) {
39
+ this.uid = options.uid || 'mock-model';
40
+ this.parentId = options.parentId;
26
41
  this.props = options.props || {};
27
42
  this.context = options.context || {};
28
43
  this.stepParams = options.stepParams || {};
44
+ this.flowEngine = options.flowEngine;
45
+ this.flowRegistryData = options.flowRegistry || {};
29
46
  }
30
47
 
31
48
  serialize() {
32
- return { flowRegistry: {} };
49
+ return { flowRegistry: this.flowRegistryData };
33
50
  }
34
51
 
35
52
  setProps(key: string, value: any) {
36
53
  this.props[key] = value;
37
54
  }
38
55
 
56
+ setStepParams(flowKey: string, stepKey: string, params: Record<string, unknown>) {
57
+ this.stepParams[flowKey] = this.stepParams[flowKey] || {};
58
+ this.stepParams[flowKey][stepKey] = {
59
+ ...(this.stepParams[flowKey][stepKey] || {}),
60
+ ...params,
61
+ };
62
+ }
63
+
64
+ openFlowSettings(options: Record<string, unknown> = {}) {
65
+ return this.flowEngine?.flowSettings?.open?.({ model: this, ...options });
66
+ }
67
+
39
68
  onInit() {}
40
69
  static registerFlow(flow: any) {
41
70
  registerFlowMock(flow);
@@ -131,6 +160,13 @@ describe('PageTabModel', () => {
131
160
  expect(keys.indexOf('documentTitle')).toBe(keys.indexOf('title') + 1);
132
161
  });
133
162
 
163
+ it('should expose tab linkage rules in page tab settings', async () => {
164
+ await import('../PageTabModel');
165
+ const flow = registerFlowMock.mock.calls.find((call) => call[0]?.key === 'pageTabSettings')?.[0];
166
+
167
+ expect(flow?.steps?.linkageRules?.use).toBe('tabLinkageRules');
168
+ });
169
+
134
170
  it('should trigger parent page title update in tab settings handler', async () => {
135
171
  await import('../PageTabModel');
136
172
  const flow = registerFlowMock.mock.calls.find((call) => call[0]?.key === 'pageTabSettings')?.[0];
@@ -705,4 +741,553 @@ describe('PageTabModel', () => {
705
741
  documentTitle: 'Server doc title',
706
742
  });
707
743
  });
744
+
745
+ describe('root tab linkage hydrate', () => {
746
+ it('should hydrate linkage rules before opening settings in configuration mode', async () => {
747
+ const { RootPageTabModel } = await import('../PageTabModel');
748
+ const linkageRules = { value: [{ key: 'rule-1' }] };
749
+ const request = vi.fn().mockResolvedValue({
750
+ data: {
751
+ data: {
752
+ uid: 'tab-1',
753
+ use: 'RouteModel',
754
+ props: { title: 'Stale anchor title' },
755
+ stepParams: {
756
+ pageTabSettings: {
757
+ tab: { title: 'Stale tab title' },
758
+ linkageRules,
759
+ },
760
+ },
761
+ },
762
+ },
763
+ });
764
+ const open = vi.fn(({ model }: { model: { stepParams: Record<string, unknown> } }) => {
765
+ expect(model.stepParams).toMatchObject({ pageTabSettings: { linkageRules } });
766
+ return 'opened';
767
+ });
768
+ const model = new RootPageTabModel({
769
+ uid: 'tab-1',
770
+ flowEngine: {
771
+ flowSettings: { open },
772
+ },
773
+ props: {
774
+ route: {
775
+ schemaUid: 'tab-1',
776
+ title: 'Current route title',
777
+ options: {},
778
+ },
779
+ },
780
+ stepParams: {
781
+ pageTabSettings: {
782
+ tab: { title: 'Current tab title' },
783
+ },
784
+ },
785
+ context: {
786
+ api: { request },
787
+ flowSettingsEnabled: true,
788
+ defineProperty: vi.fn(),
789
+ t: (value: string) => value,
790
+ },
791
+ } as any);
792
+
793
+ model.onInit({});
794
+ await model.openFlowSettings({ flowKey: 'pageTabSettings', stepKey: 'linkageRules' });
795
+
796
+ expect(request).toHaveBeenCalledWith({
797
+ url: 'flowModels:findOne',
798
+ params: { uid: 'tab-1' },
799
+ });
800
+ expect(model.props.route.title).toBe('Current route title');
801
+ expect(model.stepParams.pageTabSettings.tab.title).toBe('Current tab title');
802
+ expect(model.stepParams.pageTabSettings.linkageRules).toEqual(linkageRules);
803
+ expect(model.invalidateFlowCache).toHaveBeenCalledWith('beforeRender', true);
804
+ expect(model.rerender).toHaveBeenCalledTimes(1);
805
+ expect(open).toHaveBeenCalledTimes(1);
806
+ });
807
+
808
+ it('should only hydrate marked root tabs at runtime', async () => {
809
+ const { RootPageTabModel } = await import('../PageTabModel');
810
+ const unmarkedRequest = vi.fn().mockResolvedValue({ data: { data: null } });
811
+ const markedRequest = vi.fn().mockResolvedValue({
812
+ data: {
813
+ data: {
814
+ stepParams: {
815
+ pageTabSettings: {
816
+ linkageRules: { value: [] },
817
+ },
818
+ },
819
+ },
820
+ },
821
+ });
822
+ const createModel = (request: typeof markedRequest, marked: boolean) =>
823
+ new RootPageTabModel({
824
+ uid: marked ? 'tab-marked' : 'tab-unmarked',
825
+ props: {
826
+ route: {
827
+ schemaUid: marked ? 'tab-marked' : 'tab-unmarked',
828
+ options: marked ? { hasPersistedPageTabFlowModel: true } : {},
829
+ },
830
+ },
831
+ context: {
832
+ api: { request },
833
+ flowSettingsEnabled: false,
834
+ defineProperty: vi.fn(),
835
+ t: (value: string) => value,
836
+ },
837
+ } as any);
838
+
839
+ const unmarkedModel = createModel(unmarkedRequest, false);
840
+ const markedModel = createModel(markedRequest, true);
841
+ unmarkedModel.onInit({});
842
+ markedModel.onInit({});
843
+
844
+ await vi.waitFor(() => {
845
+ expect(markedRequest).toHaveBeenCalledTimes(1);
846
+ expect(markedModel.stepParams.pageTabSettings.linkageRules).toEqual({ value: [] });
847
+ });
848
+ expect(unmarkedRequest).not.toHaveBeenCalled();
849
+ });
850
+
851
+ it('should ignore the linkage-specific legacy marker at runtime', async () => {
852
+ const { RootPageTabModel } = await import('../PageTabModel');
853
+ const request = vi.fn().mockResolvedValue({ data: { data: null } });
854
+ const legacyMarker = ['hasPersistedPageTab', 'LinkageRules'].join('');
855
+ const model = new RootPageTabModel({
856
+ uid: 'tab-legacy-marker',
857
+ props: {
858
+ route: {
859
+ schemaUid: 'tab-legacy-marker',
860
+ options: { [legacyMarker]: true },
861
+ },
862
+ },
863
+ context: {
864
+ api: { request },
865
+ flowSettingsEnabled: false,
866
+ defineProperty: vi.fn(),
867
+ t: (value: string) => value,
868
+ },
869
+ } as any);
870
+
871
+ model.onInit({});
872
+
873
+ expect(request).not.toHaveBeenCalled();
874
+ });
875
+
876
+ it('should share one in-flight hydrate request across concurrent settings opens', async () => {
877
+ const { RootPageTabModel } = await import('../PageTabModel');
878
+ let resolveAnchor: (value: unknown) => void = () => undefined;
879
+ const request = vi.fn(
880
+ () =>
881
+ new Promise<unknown>((resolve) => {
882
+ resolveAnchor = (value) => resolve({ data: { data: value } });
883
+ }),
884
+ );
885
+ const open = vi.fn().mockResolvedValue(undefined);
886
+ const model = new RootPageTabModel({
887
+ uid: 'tab-1',
888
+ flowEngine: {
889
+ flowSettings: { open },
890
+ },
891
+ props: { route: { schemaUid: 'tab-1', options: {} } },
892
+ context: {
893
+ api: { request },
894
+ flowSettingsEnabled: false,
895
+ t: (value: string) => value,
896
+ },
897
+ } as any);
898
+
899
+ const firstOpen = model.openFlowSettings({ flowKey: 'pageTabSettings', stepKey: 'linkageRules' });
900
+ const secondOpen = model.openFlowSettings({ flowKey: 'pageTabSettings', stepKey: 'linkageRules' });
901
+
902
+ await vi.waitFor(() => expect(request).toHaveBeenCalledTimes(1));
903
+ resolveAnchor({
904
+ stepParams: {
905
+ pageTabSettings: {
906
+ linkageRules: { value: [] },
907
+ },
908
+ },
909
+ });
910
+ await Promise.all([firstOpen, secondOpen]);
911
+
912
+ expect(request).toHaveBeenCalledTimes(1);
913
+ expect(open).toHaveBeenCalledTimes(2);
914
+ });
915
+
916
+ it('should safely handle missing anchors and missing linkage steps', async () => {
917
+ const { RootPageTabModel } = await import('../PageTabModel');
918
+ const request = vi.fn().mockResolvedValue({ data: { data: null } });
919
+ const model = new RootPageTabModel({
920
+ uid: 'tab-1',
921
+ flowEngine: {
922
+ flowSettings: { open: vi.fn().mockResolvedValue(undefined) },
923
+ },
924
+ props: { route: { schemaUid: 'tab-1', options: {} } },
925
+ stepParams: {
926
+ pageTabSettings: {
927
+ tab: { title: 'Current tab title' },
928
+ },
929
+ },
930
+ context: {
931
+ api: { request },
932
+ flowSettingsEnabled: true,
933
+ defineProperty: vi.fn(),
934
+ t: (value: string) => value,
935
+ },
936
+ } as any);
937
+
938
+ model.onInit({});
939
+ await expect(
940
+ model.openFlowSettings({ flowKey: 'pageTabSettings', stepKey: 'linkageRules' }),
941
+ ).resolves.toBeUndefined();
942
+
943
+ expect(request).toHaveBeenCalledWith({
944
+ url: 'flowModels:findOne',
945
+ params: { uid: 'tab-1' },
946
+ });
947
+ expect(model.stepParams.pageTabSettings.linkageRules).toBeUndefined();
948
+ expect(model.stepParams.pageTabSettings.tab.title).toBe('Current tab title');
949
+ });
950
+ });
951
+
952
+ describe('root tab linkage persistence', () => {
953
+ it('should not touch the anchor or marker when linkage rules were never loaded', async () => {
954
+ const { RootPageTabModel } = await import('../PageTabModel');
955
+ const request = vi.fn().mockResolvedValue({});
956
+ const updateRoute = vi.fn();
957
+ const model = new RootPageTabModel({
958
+ uid: 'tab-1',
959
+ props: {
960
+ route: {
961
+ id: 10,
962
+ schemaUid: 'tab-1',
963
+ options: { badge: 'new' },
964
+ },
965
+ },
966
+ stepParams: {
967
+ pageTabSettings: {
968
+ tab: { title: 'Tab title' },
969
+ },
970
+ },
971
+ context: {
972
+ api: { request },
973
+ routeRepository: { updateRoute },
974
+ t: (value: string) => value,
975
+ },
976
+ } as any);
977
+
978
+ await model.saveStepParams();
979
+
980
+ expect(request).toHaveBeenCalledTimes(1);
981
+ expect(request.mock.calls[0][0].url).toBe('desktopRoutes:update?filter[id]=10');
982
+ expect(updateRoute).not.toHaveBeenCalled();
983
+ });
984
+
985
+ it('should merge the latest anchor without sending subModels and then set the marker', async () => {
986
+ const { RootPageTabModel } = await import('../PageTabModel');
987
+ const latestAnchor = {
988
+ uid: 'tab-1',
989
+ use: 'CustomRouteModel',
990
+ props: { anchorProp: true },
991
+ decoratorProps: { compact: true },
992
+ stepParams: {
993
+ pageTabSettings: {
994
+ tab: { title: 'Anchor tab title' },
995
+ linkageRules: { value: [{ key: 'old-rule' }] },
996
+ },
997
+ otherFlow: {
998
+ otherStep: { value: 1 },
999
+ },
1000
+ },
1001
+ flowRegistry: { customFlow: { steps: {} } },
1002
+ unknownRoot: { keep: true },
1003
+ subModels: {
1004
+ grid: { uid: 'grid-1' },
1005
+ },
1006
+ };
1007
+ const request = vi.fn(async ({ url }: { url: string }) => {
1008
+ if (url === 'flowModels:findOne') {
1009
+ return { data: { data: latestAnchor } };
1010
+ }
1011
+ return { data: { data: {} } };
1012
+ });
1013
+ const updateRoute = vi.fn().mockResolvedValue(undefined);
1014
+ const currentRoute = {
1015
+ id: 10,
1016
+ schemaUid: 'tab-1',
1017
+ options: {
1018
+ badge: 'new',
1019
+ pluginOption: { keep: true },
1020
+ serverHookState: true,
1021
+ flowRegistry: { routeFlow: { steps: {} } },
1022
+ },
1023
+ };
1024
+ const linkageRules = { value: [{ key: 'new-rule' }] };
1025
+ const model = new RootPageTabModel({
1026
+ uid: 'tab-1',
1027
+ flowRegistry: { routeFlow: { steps: {} } },
1028
+ props: {
1029
+ route: {
1030
+ id: 10,
1031
+ schemaUid: 'tab-1',
1032
+ options: {
1033
+ badge: 'new',
1034
+ pluginOption: { keep: true },
1035
+ flowRegistry: { routeFlow: { steps: {} } },
1036
+ },
1037
+ },
1038
+ },
1039
+ stepParams: {
1040
+ pageTabSettings: {
1041
+ tab: {
1042
+ title: 'Tab title',
1043
+ documentTitle: 'Tab document title',
1044
+ },
1045
+ linkageRules,
1046
+ },
1047
+ },
1048
+ context: {
1049
+ api: { request },
1050
+ routeRepository: {
1051
+ getRouteBySchemaUid: vi.fn(() => currentRoute),
1052
+ refreshAccessible: vi.fn().mockResolvedValue([currentRoute]),
1053
+ updateRoute,
1054
+ },
1055
+ t: (value: string) => value,
1056
+ },
1057
+ } as any);
1058
+
1059
+ await model.saveStepParams();
1060
+
1061
+ const urls = request.mock.calls.map(([config]) => config.url);
1062
+ expect(urls).toEqual(['desktopRoutes:update?filter[id]=10', 'flowModels:findOne', 'flowModels:save']);
1063
+ expect(request.mock.calls[0][0].data.options).toMatchObject({
1064
+ badge: 'new',
1065
+ pluginOption: { keep: true },
1066
+ serverHookState: true,
1067
+ flowRegistry: { routeFlow: { steps: {} } },
1068
+ documentTitle: 'Tab document title',
1069
+ });
1070
+
1071
+ const anchorPayload = request.mock.calls[2][0].data;
1072
+ expect(anchorPayload).toMatchObject({
1073
+ uid: 'tab-1',
1074
+ use: 'CustomRouteModel',
1075
+ props: { anchorProp: true },
1076
+ decoratorProps: { compact: true },
1077
+ stepParams: {
1078
+ pageTabSettings: {
1079
+ tab: { title: 'Anchor tab title' },
1080
+ linkageRules,
1081
+ },
1082
+ otherFlow: {
1083
+ otherStep: { value: 1 },
1084
+ },
1085
+ },
1086
+ flowRegistry: { customFlow: { steps: {} } },
1087
+ unknownRoot: { keep: true },
1088
+ });
1089
+ expect(anchorPayload).not.toHaveProperty('subModels');
1090
+ expect(updateRoute).toHaveBeenCalledWith(
1091
+ 10,
1092
+ {
1093
+ options: expect.objectContaining({
1094
+ badge: 'new',
1095
+ pluginOption: { keep: true },
1096
+ serverHookState: true,
1097
+ hasPersistedPageTabFlowModel: true,
1098
+ }),
1099
+ },
1100
+ { refreshAfterMutation: false },
1101
+ );
1102
+ expect(request.mock.invocationCallOrder[2]).toBeLessThan(updateRoute.mock.invocationCallOrder[0]);
1103
+ expect(model.props.route.options.hasPersistedPageTabFlowModel).toBe(true);
1104
+ expect(model.props.route.options.serverHookState).toBe(true);
1105
+ });
1106
+
1107
+ it('should read the latest anchor again before every linkage save', async () => {
1108
+ const { RootPageTabModel } = await import('../PageTabModel');
1109
+ const request = vi.fn(async ({ url }: { url: string }) => {
1110
+ if (url === 'flowModels:findOne') {
1111
+ return { data: { data: { uid: 'tab-1', use: 'RouteModel' } } };
1112
+ }
1113
+ return {};
1114
+ });
1115
+ const model = new RootPageTabModel({
1116
+ uid: 'tab-1',
1117
+ props: { route: { id: 10, schemaUid: 'tab-1', options: {} } },
1118
+ stepParams: {
1119
+ pageTabSettings: {
1120
+ tab: { title: 'Tab title' },
1121
+ linkageRules: { value: [] },
1122
+ },
1123
+ },
1124
+ context: {
1125
+ api: { request },
1126
+ routeRepository: { updateRoute: vi.fn().mockResolvedValue(undefined) },
1127
+ t: (value: string) => value,
1128
+ },
1129
+ } as any);
1130
+
1131
+ await model.saveStepParams();
1132
+ await model.saveStepParams();
1133
+
1134
+ expect(request.mock.calls.filter(([config]) => config.url === 'flowModels:findOne')).toHaveLength(2);
1135
+ });
1136
+
1137
+ it('should persist empty rules without destroying the anchor and clear the marker', async () => {
1138
+ const { RootPageTabModel } = await import('../PageTabModel');
1139
+ const request = vi.fn(async ({ url }: { url: string }) => {
1140
+ if (url === 'flowModels:findOne') {
1141
+ return {
1142
+ data: {
1143
+ data: {
1144
+ uid: 'tab-1',
1145
+ use: 'RouteModel',
1146
+ subModels: { grid: { uid: 'grid-1' } },
1147
+ },
1148
+ },
1149
+ };
1150
+ }
1151
+ return {};
1152
+ });
1153
+ const updateRoute = vi.fn().mockResolvedValue(undefined);
1154
+ const model = new RootPageTabModel({
1155
+ uid: 'tab-1',
1156
+ props: {
1157
+ route: {
1158
+ id: 10,
1159
+ schemaUid: 'tab-1',
1160
+ options: {
1161
+ badge: 'new',
1162
+ hasPersistedPageTabFlowModel: true,
1163
+ },
1164
+ },
1165
+ },
1166
+ stepParams: {
1167
+ pageTabSettings: {
1168
+ tab: { title: 'Tab title' },
1169
+ linkageRules: { value: [] },
1170
+ },
1171
+ },
1172
+ context: {
1173
+ api: { request },
1174
+ routeRepository: { updateRoute },
1175
+ t: (value: string) => value,
1176
+ },
1177
+ } as any);
1178
+
1179
+ await model.saveStepParams();
1180
+
1181
+ const urls = request.mock.calls.map(([config]) => config.url);
1182
+ expect(urls).toContain('flowModels:save');
1183
+ expect(urls).not.toContain('flowModels:destroy');
1184
+ const anchorPayload = request.mock.calls.find(([config]) => config.url === 'flowModels:save')?.[0].data;
1185
+ expect(anchorPayload.stepParams.pageTabSettings.linkageRules).toEqual({ value: [] });
1186
+ expect(anchorPayload).not.toHaveProperty('subModels');
1187
+ expect(updateRoute.mock.calls[0][1].options).toMatchObject({ badge: 'new' });
1188
+ expect(updateRoute.mock.calls[0][1].options).not.toHaveProperty('hasPersistedPageTabFlowModel');
1189
+ expect(model.props.route.options).not.toHaveProperty('hasPersistedPageTabFlowModel');
1190
+ });
1191
+
1192
+ it('should create a minimal RouteModel anchor when the anchor is missing', async () => {
1193
+ const { RootPageTabModel } = await import('../PageTabModel');
1194
+ const request = vi.fn(async ({ url }: { url: string }) => {
1195
+ if (url === 'flowModels:findOne') {
1196
+ return { data: { data: null } };
1197
+ }
1198
+ return {};
1199
+ });
1200
+ const model = new RootPageTabModel({
1201
+ uid: 'tab-1',
1202
+ props: { route: { id: 10, schemaUid: 'tab-1', options: {} } },
1203
+ stepParams: {
1204
+ pageTabSettings: {
1205
+ tab: { title: 'Tab title' },
1206
+ linkageRules: { value: [{ key: 'rule-1' }] },
1207
+ },
1208
+ },
1209
+ context: {
1210
+ api: { request },
1211
+ routeRepository: { updateRoute: vi.fn().mockResolvedValue(undefined) },
1212
+ t: (value: string) => value,
1213
+ },
1214
+ } as any);
1215
+
1216
+ await model.saveStepParams();
1217
+
1218
+ const anchorPayload = request.mock.calls.find(([config]) => config.url === 'flowModels:save')?.[0].data;
1219
+ expect(anchorPayload).toMatchObject({
1220
+ uid: 'tab-1',
1221
+ use: 'RouteModel',
1222
+ stepParams: {
1223
+ pageTabSettings: {
1224
+ linkageRules: { value: [{ key: 'rule-1' }] },
1225
+ },
1226
+ },
1227
+ });
1228
+ expect(anchorPayload).not.toHaveProperty('props.route');
1229
+ expect(anchorPayload).not.toHaveProperty('subModels');
1230
+ });
1231
+
1232
+ it('should not update the marker when saving the anchor fails', async () => {
1233
+ const { RootPageTabModel } = await import('../PageTabModel');
1234
+ const error = new Error('anchor save failed');
1235
+ const request = vi.fn(async ({ url }: { url: string }) => {
1236
+ if (url === 'flowModels:findOne') {
1237
+ return { data: { data: { uid: 'tab-1', use: 'RouteModel' } } };
1238
+ }
1239
+ if (url === 'flowModels:save') {
1240
+ throw error;
1241
+ }
1242
+ return {};
1243
+ });
1244
+ const updateRoute = vi.fn();
1245
+ const model = new RootPageTabModel({
1246
+ uid: 'tab-1',
1247
+ props: { route: { id: 10, schemaUid: 'tab-1', options: {} } },
1248
+ stepParams: {
1249
+ pageTabSettings: {
1250
+ linkageRules: { value: [{ key: 'rule-1' }] },
1251
+ },
1252
+ },
1253
+ context: {
1254
+ api: { request },
1255
+ routeRepository: { updateRoute },
1256
+ t: (value: string) => value,
1257
+ },
1258
+ } as any);
1259
+
1260
+ await expect(model.saveStepParams()).rejects.toBe(error);
1261
+ expect(updateRoute).not.toHaveBeenCalled();
1262
+ });
1263
+
1264
+ it('should reject when updating the route marker fails', async () => {
1265
+ const { RootPageTabModel } = await import('../PageTabModel');
1266
+ const error = new Error('marker update failed');
1267
+ const request = vi.fn(async ({ url }: { url: string }) => {
1268
+ if (url === 'flowModels:findOne') {
1269
+ return { data: { data: { uid: 'tab-1', use: 'RouteModel' } } };
1270
+ }
1271
+ return {};
1272
+ });
1273
+ const updateRoute = vi.fn().mockRejectedValue(error);
1274
+ const model = new RootPageTabModel({
1275
+ uid: 'tab-1',
1276
+ props: { route: { id: 10, schemaUid: 'tab-1', options: {} } },
1277
+ stepParams: {
1278
+ pageTabSettings: {
1279
+ linkageRules: { value: [{ key: 'rule-1' }] },
1280
+ },
1281
+ },
1282
+ context: {
1283
+ api: { request },
1284
+ routeRepository: { updateRoute },
1285
+ t: (value: string) => value,
1286
+ },
1287
+ } as any);
1288
+
1289
+ await expect(model.saveStepParams()).rejects.toBe(error);
1290
+ expect(request.mock.calls.some(([config]) => config.url === 'flowModels:save')).toBe(true);
1291
+ });
1292
+ });
708
1293
  });
@@ -0,0 +1,83 @@
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 { FlowEngine, FlowRuntimeContext } from '@nocobase/flow-engine';
11
+ import { describe, expect, it } from 'vitest';
12
+ import { ActionModel } from '../ActionModel';
13
+
14
+ class IconActionModel extends ActionModel {
15
+ defaultProps = {
16
+ type: 'default' as const,
17
+ title: 'Icon action',
18
+ icon: 'PlusOutlined',
19
+ };
20
+ }
21
+
22
+ class PlainActionModel extends ActionModel {
23
+ defaultProps = {
24
+ type: 'default' as const,
25
+ title: 'Plain action',
26
+ };
27
+ }
28
+
29
+ function getButtonSettingsDefaultParams(model: ActionModel) {
30
+ const defaultParams = model.getFlow('buttonSettings')?.getStep('general')?.defaultParams;
31
+ if (typeof defaultParams !== 'function') {
32
+ throw new Error('buttonSettings.general.defaultParams is unavailable.');
33
+ }
34
+ return defaultParams(new FlowRuntimeContext(model, 'buttonSettings', 'settings'));
35
+ }
36
+
37
+ describe('ActionModel button settings', () => {
38
+ it('uses icon-only buttons by default for mobile icon actions', () => {
39
+ const engine = new FlowEngine();
40
+ engine.registerModels({ IconActionModel });
41
+ const model = engine.createModel<IconActionModel>({
42
+ use: 'IconActionModel',
43
+ uid: 'mobile-icon-action',
44
+ });
45
+
46
+ model.context.defineProperty('isMobileLayout', { value: true });
47
+
48
+ expect(getButtonSettingsDefaultParams(model)).toMatchObject({
49
+ icon: 'PlusOutlined',
50
+ iconOnly: true,
51
+ });
52
+ });
53
+
54
+ it('keeps button titles visible by default outside mobile layouts', () => {
55
+ const engine = new FlowEngine();
56
+ engine.registerModels({ IconActionModel });
57
+ const model = engine.createModel<IconActionModel>({
58
+ use: 'IconActionModel',
59
+ uid: 'desktop-icon-action',
60
+ });
61
+
62
+ expect(getButtonSettingsDefaultParams(model)).toMatchObject({
63
+ icon: 'PlusOutlined',
64
+ });
65
+ expect(getButtonSettingsDefaultParams(model)).not.toHaveProperty('iconOnly', true);
66
+ });
67
+
68
+ it('does not force icon-only buttons for mobile actions without icons', () => {
69
+ const engine = new FlowEngine();
70
+ engine.registerModels({ PlainActionModel });
71
+ const model = engine.createModel<PlainActionModel>({
72
+ use: 'PlainActionModel',
73
+ uid: 'mobile-plain-action',
74
+ });
75
+
76
+ model.context.defineProperty('isMobileLayout', { value: true });
77
+
78
+ expect(getButtonSettingsDefaultParams(model)).toMatchObject({
79
+ title: 'Plain action',
80
+ });
81
+ expect(getButtonSettingsDefaultParams(model)).not.toHaveProperty('iconOnly', true);
82
+ });
83
+ });