@nocobase/client-v2 2.2.0-beta.8 → 2.3.0-alpha.1

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 (164) hide show
  1. package/es/APIClient.d.ts +1 -3
  2. package/es/BaseApplication.d.ts +3 -0
  3. package/es/RouteRepository.d.ts +8 -0
  4. package/es/RouterManager.d.ts +15 -0
  5. package/es/authRedirect.d.ts +1 -0
  6. package/es/collection-field-interface/CollectionFieldInterface.d.ts +1 -0
  7. package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +1 -0
  8. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  9. package/es/components/category-tabs/index.d.ts +9 -0
  10. package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -1
  11. package/es/components/form/TypedVariableInput.d.ts +31 -5
  12. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  13. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  14. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  15. package/es/components/form/filter/index.d.ts +2 -0
  16. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  17. package/es/components/index.d.ts +1 -0
  18. package/es/entry-actions/EntryActionManager.d.ts +24 -0
  19. package/es/entry-actions/index.d.ts +9 -0
  20. package/es/flow/actions/index.d.ts +1 -1
  21. package/es/flow/actions/linkageRules.d.ts +2 -0
  22. package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
  23. package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
  24. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -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/useApplications.d.ts +7 -2
  29. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  30. package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
  31. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  32. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  33. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  34. package/es/flow/index.d.ts +1 -0
  35. package/es/flow/models/base/ActionModelCore.d.ts +2 -0
  36. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  37. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  38. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  39. package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +17 -2
  40. package/es/flow/routeTransientInputArgs.d.ts +14 -0
  41. package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
  42. package/es/flow-compat/routeTypes.d.ts +1 -0
  43. package/es/index.d.ts +6 -0
  44. package/es/index.mjs +279 -158
  45. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  46. package/es/utils/index.d.ts +1 -0
  47. package/es/utils/markdownSanitize.d.ts +11 -0
  48. package/lib/index.js +280 -159
  49. package/lib/locale/languageCodes.js +2 -1
  50. package/package.json +8 -7
  51. package/src/APIClient.ts +1 -10
  52. package/src/Application.tsx +4 -0
  53. package/src/BaseApplication.tsx +13 -6
  54. package/src/RouteRepository.ts +25 -0
  55. package/src/RouterManager.tsx +142 -1
  56. package/src/__tests__/RouteRepository.test.ts +23 -0
  57. package/src/__tests__/RouterManager.test.ts +125 -0
  58. package/src/__tests__/app.test.tsx +73 -0
  59. package/src/__tests__/authRedirect.test.ts +17 -0
  60. package/src/__tests__/browserChecker.test.ts +61 -0
  61. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  62. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
  63. package/src/authRedirect.ts +38 -0
  64. package/src/collection-field-interface/CollectionFieldInterface.ts +1 -0
  65. package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +1 -0
  66. package/src/collection-manager/field-validation.ts +1 -1
  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/ScanInput/CodeScanner.tsx +23 -6
  73. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +180 -3
  74. package/src/components/form/ScanInput/useCodeScanner.ts +170 -5
  75. package/src/components/form/TypedVariableInput.tsx +452 -101
  76. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  77. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  78. package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
  79. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  80. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
  81. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  82. package/src/components/form/filter/index.ts +2 -0
  83. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  84. package/src/components/index.ts +1 -0
  85. package/src/entry-actions/EntryActionManager.ts +76 -0
  86. package/src/entry-actions/index.ts +10 -0
  87. package/src/flow/FlowPage.tsx +38 -3
  88. package/src/flow/__tests__/FlowPage.test.tsx +201 -27
  89. package/src/flow/__tests__/FlowRoute.test.tsx +549 -4
  90. package/src/flow/actions/__tests__/dataScopeFilter.test.ts +62 -0
  91. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  92. package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +7 -3
  93. package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +80 -20
  94. package/src/flow/actions/dataScopeFilter.ts +10 -1
  95. package/src/flow/actions/dateTimeFormat.tsx +2 -2
  96. package/src/flow/actions/index.ts +2 -0
  97. package/src/flow/actions/linkageRules.tsx +86 -11
  98. package/src/flow/actions/linkageRulesRefresh.tsx +2 -6
  99. package/src/flow/actions/openView.tsx +21 -1
  100. package/src/flow/admin-shell/BaseLayoutModel.tsx +124 -0
  101. package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +184 -42
  102. package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1016 -119
  103. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +41 -5
  104. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
  105. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
  106. package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
  107. package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
  108. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
  109. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +436 -2
  110. package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
  111. package/src/flow/admin-shell/admin-layout/index.ts +1 -0
  112. package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
  113. package/src/flow/common/Markdown/Display.tsx +14 -3
  114. package/src/flow/common/Markdown/Edit.tsx +19 -7
  115. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  116. package/src/flow/components/FieldAssignValueInput.tsx +91 -20
  117. package/src/flow/components/FlowRoute.tsx +134 -18
  118. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  119. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +216 -0
  120. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  121. package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
  122. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  123. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  124. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
  125. package/src/flow/index.ts +1 -0
  126. package/src/flow/internal/components/Markdown/util.ts +2 -1
  127. package/src/flow/models/base/ActionModel.tsx +10 -8
  128. package/src/flow/models/base/ActionModelCore.tsx +5 -0
  129. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  130. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  131. package/src/flow/models/base/PageModel/PageTabModel.tsx +184 -3
  132. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
  133. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  134. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  135. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +572 -1
  136. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -0
  137. package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +27 -12
  138. package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +36 -0
  139. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +34 -0
  140. package/src/flow/models/blocks/form/QuickEditFormModel.tsx +189 -36
  141. package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +350 -2
  142. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +2 -1
  143. package/src/flow/models/blocks/table/TableBlockModel.tsx +1 -1
  144. package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
  145. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
  146. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +2 -1
  147. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
  148. package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
  149. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  150. package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
  151. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  152. package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +20 -10
  153. package/src/flow/models/fields/mobile-components/MobileSelect.tsx +24 -12
  154. package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
  155. package/src/flow/routeTransientInputArgs.ts +27 -0
  156. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
  157. package/src/flow-compat/fieldValidationConstants.ts +1 -1
  158. package/src/flow-compat/routeTypes.ts +1 -0
  159. package/src/index.ts +6 -0
  160. package/src/locale/languageCodes.ts +2 -1
  161. package/src/nocobase-buildin-plugin/index.tsx +19 -1
  162. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  163. package/src/utils/index.tsx +1 -0
  164. package/src/utils/markdownSanitize.ts +88 -0
@@ -0,0 +1,95 @@
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, FlowEngineProvider, type Collection } from '@nocobase/flow-engine';
11
+ import { renderHook } from '@testing-library/react';
12
+ import React from 'react';
13
+ import { describe, expect, it, vi } from 'vitest';
14
+ import { useFilterActionProps } from '../useFilterActionProps';
15
+
16
+ vi.mock('../../../flow/components/filter/useFilterOptions', () => ({
17
+ useFilterOptions: () => [],
18
+ }));
19
+
20
+ vi.mock('../CollectionFilterItem', () => ({
21
+ createCollectionFilterItem: () => undefined,
22
+ }));
23
+
24
+ function makeCollection(): Collection {
25
+ return {
26
+ getFields: () => [{ name: 'title' }, { name: 'type' }],
27
+ } as unknown as Collection;
28
+ }
29
+
30
+ function makeWrapper() {
31
+ const engine = new FlowEngine();
32
+ const Wrapper: React.FC = ({ children }) => <FlowEngineProvider engine={engine}>{children}</FlowEngineProvider>;
33
+ return Wrapper;
34
+ }
35
+
36
+ describe('useFilterActionProps', () => {
37
+ it('seeds the editable group from defaultValue when initialValue is missing', () => {
38
+ const { result } = renderHook(
39
+ () =>
40
+ useFilterActionProps({
41
+ collection: makeCollection(),
42
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
43
+ onApply: () => undefined,
44
+ }),
45
+ { wrapper: makeWrapper() },
46
+ );
47
+
48
+ expect(result.current.value).toMatchObject({
49
+ logic: '$and',
50
+ items: [
51
+ { path: 'title', operator: '$includes', value: '' },
52
+ { path: 'type', operator: '$eq', value: undefined },
53
+ ],
54
+ });
55
+ });
56
+
57
+ it('reset restores defaultValue and emits its compiled filter', () => {
58
+ const onApply = vi.fn();
59
+ const { result } = renderHook(
60
+ () =>
61
+ useFilterActionProps({
62
+ collection: makeCollection(),
63
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
64
+ initialValue: { $and: [{ title: { $includes: 'abc' } }] },
65
+ onApply,
66
+ }),
67
+ { wrapper: makeWrapper() },
68
+ );
69
+
70
+ result.current.onReset();
71
+
72
+ expect(result.current.value).toMatchObject({
73
+ logic: '$and',
74
+ items: [
75
+ { path: 'title', operator: '$includes', value: '' },
76
+ { path: 'type', operator: '$eq', value: undefined },
77
+ ],
78
+ });
79
+ expect(onApply).toHaveBeenCalledWith(undefined, 'reset');
80
+ });
81
+
82
+ it('counts only effective compiled conditions, so empty default rows do not highlight the button', () => {
83
+ const { result } = renderHook(
84
+ () =>
85
+ useFilterActionProps({
86
+ collection: makeCollection(),
87
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
88
+ onApply: () => undefined,
89
+ }),
90
+ { wrapper: makeWrapper() },
91
+ );
92
+
93
+ expect(result.current.conditionCount).toBe(0);
94
+ });
95
+ });
@@ -11,5 +11,7 @@
11
11
  export { CollectionFilter } from './CollectionFilter';
12
12
  export type { CollectionFilterProps } from './CollectionFilter';
13
13
  export { CollectionFilterPanel } from './CollectionFilterPanel';
14
+ export { CollectionFilterItem } from './CollectionFilterItem';
15
+ export type { CollectionFilterItemValue } from './CollectionFilterItem';
14
16
  export type { CollectionFilterPanelProps, CollectionFilterPanelRef } from './CollectionFilterPanel';
15
17
  export type { CompiledFilter } from './useFilterActionProps';
@@ -43,6 +43,14 @@ const isCondition = (item: FilterGroupItem): item is CollectionFilterItemValue =
43
43
  typeof (item as CollectionFilterItemValue).path === 'string' &&
44
44
  Object.prototype.hasOwnProperty.call(item, 'operator');
45
45
 
46
+ const cloneFilterGroupItem = (item: FilterGroupItem): FilterGroupItem =>
47
+ isGroup(item) ? { logic: item.logic, items: item.items.map((child) => cloneFilterGroupItem(child)) } : { ...item };
48
+
49
+ const cloneFilterGroup = (group: FilterGroupValue): FilterGroupValue => ({
50
+ logic: group.logic,
51
+ items: group.items.map((item) => cloneFilterGroupItem(item)),
52
+ });
53
+
46
54
  /**
47
55
  * `true` when the rhs of a condition is "no real value yet" — covers `undefined` / `null` / empty string / empty array / empty plain object. Mirrors v1's `removeNullCondition` `isEmpty` predicate so half-filled rows ("Locked time → is → (no date picked yet)") get dropped on Submit instead of being sent to the server as `{lockedTs:{}}` and triggering a 500.
48
56
  */
@@ -164,6 +172,8 @@ export interface UseFilterActionPropsArgs extends UseFilterOptionsArgs {
164
172
  collection: Collection | undefined;
165
173
  /** Previously compiled filter param used to seed the editable filter group. */
166
174
  initialValue?: CompiledFilter;
175
+ /** Default compiled filter used both for initial empty state and Reset. */
176
+ defaultValue?: CompiledFilter;
167
177
  /**
168
178
  * Called when the user submits or resets the filter popover. Receives the compiled filter param (`undefined` when cleared) and which footer button triggered the call. Typical implementation: `(filter, action) => { listRequest.run(filter); if (action === 'submit') closePopover(); }`.
169
179
  */
@@ -216,12 +226,23 @@ export interface UseFilterActionPropsResult {
216
226
  * ```
217
227
  */
218
228
  export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterActionPropsResult {
219
- const { collection, initialValue, onApply, filterableFieldNames, nonfilterableFieldNames, noIgnore, t } = args;
229
+ const {
230
+ collection,
231
+ initialValue,
232
+ defaultValue,
233
+ onApply,
234
+ filterableFieldNames,
235
+ nonfilterableFieldNames,
236
+ noIgnore,
237
+ t,
238
+ } = args;
239
+ const seedValue = initialValue ?? defaultValue;
240
+ const defaultGroup = decompileFilterGroup(defaultValue) || createEmptyGroup();
220
241
 
221
242
  // Held in a ref so the group object identity is stable for the lifetime of the host component — `<FilterContent>` mutates this object directly (push/splice on `items`, swap `logic`), and a fresh observable on every render would reset that internal state.
222
243
  const valueRef = useRef<FilterGroupValue>();
223
244
  if (!valueRef.current) {
224
- valueRef.current = observable(decompileFilterGroup(initialValue) || createEmptyGroup()) as FilterGroupValue;
245
+ valueRef.current = observable(decompileFilterGroup(seedValue) || createEmptyGroup()) as FilterGroupValue;
225
246
  }
226
247
  const value = valueRef.current;
227
248
 
@@ -240,9 +261,10 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
240
261
  });
241
262
 
242
263
  const onReset = useMemoizedFn(() => {
243
- value.logic = '$and';
244
- value.items = [];
245
- onApply(undefined, 'reset');
264
+ const next = cloneFilterGroup(defaultGroup);
265
+ value.logic = next.logic;
266
+ value.items = next.items;
267
+ onApply(compileFilterGroup(value), 'reset');
246
268
  });
247
269
 
248
270
  const translate = useMemoizedFn((key: string) => (t ? t(key) : key));
@@ -261,7 +283,16 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
261
283
  );
262
284
 
263
285
  // Re-read on each render so `observer`-wrapped hosts re-render when the reactive `items` array length changes. No useMemo needed — the `value` object's identity is stable (held in a ref), but its observable `items.length` is what we actually care about, and the eslint exhaustive-deps rule rightly complains about depending on a mutable property of a stable ref.
264
- const conditionCount = value.items.length;
286
+ const conditionCount = (() => {
287
+ const compiled = compileFilterGroup(value);
288
+ if (compiled?.$and && Array.isArray(compiled.$and)) {
289
+ return compiled.$and.length;
290
+ }
291
+ if (compiled?.$or && Array.isArray(compiled.$or)) {
292
+ return compiled.$or.length;
293
+ }
294
+ return 0;
295
+ })();
265
296
 
266
297
  return { value, options, FilterItem, ctx, onSubmit, onReset, conditionCount };
267
298
  }
@@ -9,6 +9,7 @@
9
9
 
10
10
  export * from './AppComponents';
11
11
  export * from './BlankComponent';
12
+ export * from './category-tabs';
12
13
  export * from './form/table/dnd';
13
14
  export * from './form';
14
15
  export * from './Icon';
@@ -0,0 +1,76 @@
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
+ define,
12
+ observable,
13
+ type FlowModelContext,
14
+ type SubModelItem,
15
+ type SubModelItemsType,
16
+ } from '@nocobase/flow-engine';
17
+
18
+ export type EntryActionScope = 'action-panel' | 'app-switcher' | string;
19
+
20
+ export type EntryActionProvider = (ctx: FlowModelContext) => SubModelItem[] | Promise<SubModelItem[]>;
21
+
22
+ type ProviderRecord = {
23
+ name: string;
24
+ scope: EntryActionScope;
25
+ provider: EntryActionProvider;
26
+ sort: number;
27
+ };
28
+
29
+ export class EntryActionManager {
30
+ private readonly providers = new Map<string, ProviderRecord>();
31
+ revision = 0;
32
+
33
+ constructor() {
34
+ define(this, {
35
+ revision: observable.ref,
36
+ });
37
+ }
38
+
39
+ register(name: string, options: { scope: EntryActionScope; provider: EntryActionProvider; sort?: number }) {
40
+ this.providers.set(name, {
41
+ name,
42
+ scope: options.scope,
43
+ provider: options.provider,
44
+ sort: options.sort ?? 0,
45
+ });
46
+ this.invalidate();
47
+ }
48
+
49
+ unregister(name: string) {
50
+ this.providers.delete(name);
51
+ this.invalidate();
52
+ }
53
+
54
+ invalidate() {
55
+ this.revision += 1;
56
+ }
57
+
58
+ getItems(scope: EntryActionScope): SubModelItemsType {
59
+ return async (ctx) => {
60
+ const providers = [...this.providers.values()]
61
+ .filter((item) => item.scope === scope)
62
+ .sort((a, b) => a.sort - b.sort);
63
+ const groups = await Promise.all(
64
+ providers.map(async (item) => {
65
+ try {
66
+ return await item.provider(ctx);
67
+ } catch (error) {
68
+ console.error(`[NocoBase] Failed to load entry action provider "${item.name}".`, error);
69
+ return [];
70
+ }
71
+ }),
72
+ );
73
+ return groups.flat();
74
+ };
75
+ }
76
+ }
@@ -0,0 +1,10 @@
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
+ export * from './EntryActionManager';
@@ -14,7 +14,7 @@ import {
14
14
  useFlowModelById,
15
15
  useFlowViewContext,
16
16
  } from '@nocobase/flow-engine';
17
- import type { FlowModel, FlowModelRendererProps, ModelConstructor } from '@nocobase/flow-engine';
17
+ import type { FlowEngineContext, FlowModel, FlowModelRendererProps, ModelConstructor } from '@nocobase/flow-engine';
18
18
  import { useRequest } from 'ahooks';
19
19
  import React from 'react';
20
20
  import FlowRoute from './components/FlowRoute';
@@ -57,10 +57,38 @@ type FlowPageProps = {
57
57
  showFlowSettings?: FlowModelRendererProps['showFlowSettings'];
58
58
  };
59
59
 
60
+ type FlowPageViewContext = FlowEngineContext & {
61
+ view?: {
62
+ inputArgs?: {
63
+ filterByTk?: unknown;
64
+ isMobileLayout?: unknown;
65
+ sourceId?: unknown;
66
+ };
67
+ };
68
+ };
69
+
70
+ const bindViewLayoutState = (model: FlowModel, ctx?: FlowPageViewContext | null) => {
71
+ const hasViewMobileLayout = typeof ctx?.view?.inputArgs?.isMobileLayout === 'boolean';
72
+ const hasContextMobileLayout = typeof ctx?.isMobileLayout === 'boolean';
73
+ if (!hasViewMobileLayout && !hasContextMobileLayout) {
74
+ return;
75
+ }
76
+
77
+ model.context.defineProperty('isMobileLayout', {
78
+ get: () => {
79
+ if (typeof ctx?.isMobileLayout === 'boolean') {
80
+ return ctx.isMobileLayout;
81
+ }
82
+ return !!ctx?.view?.inputArgs?.isMobileLayout;
83
+ },
84
+ cache: false,
85
+ });
86
+ };
87
+
60
88
  export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknown>) => {
61
89
  const { pageModelClass = 'ChildPageModel', parentId, onModelLoaded, defaultTabTitle, ...rest } = props;
62
90
  const flowEngine = useFlowEngine();
63
- const ctx = useFlowViewContext();
91
+ const ctx = useFlowViewContext<FlowPageViewContext>();
64
92
  const { loading, data, error } = useRequest(
65
93
  async () => {
66
94
  const ModelClass = await flowEngine.getModelClassAsync(pageModelClass);
@@ -76,6 +104,10 @@ export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknow
76
104
  subType: 'object',
77
105
  use: pageModelClass,
78
106
  };
107
+ const isRuntimeRecordScopedPage =
108
+ !flowEngine.context.flowSettingsEnabled &&
109
+ (typeof ctx?.view?.inputArgs?.filterByTk !== 'undefined' ||
110
+ typeof ctx?.view?.inputArgs?.sourceId !== 'undefined');
79
111
  if (shouldInjectDefaultChildTab) {
80
112
  const tabTitle = defaultTabTitle || flowEngine.translate?.('Details');
81
113
  options['subModels'] = {
@@ -102,9 +134,12 @@ export const FlowPage = React.memo((props: FlowPageProps & Record<string, unknow
102
134
  },
103
135
  };
104
136
  }
105
- const data = await flowEngine.loadOrCreateModel(options, { skipSave: !flowEngine.context.flowSettingsEnabled });
137
+ const data =
138
+ (isRuntimeRecordScopedPage && (await flowEngine.loadModel({ ...options, refresh: true }))) ||
139
+ (await flowEngine.loadOrCreateModel(options, { skipSave: !flowEngine.context.flowSettingsEnabled }));
106
140
  if (data?.uid && onModelLoaded) {
107
141
  data.context.addDelegate(ctx);
142
+ bindViewLayoutState(data, ctx);
108
143
  data.removeParentDelegate();
109
144
  onModelLoaded(data.uid, data);
110
145
  }
@@ -7,44 +7,115 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import { render } from '@testing-library/react';
10
+ import { render, waitFor } from '@testing-library/react';
11
11
  import React from 'react';
12
- import { afterEach, describe, expect, it, vi } from 'vitest';
12
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
13
13
  import { FlowPage } from '../FlowPage';
14
14
 
15
- const mocks = vi.hoisted(() => ({
16
- rendererProps: undefined as any,
17
- model: {
15
+ type TestContextProperty = {
16
+ value?: unknown;
17
+ get?: () => unknown;
18
+ };
19
+
20
+ type TestModelContext = {
21
+ isMobileLayout: boolean;
22
+ themeToken: {
23
+ marginBlock: number;
24
+ };
25
+ addDelegate: ReturnType<typeof vi.fn>;
26
+ defineProperty: ReturnType<typeof vi.fn>;
27
+ };
28
+
29
+ type TestPageModel = {
30
+ uid: string;
31
+ props: {
32
+ showFlowSettings: boolean;
33
+ };
34
+ context: TestModelContext;
35
+ removeParentDelegate: ReturnType<typeof vi.fn>;
36
+ };
37
+
38
+ type RendererProps = {
39
+ model?: TestPageModel;
40
+ showFlowSettings?: boolean;
41
+ } & Record<string, unknown>;
42
+
43
+ const defineContextProperty = (context: TestModelContext, key: string, property: TestContextProperty) => {
44
+ Object.defineProperty(context, key, {
45
+ configurable: true,
46
+ enumerable: true,
47
+ get: property.get || (() => property.value),
48
+ });
49
+ };
50
+
51
+ const createPageModel = (): TestPageModel => {
52
+ const context = {
53
+ isMobileLayout: false,
54
+ themeToken: {
55
+ marginBlock: 16,
56
+ },
57
+ addDelegate: vi.fn(),
58
+ defineProperty: vi.fn((key: string, property: TestContextProperty) => {
59
+ defineContextProperty(context, key, property);
60
+ }),
61
+ };
62
+
63
+ return {
18
64
  uid: 'public-form-page',
19
65
  props: {
20
66
  showFlowSettings: false,
21
67
  },
22
- context: {
23
- isMobileLayout: false,
24
- themeToken: {
25
- marginBlock: 16,
26
- },
27
- },
28
- },
68
+ context,
69
+ removeParentDelegate: vi.fn(),
70
+ };
71
+ };
72
+
73
+ const mocks = vi.hoisted(() => ({
74
+ flowSettingsEnabled: false,
75
+ loadModel: vi.fn(),
76
+ loadOrCreateModel: vi.fn(),
77
+ rendererMobileStates: [] as boolean[],
78
+ rendererProps: undefined as RendererProps | undefined,
79
+ model: undefined as TestPageModel | undefined,
80
+ viewFilterByTk: undefined as unknown,
81
+ viewInputMobileLayout: true as boolean | undefined,
82
+ viewSourceId: undefined as unknown,
83
+ contextMobileLayout: undefined as boolean | undefined,
29
84
  }));
30
85
 
31
86
  vi.mock('@nocobase/flow-engine', async () => {
32
- const actual = await vi.importActual<any>('@nocobase/flow-engine');
87
+ const actual = await vi.importActual<typeof import('@nocobase/flow-engine')>('@nocobase/flow-engine');
33
88
  const ReactModule = await import('react');
89
+ class TestPageModelClass {}
34
90
 
35
91
  return {
36
92
  ...actual,
37
- FlowModelRenderer: vi.fn((props: any) => {
93
+ FlowModelRenderer: vi.fn((props: RendererProps) => {
38
94
  mocks.rendererProps = props;
95
+ if (typeof props.model?.context.isMobileLayout === 'boolean') {
96
+ mocks.rendererMobileStates.push(props.model.context.isMobileLayout);
97
+ }
39
98
  return ReactModule.createElement('div', { 'data-testid': 'flow-model-renderer' });
40
99
  }),
41
100
  useFlowEngine: vi.fn(() => ({
42
- getModelClassAsync: vi.fn(),
43
- loadOrCreateModel: vi.fn(),
44
- context: {},
101
+ getModelClassAsync: vi.fn(async () => TestPageModelClass),
102
+ loadModel: mocks.loadModel,
103
+ loadOrCreateModel: mocks.loadOrCreateModel,
104
+ context: {
105
+ flowSettingsEnabled: mocks.flowSettingsEnabled,
106
+ },
107
+ translate: vi.fn((value: string) => value),
45
108
  })),
46
109
  useFlowModelById: vi.fn(() => mocks.model),
47
110
  useFlowViewContext: vi.fn(() => ({
111
+ view: {
112
+ inputArgs: {
113
+ ...(typeof mocks.viewFilterByTk !== 'undefined' ? { filterByTk: mocks.viewFilterByTk } : {}),
114
+ ...(typeof mocks.viewInputMobileLayout === 'boolean' ? { isMobileLayout: mocks.viewInputMobileLayout } : {}),
115
+ ...(typeof mocks.viewSourceId !== 'undefined' ? { sourceId: mocks.viewSourceId } : {}),
116
+ },
117
+ },
118
+ ...(typeof mocks.contextMobileLayout === 'boolean' ? { isMobileLayout: mocks.contextMobileLayout } : {}),
48
119
  themeToken: {
49
120
  marginBlock: 16,
50
121
  },
@@ -53,27 +124,130 @@ vi.mock('@nocobase/flow-engine', async () => {
53
124
  });
54
125
 
55
126
  vi.mock('ahooks', async () => {
56
- const actual = await vi.importActual<any>('ahooks');
127
+ const actual = await vi.importActual<typeof import('ahooks')>('ahooks');
128
+ const ReactModule = await import('react');
57
129
  return {
58
130
  ...actual,
59
- useRequest: vi.fn(() => ({
60
- loading: false,
61
- data: {
62
- uid: 'public-form-page',
63
- },
64
- error: null,
65
- })),
131
+ useRequest: vi.fn((service: () => Promise<unknown>) => {
132
+ const serviceRef = ReactModule.useRef(service);
133
+ const [state, setState] = ReactModule.useState<{
134
+ loading: boolean;
135
+ data?: unknown;
136
+ error?: unknown;
137
+ }>({
138
+ loading: true,
139
+ });
140
+
141
+ ReactModule.useEffect(() => {
142
+ let active = true;
143
+ serviceRef
144
+ .current()
145
+ .then((data) => {
146
+ if (active) {
147
+ setState({ loading: false, data, error: null });
148
+ }
149
+ })
150
+ .catch((error) => {
151
+ if (active) {
152
+ setState({ loading: false, data: undefined, error });
153
+ }
154
+ });
155
+
156
+ return () => {
157
+ active = false;
158
+ };
159
+ }, []);
160
+
161
+ return state;
162
+ }),
66
163
  };
67
164
  });
68
165
 
69
166
  describe('FlowPage', () => {
167
+ beforeEach(() => {
168
+ mocks.loadModel.mockImplementation(async () => null);
169
+ mocks.loadOrCreateModel.mockImplementation(async () => mocks.model);
170
+ });
171
+
70
172
  afterEach(() => {
173
+ mocks.flowSettingsEnabled = false;
174
+ mocks.loadModel.mockReset();
175
+ mocks.loadOrCreateModel.mockReset();
176
+ mocks.rendererMobileStates = [];
71
177
  mocks.rendererProps = undefined;
178
+ mocks.model = undefined;
179
+ mocks.viewFilterByTk = undefined;
180
+ mocks.viewInputMobileLayout = true;
181
+ mocks.viewSourceId = undefined;
182
+ mocks.contextMobileLayout = undefined;
72
183
  });
73
184
 
74
- it('uses showFlowSettings from page model props', () => {
185
+ it('uses showFlowSettings from page model props', async () => {
186
+ mocks.model = createPageModel();
75
187
  render(<FlowPage />);
76
188
 
77
- expect(mocks.rendererProps?.showFlowSettings).toBe(false);
189
+ await waitFor(() => {
190
+ expect((mocks.rendererProps as { showFlowSettings?: boolean } | undefined)?.showFlowSettings).toBe(false);
191
+ });
192
+ });
193
+
194
+ it('exposes mobile layout state from route-managed view inputArgs before first render', async () => {
195
+ mocks.model = createPageModel();
196
+ render(<FlowPage onModelLoaded={vi.fn()} />);
197
+
198
+ await waitFor(() => {
199
+ expect(mocks.rendererMobileStates.length).toBeGreaterThan(0);
200
+ });
201
+ expect(mocks.rendererMobileStates[0]).toBe(true);
202
+ });
203
+
204
+ it.each([
205
+ { viewInputMobileLayout: true, contextMobileLayout: false, expected: false },
206
+ { viewInputMobileLayout: false, contextMobileLayout: true, expected: true },
207
+ { viewInputMobileLayout: undefined, contextMobileLayout: true, expected: true },
208
+ { viewInputMobileLayout: undefined, contextMobileLayout: false, expected: false },
209
+ { viewInputMobileLayout: true, contextMobileLayout: undefined, expected: true },
210
+ { viewInputMobileLayout: false, contextMobileLayout: undefined, expected: false },
211
+ ])(
212
+ 'resolves mobile layout state from view input args and layout context %#',
213
+ async ({ viewInputMobileLayout, contextMobileLayout, expected }) => {
214
+ mocks.viewInputMobileLayout = viewInputMobileLayout;
215
+ mocks.contextMobileLayout = contextMobileLayout;
216
+ mocks.model = createPageModel();
217
+
218
+ render(<FlowPage onModelLoaded={vi.fn()} />);
219
+
220
+ await waitFor(() => {
221
+ expect(mocks.rendererMobileStates.length).toBeGreaterThan(0);
222
+ });
223
+ expect(mocks.rendererMobileStates[0]).toBe(expected);
224
+ },
225
+ );
226
+
227
+ it('reloads runtime page models for record scoped views', async () => {
228
+ mocks.model = createPageModel();
229
+ mocks.viewFilterByTk = 1;
230
+ mocks.loadModel.mockImplementation(async () => mocks.model);
231
+
232
+ render(<FlowPage onModelLoaded={vi.fn()} />);
233
+
234
+ await waitFor(() => {
235
+ expect(mocks.loadModel).toHaveBeenCalled();
236
+ });
237
+ expect(mocks.loadModel.mock.calls[0]?.[0]).toMatchObject({ refresh: true });
238
+ expect(mocks.loadOrCreateModel).not.toHaveBeenCalled();
239
+ });
240
+
241
+ it('keeps configured page model cache behavior in flow settings mode', async () => {
242
+ mocks.flowSettingsEnabled = true;
243
+ mocks.model = createPageModel();
244
+ mocks.viewFilterByTk = 1;
245
+
246
+ render(<FlowPage onModelLoaded={vi.fn()} />);
247
+
248
+ await waitFor(() => {
249
+ expect(mocks.loadOrCreateModel).toHaveBeenCalled();
250
+ });
251
+ expect(mocks.loadModel).not.toHaveBeenCalled();
78
252
  });
79
253
  });