@nocobase/client-v2 2.2.0-beta.9 → 2.2.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.
- package/es/APIClient.d.ts +13 -3
- package/es/BaseApplication.d.ts +1 -0
- package/es/collection-field-interface/CollectionFieldInterface.d.ts +1 -0
- package/es/collection-field-interface/CollectionFieldInterfaceManager.d.ts +1 -0
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +3 -2
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +1 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +27 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +7 -24
- package/es/flow/components/FlowRoute.d.ts +2 -2
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- 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/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -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/ActionModelCore.d.ts +4 -2
- package/es/flow/models/base/BlockGridModel.d.ts +3 -0
- package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -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/QuickEditFormModel.d.ts +17 -2
- 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 +12 -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/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
- package/es/flow-compat/fieldValidationConstants.d.ts +1 -1
- package/es/flow-compat/passwordUtils.d.ts +1 -1
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +5 -0
- package/es/index.mjs +199 -161
- package/es/ui-operation/index.d.ts +15 -0
- package/es/ui-operation/ui-operation-codec.d.ts +10 -0
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +215 -177
- package/lib/locale/languageCodes.js +3 -1
- package/package.json +9 -7
- package/src/APIClient.ts +90 -7
- package/src/Application.tsx +7 -1
- package/src/BaseApplication.tsx +11 -6
- package/src/__tests__/APIClient.test.tsx +58 -0
- package/src/__tests__/app.test.tsx +73 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +35 -2
- package/src/__tests__/settings-center.test.tsx +270 -6
- package/src/acl/ACLProvider.tsx +2 -0
- package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
- package/src/collection-field-interface/CollectionFieldInterface.ts +1 -0
- package/src/collection-field-interface/CollectionFieldInterfaceManager.ts +1 -0
- package/src/collection-manager/field-validation.ts +1 -1
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/ScanInput/CodeScanner.tsx +79 -35
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +284 -11
- package/src/components/form/ScanInput/useCodeScanner.ts +332 -24
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +36 -9
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +55 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/components/index.ts +1 -0
- package/src/flow/FlowPage.tsx +9 -1
- package/src/flow/__tests__/FlowPage.test.tsx +50 -3
- package/src/flow/__tests__/FlowRoute.test.tsx +128 -10
- package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
- package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -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/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/__tests__/linkageRulesRefresh.test.ts +7 -3
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +144 -26
- package/src/flow/actions/linkageRulesRefresh.tsx +2 -6
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +0 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
- package/src/flow/common/Markdown/style.ts +4 -0
- package/src/flow/components/BlockItemCard.tsx +2 -2
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +72 -584
- package/src/flow/components/FlowRoute.tsx +78 -32
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +216 -0
- 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/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +170 -13
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +195 -1
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
- package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
- package/src/flow/index.ts +3 -0
- package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
- 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/ActionModelCore.tsx +11 -2
- package/src/flow/models/base/BlockGridModel.tsx +26 -0
- package/src/flow/models/base/CollectionBlockModel.tsx +38 -3
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +249 -18
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +1075 -7
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
- package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
- 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/FilterFormBlockModel.tsx +28 -3
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +155 -25
- 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 +395 -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-form/__tests__/defaultValues.wiring.test.ts +66 -4
- 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/QuickEditFormModel.tsx +189 -36
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
- package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +350 -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/js-block/JSBlock.tsx +1 -1
- package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +2 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +29 -3
- package/src/flow/models/blocks/table/TableColumnModel.tsx +48 -9
- 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/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -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 +10 -1
- 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/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
- package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
- package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
- package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
- package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +26 -10
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +51 -14
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
- package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
- package/src/flow-compat/fieldValidationConstants.ts +1 -1
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +5 -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/locale/languageCodes.ts +3 -1
- package/src/nocobase-buildin-plugin/index.tsx +12 -0
- package/src/settings-center/AdminSettingsLayout.tsx +23 -2
- package/src/ui-operation/index.ts +33 -0
- package/src/ui-operation/ui-operation-codec.ts +54 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowContext } from '@nocobase/flow-engine';
|
|
10
|
+
import { FlowContext, FlowEngine, FlowModel } from '@nocobase/flow-engine';
|
|
11
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
11
12
|
import { describe, expect, it, vi } from 'vitest';
|
|
12
13
|
import {
|
|
13
14
|
buildCurrentItemTitle,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
} from '../itemChain';
|
|
22
23
|
import { injectRecordPickerPopupContext } from '@nocobase/client-v2';
|
|
23
24
|
import {
|
|
25
|
+
RecordPickerFieldModel,
|
|
24
26
|
canRecordPickerSelectMultiple,
|
|
25
27
|
getRecordPickerClearedValue,
|
|
26
28
|
getRecordPickerEmptyValue,
|
|
@@ -28,8 +30,12 @@ import {
|
|
|
28
30
|
normalizeRecordPickerValue,
|
|
29
31
|
shouldClearRecordPickerValueOnMultipleChange,
|
|
30
32
|
} from '../RecordPickerFieldModel';
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
+
import {
|
|
34
|
+
collectAssociationHydrationCandidates,
|
|
35
|
+
useAssociationValueHydration,
|
|
36
|
+
getAssociationHydrationNamePath,
|
|
37
|
+
getAssociationHydrationSetterContext,
|
|
38
|
+
} from '../recordSelectShared';
|
|
33
39
|
function createMockCollection() {
|
|
34
40
|
return {
|
|
35
41
|
name: 'users',
|
|
@@ -78,6 +84,118 @@ describe('RecordPickerFieldModel item context', () => {
|
|
|
78
84
|
expect(normalizeRecordPickerValue(undefined, fieldNames, false)).toBeUndefined();
|
|
79
85
|
});
|
|
80
86
|
|
|
87
|
+
it('queues ID-only picker values for association label hydration', () => {
|
|
88
|
+
const statusMap = new Map<string, 'pending' | 'done'>();
|
|
89
|
+
const fieldNames = { label: 'name', value: 'id' };
|
|
90
|
+
|
|
91
|
+
expect(
|
|
92
|
+
collectAssociationHydrationCandidates({
|
|
93
|
+
value: [{ id: 1 }, { id: 2, name: 'Already hydrated' }],
|
|
94
|
+
isMultiple: true,
|
|
95
|
+
valueKey: fieldNames.value,
|
|
96
|
+
labelKey: fieldNames.label,
|
|
97
|
+
statusMap,
|
|
98
|
+
}),
|
|
99
|
+
).toEqual([{ item: { id: 1 }, tk: 1, tkKey: '1' }]);
|
|
100
|
+
expect(statusMap).toEqual(new Map([['1', 'pending']]));
|
|
101
|
+
|
|
102
|
+
expect(
|
|
103
|
+
collectAssociationHydrationCandidates({
|
|
104
|
+
value: { id: 1 },
|
|
105
|
+
isMultiple: false,
|
|
106
|
+
valueKey: fieldNames.value,
|
|
107
|
+
labelKey: fieldNames.label,
|
|
108
|
+
statusMap,
|
|
109
|
+
}),
|
|
110
|
+
).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('hydrates an ID-only picker value back into the form', async () => {
|
|
114
|
+
const resource = {
|
|
115
|
+
get: vi.fn().mockResolvedValue({ id: 1, name: '北京启明教育' }),
|
|
116
|
+
};
|
|
117
|
+
const setFormValue = vi.fn();
|
|
118
|
+
const onChange = vi.fn();
|
|
119
|
+
const model = {
|
|
120
|
+
resource,
|
|
121
|
+
props: { name: 'company' },
|
|
122
|
+
context: {
|
|
123
|
+
fieldPathArray: ['company'],
|
|
124
|
+
setFormValue,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const { rerender } = renderHook(() =>
|
|
129
|
+
useAssociationValueHydration({
|
|
130
|
+
model,
|
|
131
|
+
value: { id: 1 },
|
|
132
|
+
isMultiple: false,
|
|
133
|
+
fieldNames: { label: 'name', value: 'id' },
|
|
134
|
+
onChange,
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
await waitFor(() => {
|
|
139
|
+
expect(setFormValue).toHaveBeenCalledWith(
|
|
140
|
+
['company'],
|
|
141
|
+
{ id: 1, name: '北京启明教育' },
|
|
142
|
+
{ source: 'default', markExplicit: false, triggerEvent: false },
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
rerender();
|
|
146
|
+
|
|
147
|
+
expect(resource.get).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('initializes a target resource before hydrating an ID-only picker value', async () => {
|
|
152
|
+
const engine = new FlowEngine();
|
|
153
|
+
engine.registerModels({ RecordPickerFieldModel });
|
|
154
|
+
|
|
155
|
+
const formItem = engine.createModel<FlowModel>({
|
|
156
|
+
use: 'FlowModel',
|
|
157
|
+
uid: 'form-item',
|
|
158
|
+
});
|
|
159
|
+
const field = engine.createModel<RecordPickerFieldModel>({
|
|
160
|
+
use: 'RecordPickerFieldModel',
|
|
161
|
+
uid: 'company-field',
|
|
162
|
+
parentId: formItem.uid,
|
|
163
|
+
});
|
|
164
|
+
const setFormValue = vi.fn();
|
|
165
|
+
field.context.defineProperty('collectionField', {
|
|
166
|
+
value: {
|
|
167
|
+
dataSourceKey: 'main',
|
|
168
|
+
target: 'rp_na_companies',
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
field.context.defineProperty('fieldPathArray', { value: ['company'] });
|
|
172
|
+
field.context.defineProperty('setFormValue', { value: setFormValue });
|
|
173
|
+
|
|
174
|
+
await field.applyFlow('recordPickerSettings');
|
|
175
|
+
const get = vi.spyOn(field.resource, 'get').mockResolvedValue({ id: 1, name: '北京启明教育' });
|
|
176
|
+
const onChange = vi.fn();
|
|
177
|
+
|
|
178
|
+
renderHook(() =>
|
|
179
|
+
useAssociationValueHydration({
|
|
180
|
+
model: field,
|
|
181
|
+
value: { id: 1 },
|
|
182
|
+
isMultiple: false,
|
|
183
|
+
fieldNames: { label: 'name', value: 'id' },
|
|
184
|
+
onChange,
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
await waitFor(() => {
|
|
189
|
+
expect(get).toHaveBeenCalledWith(1);
|
|
190
|
+
expect(setFormValue).toHaveBeenCalledWith(
|
|
191
|
+
['company'],
|
|
192
|
+
{ id: 1, name: '北京启明教育' },
|
|
193
|
+
{ source: 'default', markExplicit: false, triggerEvent: false },
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
197
|
+
});
|
|
198
|
+
|
|
81
199
|
it('returns the empty popup select value for the current multiple mode', () => {
|
|
82
200
|
expect(getRecordPickerEmptyValue(true)).toEqual([]);
|
|
83
201
|
expect(getRecordPickerEmptyValue(false)).toBeUndefined();
|
|
@@ -243,6 +361,52 @@ describe('RecordPickerFieldModel item context', () => {
|
|
|
243
361
|
expect(associationOpts.serverOnlyWhenContextParams).toBe(true);
|
|
244
362
|
});
|
|
245
363
|
|
|
364
|
+
it('builds whole-association descriptors for current and recursive parent item values', async () => {
|
|
365
|
+
const people = {
|
|
366
|
+
name: 'people',
|
|
367
|
+
dataSourceKey: 'main',
|
|
368
|
+
filterTargetKey: 'id',
|
|
369
|
+
getFields: () => [],
|
|
370
|
+
getField: () => undefined,
|
|
371
|
+
} as any;
|
|
372
|
+
const owner = {
|
|
373
|
+
name: 'owner',
|
|
374
|
+
target: 'people',
|
|
375
|
+
targetCollection: people,
|
|
376
|
+
isAssociationField: () => true,
|
|
377
|
+
} as any;
|
|
378
|
+
const collection = {
|
|
379
|
+
name: 'tasks',
|
|
380
|
+
dataSourceKey: 'main',
|
|
381
|
+
getFields: () => [owner],
|
|
382
|
+
getField: (name: string) => (name === 'owner' ? owner : undefined),
|
|
383
|
+
} as any;
|
|
384
|
+
const options = createAssociationItemChainContextPropertyOptions({
|
|
385
|
+
t: (value) => value,
|
|
386
|
+
title: 'Current item',
|
|
387
|
+
collectionAccessor: () => collection,
|
|
388
|
+
propertiesAccessor: (ctx) => ctx.item.value,
|
|
389
|
+
resolverPropertiesAccessor: () => ({ owner: { id: 7 } }),
|
|
390
|
+
parentCollectionAccessor: () => collection,
|
|
391
|
+
parentAccessors: {
|
|
392
|
+
parentPropertiesAccessor: () => ({ owner: { id: 8 } }),
|
|
393
|
+
parentItemMetaAccessor: () => undefined,
|
|
394
|
+
parentItemResolverAccessor: () => undefined,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
const meta = await options.meta();
|
|
398
|
+
const params = await meta.buildVariablesParams({
|
|
399
|
+
item: { value: { owner: { id: 7 } }, parentItem: { value: { owner: { id: 8 } } } },
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
expect(params).toEqual({
|
|
403
|
+
parentItem: { value: { owner: { collection: 'people', dataSourceKey: 'main', filterByTk: 8 } } },
|
|
404
|
+
value: { owner: { collection: 'people', dataSourceKey: 'main', filterByTk: 7 } },
|
|
405
|
+
});
|
|
406
|
+
expect(options.resolveOnServer('value.owner.name')).toBe(true);
|
|
407
|
+
expect(options.resolveOnServer('parentItem.value.owner.name')).toBe(true);
|
|
408
|
+
});
|
|
409
|
+
|
|
246
410
|
it('disables current item attributes for select-record popup item context', async () => {
|
|
247
411
|
const parentCtx = new FlowContext();
|
|
248
412
|
const departmentsCollection = {
|
|
@@ -119,6 +119,162 @@ export interface LazySelectProps extends Omit<SelectProps<any>, 'mode' | 'option
|
|
|
119
119
|
allowEdit?: boolean;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
type AssociationHydrationSetterOptions = {
|
|
123
|
+
source?: string;
|
|
124
|
+
markExplicit?: boolean;
|
|
125
|
+
triggerEvent?: boolean;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type AssociationHydrationSetterContext = {
|
|
129
|
+
setFormValue?: (
|
|
130
|
+
namePath: unknown,
|
|
131
|
+
value: unknown,
|
|
132
|
+
options?: AssociationHydrationSetterOptions,
|
|
133
|
+
) => Promise<unknown> | void;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type AssociationHydrationModel = {
|
|
137
|
+
resource?: {
|
|
138
|
+
get?: (tk: unknown) => Promise<unknown> | unknown;
|
|
139
|
+
};
|
|
140
|
+
context?: unknown;
|
|
141
|
+
props?: {
|
|
142
|
+
name?: unknown;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
type AssociationHydrationStatus = 'pending' | 'done';
|
|
147
|
+
|
|
148
|
+
type AssociationHydrationCandidate = {
|
|
149
|
+
item: AssociationOption;
|
|
150
|
+
tk: unknown;
|
|
151
|
+
tkKey: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export function isAssociationRecord(value: unknown): value is AssociationOption {
|
|
155
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function collectAssociationHydrationCandidates(options: {
|
|
159
|
+
value: LazySelectProps['value'];
|
|
160
|
+
isMultiple: boolean;
|
|
161
|
+
valueKey: string;
|
|
162
|
+
labelKey: string;
|
|
163
|
+
statusMap: Map<string, AssociationHydrationStatus>;
|
|
164
|
+
}): AssociationHydrationCandidate[] {
|
|
165
|
+
const { value, isMultiple, valueKey, labelKey, statusMap } = options;
|
|
166
|
+
const list = isMultiple ? (Array.isArray(value) ? value : []) : value != null ? [value] : [];
|
|
167
|
+
const activeTkKeys = new Set<string>();
|
|
168
|
+
|
|
169
|
+
for (const item of list) {
|
|
170
|
+
if (!isAssociationRecord(item)) continue;
|
|
171
|
+
const tk = item[valueKey];
|
|
172
|
+
if (tk == null) continue;
|
|
173
|
+
const tkKey = typeof tk === 'object' ? JSON.stringify(tk) : String(tk);
|
|
174
|
+
if (tkKey) activeTkKeys.add(tkKey);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
for (const key of Array.from(statusMap.keys())) {
|
|
178
|
+
if (!activeTkKeys.has(key)) statusMap.delete(key);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const candidates: AssociationHydrationCandidate[] = [];
|
|
182
|
+
for (const item of list) {
|
|
183
|
+
if (!isAssociationRecord(item)) continue;
|
|
184
|
+
const tk = item[valueKey];
|
|
185
|
+
if (tk == null || item[labelKey] != null) continue;
|
|
186
|
+
|
|
187
|
+
const tkKey = typeof tk === 'object' ? JSON.stringify(tk) : String(tk);
|
|
188
|
+
if (!tkKey || statusMap.has(tkKey)) continue;
|
|
189
|
+
|
|
190
|
+
statusMap.set(tkKey, 'pending');
|
|
191
|
+
candidates.push({ item, tk, tkKey });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return candidates;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function hasAssociationHydrationSetter(value: unknown): value is AssociationHydrationSetterContext {
|
|
198
|
+
return isAssociationRecord(value) && typeof value.setFormValue === 'function';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function getAssociationHydrationNamePath(model: AssociationHydrationModel) {
|
|
202
|
+
const context = isAssociationRecord(model.context) ? model.context : undefined;
|
|
203
|
+
return context?.fieldPathArray ?? context?.fieldPath ?? model.props?.name;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function getAssociationHydrationSetterContext(model: AssociationHydrationModel) {
|
|
207
|
+
if (hasAssociationHydrationSetter(model.context)) return model.context;
|
|
208
|
+
|
|
209
|
+
const context = isAssociationRecord(model.context) ? model.context : undefined;
|
|
210
|
+
const blockModel = isAssociationRecord(context?.blockModel) ? context.blockModel : undefined;
|
|
211
|
+
return hasAssociationHydrationSetter(blockModel?.context) ? blockModel.context : undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function useAssociationValueHydration(options: {
|
|
215
|
+
model: AssociationHydrationModel;
|
|
216
|
+
value: LazySelectProps['value'];
|
|
217
|
+
isMultiple: boolean;
|
|
218
|
+
fieldNames: AssociationFieldNames;
|
|
219
|
+
onChange: LazySelectProps['onChange'];
|
|
220
|
+
}) {
|
|
221
|
+
const { model, value, isMultiple, fieldNames, onChange } = options;
|
|
222
|
+
const hydrateStatusRef = React.useRef<Map<string, AssociationHydrationStatus>>(new Map());
|
|
223
|
+
|
|
224
|
+
React.useEffect(() => {
|
|
225
|
+
const resource = model.resource;
|
|
226
|
+
if (typeof resource?.get !== 'function' || !fieldNames.value || !fieldNames.label) return;
|
|
227
|
+
|
|
228
|
+
const current = value;
|
|
229
|
+
const candidates = collectAssociationHydrationCandidates({
|
|
230
|
+
value: current,
|
|
231
|
+
isMultiple,
|
|
232
|
+
valueKey: fieldNames.value,
|
|
233
|
+
labelKey: fieldNames.label,
|
|
234
|
+
statusMap: hydrateStatusRef.current,
|
|
235
|
+
});
|
|
236
|
+
if (!candidates.length) return;
|
|
237
|
+
|
|
238
|
+
const namePath = getAssociationHydrationNamePath(model);
|
|
239
|
+
const setterContext = getAssociationHydrationSetterContext(model);
|
|
240
|
+
|
|
241
|
+
const hydrateCandidate = async ({ item, tk, tkKey }: AssociationHydrationCandidate) => {
|
|
242
|
+
try {
|
|
243
|
+
const record = await resource.get?.(tk);
|
|
244
|
+
if (!isAssociationRecord(record)) return;
|
|
245
|
+
|
|
246
|
+
const merged = { ...item, ...record };
|
|
247
|
+
if (merged[fieldNames.label] == null) return;
|
|
248
|
+
|
|
249
|
+
const nextValue = isMultiple
|
|
250
|
+
? (Array.isArray(current) ? current : []).map((entry) =>
|
|
251
|
+
isAssociationRecord(entry) && entry[fieldNames.value] === tk ? merged : entry,
|
|
252
|
+
)
|
|
253
|
+
: merged;
|
|
254
|
+
|
|
255
|
+
if (typeof setterContext?.setFormValue === 'function' && namePath != null) {
|
|
256
|
+
await setterContext.setFormValue(namePath, nextValue, {
|
|
257
|
+
source: 'default',
|
|
258
|
+
markExplicit: false,
|
|
259
|
+
triggerEvent: false,
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
onChange(nextValue);
|
|
265
|
+
} catch {
|
|
266
|
+
// Keep the original ID-only value when the related record cannot be loaded.
|
|
267
|
+
} finally {
|
|
268
|
+
hydrateStatusRef.current.set(tkKey, 'done');
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
candidates.forEach((candidate) => {
|
|
273
|
+
hydrateCandidate(candidate);
|
|
274
|
+
});
|
|
275
|
+
}, [fieldNames.label, fieldNames.value, isMultiple, model, onChange, value]);
|
|
276
|
+
}
|
|
277
|
+
|
|
122
278
|
export interface LabelByFieldProps {
|
|
123
279
|
option: AssociationOption;
|
|
124
280
|
fieldNames: AssociationFieldNames;
|
|
@@ -17,6 +17,8 @@ import { DateTimeNoTzPicker } from '../DateTimeNoTzFieldModel';
|
|
|
17
17
|
let capturedDatePickerProps: any;
|
|
18
18
|
let currentForm: any;
|
|
19
19
|
const mockResolveJsonTemplate = vi.fn();
|
|
20
|
+
const mockRunjs = vi.fn();
|
|
21
|
+
const mockLoggerWarn = vi.fn();
|
|
20
22
|
|
|
21
23
|
vi.mock('@nocobase/flow-engine', async (importOriginal) => {
|
|
22
24
|
const actual = await importOriginal<typeof import('@nocobase/flow-engine')>();
|
|
@@ -32,6 +34,10 @@ vi.mock('@nocobase/flow-engine', async (importOriginal) => {
|
|
|
32
34
|
}),
|
|
33
35
|
useFlowContext: () => ({
|
|
34
36
|
resolveJsonTemplate: mockResolveJsonTemplate,
|
|
37
|
+
runjs: mockRunjs,
|
|
38
|
+
logger: {
|
|
39
|
+
warn: mockLoggerWarn,
|
|
40
|
+
},
|
|
35
41
|
}),
|
|
36
42
|
};
|
|
37
43
|
});
|
|
@@ -64,6 +70,9 @@ describe('DateTimeNoTzPicker date range limit', () => {
|
|
|
64
70
|
currentForm = undefined;
|
|
65
71
|
capturedDatePickerProps = undefined;
|
|
66
72
|
mockResolveJsonTemplate.mockReset();
|
|
73
|
+
mockRunjs.mockReset();
|
|
74
|
+
mockLoggerWarn.mockReset();
|
|
75
|
+
mockRunjs.mockResolvedValue({ success: true, value: undefined });
|
|
67
76
|
mockResolveJsonTemplate.mockImplementation(async (params) => ({
|
|
68
77
|
...params,
|
|
69
78
|
_maxDate: currentForm?.getFieldValue?.('b'),
|
|
@@ -239,4 +248,144 @@ describe('DateTimeNoTzPicker date range limit', () => {
|
|
|
239
248
|
expect(timeConfig?.disabledMinutes?.(12)).toEqual([]);
|
|
240
249
|
expect(timeConfig?.disabledSeconds?.(12, 34)).toEqual([]);
|
|
241
250
|
});
|
|
251
|
+
|
|
252
|
+
it('evaluates RunJS before applying minDate', async () => {
|
|
253
|
+
const code = 'return new Date("2026-05-10T08:09:10.000Z").toISOString();';
|
|
254
|
+
mockRunjs.mockResolvedValue({ success: true, value: '2026-05-10T08:09:10.000Z' });
|
|
255
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
256
|
+
|
|
257
|
+
render(<TestWrapper picker="date" showTime _minDate={{ code, version: 'v2' }} onChange={vi.fn()} value={null} />);
|
|
258
|
+
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
261
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-10 00:00:00'))).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(mockRunjs.mock.calls[0]?.[0]).toBe(code);
|
|
265
|
+
expect(mockRunjs.mock.calls[0]?.[2]).toEqual({ version: 'v2' });
|
|
266
|
+
expect(mockResolveJsonTemplate).toHaveBeenCalledWith({
|
|
267
|
+
_minDate: '2026-05-10T08:09:10.000Z',
|
|
268
|
+
_maxDate: undefined,
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('supports a RunJS minDate together with a variable maxDate', async () => {
|
|
273
|
+
mockRunjs.mockResolvedValue({ success: true, value: '2026-05-10 08:00:00' });
|
|
274
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => ({
|
|
275
|
+
...params,
|
|
276
|
+
_maxDate: '2026-05-12 18:30:40',
|
|
277
|
+
}));
|
|
278
|
+
|
|
279
|
+
render(
|
|
280
|
+
<TestWrapper
|
|
281
|
+
picker="date"
|
|
282
|
+
showTime
|
|
283
|
+
_minDate={{ code: 'return "2026-05-10 08:00:00";', version: 'v2' }}
|
|
284
|
+
_maxDate={'{{ $nForm.max }}'}
|
|
285
|
+
onChange={vi.fn()}
|
|
286
|
+
value={null}
|
|
287
|
+
/>,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
await waitFor(() => {
|
|
291
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
292
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-13 00:00:00'))).toBe(true);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-11 00:00:00'))).toBe(false);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('clears stale restrictions when RunJS execution fails', async () => {
|
|
299
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
300
|
+
mockRunjs.mockImplementation(async (code) => {
|
|
301
|
+
if (code === 'throw new Error("failed");') {
|
|
302
|
+
return { success: false, error: new Error('failed') };
|
|
303
|
+
}
|
|
304
|
+
return { success: true, value: '2026-05-10 08:00:00' };
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const view = render(
|
|
308
|
+
<TestWrapper
|
|
309
|
+
picker="date"
|
|
310
|
+
showTime
|
|
311
|
+
_minDate={{ code: 'return "2026-05-10 08:00:00";', version: 'v2' }}
|
|
312
|
+
onChange={vi.fn()}
|
|
313
|
+
value={null}
|
|
314
|
+
/>,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
await waitFor(() => {
|
|
318
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-09 00:00:00'))).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
view.rerender(
|
|
322
|
+
<TestWrapper
|
|
323
|
+
picker="date"
|
|
324
|
+
showTime
|
|
325
|
+
_minDate={{ code: 'throw new Error("failed");', version: 'v2' }}
|
|
326
|
+
onChange={vi.fn()}
|
|
327
|
+
value={null}
|
|
328
|
+
/>,
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
await waitFor(() => {
|
|
332
|
+
expect(mockLoggerWarn).toHaveBeenCalled();
|
|
333
|
+
expect(capturedDatePickerProps?.minDate).toBeNull();
|
|
334
|
+
expect(capturedDatePickerProps?.disabledDate).toBeNull();
|
|
335
|
+
expect(capturedDatePickerProps?.disabledTime).toBeNull();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('keeps the latest RunJS result when an earlier execution finishes later', async () => {
|
|
340
|
+
const slowResolvers: Array<(result: { success: boolean; value: string }) => void> = [];
|
|
341
|
+
mockResolveJsonTemplate.mockImplementation(async (params) => params);
|
|
342
|
+
mockRunjs.mockImplementation((code) => {
|
|
343
|
+
if (code === 'return "slow";') {
|
|
344
|
+
return new Promise((resolve) => {
|
|
345
|
+
slowResolvers.push(resolve);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return Promise.resolve({ success: true, value: '2026-06-01 00:00:00' });
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const view = render(
|
|
352
|
+
<TestWrapper
|
|
353
|
+
picker="date"
|
|
354
|
+
showTime
|
|
355
|
+
_minDate={{ code: 'return "slow";', version: 'v2' }}
|
|
356
|
+
onChange={vi.fn()}
|
|
357
|
+
value={null}
|
|
358
|
+
/>,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
await waitFor(() => {
|
|
362
|
+
expect(slowResolvers.length).toBeGreaterThan(0);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
view.rerender(
|
|
366
|
+
<TestWrapper
|
|
367
|
+
picker="date"
|
|
368
|
+
showTime
|
|
369
|
+
_minDate={{ code: 'return "fast";', version: 'v2' }}
|
|
370
|
+
onChange={vi.fn()}
|
|
371
|
+
value={null}
|
|
372
|
+
/>,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
await waitFor(() => {
|
|
376
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-05-31 00:00:00'))).toBe(true);
|
|
377
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-07-01 00:00:00'))).toBe(false);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
slowResolvers.forEach((resolve) => resolve({ success: true, value: '2026-12-01 00:00:00' }));
|
|
381
|
+
|
|
382
|
+
await waitFor(() => {
|
|
383
|
+
expect(mockResolveJsonTemplate).toHaveBeenCalledWith({
|
|
384
|
+
_minDate: '2026-12-01 00:00:00',
|
|
385
|
+
_maxDate: undefined,
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(capturedDatePickerProps?.disabledDate?.(dayjs('2026-07-01 00:00:00'))).toBe(false);
|
|
390
|
+
});
|
|
242
391
|
});
|