@nocobase/client-v2 2.1.0-alpha.30 → 2.1.0-alpha.32

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 (103) hide show
  1. package/es/components/form/JsonTextArea.d.ts +18 -0
  2. package/es/components/index.d.ts +1 -0
  3. package/es/flow/actions/dateRangeLimit.d.ts +9 -0
  4. package/es/flow/actions/index.d.ts +1 -0
  5. package/es/flow/actions/linkageRulesFormValueRefresh.d.ts +10 -0
  6. package/es/flow/index.d.ts +1 -0
  7. package/es/flow/models/actions/AssociateActionModel.d.ts +19 -0
  8. package/es/flow/models/actions/AssociationActionUtils.d.ts +17 -0
  9. package/es/flow/models/actions/DisassociateActionModel.d.ts +16 -0
  10. package/es/flow/models/actions/index.d.ts +3 -0
  11. package/es/flow/models/base/GridModel.d.ts +3 -1
  12. package/es/flow/models/base/PageModel/PageModel.d.ts +4 -0
  13. package/es/flow/models/base/PageModel/RootPageModel.d.ts +9 -0
  14. package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +15 -6
  15. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +7 -0
  16. package/es/flow/models/blocks/shared/filterOperators.d.ts +9 -0
  17. package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +3 -0
  18. package/es/flow/models/fields/AssociationFieldModel/recordSelectSettingsUtils.d.ts +9 -0
  19. package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +20 -0
  20. package/es/flow/models/fields/JSEditableFieldModel.d.ts +4 -0
  21. package/es/flow-compat/data.d.ts +9 -2
  22. package/es/flow-compat/index.d.ts +1 -1
  23. package/es/index.d.ts +1 -0
  24. package/es/index.mjs +100 -93
  25. package/lib/index.js +101 -94
  26. package/package.json +6 -5
  27. package/src/BaseApplication.tsx +1 -1
  28. package/src/__tests__/app.test.tsx +23 -6
  29. package/src/__tests__/globalDeps.test.ts +5 -0
  30. package/src/components/form/JsonTextArea.tsx +129 -0
  31. package/src/components/index.ts +1 -0
  32. package/src/flow/actions/__tests__/fieldLinkageRules.scopeDepth.test.ts +478 -0
  33. package/src/flow/actions/__tests__/linkageRules.formValueDrivenRefresh.test.ts +438 -0
  34. package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +42 -0
  35. package/src/flow/actions/__tests__/pattern.test.ts +190 -0
  36. package/src/flow/actions/dateRangeLimit.tsx +66 -0
  37. package/src/flow/actions/index.ts +1 -0
  38. package/src/flow/actions/linkageRules.tsx +119 -14
  39. package/src/flow/actions/linkageRulesFormValueRefresh.ts +492 -0
  40. package/src/flow/actions/linkageRulesRefresh.tsx +4 -2
  41. package/src/flow/actions/openView.tsx +2 -1
  42. package/src/flow/actions/pattern.tsx +25 -2
  43. package/src/flow/actions/titleField.tsx +8 -3
  44. package/src/flow/admin-shell/AdminLayoutRouteCoordinator.ts +7 -1
  45. package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +117 -0
  46. package/src/flow/components/FieldAssignValueInput.tsx +1 -0
  47. package/src/flow/components/filter/LinkageFilterItem.tsx +6 -5
  48. package/src/flow/components/filter/VariableFilterItem.tsx +14 -13
  49. package/src/flow/components/filter/__tests__/LinkageFilterItem.test.tsx +33 -0
  50. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +48 -5
  51. package/src/flow/index.ts +1 -0
  52. package/src/flow/internal/utils/__tests__/titleFieldQuickSync.test.ts +1 -0
  53. package/src/flow/internal/utils/titleFieldQuickSync.ts +2 -2
  54. package/src/flow/models/actions/AssociateActionModel.tsx +196 -0
  55. package/src/flow/models/actions/AssociationActionUtils.ts +90 -0
  56. package/src/flow/models/actions/DisassociateActionModel.tsx +57 -0
  57. package/src/flow/models/actions/FilterActionModel.tsx +17 -9
  58. package/src/flow/models/actions/__tests__/AssociationActionModel.test.ts +250 -0
  59. package/src/flow/models/actions/index.ts +3 -0
  60. package/src/flow/models/base/GridModel.tsx +21 -1
  61. package/src/flow/models/base/PageModel/PageModel.tsx +15 -3
  62. package/src/flow/models/base/PageModel/RootPageModel.tsx +37 -2
  63. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +73 -0
  64. package/src/flow/models/base/PageModel/__tests__/RootPageModel.test.ts +116 -0
  65. package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +98 -0
  66. package/src/flow/models/blocks/details/DetailsItemModel.tsx +3 -0
  67. package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +200 -36
  68. package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +270 -1
  69. package/src/flow/models/blocks/filter-form/__tests__/customFieldOperators.test.tsx +23 -0
  70. package/src/flow/models/blocks/filter-form/customFieldOperators.ts +12 -1
  71. package/src/flow/models/blocks/filter-form/fields/FieldComponentProps.tsx +22 -8
  72. package/src/flow/models/blocks/filter-form/fields/__tests__/FilterFormCustomFieldModel.recordSelect.test.tsx +18 -0
  73. package/src/flow/models/blocks/filter-manager/FilterManager.ts +51 -1
  74. package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +75 -0
  75. package/src/flow/models/blocks/form/FormItemModel.tsx +48 -28
  76. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +167 -1
  77. package/src/flow/models/blocks/form/value-runtime/runtime.ts +103 -11
  78. package/src/flow/models/blocks/shared/filterOperators.ts +14 -0
  79. package/src/flow/models/blocks/table/TableBlockModel.tsx +19 -3
  80. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +5 -1
  81. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +48 -8
  82. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +47 -0
  83. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +42 -0
  84. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableField.refresh.test.tsx +122 -0
  85. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +2 -0
  86. package/src/flow/models/fields/AssociationFieldModel/recordSelectSettingsUtils.ts +20 -0
  87. package/src/flow/models/fields/ClickableFieldModel.tsx +21 -9
  88. package/src/flow/models/fields/DateTimeFieldModel/DateOnlyFieldModel.tsx +9 -0
  89. package/src/flow/models/fields/DateTimeFieldModel/DateTimeFieldModel.tsx +4 -0
  90. package/src/flow/models/fields/DateTimeFieldModel/DateTimeNoTzFieldModel.tsx +9 -0
  91. package/src/flow/models/fields/DateTimeFieldModel/DateTimeTzFieldModel.tsx +9 -0
  92. package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +242 -0
  93. package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +152 -0
  94. package/src/flow/models/fields/DividerItemModel.tsx +30 -15
  95. package/src/flow/models/fields/JSEditableFieldModel.tsx +110 -14
  96. package/src/flow/models/fields/__tests__/ClickableFieldModel.test.ts +87 -0
  97. package/src/flow/models/fields/__tests__/JSEditableFieldModel.test.tsx +210 -0
  98. package/src/flow/models/fields/mobile-components/MobileSelect.tsx +11 -3
  99. package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +235 -0
  100. package/src/flow-compat/data.ts +25 -3
  101. package/src/flow-compat/index.ts +7 -1
  102. package/src/index.ts +1 -0
  103. package/src/utils/globalDeps.ts +6 -0
@@ -0,0 +1,117 @@
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 } from '@nocobase/flow-engine';
11
+ import { describe, expect, it, vi, beforeEach } from 'vitest';
12
+ import { getViewDiffAndUpdateHidden } from '../../getViewDiffAndUpdateHidden';
13
+ import { getOpenViewStepParams } from '../../flows/openViewFlow';
14
+ import { resolveViewParamsToViewList } from '../../resolveViewParamsToViewList';
15
+ import { AdminLayoutRouteCoordinator } from '../AdminLayoutRouteCoordinator';
16
+ import { RouteModel } from '../../models/base/RouteModel';
17
+
18
+ vi.mock('../../resolveViewParamsToViewList', () => ({
19
+ resolveViewParamsToViewList: vi.fn(),
20
+ updateViewListHidden: vi.fn(),
21
+ }));
22
+
23
+ vi.mock('../../getViewDiffAndUpdateHidden', () => ({
24
+ getViewDiffAndUpdateHidden: vi.fn(),
25
+ getKey: vi.fn((viewItem) => viewItem.params.viewUid),
26
+ }));
27
+
28
+ vi.mock('../../flows/openViewFlow', async (importOriginal) => {
29
+ const actual = await importOriginal();
30
+ return {
31
+ ...(actual as any),
32
+ getOpenViewStepParams: vi.fn(),
33
+ };
34
+ });
35
+
36
+ const mockResolveViewParamsToViewList = vi.mocked(resolveViewParamsToViewList);
37
+ const mockGetViewDiffAndUpdateHidden = vi.mocked(getViewDiffAndUpdateHidden);
38
+ const mockGetOpenViewStepParams = vi.mocked(getOpenViewStepParams);
39
+
40
+ function setupRouteReplay(viewParams: Record<string, any>) {
41
+ const engine = new FlowEngine();
42
+ engine.registerModels({ RouteModel });
43
+ engine.context.defineProperty('route', {
44
+ value: {
45
+ params: { name: 'test-route' },
46
+ pathname: '/admin/popup/filterbytk/member',
47
+ },
48
+ });
49
+ engine.context.defineProperty('routeRepository', {
50
+ value: {
51
+ getRouteBySchemaUid: vi.fn(() => ({})),
52
+ },
53
+ });
54
+
55
+ const dispatchEvent = vi.fn(() => Promise.resolve());
56
+ const viewItem = {
57
+ params: {
58
+ viewUid: 'popup',
59
+ filterByTk: 'member',
60
+ ...viewParams,
61
+ },
62
+ modelUid: 'popup',
63
+ model: { uid: 'popup', dispatchEvent } as any,
64
+ hidden: { value: false },
65
+ index: 0,
66
+ };
67
+
68
+ mockResolveViewParamsToViewList.mockReturnValue([viewItem]);
69
+ mockGetViewDiffAndUpdateHidden.mockReturnValue({
70
+ viewsToClose: [],
71
+ viewsToOpen: [viewItem],
72
+ });
73
+ mockGetOpenViewStepParams.mockReturnValue({
74
+ collectionName: 'roles',
75
+ associationName: 'users.roles',
76
+ dataSourceKey: 'main',
77
+ } as any);
78
+
79
+ const coordinator = new AdminLayoutRouteCoordinator(engine);
80
+ coordinator.registerPage('test-route', {
81
+ active: true,
82
+ layoutContentElement: document.createElement('div'),
83
+ });
84
+
85
+ return { dispatchEvent };
86
+ }
87
+
88
+ describe('AdminLayoutRouteCoordinator', () => {
89
+ beforeEach(() => {
90
+ vi.clearAllMocks();
91
+ });
92
+
93
+ it('drops configured associationName during route replay when sourceId is absent', () => {
94
+ const { dispatchEvent } = setupRouteReplay({});
95
+
96
+ expect(dispatchEvent.mock.calls[0][1]).toMatchObject({
97
+ collectionName: 'roles',
98
+ associationName: null,
99
+ dataSourceKey: 'main',
100
+ filterByTk: 'member',
101
+ triggerByRouter: true,
102
+ });
103
+ });
104
+
105
+ it('keeps configured associationName during route replay when sourceId is present', () => {
106
+ const { dispatchEvent } = setupRouteReplay({ sourceId: '1' });
107
+
108
+ expect(dispatchEvent.mock.calls[0][1]).toMatchObject({
109
+ collectionName: 'roles',
110
+ associationName: 'users.roles',
111
+ dataSourceKey: 'main',
112
+ filterByTk: 'member',
113
+ sourceId: '1',
114
+ triggerByRouter: true,
115
+ });
116
+ });
117
+ });
@@ -485,6 +485,7 @@ type AssignValueFieldSource = {
485
485
  const ASSIGN_VALUE_IGNORED_PROP_KEYS = new Set([
486
486
  'value',
487
487
  'defaultValue',
488
+ 'hidden',
488
489
  'onChange',
489
490
  'onClick',
490
491
  'open',
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
- import { lazy } from '../../../flow-compat';
11
+ import { getFlowFieldInterfaceOptions, lazy } from '../../../flow-compat';
12
12
  import { Input, InputNumber, Select, Space, Switch } from 'antd';
13
13
  import merge from 'lodash/merge';
14
14
  import uniqBy from 'lodash/uniqBy';
@@ -227,11 +227,12 @@ export const LinkageFilterItem: React.FC<LinkageFilterItemProps> = observer((pro
227
227
 
228
228
  const operatorMetadataList: OperatorMeta[] = useMemo(() => {
229
229
  if (leftFieldMeta) {
230
- const dataSourceManager = model.context.app.dataSourceManager;
231
230
  const fieldInterface = leftFieldMeta.interface
232
- ? (dataSourceManager.collectionFieldInterfaceManager.getFieldInterface(
231
+ ? (getFlowFieldInterfaceOptions(
233
232
  leftFieldMeta.interface,
234
- ) as FieldInterfaceDef)
233
+ model.context.dataSourceManager,
234
+ model.context.app?.dataSourceManager,
235
+ ) as FieldInterfaceDef | undefined)
235
236
  : undefined;
236
237
  const schemaOperators = (leftFieldMeta as any)?.uiSchema?.['x-filter-operators'] as
237
238
  | Array<OperatorMeta & { visible?: (meta: MetaTreeNode) => boolean }>
@@ -392,7 +393,7 @@ export const LinkageFilterItem: React.FC<LinkageFilterItemProps> = observer((pro
392
393
  const base = Array.isArray(tree) ? tree : [];
393
394
  const merged = mergeExtraMetaTreeWithBase(base, extraMetaTree);
394
395
  const getFieldInterface = (name: string) =>
395
- model.context.app?.dataSourceManager?.collectionFieldInterfaceManager?.getFieldInterface?.(name) as
396
+ getFlowFieldInterfaceOptions(name, model.context.dataSourceManager, model.context.app?.dataSourceManager) as
396
397
  | FieldInterfaceDef
397
398
  | undefined;
398
399
  return await enhanceMetaTreeWithFilterableChildren(merged, getFieldInterface);
@@ -9,7 +9,7 @@
9
9
 
10
10
  import React, { useState, useMemo, useCallback, useEffect } from 'react';
11
11
  import { Cascader, Checkbox, Input, InputNumber, Radio, Select, Space, Switch } from 'antd';
12
- import { lazy } from '../../../flow-compat';
12
+ import { getFlowFieldInterfaceOptions, lazy } from '../../../flow-compat';
13
13
  import merge from 'lodash/merge';
14
14
  import type { ISchema } from '@formily/json-schema';
15
15
  import {
@@ -286,18 +286,24 @@ export const VariableFilterItem: React.FC<VariableFilterItemProps> = observer(
286
286
  children?: Array<{ name: string; title?: string; schema?: ISchema; operators?: OperatorMeta[] }>;
287
287
  };
288
288
  };
289
+ const getFieldInterface = useCallback(
290
+ (interfaceName: string | undefined) =>
291
+ getFlowFieldInterfaceOptions(
292
+ interfaceName,
293
+ model.context.dataSourceManager,
294
+ model.context.app?.dataSourceManager,
295
+ ) as FieldInterfaceDef | undefined,
296
+ [model],
297
+ );
289
298
 
290
299
  // 基于字段接口的动态操作符元数据(优先使用子菜单 schema 中自定义的 operators,其次再用接口默认 operators)
291
300
  const operatorMetaList: OperatorMeta[] = useMemo(() => {
292
301
  if (!leftMeta) return [];
293
- const dm = model.context.app?.dataSourceManager;
294
- const fi = leftMeta.interface
295
- ? (dm?.collectionFieldInterfaceManager?.getFieldInterface(leftMeta.interface) as FieldInterfaceDef | undefined)
296
- : undefined;
302
+ const fi = leftMeta.interface ? getFieldInterface(leftMeta.interface) : undefined;
297
303
  const schemaOps: OperatorMeta[] | undefined = (leftMeta as any)?.uiSchema?.['x-filter-operators'];
298
304
  const baseOps = (Array.isArray(schemaOps) && schemaOps.length ? schemaOps : fi?.filterable?.operators) || [];
299
305
  return baseOps.filter((op) => !op.visible || op.visible(leftMeta));
300
- }, [leftMeta, model]);
306
+ }, [getFieldInterface, leftMeta]);
301
307
 
302
308
  useEffect(() => {
303
309
  if (!operatorMetaList.length) return;
@@ -578,16 +584,11 @@ export const VariableFilterItem: React.FC<VariableFilterItemProps> = observer(
578
584
  const enhancedMetaTree = useMemo(() => {
579
585
  type MetaTreeProvider = () => MetaTreeNode[] | Promise<MetaTreeNode[]>;
580
586
  return async () => {
581
- const dm = model.context.app?.dataSourceManager;
582
- const fiMgr = dm?.collectionFieldInterfaceManager;
583
-
584
587
  // 优先复用已注入 meta;否则在本组件范围内临时构建
585
588
  const nodes: MetaTreeNode[] = await buildCollectionLeftMetaTreeLocal(model.context);
586
589
 
587
590
  const enhanceNode = async (node: MetaTreeNode): Promise<MetaTreeNode> => {
588
- const fi = node.interface
589
- ? (fiMgr?.getFieldInterface(node.interface) as FieldInterfaceDef | undefined)
590
- : undefined;
591
+ const fi = node.interface ? getFieldInterface(node.interface) : undefined;
591
592
  const extraChildren: MetaTreeNode[] = [];
592
593
  const filterable = fi?.filterable;
593
594
  const childrenDefs = filterable?.children as
@@ -634,7 +635,7 @@ export const VariableFilterItem: React.FC<VariableFilterItemProps> = observer(
634
635
  }
635
636
  return out;
636
637
  };
637
- }, [model]);
638
+ }, [getFieldInterface, model]);
638
639
 
639
640
  return (
640
641
  <Space wrap style={{ width: '100%' }}>
@@ -110,6 +110,39 @@ describe('LinkageFilterItem', () => {
110
110
  expect(screen.queryByText('[object Object]')).toBeNull();
111
111
  });
112
112
 
113
+ it('uses scoped context dataSourceManager when app dataSourceManager has no field interface manager', async () => {
114
+ const value = observable({ path: '', operator: '', value: '' }) as any;
115
+ const { model, app } = createModel();
116
+ const getRuntimeFieldInterface = vi.fn((name: string) => ({
117
+ name,
118
+ filterable: {
119
+ operators: [{ value: '$eq', label: 'Equals', selected: true }],
120
+ },
121
+ }));
122
+ model.context.dataSourceManager.setCollectionFieldInterfaceManager({
123
+ getFieldInterface: getRuntimeFieldInterface,
124
+ });
125
+ (app as any).dataSourceManager = {};
126
+
127
+ (globalThis as any).__TEST_PATH__ = 'assignee';
128
+ (globalThis as any).__TEST_META__ = {
129
+ interface: 'belongsTo',
130
+ uiSchema: { 'x-component': 'RecordPicker' },
131
+ paths: ['collection', 'assignee'],
132
+ name: 'assignee',
133
+ title: 'Assignee',
134
+ type: 'object',
135
+ };
136
+
137
+ render(<LinkageFilterItem value={value} model={model} />);
138
+ fireEvent.click(screen.getByTestId('variable-input'));
139
+
140
+ await waitFor(() => {
141
+ expect(value.operator).toBe('$eq');
142
+ expect(getRuntimeFieldInterface).toHaveBeenCalledWith('belongsTo');
143
+ });
144
+ });
145
+
113
146
  it('renders operator schema component for multi-keyword constants', async () => {
114
147
  const value = observable({ path: '', operator: '', value: 'foo\nbar' }) as any;
115
148
  const { model, app } = createModel();
@@ -121,6 +121,8 @@ describe('VariableFilterItem', () => {
121
121
  // Ensure document body for antd portals if needed
122
122
  document.body.innerHTML = '';
123
123
  delete (globalThis as any).__LAST_VARIABLE_INPUT_PROPS__;
124
+ delete (globalThis as any).__TEST_PATH__;
125
+ delete (globalThis as any).__TEST_META__;
124
126
  });
125
127
 
126
128
  it('returns undefined path for empty left value in converter', () => {
@@ -153,9 +155,53 @@ describe('VariableFilterItem', () => {
153
155
  expect(value.value).toBe('abc');
154
156
  });
155
157
 
158
+ it('uses scoped context dataSourceManager when app dataSourceManager has no field interface manager', async () => {
159
+ const value = observable({ path: '', operator: '', value: '' }) as any;
160
+ const model = CreateModel();
161
+ const getRuntimeFieldInterface = vi.fn((name: string) => ({
162
+ name,
163
+ filterable: {
164
+ operators: [{ value: '$eq', label: 'Equals' }],
165
+ children: [
166
+ {
167
+ name: 'runtimeChild',
168
+ title: 'Runtime child',
169
+ schema: { 'x-component': 'Input' },
170
+ operators: [{ value: '$includes', label: 'contains' }],
171
+ },
172
+ ],
173
+ },
174
+ }));
175
+
176
+ model.context.dataSourceManager.setCollectionFieldInterfaceManager({
177
+ getFieldInterface: getRuntimeFieldInterface,
178
+ });
179
+ (model.context.app as any).dataSourceManager = {};
180
+ (globalThis as any).__TEST_PATH__ = 'assignee';
181
+ (globalThis as any).__TEST_META__ = {
182
+ interface: 'belongsTo',
183
+ uiSchema: { 'x-component': 'RecordPicker' },
184
+ paths: ['collection', 'assignee'],
185
+ name: 'assignee',
186
+ title: 'Assignee',
187
+ type: 'object',
188
+ };
189
+
190
+ render(<VariableFilterItem value={value} model={model} rightAsVariable={false} />);
191
+ const leftVariableInputProps = (globalThis as any).__LAST_VARIABLE_INPUT_PROPS__;
192
+ const metaTree = await leftVariableInputProps.metaTree();
193
+ const nameNode = metaTree.find((node: any) => node.name === 'name');
194
+ expect(nameNode?.children?.some((child: any) => child.name === 'runtimeChild')).toBe(true);
195
+
196
+ fireEvent.click(screen.getByTestId('variable-input'));
197
+
198
+ await waitFor(() => {
199
+ expect(value.operator).toBe('$eq');
200
+ expect(getRuntimeFieldInterface).toHaveBeenCalledWith('belongsTo');
201
+ });
202
+ });
203
+
156
204
  it('keeps numeric string when x-component uses InputNumber with stringMode', async () => {
157
- const prevMeta = (globalThis as any).__TEST_META__;
158
- const prevPath = (globalThis as any).__TEST_PATH__;
159
205
  (globalThis as any).__TEST_PATH__ = 'price';
160
206
  (globalThis as any).__TEST_META__ = {
161
207
  interface: 'input',
@@ -177,9 +223,6 @@ describe('VariableFilterItem', () => {
177
223
  expect(input.value).toBe('123.45');
178
224
  expect(value.value).toBe('123.45');
179
225
  });
180
-
181
- (globalThis as any).__TEST_META__ = prevMeta;
182
- (globalThis as any).__TEST_PATH__ = prevPath;
183
226
  });
184
227
 
185
228
  it('normalizes synthetic event value when formula field renders Input from app components', async () => {
package/src/flow/index.ts CHANGED
@@ -104,5 +104,6 @@ export * from './admin-shell/AdminLayoutRouteCoordinator';
104
104
  export * from '../settings-center';
105
105
  export { openViewFlow } from './flows/openViewFlow';
106
106
  export { editMarkdownFlow } from './flows/editMarkdownFlow';
107
+ export { resolveDynamicNamePath } from './models/blocks/form/value-runtime/path';
107
108
 
108
109
  export { TextAreaWithContextSelector } from './components/TextAreaWithContextSelector';
@@ -26,6 +26,7 @@ describe('titleFieldQuickSync', () => {
26
26
  expect(isTitleUsableField(dm, { interface: 'formula' } as any)).toBe(false);
27
27
  expect(isTitleUsableField(dm, { interface: 'unknown' } as any)).toBe(false);
28
28
  expect(isTitleUsableField(undefined, { interface: 'input' } as any)).toBe(false);
29
+ expect(isTitleUsableField({} as any, { interface: 'input' } as any)).toBe(false);
29
30
  });
30
31
 
31
32
  it('syncs title field to main data source collection', async () => {
@@ -7,7 +7,7 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- import { DataSourceManager } from '@nocobase/flow-engine';
10
+ import { DataSourceManager, getCollectionFieldInterface } from '@nocobase/flow-engine';
11
11
  import type { CollectionFieldOptions } from '../../../flow-compat';
12
12
  import { DEFAULT_DATA_SOURCE_KEY } from '../../../flow-compat';
13
13
 
@@ -33,7 +33,7 @@ export function isTitleUsableField(
33
33
  ): boolean {
34
34
  const ifaceName = typeof field?.interface === 'string' ? field.interface : undefined;
35
35
  if (!dm || !ifaceName) return false;
36
- return !!dm.collectionFieldInterfaceManager.getFieldInterface(ifaceName)?.titleUsable;
36
+ return !!getCollectionFieldInterface(ifaceName, dm)?.titleUsable;
37
37
  }
38
38
 
39
39
  function resolveDataSourceKey(targetCollection: CollectionLike | null | undefined): string {
@@ -0,0 +1,196 @@
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 { FlowModel, FlowModelRenderer, tExpr, useFlowViewContext } from '@nocobase/flow-engine';
11
+ import { useRequest } from 'ahooks';
12
+ import { Button } from 'antd';
13
+ import type { ButtonProps } from 'antd';
14
+ import React from 'react';
15
+ import { SkeletonFallback } from '../../components/SkeletonFallback';
16
+ import { ActionModel, ActionSceneEnum } from '../base';
17
+ import {
18
+ applyAssociateAction,
19
+ getAssociationTargetResourceSettings,
20
+ isAssociationBlockContext,
21
+ } from './AssociationActionUtils';
22
+
23
+ function AssociateSelectorGridRenderer({ options }: { options: any }) {
24
+ const ctx = useFlowViewContext();
25
+ const { data, loading } = useRequest(
26
+ async () => {
27
+ return await ctx.engine.loadOrCreateModel(options, {
28
+ delegateToParent: false,
29
+ delegate: ctx,
30
+ skipSave: !ctx.flowSettingsEnabled,
31
+ });
32
+ },
33
+ {
34
+ refreshDeps: [ctx, options],
35
+ },
36
+ );
37
+
38
+ if (loading || !data?.uid) {
39
+ return <SkeletonFallback style={{ margin: 16 }} />;
40
+ }
41
+ return <FlowModelRenderer model={data as FlowModel} fallback={<SkeletonFallback style={{ margin: 16 }} />} />;
42
+ }
43
+
44
+ function AssociateSelectorContent({ model }: { model: AssociateActionModel }) {
45
+ const ctx = useFlowViewContext();
46
+ const { Header, Footer, type } = ctx.view;
47
+ return (
48
+ <div>
49
+ <Header
50
+ title={
51
+ type === 'dialog' ? (
52
+ <div
53
+ style={{
54
+ padding: `${ctx.themeToken.paddingLG}px ${ctx.themeToken.paddingLG}px 0`,
55
+ marginBottom: -ctx.themeToken.marginSM,
56
+ backgroundColor: 'var(--colorBgLayout)',
57
+ }}
58
+ >
59
+ {ctx.t('Select record')}
60
+ </div>
61
+ ) : (
62
+ ctx.t('Select record')
63
+ )
64
+ }
65
+ />
66
+ <AssociateSelectorGridRenderer
67
+ options={{
68
+ parentId: ctx.view.inputArgs.parentId,
69
+ subKey: 'associate-selector-grid',
70
+ async: true,
71
+ delegateToParent: false,
72
+ subType: 'object',
73
+ use: 'BlockGridModel',
74
+ }}
75
+ />
76
+ <Footer>
77
+ {type === 'dialog' ? (
78
+ <div style={{ padding: `0 ${ctx.themeToken.paddingLG}px ${ctx.themeToken.paddingLG}px` }}>
79
+ <Button
80
+ type="primary"
81
+ onClick={async () => {
82
+ await model.associateSelectedRows();
83
+ ctx.view.close();
84
+ }}
85
+ >
86
+ {ctx.t('Submit')}
87
+ </Button>
88
+ </div>
89
+ ) : (
90
+ <Button
91
+ type="primary"
92
+ onClick={async () => {
93
+ await model.associateSelectedRows();
94
+ ctx.view.close();
95
+ }}
96
+ >
97
+ {ctx.t('Submit')}
98
+ </Button>
99
+ )}
100
+ </Footer>
101
+ </div>
102
+ );
103
+ }
104
+
105
+ export class AssociateActionModel extends ActionModel {
106
+ static scene = ActionSceneEnum.collection;
107
+ static capabilityActionName = 'update';
108
+
109
+ defaultPopupTitle = tExpr('Select record');
110
+ selectedRows: any[] = [];
111
+
112
+ defaultProps: ButtonProps = {
113
+ title: tExpr('Associate'),
114
+ icon: 'LinkOutlined',
115
+ };
116
+
117
+ getAclActionName() {
118
+ return 'update';
119
+ }
120
+
121
+ async associateSelectedRows() {
122
+ await applyAssociateAction(this.context, this.selectedRows);
123
+ this.selectedRows = [];
124
+ }
125
+ }
126
+
127
+ AssociateActionModel.define({
128
+ label: tExpr('Associate'),
129
+ sort: 15,
130
+ hide(ctx) {
131
+ return !isAssociationBlockContext(ctx);
132
+ },
133
+ });
134
+
135
+ AssociateActionModel.registerFlow({
136
+ key: 'associateSettings',
137
+ title: tExpr('Associate settings'),
138
+ on: 'click',
139
+ steps: {
140
+ openSelector: {
141
+ async handler(ctx, params) {
142
+ const blockModel = ctx.blockModel;
143
+ const targetResourceSettings = getAssociationTargetResourceSettings(ctx);
144
+ const openMode = ctx.inputArgs?.isMobileLayout ? 'embed' : ctx.inputArgs?.mode || params?.mode || 'drawer';
145
+ const size = ctx.inputArgs?.size || params?.size || 'medium';
146
+ const sizeToWidthMap: Record<string, Record<string, string | undefined>> = {
147
+ drawer: {
148
+ small: '30%',
149
+ medium: '50%',
150
+ large: '70%',
151
+ },
152
+ dialog: {
153
+ small: '40%',
154
+ medium: '50%',
155
+ large: '80%',
156
+ },
157
+ embed: {},
158
+ };
159
+
160
+ ctx.model.selectedRows = [];
161
+ await ctx.viewer.open({
162
+ type: openMode,
163
+ width: sizeToWidthMap[openMode][size],
164
+ inheritContext: false,
165
+ target: ctx.layoutContentElement,
166
+ inputArgs: {
167
+ parentId: ctx.model.uid,
168
+ scene: 'select',
169
+ dataSourceKey: targetResourceSettings.dataSourceKey,
170
+ collectionName: targetResourceSettings.collectionName,
171
+ rowSelectionProps: {
172
+ type: 'checkbox',
173
+ defaultSelectedRows: () => blockModel?.resource?.getData?.() || [],
174
+ renderCell: undefined,
175
+ selectedRowKeys: undefined,
176
+ onChange: (_, selectedRows) => {
177
+ ctx.model.selectedRows = selectedRows || [];
178
+ },
179
+ },
180
+ },
181
+ content: () => <AssociateSelectorContent model={ctx.model as AssociateActionModel} />,
182
+ styles: {
183
+ content: {
184
+ padding: 0,
185
+ backgroundColor: ctx.model.flowEngine.context.themeToken.colorBgLayout,
186
+ ...(openMode === 'embed' ? { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 } : {}),
187
+ },
188
+ body: {
189
+ padding: 0,
190
+ },
191
+ },
192
+ });
193
+ },
194
+ },
195
+ },
196
+ });
@@ -0,0 +1,90 @@
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 type { FlowModelContext } from '@nocobase/flow-engine';
11
+
12
+ export const getAssociationBlockResourceSettings = (ctx: FlowModelContext | any) => {
13
+ const blockModel = ctx?.blockModel || ctx?.model?.context?.blockModel;
14
+ return (
15
+ blockModel?.getResourceSettingsInitParams?.() ||
16
+ blockModel?.getStepParams?.('resourceSettings', 'init') ||
17
+ ctx?.model?.getStepParams?.('resourceSettings', 'init')
18
+ );
19
+ };
20
+
21
+ export const isAssociationBlockContext = (ctx: FlowModelContext | any) => {
22
+ return !!getAssociationBlockResourceSettings(ctx)?.associationName;
23
+ };
24
+
25
+ export const getAssociationTargetResourceSettings = (ctx: FlowModelContext | any) => {
26
+ const resourceSettings = getAssociationBlockResourceSettings(ctx);
27
+ const association = ctx?.blockModel?.association || ctx?.model?.context?.blockModel?.association;
28
+ const targetCollection = association?.targetCollection;
29
+
30
+ return {
31
+ dataSourceKey: targetCollection?.dataSourceKey || resourceSettings?.dataSourceKey,
32
+ collectionName: targetCollection?.name || association?.target || resourceSettings?.collectionName,
33
+ };
34
+ };
35
+
36
+ const callAssociationResourceAction = async (resource: any, action: 'add' | 'remove', values: any[]) => {
37
+ if (typeof resource?.[action] === 'function') {
38
+ return await resource[action]({ values });
39
+ }
40
+
41
+ return await resource?.runAction?.(action, {
42
+ data: values,
43
+ });
44
+ };
45
+
46
+ export const applyDisassociateAction = async (ctx: FlowModelContext | any) => {
47
+ const resource = ctx?.blockModel?.resource || ctx?.resource;
48
+ const collection = ctx?.blockModel?.collection || ctx?.collection;
49
+
50
+ if (!isAssociationBlockContext(ctx)) {
51
+ ctx.message?.error?.(ctx.t('No association block selected'));
52
+ return;
53
+ }
54
+ if (!resource) {
55
+ ctx.message?.error?.(ctx.t('No resource selected for disassociation'));
56
+ return;
57
+ }
58
+ if (!ctx.record) {
59
+ ctx.message?.error?.(ctx.t('No record selected for disassociation'));
60
+ return;
61
+ }
62
+
63
+ const filterByTk = collection?.getFilterByTK?.(ctx.record);
64
+ await callAssociationResourceAction(resource, 'remove', [filterByTk]);
65
+ await resource.refresh?.();
66
+ ctx.message?.success?.(ctx.t('Record disassociated successfully'));
67
+ };
68
+
69
+ export const applyAssociateAction = async (ctx: FlowModelContext | any, selectedRows: any[]) => {
70
+ const resource = ctx?.blockModel?.resource || ctx?.resource;
71
+ const collection = ctx?.blockModel?.collection || ctx?.collection;
72
+
73
+ if (!isAssociationBlockContext(ctx)) {
74
+ ctx.message?.error?.(ctx.t('No association block selected'));
75
+ return;
76
+ }
77
+ if (!resource) {
78
+ ctx.message?.error?.(ctx.t('No resource selected for association'));
79
+ return;
80
+ }
81
+ if (!selectedRows?.length) {
82
+ ctx.message?.warning?.(ctx.t('Please select at least one record'));
83
+ return;
84
+ }
85
+
86
+ const values = selectedRows.map((row) => collection?.getFilterByTK?.(row) ?? row).filter((value) => value != null);
87
+ await callAssociationResourceAction(resource, 'add', values);
88
+ await resource.refresh?.();
89
+ ctx.message?.success?.(ctx.t('Record associated successfully'));
90
+ };