@nocobase/client-v2 2.1.5 → 2.1.7

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 (37) hide show
  1. package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +2 -0
  2. package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +1 -0
  3. package/es/flow/utils/dateTimeDisplayProps.d.ts +49 -0
  4. package/es/index.mjs +110 -90
  5. package/lib/index.js +89 -69
  6. package/package.json +7 -7
  7. package/src/flow/actions/__tests__/linkageRules.hiddenSync.restore.test.ts +19 -5
  8. package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +92 -0
  9. package/src/flow/actions/dateTimeFormat.tsx +42 -28
  10. package/src/flow/actions/linkageRules.tsx +45 -11
  11. package/src/flow/admin-shell/admin-layout/HelpLite.tsx +1 -3
  12. package/src/flow/components/DynamicFlowsIcon.tsx +447 -126
  13. package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +148 -2
  14. package/src/flow/flows/editMarkdownFlow.tsx +1 -1
  15. package/src/flow/index.ts +1 -1
  16. package/src/flow/internal/utils/operatorSchemaHelper.ts +15 -1
  17. package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +56 -1
  18. package/src/flow/models/blocks/table/TableColumnModel.tsx +36 -3
  19. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +159 -1
  20. package/src/flow/models/fields/AssociationFieldModel/AssociationFieldModel.tsx +1 -1
  21. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +29 -6
  22. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +16 -4
  23. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +24 -1
  24. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +13 -1
  25. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +12 -0
  26. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableFieldModel.reset.test.ts +180 -0
  27. package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +6 -4
  28. package/src/flow/models/fields/AssociationFieldModel/__tests__/AssociationFieldModel.updateAssociation.test.ts +72 -0
  29. package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +23 -0
  30. package/src/flow/models/fields/ClickableFieldModel.tsx +5 -0
  31. package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +29 -1
  32. package/src/flow/models/fields/SelectFieldModel.tsx +6 -4
  33. package/src/flow/models/fields/__tests__/DisplayDateTimeFieldModel.test.tsx +96 -0
  34. package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +43 -0
  35. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +258 -0
  36. package/src/flow/utils/dateTimeDisplayProps.ts +135 -0
  37. package/src/settings-center/plugin-manager/index.tsx +3 -0
@@ -0,0 +1,96 @@
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 { render, screen } from '@testing-library/react';
12
+ import { describe, expect, it } from 'vitest';
13
+ import { DisplayDateTimeFieldModel } from '../DisplayDateTimeFieldModel';
14
+
15
+ describe('DisplayDateTimeFieldModel', () => {
16
+ it('uses dateFormat, showTime, and timeFormat when rendering read pretty datetime text', () => {
17
+ const engine = new FlowEngine();
18
+ engine.registerModels({ DisplayDateTimeFieldModel });
19
+
20
+ const model = engine.createModel<DisplayDateTimeFieldModel>({
21
+ use: DisplayDateTimeFieldModel,
22
+ uid: 'display-datetime-field-format',
23
+ props: {
24
+ value: '2026-06-15 13:05:06',
25
+ dateFormat: 'YYYY-MM-DD',
26
+ showTime: true,
27
+ timeFormat: 'HH:mm:ss',
28
+ },
29
+ });
30
+
31
+ render(model.render());
32
+
33
+ expect(screen.getByText('2026-06-15 13:05:06')).toBeInTheDocument();
34
+ });
35
+
36
+ it('does not reuse a time-only format when rendering datetime text', () => {
37
+ const engine = new FlowEngine();
38
+ engine.registerModels({ DisplayDateTimeFieldModel });
39
+
40
+ const model = engine.createModel<DisplayDateTimeFieldModel>({
41
+ use: DisplayDateTimeFieldModel,
42
+ uid: 'display-datetime-field-stale-time-format',
43
+ props: {
44
+ value: '2026-06-15 13:05:06',
45
+ format: 'HH:mm:ss',
46
+ showTime: true,
47
+ timeFormat: 'HH:mm:ss',
48
+ },
49
+ });
50
+
51
+ render(model.render());
52
+
53
+ expect(screen.getByText('2026-06-15 13:05:06')).toBeInTheDocument();
54
+ expect(screen.queryByText('13:05:06')).not.toBeInTheDocument();
55
+ });
56
+
57
+ it('keeps an existing complete datetime format when no split format props are configured', () => {
58
+ const engine = new FlowEngine();
59
+ engine.registerModels({ DisplayDateTimeFieldModel });
60
+
61
+ const model = engine.createModel<DisplayDateTimeFieldModel>({
62
+ use: DisplayDateTimeFieldModel,
63
+ uid: 'display-datetime-field-complete-format',
64
+ props: {
65
+ value: '2026-06-15 13:05:06',
66
+ format: 'YYYY/MM/DD HH:mm:ss',
67
+ },
68
+ });
69
+
70
+ render(model.render());
71
+
72
+ expect(screen.getByText('2026/06/15 13:05:06')).toBeInTheDocument();
73
+ });
74
+
75
+ it('renders only the date for date-only fields even when a datetime format remains', () => {
76
+ const engine = new FlowEngine();
77
+ engine.registerModels({ DisplayDateTimeFieldModel });
78
+
79
+ const model = engine.createModel<DisplayDateTimeFieldModel>({
80
+ use: DisplayDateTimeFieldModel,
81
+ uid: 'display-datetime-field-date-only',
82
+ props: {
83
+ value: '2026-06-15 13:05:06',
84
+ dateOnly: true,
85
+ format: 'YYYY-MM-DD HH:mm:ss',
86
+ showTime: false,
87
+ timeFormat: 'HH:mm:ss',
88
+ },
89
+ });
90
+
91
+ render(model.render());
92
+
93
+ expect(screen.getByText('2026-06-15')).toBeInTheDocument();
94
+ expect(screen.queryByText('2026-06-15 13:05:06')).not.toBeInTheDocument();
95
+ });
96
+ });
@@ -0,0 +1,43 @@
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 React from 'react';
11
+ import { describe, expect, it } from 'vitest';
12
+ import { SelectFieldModel } from '../SelectFieldModel';
13
+
14
+ function mockT(text: string) {
15
+ if (text === '{{t("Yes")}}') return '是';
16
+ if (text === '{{t("No")}}') return '否';
17
+ return text;
18
+ }
19
+
20
+ describe('SelectFieldModel', () => {
21
+ it('translates enum fallback labels for selected values', () => {
22
+ const model = {
23
+ props: {
24
+ value: true,
25
+ },
26
+ context: {
27
+ collectionField: {
28
+ uiSchema: {
29
+ enum: [
30
+ { label: '{{t("Yes")}}', value: true },
31
+ { label: '{{t("No")}}', value: false },
32
+ ],
33
+ },
34
+ },
35
+ },
36
+ translate: mockT,
37
+ } as unknown as SelectFieldModel;
38
+
39
+ const element = SelectFieldModel.prototype.render.call(model) as React.ReactElement;
40
+
41
+ expect(element.props.value).toEqual({ label: '是', value: true });
42
+ });
43
+ });
@@ -48,6 +48,264 @@ describe('dateTimeFormat', () => {
48
48
  });
49
49
  });
50
50
 
51
+ it('uses the association title field when deciding the format schema', () => {
52
+ const ctx = {
53
+ model: {
54
+ props: {
55
+ titleField: 'shipmentsTime',
56
+ },
57
+ context: {
58
+ collectionField: {
59
+ type: 'belongsTo',
60
+ targetCollection: {
61
+ getField: (name) =>
62
+ name === 'shipmentsTime'
63
+ ? {
64
+ type: 'time',
65
+ interface: 'time',
66
+ }
67
+ : null,
68
+ },
69
+ },
70
+ },
71
+ },
72
+ };
73
+
74
+ expect(Object.keys(dateTimeFormat.uiSchema(ctx))).toEqual(['timeFormat']);
75
+ });
76
+
77
+ it('saves association title time field format as a time format', () => {
78
+ const setProps = vi.fn();
79
+ const ctx = {
80
+ model: {
81
+ props: {
82
+ titleField: 'shipmentsTime',
83
+ },
84
+ context: {
85
+ collectionField: {
86
+ type: 'belongsTo',
87
+ targetCollection: {
88
+ getField: (name) =>
89
+ name === 'shipmentsTime'
90
+ ? {
91
+ type: 'time',
92
+ interface: 'time',
93
+ }
94
+ : null,
95
+ },
96
+ },
97
+ },
98
+ setProps,
99
+ },
100
+ };
101
+
102
+ dateTimeFormat.handler(ctx, { timeFormat: 'hh:mm:ss a' });
103
+
104
+ expect(setProps).toHaveBeenCalledWith({
105
+ timeFormat: 'hh:mm:ss a',
106
+ format: 'hh:mm:ss a',
107
+ });
108
+ });
109
+
110
+ it('applies and persists date time format params when settings are saved', async () => {
111
+ const setProps = vi.fn();
112
+ const save = vi.fn();
113
+ const ctx = {
114
+ model: {
115
+ props: {
116
+ titleField: 'shipmentsDatetime',
117
+ },
118
+ context: {
119
+ collectionField: {
120
+ type: 'belongsTo',
121
+ targetCollection: {
122
+ getField: (name) =>
123
+ name === 'shipmentsDatetime'
124
+ ? {
125
+ type: 'datetime',
126
+ interface: 'datetime',
127
+ }
128
+ : null,
129
+ },
130
+ },
131
+ },
132
+ setProps,
133
+ save,
134
+ },
135
+ };
136
+
137
+ await dateTimeFormat.beforeParamsSave(ctx, {
138
+ picker: 'date',
139
+ dateFormat: 'YYYY-MM-DD',
140
+ showTime: true,
141
+ timeFormat: 'hh:mm:ss a',
142
+ });
143
+
144
+ expect(setProps).toHaveBeenCalledWith({
145
+ picker: 'date',
146
+ dateFormat: 'YYYY-MM-DD',
147
+ showTime: true,
148
+ timeFormat: 'hh:mm:ss a',
149
+ format: 'YYYY-MM-DD hh:mm:ss a',
150
+ });
151
+ expect(save).toHaveBeenCalled();
152
+ });
153
+
154
+ it('syncs table association column props when title date time format settings are saved', async () => {
155
+ const setProps = vi.fn();
156
+ const save = vi.fn();
157
+ const setParentProps = vi.fn();
158
+ const model = {
159
+ props: {
160
+ titleField: 'shipmentsDatetime',
161
+ },
162
+ context: {
163
+ collectionField: {
164
+ type: 'belongsTo',
165
+ targetCollection: {
166
+ getField: (name) =>
167
+ name === 'shipmentsDatetime'
168
+ ? {
169
+ type: 'datetime',
170
+ interface: 'datetime',
171
+ }
172
+ : null,
173
+ },
174
+ },
175
+ },
176
+ setProps,
177
+ save,
178
+ parent: {
179
+ use: 'TableColumnModel',
180
+ collectionField: {
181
+ isAssociationField: () => true,
182
+ },
183
+ setProps: setParentProps,
184
+ },
185
+ };
186
+ model.parent['subModels'] = {
187
+ field: model,
188
+ };
189
+
190
+ await dateTimeFormat.beforeParamsSave(
191
+ { model },
192
+ {
193
+ picker: 'date',
194
+ dateFormat: 'YYYY-MM-DD',
195
+ showTime: true,
196
+ timeFormat: 'hh:mm:ss a',
197
+ },
198
+ );
199
+
200
+ expect(setParentProps).toHaveBeenCalledWith({
201
+ picker: 'date',
202
+ dateFormat: 'YYYY-MM-DD',
203
+ showTime: true,
204
+ timeFormat: 'hh:mm:ss a',
205
+ format: 'YYYY-MM-DD hh:mm:ss a',
206
+ });
207
+ expect(save).toHaveBeenCalled();
208
+ });
209
+
210
+ it('hides time format for association title date-only fields', () => {
211
+ const ctx = {
212
+ model: {
213
+ props: {
214
+ titleField: 'shipmentsDateOnly',
215
+ showTime: true,
216
+ },
217
+ context: {
218
+ collectionField: {
219
+ type: 'belongsTo',
220
+ targetCollection: {
221
+ getField: (name) =>
222
+ name === 'shipmentsDateOnly'
223
+ ? {
224
+ type: 'dateOnly',
225
+ interface: 'date',
226
+ getComponentProps: () => ({
227
+ dateOnly: true,
228
+ showTime: false,
229
+ }),
230
+ }
231
+ : null,
232
+ },
233
+ },
234
+ },
235
+ },
236
+ };
237
+ const schema = dateTimeFormat.uiSchema(ctx);
238
+ const timeFormatField: any = schema.timeFormat;
239
+ const showTimeField: any = schema.showTime;
240
+ const timeFormatState = {
241
+ hidden: false,
242
+ form: {
243
+ values: {
244
+ picker: 'date',
245
+ showTime: true,
246
+ },
247
+ },
248
+ };
249
+ const showTimeState = {
250
+ hidden: false,
251
+ value: true,
252
+ form: {
253
+ values: {
254
+ picker: 'date',
255
+ },
256
+ },
257
+ };
258
+
259
+ timeFormatField['x-reactions'][0](timeFormatState);
260
+ showTimeField['x-reactions'][1](showTimeState);
261
+
262
+ expect(timeFormatState.hidden).toBe(true);
263
+ expect(showTimeState.hidden).toBe(true);
264
+ expect(showTimeState.value).toBe(false);
265
+ expect(dateTimeFormat.defaultParams(ctx)).toMatchObject({
266
+ showTime: false,
267
+ });
268
+ });
269
+
270
+ it('saves association title date-only field format without time even when params contain showTime', () => {
271
+ const setProps = vi.fn();
272
+ const ctx = {
273
+ model: {
274
+ props: {
275
+ titleField: 'shipmentsDateOnly',
276
+ },
277
+ context: {
278
+ collectionField: {
279
+ type: 'belongsTo',
280
+ targetCollection: {
281
+ getField: (name) =>
282
+ name === 'shipmentsDateOnly'
283
+ ? {
284
+ type: 'dateOnly',
285
+ interface: 'date',
286
+ }
287
+ : null,
288
+ },
289
+ },
290
+ },
291
+ setProps,
292
+ },
293
+ };
294
+
295
+ dateTimeFormat.handler(ctx, {
296
+ dateFormat: 'YYYY-MM-DD',
297
+ showTime: true,
298
+ timeFormat: 'HH:mm:ss',
299
+ });
300
+
301
+ expect(setProps).toHaveBeenCalledWith({
302
+ dateFormat: 'YYYY-MM-DD',
303
+ showTime: false,
304
+ timeFormat: 'HH:mm:ss',
305
+ format: 'YYYY-MM-DD',
306
+ });
307
+ });
308
+
51
309
  it('uses format as the default time format when timeFormat is missing', () => {
52
310
  const ctx = {
53
311
  model: {
@@ -0,0 +1,135 @@
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
+ type DateTimeDisplayProps = {
13
+ dateOnly?: boolean;
14
+ dateFormat?: string;
15
+ format?: string;
16
+ picker?: string;
17
+ showTime?: boolean;
18
+ timeFormat?: string;
19
+ };
20
+
21
+ type DateTimeCollectionField = {
22
+ type?: string;
23
+ interface?: string;
24
+ getComponentProps?: () => DateTimeDisplayProps;
25
+ targetCollection?: {
26
+ getField?: (name?: string) => DateTimeCollectionField | undefined;
27
+ };
28
+ };
29
+
30
+ type DateTimeModelContext = FlowModelContext & {
31
+ collectionField?: DateTimeCollectionField;
32
+ };
33
+
34
+ type DateTimeModel = {
35
+ props?: DateTimeDisplayProps & {
36
+ titleField?: string;
37
+ };
38
+ context?: DateTimeModelContext;
39
+ getStepParams?: (flowKey: string, stepKey: string) => DateTimeDisplayProps | undefined;
40
+ };
41
+
42
+ type ResolveDateTimeDisplayPropsOptions = {
43
+ model?: DateTimeModel;
44
+ collectionField?: DateTimeCollectionField;
45
+ titleField?: string;
46
+ currentProps?: DateTimeDisplayProps;
47
+ params?: DateTimeDisplayProps;
48
+ withDefaults?: boolean;
49
+ };
50
+
51
+ const dateTimeDisplayPropKeys: Array<keyof DateTimeDisplayProps> = [
52
+ 'dateOnly',
53
+ 'dateFormat',
54
+ 'format',
55
+ 'picker',
56
+ 'showTime',
57
+ 'timeFormat',
58
+ ];
59
+
60
+ const pickDateTimeDisplayProps = (source?: DateTimeDisplayProps) => {
61
+ if (!source) {
62
+ return {};
63
+ }
64
+
65
+ const result: DateTimeDisplayProps = {};
66
+ for (const key of dateTimeDisplayPropKeys) {
67
+ if (key === 'dateOnly' || key === 'showTime') {
68
+ if (typeof source[key] !== 'undefined') {
69
+ result[key] = source[key];
70
+ }
71
+ } else if (typeof source[key] !== 'undefined') {
72
+ result[key] = source[key];
73
+ }
74
+ }
75
+ return result;
76
+ };
77
+
78
+ const stripUndefined = (props: DateTimeDisplayProps) =>
79
+ Object.fromEntries(Object.entries(props).filter(([, value]) => typeof value !== 'undefined')) as DateTimeDisplayProps;
80
+
81
+ const getModelCollectionField = (model?: DateTimeModel) => model?.context?.collectionField;
82
+
83
+ export const getDateTimeFormatCollectionField = (options: ResolveDateTimeDisplayPropsOptions) => {
84
+ const collectionField = options.collectionField || getModelCollectionField(options.model);
85
+ const titleField = options.titleField || options.model?.props?.titleField;
86
+ return collectionField?.targetCollection?.getField?.(titleField) || collectionField;
87
+ };
88
+
89
+ export const isTimeCollectionField = (collectionField?: DateTimeCollectionField) =>
90
+ collectionField?.type === 'time' || collectionField?.interface === 'time';
91
+
92
+ export const isDateOnlyCollectionField = (collectionField?: DateTimeCollectionField) =>
93
+ collectionField?.type === 'dateOnly' || collectionField?.interface === 'dateOnly';
94
+
95
+ export const getSavedDateTimeFormatParams = (model?: DateTimeModel) =>
96
+ model?.getStepParams?.('datetimeSettings', 'dateFormat') || model?.getStepParams?.('timeSettings', 'dateFormat');
97
+
98
+ export const resolveDateTimeDisplayProps = (options: ResolveDateTimeDisplayPropsOptions) => {
99
+ const collectionField = options.collectionField || getModelCollectionField(options.model);
100
+ const targetCollectionField = getDateTimeFormatCollectionField(options);
101
+ const mergedProps = {
102
+ ...pickDateTimeDisplayProps(collectionField?.getComponentProps?.()),
103
+ ...pickDateTimeDisplayProps(
104
+ targetCollectionField !== collectionField ? targetCollectionField?.getComponentProps?.() : undefined,
105
+ ),
106
+ ...pickDateTimeDisplayProps(options.currentProps || options.model?.props),
107
+ ...pickDateTimeDisplayProps(getSavedDateTimeFormatParams(options.model)),
108
+ ...pickDateTimeDisplayProps(options.params),
109
+ };
110
+
111
+ if (isTimeCollectionField(targetCollectionField)) {
112
+ const timeFormat = mergedProps.timeFormat || mergedProps.format || 'HH:mm:ss';
113
+ return stripUndefined({
114
+ ...mergedProps,
115
+ timeFormat,
116
+ format: timeFormat,
117
+ });
118
+ }
119
+
120
+ const picker = mergedProps.picker || (options.withDefaults ? 'date' : undefined);
121
+ const dateFormat = mergedProps.dateFormat || (options.withDefaults ? 'YYYY-MM-DD' : undefined);
122
+ const timeFormat = mergedProps.timeFormat || (options.withDefaults ? 'HH:mm:ss' : undefined);
123
+ const showTime = isDateOnlyCollectionField(targetCollectionField) ? false : mergedProps.showTime;
124
+ const finalDateFormat = dateFormat || 'YYYY-MM-DD';
125
+ const finalTimeFormat = timeFormat || 'HH:mm:ss';
126
+
127
+ return stripUndefined({
128
+ ...mergedProps,
129
+ picker,
130
+ dateFormat,
131
+ timeFormat,
132
+ showTime,
133
+ format: showTime ? `${finalDateFormat} ${finalTimeFormat}` : finalDateFormat,
134
+ });
135
+ };
@@ -86,6 +86,9 @@ export const PluginManagerPage: React.FC = () => {
86
86
  async () => {
87
87
  const response = await app.apiClient.request({
88
88
  url: 'pm:list',
89
+ params: {
90
+ v2: true,
91
+ },
89
92
  skipNotify: true,
90
93
  });
91
94
  return Array.isArray(response?.data?.data) ? response.data.data : [];