@nocobase/client-v2 2.1.0-alpha.46 → 2.1.0-alpha.47
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/collection-manager/filter-operators/index.d.ts +1 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +5 -1
- package/es/components/form/filter/FilterValueInput.d.ts +5 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +26 -3
- package/es/flow/models/blocks/filter-manager/utils.d.ts +23 -1
- package/es/index.mjs +77 -77
- package/lib/index.js +82 -82
- package/package.json +7 -7
- package/src/__tests__/browserChecker.test.ts +103 -0
- package/src/__tests__/dataSourceRuntime.test.tsx +22 -1
- package/src/collection-field-interface/CollectionFieldInterface.ts +14 -7
- package/src/collection-manager/filter-operators/index.ts +29 -2
- package/src/components/form/filter/CollectionFilterItem.tsx +10 -2
- package/src/components/form/filter/FilterValueInput.tsx +27 -2
- package/src/components/form/filter/__tests__/FilterValueInput.test.tsx +39 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +369 -2
- package/src/flow/actions/linkageRules.tsx +53 -0
- package/src/flow/components/DefaultValue.tsx +14 -8
- package/src/flow/components/FieldAssignValueInput.tsx +6 -10
- package/src/flow/components/filter/LinkageFilterItem.tsx +4 -3
- package/src/flow/components/filter/VariableFilterItem.tsx +5 -4
- package/src/flow/internal/utils/operatorSchemaHelper.ts +112 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +13 -11
- package/src/flow/models/blocks/filter-manager/__tests__/getDefaultOperator.test.ts +35 -1
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +148 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/defaultOperator.test.tsx +85 -0
- package/src/flow/models/blocks/filter-manager/flow-actions/customizeFilterRender.tsx +14 -44
- package/src/flow/models/blocks/filter-manager/flow-actions/defaultOperator.tsx +3 -5
- package/src/flow/models/blocks/filter-manager/flow-actions/operatorComponentProps.tsx +2 -12
- package/src/flow/models/blocks/filter-manager/utils.ts +143 -4
|
@@ -8,14 +8,153 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { FlowModel } from '@nocobase/flow-engine';
|
|
11
|
+
import {
|
|
12
|
+
normalizeFilterableOperators,
|
|
13
|
+
type FieldFilterable,
|
|
14
|
+
type FieldFilterOperator,
|
|
15
|
+
} from '../../../../collection-manager/filter-operators';
|
|
16
|
+
import { operators } from '../../../../flow-compat';
|
|
11
17
|
import { BlockGridModel, CollectionBlockModel } from '../../base';
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
type FilterFormFieldMeta = {
|
|
20
|
+
filterable?: FieldFilterable<unknown> | false;
|
|
21
|
+
interface?: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type FilterFormOperatorModel = FlowModel & {
|
|
26
|
+
operator?: string;
|
|
27
|
+
collectionField?: FilterFormFieldMeta;
|
|
28
|
+
filterField?: FilterFormFieldMeta;
|
|
29
|
+
subModels?: {
|
|
30
|
+
field?: {
|
|
31
|
+
operator?: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
getStepParams?: (flowKey: string, stepKey: string) => { value?: string } | undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function getModelContext(model: FlowModel) {
|
|
38
|
+
return model.context as unknown as Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getModelField(model: FlowModel, key: 'collectionField' | 'filterField') {
|
|
42
|
+
const modelWithFields = model as FilterFormOperatorModel;
|
|
43
|
+
const field = modelWithFields[key] || getModelContext(model)?.[key];
|
|
44
|
+
return field && typeof field === 'object' ? (field as FilterFormFieldMeta) : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getDataSourceManager(model: FlowModel) {
|
|
48
|
+
const contextManager = getModelContext(model)?.dataSourceManager;
|
|
49
|
+
if (contextManager) {
|
|
50
|
+
return contextManager as Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
return model.flowEngine?.context?.dataSourceManager as unknown as Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function cloneFilterable(filterable: FieldFilterable<unknown>): FieldFilterable<unknown> {
|
|
56
|
+
return {
|
|
57
|
+
operatorGroup: filterable.operatorGroup,
|
|
58
|
+
operators: Array.isArray(filterable.operators) ? [...filterable.operators] : filterable.operators,
|
|
59
|
+
operatorOverrides: Array.isArray(filterable.operatorOverrides)
|
|
60
|
+
? [...filterable.operatorOverrides]
|
|
61
|
+
: filterable.operatorOverrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getFilterableOperators(filterable?: FieldFilterable<unknown> | false) {
|
|
66
|
+
if (filterable === false) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!filterable || typeof filterable !== 'object') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const normalized = normalizeFilterableOperators(cloneFilterable(filterable));
|
|
75
|
+
if (Array.isArray(normalized?.operators) && normalized.operators.length > 0) {
|
|
76
|
+
return normalized.operators;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (Array.isArray(normalized?.operatorOverrides) && normalized.operatorOverrides.length > 0) {
|
|
80
|
+
return normalized.operatorOverrides;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getFieldInterfaceFilterable(model: FlowModel, field?: FilterFormFieldMeta) {
|
|
85
|
+
const interfaceName = typeof field?.interface === 'string' ? field.interface : undefined;
|
|
86
|
+
if (!interfaceName) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const dataSourceManager = getDataSourceManager(model);
|
|
91
|
+
const fieldInterfaceManager = dataSourceManager?.collectionFieldInterfaceManager as
|
|
92
|
+
| {
|
|
93
|
+
getFieldInterface?: (name: string) => { filterable?: FieldFilterable<unknown> | false } | undefined;
|
|
94
|
+
}
|
|
95
|
+
| undefined;
|
|
96
|
+
const fieldInterface = fieldInterfaceManager?.getFieldInterface?.(interfaceName);
|
|
97
|
+
return fieldInterface?.filterable;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getFallbackOperators(field?: FilterFormFieldMeta) {
|
|
101
|
+
const fallbackKeys = [field?.interface, field?.type].filter((item): item is string => typeof item === 'string');
|
|
102
|
+
const standardOperators = operators as Record<string, FieldFilterOperator<unknown>[] | undefined>;
|
|
103
|
+
for (const key of fallbackKeys) {
|
|
104
|
+
const operatorList = standardOperators[key];
|
|
105
|
+
if (operatorList?.length) {
|
|
106
|
+
return operatorList;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function getFilterFormOperatorList(model: FlowModel) {
|
|
113
|
+
const collectionField = getModelField(model, 'collectionField');
|
|
114
|
+
const filterField = getModelField(model, 'filterField');
|
|
115
|
+
const field = collectionField || filterField;
|
|
116
|
+
|
|
117
|
+
if (field?.filterable === false) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const fieldOperators = getFilterableOperators(field?.filterable);
|
|
122
|
+
if (fieldOperators?.length) {
|
|
123
|
+
return fieldOperators;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const fieldInterfaceFilterable = getFieldInterfaceFilterable(model, field);
|
|
127
|
+
if (fieldInterfaceFilterable === false) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const fieldInterfaceOperators = getFilterableOperators(fieldInterfaceFilterable);
|
|
132
|
+
if (fieldInterfaceOperators?.length) {
|
|
133
|
+
return fieldInterfaceOperators;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return getFallbackOperators(field);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function getFilterFormOperatorMeta(model: FlowModel, operator = getDefaultOperator(model)) {
|
|
140
|
+
if (!operator) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const meta = getModelField(model, 'collectionField') || getModelField(model, 'filterField');
|
|
145
|
+
return (
|
|
146
|
+
getFilterFormOperatorList(model).find((op) => op.value === operator && (!op.visible || op.visible(meta))) || null
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function getDefaultOperator(model: FilterFormOperatorModel) {
|
|
151
|
+
const operatorList = getFilterFormOperatorList(model);
|
|
14
152
|
return (
|
|
15
153
|
model.operator ||
|
|
16
|
-
model.getStepParams('filterFormItemSettings', 'defaultOperator')?.value ||
|
|
17
|
-
model.subModels
|
|
18
|
-
|
|
154
|
+
model.getStepParams?.('filterFormItemSettings', 'defaultOperator')?.value ||
|
|
155
|
+
model.subModels?.field?.operator ||
|
|
156
|
+
operatorList.find((op) => op.selected)?.value ||
|
|
157
|
+
operatorList[0]?.value ||
|
|
19
158
|
'$includes'
|
|
20
159
|
);
|
|
21
160
|
}
|