@nocobase/client-v2 3.0.0-alpha.1 → 3.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/APIClient.d.ts +12 -0
- package/es/acl/aclCheckReadiness.d.ts +11 -0
- package/es/authRedirect.d.ts +6 -2
- package/es/flow/actions/linkageRules.d.ts +24 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +4 -30
- package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
- package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
- package/es/flow/components/field-value-variable/index.d.ts +11 -0
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
- package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
- package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
- package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +3 -1
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +7 -0
- package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
- package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +11 -0
- package/es/flow/models/blocks/table/utils.d.ts +1 -0
- package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +2 -1
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +0 -17
- package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +41 -0
- package/es/flow-compat/passwordUtils.d.ts +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.mjs +140 -140
- package/es/nocobase-buildin-plugin/index.d.ts +1 -0
- package/es/settings-app/SettingsGroupNav.d.ts +3 -2
- package/es/settings-app/SettingsSearch.d.ts +1 -1
- package/es/ui-operation/index.d.ts +15 -0
- package/es/ui-operation/ui-operation-codec.d.ts +10 -0
- package/lib/index.js +145 -145
- package/package.json +7 -7
- package/src/APIClient.ts +92 -0
- package/src/Application.tsx +3 -1
- package/src/__tests__/APIClient.test.tsx +58 -0
- package/src/__tests__/app.test.tsx +122 -3
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/browserChecker.test.ts +81 -33
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +37 -0
- package/src/__tests__/settings-center.test.tsx +312 -11
- package/src/__tests__/settings-layout-root.test.tsx +346 -6
- package/src/__tests__/settings-runtime-paths.test.ts +1 -1
- package/src/__tests__/settings-search-shortcut.test.tsx +321 -0
- package/src/__tests__/settings-shell.test.tsx +62 -1
- package/src/acl/ACLProvider.tsx +34 -3
- package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
- package/src/acl/aclCheckReadiness.ts +44 -0
- package/src/authRedirect.ts +13 -5
- package/src/components/AppComponents.tsx +16 -7
- package/src/components/form/filter/CollectionFilterItem.tsx +4 -2
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +17 -0
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
- package/src/flow/actions/linkageRules.tsx +33 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
- package/src/flow/components/FieldAssignValueInput.tsx +38 -621
- package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
- package/src/flow/components/field-value-variable/dateValue.ts +223 -0
- package/src/flow/components/field-value-variable/index.ts +12 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +12 -3
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +125 -0
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
- package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
- package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
- package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
- package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
- package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
- package/src/flow/models/base/CollectionBlockModel.tsx +32 -1
- package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +125 -9
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
- package/src/flow/models/blocks/details/DetailsBlockModel.tsx +8 -3
- package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +32 -1
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +129 -14
- package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +57 -4
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +174 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +359 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +72 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormSubmitActionModel.lifecycle.test.ts +90 -0
- package/src/flow/models/blocks/filter-manager/FilterManager.ts +5 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +40 -0
- package/src/flow/models/blocks/form/FormBlockModel.tsx +47 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
- package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
- package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +18 -8
- package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
- package/src/flow/models/blocks/table/utils.ts +7 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +33 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +8 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
- package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +24 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +9 -136
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +167 -3
- package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
- package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +6 -0
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +27 -2
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
- package/src/index.ts +2 -0
- package/src/layout-manager/LayoutContentRoute.tsx +2 -1
- package/src/layout-manager/LayoutRoute.tsx +2 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
- package/src/nocobase-buildin-plugin/index.tsx +14 -1
- package/src/settings-app/SettingsGroupNav.tsx +11 -11
- package/src/settings-app/SettingsSearch.tsx +115 -10
- package/src/settings-app/SettingsShell.tsx +23 -6
- package/src/settings-app/runtimePaths.ts +0 -1
- package/src/settings-app/settingsTheme.ts +82 -14
- package/src/settings-center/AdminSettingsLayout.tsx +132 -107
- package/src/settings-center/__tests__/groups.test.ts +25 -0
- package/src/settings-center/groups.ts +1 -1
- package/src/ui-operation/index.ts +33 -0
- package/src/ui-operation/ui-operation-codec.ts +54 -0
|
@@ -31,6 +31,12 @@ import {
|
|
|
31
31
|
import { FilterFormFieldModel } from './fields';
|
|
32
32
|
import { normalizeFilterValueByOperator } from './valueNormalization';
|
|
33
33
|
|
|
34
|
+
type CollectionWithManager = Collection & {
|
|
35
|
+
collectionManager?: {
|
|
36
|
+
getCollection?: (name: string) => Collection | undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
34
40
|
const getAssociationTargetCollection = (field: any, collection?: Collection, model?: CollectionBlockModel) => {
|
|
35
41
|
if (field?.targetCollection) {
|
|
36
42
|
return field.targetCollection;
|
|
@@ -42,6 +48,10 @@ const getAssociationTargetCollection = (field: any, collection?: Collection, mod
|
|
|
42
48
|
if (collection?.dataSource?.getCollection) {
|
|
43
49
|
return collection.dataSource.getCollection(targetName);
|
|
44
50
|
}
|
|
51
|
+
const collectionManager = (collection as CollectionWithManager | undefined)?.collectionManager;
|
|
52
|
+
if (collectionManager?.getCollection) {
|
|
53
|
+
return collectionManager.getCollection(targetName);
|
|
54
|
+
}
|
|
45
55
|
const dataSourceKey = collection?.dataSourceKey;
|
|
46
56
|
if (dataSourceKey && model?.context?.dataSourceManager?.getCollection) {
|
|
47
57
|
return model.context.dataSourceManager.getCollection(dataSourceKey, targetName);
|
|
@@ -168,6 +178,74 @@ const buildVirtualFilterCollectionField = (ctx: FlowModelContext, filterField: a
|
|
|
168
178
|
return result;
|
|
169
179
|
};
|
|
170
180
|
|
|
181
|
+
const getFilterableChildren = (field: any) => {
|
|
182
|
+
const children = field?.filterable?.children;
|
|
183
|
+
return Array.isArray(children) ? children : [];
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const hasAssociationChildren = (field: any, collection?: Collection, model?: CollectionBlockModel) => {
|
|
187
|
+
return (
|
|
188
|
+
isAssociationCollectionField(field) &&
|
|
189
|
+
(getFilterableChildren(field).length > 0 || !!getAssociationTargetCollection(field, collection, model))
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const inferFilterableChildInterface = (child: any) => {
|
|
194
|
+
if (child?.interface) {
|
|
195
|
+
return child.interface;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const schema = child?.schema || child?.uiSchema;
|
|
199
|
+
const component = schema?.['x-component'];
|
|
200
|
+
if (component === 'Select') {
|
|
201
|
+
return 'select';
|
|
202
|
+
}
|
|
203
|
+
if (component === 'Checkbox.Group') {
|
|
204
|
+
return 'checkboxGroup';
|
|
205
|
+
}
|
|
206
|
+
if (component === 'Checkbox') {
|
|
207
|
+
return 'checkbox';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const type = child?.type || schema?.type;
|
|
211
|
+
if (type === 'number' || type === 'integer') {
|
|
212
|
+
return 'number';
|
|
213
|
+
}
|
|
214
|
+
return 'input';
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const translateFilterableChildTitle = (title: unknown, t: (value: string) => string) => {
|
|
218
|
+
return typeof title === 'string' ? t(title) : title;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const buildFilterableChildField = (child: any, t: (value: string) => string) => {
|
|
222
|
+
const name = child?.name || child?.value;
|
|
223
|
+
if (!name) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const schema = child?.schema || child?.uiSchema || {};
|
|
228
|
+
const rawTitle = child?.title || child?.label || schema?.title || name;
|
|
229
|
+
const title = translateFilterableChildTitle(rawTitle, t);
|
|
230
|
+
const filterable = child?.filterable || (child?.operators ? { operators: child.operators } : undefined);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
...child,
|
|
234
|
+
name,
|
|
235
|
+
title,
|
|
236
|
+
type: child?.type || schema?.type || 'string',
|
|
237
|
+
interface: inferFilterableChildInterface(child),
|
|
238
|
+
uiSchema: {
|
|
239
|
+
...schema,
|
|
240
|
+
title: translateFilterableChildTitle(schema?.title || title, t),
|
|
241
|
+
},
|
|
242
|
+
filterable,
|
|
243
|
+
__filterFormVirtual: true,
|
|
244
|
+
isAssociationField: () => false,
|
|
245
|
+
getComponentProps: () => schema?.['x-component-props'] || {},
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
171
249
|
const buildFilterFormFieldItem = ({
|
|
172
250
|
model,
|
|
173
251
|
collection,
|
|
@@ -187,11 +265,7 @@ const buildFilterFormFieldItem = ({
|
|
|
187
265
|
if (!binding) {
|
|
188
266
|
return;
|
|
189
267
|
}
|
|
190
|
-
const
|
|
191
|
-
const fieldModel =
|
|
192
|
-
isAssociation && ctxWithFlags.engine?.getModelClass?.('FilterFormRecordSelectFieldModel')
|
|
193
|
-
? 'FilterFormRecordSelectFieldModel'
|
|
194
|
-
: binding.modelName;
|
|
268
|
+
const fieldModel = binding.modelName;
|
|
195
269
|
const label = field.title || field.name;
|
|
196
270
|
const displayLabel = labelPrefix ? `${labelPrefix} / ${label}` : label;
|
|
197
271
|
return {
|
|
@@ -211,7 +285,10 @@ const buildFilterFormFieldItem = ({
|
|
|
211
285
|
},
|
|
212
286
|
filterFormItemSettings: {
|
|
213
287
|
init: {
|
|
214
|
-
filterField:
|
|
288
|
+
filterField: {
|
|
289
|
+
..._.pick(field, ['name', 'title', 'interface', 'type', 'filterable', 'uiSchema', '__filterFormVirtual']),
|
|
290
|
+
title: displayLabel,
|
|
291
|
+
},
|
|
215
292
|
defaultTargetUid: model.uid,
|
|
216
293
|
},
|
|
217
294
|
},
|
|
@@ -245,7 +322,8 @@ const buildAssociationFieldMenuItem = ({
|
|
|
245
322
|
depth: number;
|
|
246
323
|
}) => {
|
|
247
324
|
const targetCollection = getAssociationTargetCollection(field, collection, model);
|
|
248
|
-
|
|
325
|
+
const filterableChildren = getFilterableChildren(field);
|
|
326
|
+
if (!targetCollection && !filterableChildren.length) {
|
|
249
327
|
return;
|
|
250
328
|
}
|
|
251
329
|
if (depth > MAX_ASSOCIATION_DEPTH) {
|
|
@@ -262,10 +340,35 @@ const buildAssociationFieldMenuItem = ({
|
|
|
262
340
|
const targetFields = getTargetFilterableFields(field, collection, model);
|
|
263
341
|
const fieldItems: any[] = [];
|
|
264
342
|
const associationItems: any[] = [];
|
|
343
|
+
const addedFieldPaths = new Set<string>();
|
|
344
|
+
|
|
345
|
+
filterableChildren.forEach((child: any) => {
|
|
346
|
+
const virtualChildField = buildFilterableChildField(child, t);
|
|
347
|
+
if (!virtualChildField) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const childFieldPath = `${fieldPath}.${virtualChildField.name}`;
|
|
352
|
+
const childItem = buildFilterFormFieldItem({
|
|
353
|
+
model,
|
|
354
|
+
collection,
|
|
355
|
+
ctxWithFlags,
|
|
356
|
+
field: virtualChildField,
|
|
357
|
+
fieldPath: childFieldPath,
|
|
358
|
+
labelPrefix: label,
|
|
359
|
+
});
|
|
360
|
+
if (childItem) {
|
|
361
|
+
addedFieldPaths.add(childFieldPath);
|
|
362
|
+
fieldItems.push(childItem);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
265
365
|
|
|
266
366
|
targetFields.forEach((targetField: any) => {
|
|
267
367
|
const targetFieldPath = `${fieldPath}.${targetField.name}`;
|
|
268
|
-
if (
|
|
368
|
+
if (addedFieldPaths.has(targetFieldPath)) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (hasAssociationChildren(targetField, collection, model)) {
|
|
269
372
|
const associationItem = buildAssociationFieldMenuItem({
|
|
270
373
|
model,
|
|
271
374
|
collection,
|
|
@@ -358,7 +461,7 @@ const getModelFieldGroups = async (model: CollectionBlockModel) => {
|
|
|
358
461
|
baseItems.push(baseItem);
|
|
359
462
|
}
|
|
360
463
|
|
|
361
|
-
if (field
|
|
464
|
+
if (hasAssociationChildren(field, collection, model)) {
|
|
362
465
|
const associationItem = buildAssociationFieldMenuItem({
|
|
363
466
|
model,
|
|
364
467
|
collection,
|
|
@@ -489,6 +592,14 @@ export class FilterFormItemModel extends FilterableItemModel<{
|
|
|
489
592
|
title: initFilterField?.title || initFilterField?.name,
|
|
490
593
|
},
|
|
491
594
|
});
|
|
595
|
+
if (initFilterField?.__filterFormVirtual) {
|
|
596
|
+
const virtualField = buildVirtualFilterCollectionField(this.context, initFilterField);
|
|
597
|
+
if (virtualField) {
|
|
598
|
+
this.context.defineProperty('collectionField', {
|
|
599
|
+
value: virtualField,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
492
603
|
}
|
|
493
604
|
}
|
|
494
605
|
|
|
@@ -692,7 +803,8 @@ FilterFormItemModel.registerFlow({
|
|
|
692
803
|
// @ts-ignore
|
|
693
804
|
(fieldSettingsInitParams?.dataSourceKey && fieldSettingsInitParams?.collectionName)
|
|
694
805
|
);
|
|
695
|
-
|
|
806
|
+
const shouldUseVirtualFilterField = !!normalizedFilterField?.__filterFormVirtual;
|
|
807
|
+
if ((shouldUseVirtualFilterField || (!hasCollectionContext && !collectionField)) && normalizedFilterField) {
|
|
696
808
|
const virtualField = buildVirtualFilterCollectionField(ctx, normalizedFilterField);
|
|
697
809
|
if (virtualField) {
|
|
698
810
|
ctx.model.context.defineProperty('collectionField', {
|
|
@@ -787,10 +899,13 @@ FilterFormItemModel.registerFlow({
|
|
|
787
899
|
type: 'select',
|
|
788
900
|
key: 'use',
|
|
789
901
|
props: {
|
|
790
|
-
options: classes.map((model) =>
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
902
|
+
options: classes.map((model) => {
|
|
903
|
+
const ModelClass = ctx.engine.getModelClass(model.modelName);
|
|
904
|
+
return {
|
|
905
|
+
label: t(ModelClass?.meta?.label || model.modelName),
|
|
906
|
+
value: model.modelName,
|
|
907
|
+
};
|
|
908
|
+
}),
|
|
794
909
|
},
|
|
795
910
|
};
|
|
796
911
|
},
|
|
@@ -8,23 +8,76 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { ButtonProps } from 'antd/es/button';
|
|
11
|
+
import { reaction } from '@formily/reactive';
|
|
11
12
|
import { tExpr } from '@nocobase/flow-engine';
|
|
12
13
|
import { FilterFormActionModel } from './FilterFormActionModel';
|
|
13
14
|
|
|
15
|
+
type FilterFormBlockState = {
|
|
16
|
+
autoTriggerFilter: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const mountedSubmitActions = new WeakSet<object>();
|
|
20
|
+
const visibleSubmitActionsByBlock = new WeakMap<FilterFormBlockState, Set<object>>();
|
|
21
|
+
const hiddenReactionDisposers = new WeakMap<object, () => void>();
|
|
22
|
+
|
|
23
|
+
const syncAutoTriggerFilter = (blockModel: FilterFormBlockState, lifecycleAction: object & { hidden?: boolean }) => {
|
|
24
|
+
let visibleSubmitActions = visibleSubmitActionsByBlock.get(blockModel);
|
|
25
|
+
|
|
26
|
+
if (mountedSubmitActions.has(lifecycleAction) && !lifecycleAction.hidden) {
|
|
27
|
+
if (!visibleSubmitActions) {
|
|
28
|
+
visibleSubmitActions = new Set<object>();
|
|
29
|
+
visibleSubmitActionsByBlock.set(blockModel, visibleSubmitActions);
|
|
30
|
+
}
|
|
31
|
+
visibleSubmitActions.add(lifecycleAction);
|
|
32
|
+
} else {
|
|
33
|
+
visibleSubmitActions?.delete(lifecycleAction);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
blockModel.autoTriggerFilter = Boolean(!visibleSubmitActions?.size);
|
|
37
|
+
if (!visibleSubmitActions?.size) {
|
|
38
|
+
visibleSubmitActionsByBlock.delete(blockModel);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
14
42
|
export class FilterFormSubmitActionModel extends FilterFormActionModel {
|
|
15
43
|
defaultProps: ButtonProps = {
|
|
16
44
|
title: tExpr('Filter'),
|
|
17
45
|
type: 'primary',
|
|
18
46
|
};
|
|
19
47
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
private getLifecycleAction(): object & { hidden?: boolean } {
|
|
49
|
+
return this.context.model || this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private syncAutoTriggerFilter(): void {
|
|
53
|
+
const blockModel = this.context.blockModel as FilterFormBlockState;
|
|
54
|
+
const lifecycleAction = this.getLifecycleAction();
|
|
55
|
+
syncAutoTriggerFilter(blockModel, lifecycleAction);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onMount(): void {
|
|
59
|
+
super.onMount();
|
|
60
|
+
const blockModel = this.context.blockModel as FilterFormBlockState;
|
|
61
|
+
const lifecycleAction = this.getLifecycleAction();
|
|
62
|
+
mountedSubmitActions.add(lifecycleAction);
|
|
63
|
+
hiddenReactionDisposers.get(lifecycleAction)?.();
|
|
64
|
+
hiddenReactionDisposers.set(
|
|
65
|
+
lifecycleAction,
|
|
66
|
+
reaction(
|
|
67
|
+
() => lifecycleAction.hidden,
|
|
68
|
+
() => syncAutoTriggerFilter(blockModel, lifecycleAction),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
this.syncAutoTriggerFilter();
|
|
23
72
|
}
|
|
24
73
|
|
|
25
74
|
onUnmount(): void {
|
|
26
75
|
super.onUnmount();
|
|
27
|
-
|
|
76
|
+
const lifecycleAction = this.getLifecycleAction();
|
|
77
|
+
hiddenReactionDisposers.get(lifecycleAction)?.();
|
|
78
|
+
hiddenReactionDisposers.delete(lifecycleAction);
|
|
79
|
+
mountedSubmitActions.delete(lifecycleAction);
|
|
80
|
+
this.syncAutoTriggerFilter();
|
|
28
81
|
}
|
|
29
82
|
}
|
|
30
83
|
|
package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts
CHANGED
|
@@ -15,7 +15,9 @@ import { FilterFormItemModel } from '../FilterFormItemModel';
|
|
|
15
15
|
import { FilterFormGridModel } from '../FilterFormGridModel';
|
|
16
16
|
import { InputFieldModel } from '../../../fields/InputFieldModel';
|
|
17
17
|
import { NumberFieldModel } from '../../../fields/NumberFieldModel';
|
|
18
|
+
import { CascadeSelectFieldModel } from '../../../fields/AssociationFieldModel/CascadeSelectFieldModel';
|
|
18
19
|
import { RecordSelectFieldModel } from '../../../fields/AssociationFieldModel/RecordSelectFieldModel';
|
|
20
|
+
import { FilterFormRecordSelectFieldModel } from '../fields/FilterFormRecordSelectFieldModel';
|
|
19
21
|
|
|
20
22
|
class DummyResource {
|
|
21
23
|
supportsFilter = true;
|
|
@@ -41,7 +43,9 @@ function createEngine() {
|
|
|
41
43
|
DummyCollectionBlockModel,
|
|
42
44
|
InputFieldModel,
|
|
43
45
|
NumberFieldModel,
|
|
46
|
+
CascadeSelectFieldModel,
|
|
44
47
|
RecordSelectFieldModel,
|
|
48
|
+
FilterFormRecordSelectFieldModel,
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
return engine;
|
|
@@ -76,7 +80,13 @@ function createGridModel(engine: FlowEngine) {
|
|
|
76
80
|
return { gridModel, saveConnectFieldsConfig };
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
function createFilterItemModel(
|
|
83
|
+
function createFilterItemModel(
|
|
84
|
+
engine: FlowEngine,
|
|
85
|
+
dataBlockModel: DummyCollectionBlockModel,
|
|
86
|
+
fieldPath: string,
|
|
87
|
+
fieldModel?: string,
|
|
88
|
+
fieldProps?: Record<string, unknown>,
|
|
89
|
+
) {
|
|
80
90
|
const subModel = engine.createModel<FilterFormItemModel>({
|
|
81
91
|
uid: `filter-item-${fieldPath}`,
|
|
82
92
|
use: 'FilterFormItemModel',
|
|
@@ -94,6 +104,14 @@ function createFilterItemModel(engine: FlowEngine, dataBlockModel: DummyCollecti
|
|
|
94
104
|
},
|
|
95
105
|
},
|
|
96
106
|
},
|
|
107
|
+
subModels: fieldModel
|
|
108
|
+
? {
|
|
109
|
+
field: {
|
|
110
|
+
use: fieldModel,
|
|
111
|
+
props: fieldProps,
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
: undefined,
|
|
97
115
|
});
|
|
98
116
|
|
|
99
117
|
subModel.context.defineProperty('blockGridModel', {
|
|
@@ -244,4 +262,159 @@ describe('FilterFormGridModel onModelCreated', () => {
|
|
|
244
262
|
],
|
|
245
263
|
});
|
|
246
264
|
});
|
|
265
|
+
|
|
266
|
+
it('keeps the target collection filter key for record select relation fields with targetKey', async () => {
|
|
267
|
+
const engine = createEngine();
|
|
268
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
269
|
+
|
|
270
|
+
ds.addCollection({
|
|
271
|
+
name: 'departments',
|
|
272
|
+
filterTargetKey: 'id',
|
|
273
|
+
fields: [
|
|
274
|
+
{ name: 'id', type: 'integer', interface: 'number', filterable: { operators: [] } },
|
|
275
|
+
{ name: 'code', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
276
|
+
{ name: 'name', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
277
|
+
],
|
|
278
|
+
});
|
|
279
|
+
ds.addCollection({
|
|
280
|
+
name: 'users',
|
|
281
|
+
filterTargetKey: 'id',
|
|
282
|
+
fields: [
|
|
283
|
+
{ name: 'id', type: 'integer', interface: 'number', filterable: { operators: [] } },
|
|
284
|
+
{
|
|
285
|
+
name: 'department',
|
|
286
|
+
type: 'belongsTo',
|
|
287
|
+
interface: 'm2o',
|
|
288
|
+
target: 'departments',
|
|
289
|
+
targetKey: 'code',
|
|
290
|
+
filterable: { operators: [] },
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const dataBlockModel = createDataBlockModel(engine);
|
|
296
|
+
const { gridModel, saveConnectFieldsConfig } = createGridModel(engine);
|
|
297
|
+
const subModel = createFilterItemModel(engine, dataBlockModel, 'department', 'FilterFormRecordSelectFieldModel');
|
|
298
|
+
|
|
299
|
+
await gridModel.onModelCreated(subModel);
|
|
300
|
+
|
|
301
|
+
expect(saveConnectFieldsConfig).toHaveBeenCalledTimes(1);
|
|
302
|
+
const [, payload] = saveConnectFieldsConfig.mock.calls[0] as unknown as [any, any];
|
|
303
|
+
expect(payload).toEqual({
|
|
304
|
+
targets: [
|
|
305
|
+
{
|
|
306
|
+
targetId: dataBlockModel.uid,
|
|
307
|
+
filterPaths: ['department.id'],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('falls back to association targetKey for non-record-select filter fields when target collection filter key is id', async () => {
|
|
314
|
+
const engine = createEngine();
|
|
315
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
316
|
+
|
|
317
|
+
ds.addCollection({
|
|
318
|
+
name: 'chinaRegions',
|
|
319
|
+
fields: [
|
|
320
|
+
{ name: 'code', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
321
|
+
{ name: 'name', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
322
|
+
],
|
|
323
|
+
});
|
|
324
|
+
ds.addCollection({
|
|
325
|
+
name: 'users',
|
|
326
|
+
filterTargetKey: 'id',
|
|
327
|
+
fields: [
|
|
328
|
+
{ name: 'id', type: 'integer', interface: 'number', filterable: { operators: [] } },
|
|
329
|
+
{
|
|
330
|
+
name: 'birthPlace',
|
|
331
|
+
type: 'belongsToMany',
|
|
332
|
+
interface: 'chinaRegion',
|
|
333
|
+
target: 'chinaRegions',
|
|
334
|
+
targetKey: 'code',
|
|
335
|
+
filterable: { operators: [] },
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const dataBlockModel = createDataBlockModel(engine);
|
|
341
|
+
const { gridModel, saveConnectFieldsConfig } = createGridModel(engine);
|
|
342
|
+
const subModel = createFilterItemModel(engine, dataBlockModel, 'birthPlace', 'InputFieldModel');
|
|
343
|
+
|
|
344
|
+
await gridModel.onModelCreated(subModel);
|
|
345
|
+
|
|
346
|
+
expect(saveConnectFieldsConfig).toHaveBeenCalledTimes(1);
|
|
347
|
+
const [, payload] = saveConnectFieldsConfig.mock.calls[0] as unknown as [any, any];
|
|
348
|
+
expect(payload).toEqual({
|
|
349
|
+
targets: [
|
|
350
|
+
{
|
|
351
|
+
targetId: dataBlockModel.uid,
|
|
352
|
+
filterPaths: ['birthPlace.code'],
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('uses the Cascader value key for both the filter value and connected field path', async () => {
|
|
359
|
+
const engine = createEngine();
|
|
360
|
+
const ds = engine.dataSourceManager.getDataSource('main');
|
|
361
|
+
|
|
362
|
+
ds.addCollection({
|
|
363
|
+
name: 'organizations',
|
|
364
|
+
template: 'tree',
|
|
365
|
+
filterTargetKey: 'id',
|
|
366
|
+
fields: [
|
|
367
|
+
{ name: 'id', type: 'integer', interface: 'number', filterable: { operators: [] } },
|
|
368
|
+
{ name: 'code', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
369
|
+
{ name: 'name', type: 'string', interface: 'input', filterable: { operators: [] } },
|
|
370
|
+
],
|
|
371
|
+
});
|
|
372
|
+
ds.addCollection({
|
|
373
|
+
name: 'users',
|
|
374
|
+
filterTargetKey: 'id',
|
|
375
|
+
fields: [
|
|
376
|
+
{ name: 'id', type: 'integer', interface: 'number', filterable: { operators: [] } },
|
|
377
|
+
{
|
|
378
|
+
name: 'organization',
|
|
379
|
+
type: 'belongsTo',
|
|
380
|
+
interface: 'm2o',
|
|
381
|
+
target: 'organizations',
|
|
382
|
+
targetKey: 'code',
|
|
383
|
+
filterable: { operators: [] },
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const dataBlockModel = createDataBlockModel(engine);
|
|
389
|
+
const { gridModel, saveConnectFieldsConfig } = createGridModel(engine);
|
|
390
|
+
const subModel = createFilterItemModel(engine, dataBlockModel, 'organization', 'CascadeSelectFieldModel', {
|
|
391
|
+
fieldNames: { label: 'name', value: 'id' },
|
|
392
|
+
value: {
|
|
393
|
+
id: 52,
|
|
394
|
+
code: 'ORG-52',
|
|
395
|
+
name: 'Leaf organization',
|
|
396
|
+
parent: { id: 1, code: 'ORG-1', name: 'Root organization', parent: null },
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
subModel.mounted = true;
|
|
400
|
+
subModel.context.defineProperty('form', {
|
|
401
|
+
value: {
|
|
402
|
+
getFieldValue: () => subModel.subModels.field.props.value,
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
await gridModel.onModelCreated(subModel);
|
|
407
|
+
|
|
408
|
+
expect(subModel.getFilterValue()).toBe(52);
|
|
409
|
+
expect(saveConnectFieldsConfig).toHaveBeenCalledTimes(1);
|
|
410
|
+
const [, payload] = saveConnectFieldsConfig.mock.calls[0] as unknown as [unknown, unknown];
|
|
411
|
+
expect(payload).toEqual({
|
|
412
|
+
targets: [
|
|
413
|
+
{
|
|
414
|
+
targetId: dataBlockModel.uid,
|
|
415
|
+
filterPaths: ['organization.id'],
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
});
|
|
419
|
+
});
|
|
247
420
|
});
|