@nocobase/client-v2 2.4.0-alpha.1 → 2.4.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/RouteRepository.d.ts +6 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +12 -2
- package/es/components/form/ScanInput/zxingWasmDecoder.d.ts +9 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +10 -1
- package/es/flow/internal/utils/quickEditDataScope.d.ts +48 -0
- package/es/flow/internal/utils/quickEditViewContainer.d.ts +27 -0
- package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +1 -0
- package/es/index.mjs +77 -77
- package/lib/index.js +131 -131
- package/package.json +9 -8
- package/src/BaseApplication.tsx +2 -0
- package/src/RouteRepository.ts +14 -0
- package/src/__tests__/RouteRepository.test.ts +51 -0
- package/src/__tests__/app.test.tsx +13 -0
- package/src/collection-manager/__tests__/field-configure.test.ts +52 -0
- package/src/collection-manager/field-configure.ts +2 -2
- package/src/components/form/ScanInput/CodeScanner.tsx +3 -1
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +7 -1
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +182 -8
- package/src/components/form/ScanInput/__tests__/zxingWasmDecoder.test.ts +78 -0
- package/src/components/form/ScanInput/useCodeScanner.ts +135 -20
- package/src/components/form/ScanInput/zxingWasmDecoder.ts +64 -0
- package/src/flow/actions/__tests__/validation.test.ts +48 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +39 -0
- package/src/flow/components/FieldAssignValueInput.tsx +4 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +21 -12
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +9 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +14 -4
- package/src/flow/components/filter/__tests__/VariableFilterItem.rightMetaTree.test.tsx +158 -0
- package/src/flow/internal/utils/__tests__/quickEditDataScope.test.ts +156 -0
- package/src/flow/internal/utils/__tests__/quickEditViewContainer.test.ts +52 -0
- package/src/flow/internal/utils/quickEditDataScope.tsx +177 -0
- package/src/flow/internal/utils/quickEditViewContainer.ts +46 -0
- package/src/flow/models/actions/JSItemActionModel.tsx +19 -3
- package/src/flow/models/actions/__tests__/JSItemActionModel.test.tsx +47 -1
- package/src/flow/models/base/GridModel.tsx +0 -1
- package/src/flow/models/blocks/assign-form/AssignFormGridModel.tsx +22 -1
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +14 -3
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.editor.test.tsx +140 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +29 -0
- package/src/flow/models/blocks/filter-form/fields/FieldComponentProps.tsx +1 -1
- package/src/flow/models/blocks/filter-form/fields/__tests__/FieldComponentProps.options.test.tsx +61 -0
- package/src/flow/models/blocks/form/FormBlockModel.tsx +26 -5
- package/src/flow/models/blocks/form/QuickEditFormModel.tsx +45 -11
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +145 -0
- package/src/flow/models/blocks/form/__tests__/QuickEditFormModel.quickEdit.test.ts +120 -0
- package/src/flow/models/blocks/form/__tests__/popupLinkage.test.tsx +175 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +5 -1
- package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +23 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +31 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +64 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +7 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +4 -3
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +9 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +47 -17
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +6 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.largeField.test.tsx +178 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableField.disabled.test.tsx +90 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordSelectFieldModel.quickCreatePopup.test.tsx +183 -0
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubTableFieldModel.tsx +42 -7
- package/src/flow/models/fields/DisplayAssociationField/__tests__/DisplaySubTableFieldModel.test.tsx +351 -0
- package/src/flow/models/fields/SelectFieldModel.tsx +5 -0
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +29 -1
|
@@ -8,13 +8,59 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import React from 'react';
|
|
11
|
-
import { render, screen, waitFor } from '@nocobase/test/client';
|
|
11
|
+
import { act, render, screen, waitFor } from '@nocobase/test/client';
|
|
12
12
|
import { App, ConfigProvider } from 'antd';
|
|
13
13
|
import { describe, expect, it } from 'vitest';
|
|
14
14
|
import { FlowEngine, FlowEngineProvider, FlowModelRenderer } from '@nocobase/flow-engine';
|
|
15
15
|
import { JSItemActionModel } from '../JSItemActionModel';
|
|
16
16
|
|
|
17
17
|
describe('JSItemActionModel', () => {
|
|
18
|
+
it('keeps empty items reachable in configuration mode without replacing rendered content', async () => {
|
|
19
|
+
const engine = new FlowEngine();
|
|
20
|
+
engine.registerModels({ JSItemActionModel });
|
|
21
|
+
const model = engine.createModel<JSItemActionModel>({ use: 'JSItemActionModel' });
|
|
22
|
+
await engine.flowSettings.disable();
|
|
23
|
+
|
|
24
|
+
render(model.render());
|
|
25
|
+
const host = model.context.ref.current;
|
|
26
|
+
expect(host).toBeInstanceOf(HTMLDivElement);
|
|
27
|
+
expect(host.style.minWidth).toBe('');
|
|
28
|
+
expect(host.textContent).toBe('');
|
|
29
|
+
|
|
30
|
+
await act(async () => {
|
|
31
|
+
await engine.flowSettings.enable();
|
|
32
|
+
});
|
|
33
|
+
await waitFor(() => expect(host.style.minWidth).toBe('40px'));
|
|
34
|
+
|
|
35
|
+
const content = document.createElement('button');
|
|
36
|
+
content.textContent = 'Custom action';
|
|
37
|
+
host.appendChild(content);
|
|
38
|
+
|
|
39
|
+
await act(async () => {
|
|
40
|
+
await engine.flowSettings.disable();
|
|
41
|
+
});
|
|
42
|
+
await waitFor(() => expect(host.style.minWidth).toBe(''));
|
|
43
|
+
expect(model.context.ref.current).toBe(host);
|
|
44
|
+
expect(host.firstElementChild).toBe(content);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('keeps hidden empty items configurable and removes them outside configuration mode', async () => {
|
|
48
|
+
const engine = new FlowEngine();
|
|
49
|
+
engine.registerModels({ JSItemActionModel });
|
|
50
|
+
const model = engine.createModel<JSItemActionModel>({ use: 'JSItemActionModel' });
|
|
51
|
+
model.setHidden(true);
|
|
52
|
+
await engine.flowSettings.enable();
|
|
53
|
+
|
|
54
|
+
const { container } = render(model.render());
|
|
55
|
+
expect(model.context.ref.current.style.minWidth).toBe('40px');
|
|
56
|
+
expect(model.context.ref.current.style.opacity).toBe('0.3');
|
|
57
|
+
|
|
58
|
+
await act(async () => {
|
|
59
|
+
await engine.flowSettings.disable();
|
|
60
|
+
});
|
|
61
|
+
await waitFor(() => expect(container).toBeEmptyDOMElement());
|
|
62
|
+
});
|
|
63
|
+
|
|
18
64
|
it('renders collection-level custom content', async () => {
|
|
19
65
|
const engine = new FlowEngine();
|
|
20
66
|
engine.registerModels({ JSItemActionModel });
|
|
@@ -922,7 +922,6 @@ export class GridModel<T extends { subModels: { items: FlowModel[] } } = Default
|
|
|
922
922
|
const baseLayout = this.context.isMobileLayout
|
|
923
923
|
? normalizeGridLayout({
|
|
924
924
|
rows: transformRowsToSingleColumn(projectLayoutToLegacyRows(rawLayout).rows),
|
|
925
|
-
itemUids: this.getItemUids(),
|
|
926
925
|
})
|
|
927
926
|
: rawLayout;
|
|
928
927
|
const baseProjection = projectLayoutToLegacyRows(baseLayout);
|
|
@@ -115,7 +115,28 @@ export class AssignFormGridModel extends FormGridModel {
|
|
|
115
115
|
(existing as any).assignValue = value;
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
if (!collection) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const field = (collection.getFields?.() || []).find((f: any) => f.name === fieldName);
|
|
122
|
+
|
|
123
|
+
if (!field) {
|
|
124
|
+
const created = this.addSubModel('items', {
|
|
125
|
+
use: 'AssignFormItemModel',
|
|
126
|
+
stepParams: {
|
|
127
|
+
fieldSettings: {
|
|
128
|
+
init: {
|
|
129
|
+
dataSourceKey: collection?.dataSourceKey,
|
|
130
|
+
collectionName: collection?.name,
|
|
131
|
+
fieldPath: fieldName,
|
|
132
|
+
},
|
|
133
|
+
assignValue: { value },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
created['assignValue'] = value;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
119
140
|
|
|
120
141
|
const binding = EditableItemModel.getDefaultBindingByField(this.context, field);
|
|
121
142
|
if (!binding) {
|
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { Input } from 'antd';
|
|
12
12
|
import { define, observable } from '@formily/reactive';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
EditableItemModel,
|
|
15
|
+
FieldDeletePlaceholder,
|
|
16
|
+
FlowModelRenderer,
|
|
17
|
+
FormItem,
|
|
18
|
+
jioToJoiSchema,
|
|
19
|
+
tExpr,
|
|
20
|
+
} from '@nocobase/flow-engine';
|
|
14
21
|
// 无需类型导入(避免未使用的类型)
|
|
15
22
|
import { FormItemModel } from '../form/FormItemModel';
|
|
16
23
|
import { EditFormModel } from '../form/EditFormModel';
|
|
@@ -160,11 +167,15 @@ export class AssignFormItemModel extends FormItemModel {
|
|
|
160
167
|
|
|
161
168
|
getAssignedEntry(): [string, any] | null {
|
|
162
169
|
const name = this.fieldPath;
|
|
163
|
-
if (!name) return null;
|
|
170
|
+
if (!name || !this.collectionField) return null;
|
|
164
171
|
return [name, this.assignValue];
|
|
165
172
|
}
|
|
166
173
|
|
|
167
174
|
render() {
|
|
175
|
+
if (!this.collectionField) {
|
|
176
|
+
return <FieldDeletePlaceholder />;
|
|
177
|
+
}
|
|
178
|
+
|
|
168
179
|
// 与 FormItemModel.render 结构保持一致,仅替换内部渲染为 VariableInput + 常量编辑器
|
|
169
180
|
const ctx: any = this.context;
|
|
170
181
|
const collection = ctx.collection;
|
|
@@ -392,7 +403,7 @@ AssignFormItemModel.registerFlow({
|
|
|
392
403
|
},
|
|
393
404
|
defaultParams: (ctx) => {
|
|
394
405
|
return {
|
|
395
|
-
label: (ctx.model as any).collectionField.
|
|
406
|
+
label: (ctx.model as any).collectionField?.title || (ctx.model as any).fieldPath,
|
|
396
407
|
};
|
|
397
408
|
},
|
|
398
409
|
handler(ctx, params) {
|
|
@@ -47,6 +47,146 @@ class MockFlowModelRepository implements IFlowModelRepository {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
describe('assignFieldValuesFlow (editor)', () => {
|
|
50
|
+
it('shows the deleted-field placeholder for a stale assigned value', async () => {
|
|
51
|
+
const engine = new FlowEngine();
|
|
52
|
+
engine.setModelRepository(new MockFlowModelRepository());
|
|
53
|
+
engine.registerModels({
|
|
54
|
+
AssignFormModel,
|
|
55
|
+
AssignFormGridModel,
|
|
56
|
+
AssignFormItemModel,
|
|
57
|
+
InputFieldModel,
|
|
58
|
+
VariableFieldFormModel,
|
|
59
|
+
});
|
|
60
|
+
engine.context.defineProperty('location', { value: { search: '' } });
|
|
61
|
+
engine.context.defineProperty('themeToken', { value: { marginLG: 24 } });
|
|
62
|
+
engine.context.defineProperty('flowSettingsEnabled', { value: true });
|
|
63
|
+
|
|
64
|
+
const main = engine.context.dataSourceManager.getDataSource('main');
|
|
65
|
+
main.addCollection({
|
|
66
|
+
name: 'users',
|
|
67
|
+
fields: [{ name: 'nickname', type: 'string', interface: 'input' }],
|
|
68
|
+
});
|
|
69
|
+
const users = engine.context.dataSourceManager.getCollection('main', 'users');
|
|
70
|
+
|
|
71
|
+
const action = engine.createModel({
|
|
72
|
+
use: 'FlowModel',
|
|
73
|
+
uid: 'act-assign-deleted-field',
|
|
74
|
+
});
|
|
75
|
+
action.setStepParams('assignSettings', 'assignFieldValues', {
|
|
76
|
+
assignedValues: { deletedField: 'stale value' },
|
|
77
|
+
});
|
|
78
|
+
action.context.defineProperty('blockModel', { value: { collection: users } });
|
|
79
|
+
|
|
80
|
+
const step = createAssignFieldValuesStep({ settingsFlowKey: 'assignSettings' });
|
|
81
|
+
const Editor = step.uiSchema().editor?.['x-component'] as React.ComponentType;
|
|
82
|
+
const flowSettingsCtx = new FlowRuntimeContext(action, 'assignSettings', 'settings');
|
|
83
|
+
|
|
84
|
+
render(
|
|
85
|
+
<FlowEngineProvider engine={engine}>
|
|
86
|
+
<ConfigProvider>
|
|
87
|
+
<App>
|
|
88
|
+
<FlowSettingsContextProvider value={flowSettingsCtx}>
|
|
89
|
+
<Editor />
|
|
90
|
+
</FlowSettingsContextProvider>
|
|
91
|
+
</App>
|
|
92
|
+
</ConfigProvider>
|
|
93
|
+
</FlowEngineProvider>,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
await waitFor(() => {
|
|
97
|
+
expect(screen.getByRole('button', { name: /Fields/ })).toBeInTheDocument();
|
|
98
|
+
expect(screen.getByText(/deletedField.*may have been deleted/)).toBeInTheDocument();
|
|
99
|
+
const form = engine.findModelByParentId<AssignFormModel>(action.uid, 'assignForm');
|
|
100
|
+
expect(form).toBeDefined();
|
|
101
|
+
expect(form?.subModels.grid.subModels.items || []).toHaveLength(1);
|
|
102
|
+
expect(form?.getAssignedValues()).toEqual({});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('shows the standard deleted-field placeholder for a persisted assigned field model', async () => {
|
|
107
|
+
const engine = new FlowEngine();
|
|
108
|
+
engine.setModelRepository(new MockFlowModelRepository());
|
|
109
|
+
engine.registerModels({
|
|
110
|
+
AssignFormModel,
|
|
111
|
+
AssignFormGridModel,
|
|
112
|
+
AssignFormItemModel,
|
|
113
|
+
InputFieldModel,
|
|
114
|
+
VariableFieldFormModel,
|
|
115
|
+
});
|
|
116
|
+
engine.context.defineProperty('location', { value: { search: '' } });
|
|
117
|
+
engine.context.defineProperty('themeToken', { value: { marginLG: 24 } });
|
|
118
|
+
engine.context.defineProperty('flowSettingsEnabled', { value: true });
|
|
119
|
+
|
|
120
|
+
const main = engine.context.dataSourceManager.getDataSource('main');
|
|
121
|
+
main.addCollection({
|
|
122
|
+
name: 'users',
|
|
123
|
+
fields: [{ name: 'nickname', type: 'string', interface: 'input' }],
|
|
124
|
+
});
|
|
125
|
+
const users = engine.context.dataSourceManager.getCollection('main', 'users');
|
|
126
|
+
|
|
127
|
+
const action = engine.createModel({
|
|
128
|
+
use: 'FlowModel',
|
|
129
|
+
uid: 'act-assign-persisted-deleted-field',
|
|
130
|
+
});
|
|
131
|
+
action.setStepParams('assignSettings', 'assignFieldValues', {
|
|
132
|
+
assignedValues: { deletedField: 'stale value' },
|
|
133
|
+
});
|
|
134
|
+
action.context.defineProperty('blockModel', { value: { collection: users } });
|
|
135
|
+
|
|
136
|
+
const form = engine.createModel<AssignFormModel>({
|
|
137
|
+
use: 'AssignFormModel',
|
|
138
|
+
uid: 'form-assign-persisted-deleted-field',
|
|
139
|
+
parentId: action.uid,
|
|
140
|
+
subKey: 'assignForm',
|
|
141
|
+
stepParams: {
|
|
142
|
+
resourceSettings: {
|
|
143
|
+
init: {
|
|
144
|
+
dataSourceKey: 'main',
|
|
145
|
+
collectionName: 'users',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
action.setSubModel('assignForm', form);
|
|
151
|
+
form.subModels.grid.addSubModel('items', {
|
|
152
|
+
use: 'AssignFormItemModel',
|
|
153
|
+
uid: 'item-assign-persisted-deleted-field',
|
|
154
|
+
stepParams: {
|
|
155
|
+
fieldSettings: {
|
|
156
|
+
init: {
|
|
157
|
+
dataSourceKey: 'main',
|
|
158
|
+
collectionName: 'users',
|
|
159
|
+
fieldPath: 'deletedField',
|
|
160
|
+
},
|
|
161
|
+
assignValue: { value: 'stale value' },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
form.subModels.grid.resetRows(true);
|
|
166
|
+
|
|
167
|
+
const step = createAssignFieldValuesStep({ settingsFlowKey: 'assignSettings' });
|
|
168
|
+
const Editor = step.uiSchema().editor?.['x-component'] as React.ComponentType;
|
|
169
|
+
const flowSettingsCtx = new FlowRuntimeContext(action, 'assignSettings', 'settings');
|
|
170
|
+
|
|
171
|
+
render(
|
|
172
|
+
<FlowEngineProvider engine={engine}>
|
|
173
|
+
<ConfigProvider>
|
|
174
|
+
<App>
|
|
175
|
+
<FlowSettingsContextProvider value={flowSettingsCtx}>
|
|
176
|
+
<Editor />
|
|
177
|
+
</FlowSettingsContextProvider>
|
|
178
|
+
</App>
|
|
179
|
+
</ConfigProvider>
|
|
180
|
+
</FlowEngineProvider>,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
await waitFor(() => {
|
|
184
|
+
expect(screen.getByText(/deletedField.*may have been deleted/)).toBeInTheDocument();
|
|
185
|
+
expect(form.subModels.grid.subModels.items).toHaveLength(1);
|
|
186
|
+
expect(form.getAssignedValues()).toEqual({});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
50
190
|
it('repairs AssignFormModel resource init and clears cached collection', async () => {
|
|
51
191
|
const engine = new FlowEngine();
|
|
52
192
|
engine.setModelRepository(new MockFlowModelRepository());
|
|
@@ -21,6 +21,35 @@ describe('FilterFormGridModel.toggleFormFieldsCollapse', () => {
|
|
|
21
21
|
engine.registerModels({ FilterFormGridModel });
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
it.each([false, true])('preserves collapsed fields in mobile layout with settings enabled: %s', (settingsEnabled) => {
|
|
25
|
+
engine.flowSettings[settingsEnabled ? 'enable' : 'disable']();
|
|
26
|
+
const rows = {
|
|
27
|
+
first: [['field-1']],
|
|
28
|
+
second: [['field-2']],
|
|
29
|
+
third: [['field-3']],
|
|
30
|
+
};
|
|
31
|
+
const model = engine.createModel<FilterFormGridModel>({
|
|
32
|
+
uid: 'mobile-filter-grid',
|
|
33
|
+
use: 'FilterFormGridModel',
|
|
34
|
+
props: { rows },
|
|
35
|
+
subModels: {
|
|
36
|
+
items: ['field-1', 'field-2', 'field-3'].map((uid) => ({ use: 'FlowModel', uid })),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
model.context.defineProperty('isMobileLayout', { value: true });
|
|
40
|
+
model.setStepParams(GRID_FLOW_KEY, GRID_STEP, { rows });
|
|
41
|
+
type VisibleLayoutReader = { getVisibleLayout(): { rows: Record<string, string[][]> } };
|
|
42
|
+
const renderedItems = () =>
|
|
43
|
+
Object.values((model as unknown as VisibleLayoutReader).getVisibleLayout().rows).flat(2);
|
|
44
|
+
|
|
45
|
+
expect(renderedItems()).toEqual(['field-1', 'field-2', 'field-3']);
|
|
46
|
+
model.toggleFormFieldsCollapse(true, 1);
|
|
47
|
+
expect(renderedItems()).toEqual(['field-1']);
|
|
48
|
+
model.toggleFormFieldsCollapse(false, 1);
|
|
49
|
+
expect(renderedItems()).toEqual(['field-1', 'field-2', 'field-3']);
|
|
50
|
+
expect(model.getStepParams(GRID_FLOW_KEY, GRID_STEP).rows).toEqual(rows);
|
|
51
|
+
});
|
|
52
|
+
|
|
24
53
|
it('uses rowOrder from the full layout when collapsing after reorder', () => {
|
|
25
54
|
const model = engine.createModel<FilterFormGridModel>({
|
|
26
55
|
uid: 'filter-grid-collapse-order',
|
|
@@ -351,7 +351,7 @@ export const FieldComponentProps: React.FC<{ fieldModel: string; source: string[
|
|
|
351
351
|
<FormItem label={t('Options')}>
|
|
352
352
|
<Space direction="vertical" size={8} style={{ width: '100%' }}>
|
|
353
353
|
{options.map((option: any, index: number) => (
|
|
354
|
-
<Space key={
|
|
354
|
+
<Space key={index} style={{ width: '100%' }} size={8} wrap align="start">
|
|
355
355
|
<Input
|
|
356
356
|
style={{ flex: 1, minWidth: 120 }}
|
|
357
357
|
placeholder={t('Option label')}
|
package/src/flow/models/blocks/filter-form/fields/__tests__/FieldComponentProps.options.test.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 { createForm } from '@formily/core';
|
|
13
|
+
import { Field, FormProvider } from '@formily/react';
|
|
14
|
+
import { render, screen } from '@nocobase/test/client';
|
|
15
|
+
import userEvent from '@testing-library/user-event';
|
|
16
|
+
import { FlowEngine, FlowEngineProvider, FlowModel, FlowModelProvider } from '@nocobase/flow-engine';
|
|
17
|
+
import { FieldComponentProps } from '../FieldComponentProps';
|
|
18
|
+
|
|
19
|
+
class HostModel extends FlowModel {
|
|
20
|
+
render() {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe.each(['RadioGroupFieldModel', 'CheckboxGroupFieldModel', 'SelectFieldModel'])('%s options', (fieldModel) => {
|
|
26
|
+
it('keeps focus while editing option values and preserves remaining rows after removal', async () => {
|
|
27
|
+
const form = createForm();
|
|
28
|
+
const engine = new FlowEngine();
|
|
29
|
+
engine.registerModels({ HostModel });
|
|
30
|
+
const model = engine.createModel<HostModel>({ use: 'HostModel' });
|
|
31
|
+
render(
|
|
32
|
+
<FlowEngineProvider engine={engine}>
|
|
33
|
+
<FlowModelProvider model={model}>
|
|
34
|
+
<FormProvider form={form}>
|
|
35
|
+
<Field name="props" component={[FieldComponentProps, { fieldModel, source: [] }]} />
|
|
36
|
+
</FormProvider>
|
|
37
|
+
</FlowModelProvider>
|
|
38
|
+
</FlowEngineProvider>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
await userEvent.click(screen.getByRole('button', { name: 'plus Add' }));
|
|
42
|
+
const valueInput = screen.getByPlaceholderText('Option value');
|
|
43
|
+
await userEvent.type(valueInput, 'abcdef');
|
|
44
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveValue('abcdef');
|
|
45
|
+
expect(valueInput).toHaveFocus();
|
|
46
|
+
|
|
47
|
+
await userEvent.keyboard('{Backspace}{Backspace}xy');
|
|
48
|
+
expect(valueInput).toHaveValue('abcdxy');
|
|
49
|
+
expect(valueInput).toHaveFocus();
|
|
50
|
+
await userEvent.type(screen.getByPlaceholderText('Option label'), 'First');
|
|
51
|
+
await userEvent.click(screen.getByRole('button', { name: 'plus Add' }));
|
|
52
|
+
await userEvent.type(screen.getAllByPlaceholderText('Option label')[1], 'Second');
|
|
53
|
+
await userEvent.type(screen.getAllByPlaceholderText('Option value')[1], 'second');
|
|
54
|
+
await userEvent.click(screen.getAllByRole('button', { name: 'close' })[0]);
|
|
55
|
+
expect(screen.getByPlaceholderText('Option label')).toHaveValue('Second');
|
|
56
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveValue('second');
|
|
57
|
+
await userEvent.type(screen.getByPlaceholderText('Option value'), '2');
|
|
58
|
+
expect(screen.getByPlaceholderText('Option value')).toHaveFocus();
|
|
59
|
+
expect(form.values.props.options).toEqual([{ label: 'Second', value: 'second2' }]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -399,20 +399,41 @@ export class FormBlockModel<
|
|
|
399
399
|
if (Array.isArray(topValue) && topValue.length === 0) return false;
|
|
400
400
|
|
|
401
401
|
// 本地优先:支持对多关系的 dot 聚合路径(例如 assignees.name)。
|
|
402
|
-
//
|
|
403
|
-
// 因而这里先用 getValuesByPath 做一次前端可解析性检查,命中则直接前端解析。
|
|
402
|
+
// 关联字段只有在本地值包含目标标题字段时才算完整;标量外键或仅含主键的轻量对象仍需服务端补全。
|
|
404
403
|
const formValuesSnapshot = runtime.getFormValuesSnapshot();
|
|
404
|
+
let shouldResolveAssociationValueOnServer = false;
|
|
405
405
|
if (formValuesSnapshot && typeof formValuesSnapshot === 'object') {
|
|
406
|
-
const localResolved = getValuesByPath(formValuesSnapshot as Record<string,
|
|
406
|
+
const localResolved = getValuesByPath(formValuesSnapshot as Record<string, unknown>, subPath);
|
|
407
407
|
if (typeof localResolved !== 'undefined') {
|
|
408
|
-
|
|
408
|
+
const fieldPath = subPath
|
|
409
|
+
.replace(/\[\d+\]/g, '')
|
|
410
|
+
.split('.')
|
|
411
|
+
.filter((segment) => !/^\d+$/.test(segment))
|
|
412
|
+
.join('.');
|
|
413
|
+
const resolvedField = this.collection?.getFieldByPath?.(fieldPath);
|
|
414
|
+
const titleFieldName = resolvedField?.targetCollectionTitleFieldName;
|
|
415
|
+
const isLoadedAssociationRecord = (value: unknown) => {
|
|
416
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
417
|
+
if (!titleFieldName) return true;
|
|
418
|
+
return typeof (value as Record<string, unknown>)[titleFieldName] !== 'undefined';
|
|
419
|
+
};
|
|
420
|
+
const isAssociationValueLoaded =
|
|
421
|
+
localResolved === null ||
|
|
422
|
+
(Array.isArray(localResolved)
|
|
423
|
+
? localResolved.length === 0 ||
|
|
424
|
+
localResolved.every((value) => value === null || isLoadedAssociationRecord(value))
|
|
425
|
+
: isLoadedAssociationRecord(localResolved));
|
|
426
|
+
if (!resolvedField?.isAssociationField?.() || isAssociationValueLoaded) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
shouldResolveAssociationValueOnServer = true;
|
|
409
430
|
}
|
|
410
431
|
}
|
|
411
432
|
|
|
412
433
|
// 已配置字段:仅关联字段的子路径按需服务端补全(保持现有语义)
|
|
413
434
|
const assocResolver = createAssociationSubpathResolver(
|
|
414
435
|
() => this.collection,
|
|
415
|
-
() => runtime.getFormValuesSnapshot(),
|
|
436
|
+
shouldResolveAssociationValueOnServer ? undefined : () => runtime.getFormValuesSnapshot(),
|
|
416
437
|
);
|
|
417
438
|
return assocResolver(subPath);
|
|
418
439
|
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '@nocobase/flow-engine';
|
|
24
24
|
import { Button, Form, Skeleton, Space } from 'antd';
|
|
25
25
|
import React from 'react';
|
|
26
|
+
import { findDataScopeStep, getQuickEditDataScopeFilter } from '../../../internal/utils/quickEditDataScope';
|
|
26
27
|
import { FieldModel } from '../../base/FieldModel';
|
|
27
28
|
import { FormComponent } from './FormBlockModel';
|
|
28
29
|
import { FormItemModel } from './FormItemModel';
|
|
@@ -36,6 +37,14 @@ const QUICK_EDIT_MOBILE_CONTENT_PADDING = '8px var(--nb-mobile-page-tabs-content
|
|
|
36
37
|
const QUICK_EDIT_MOBILE_ACTIONS_PADDING =
|
|
37
38
|
'8px var(--nb-mobile-page-tabs-content-padding, 12px) calc(80px + env(safe-area-inset-bottom, 0px))';
|
|
38
39
|
const QUICK_EDIT_MOBILE_MEDIA_QUERY = '(max-width: 768px)';
|
|
40
|
+
// Dropdown-style editors open upwards inside the desktop popover so the option list does not cover the Submit and
|
|
41
|
+
// Cancel buttons rendered right below the field. antd still flips the list downwards when there is no room above.
|
|
42
|
+
const QUICK_EDIT_DROPDOWN_UP_MODELS = [
|
|
43
|
+
'SelectFieldModel',
|
|
44
|
+
'RecordSelectFieldModel',
|
|
45
|
+
'CascadeSelectFieldModel',
|
|
46
|
+
'CascadeSelectListFieldModel',
|
|
47
|
+
];
|
|
39
48
|
|
|
40
49
|
type QuickEditViewBeforeClosePayload = {
|
|
41
50
|
result?: unknown;
|
|
@@ -159,6 +168,7 @@ export class QuickEditFormModel extends FlowModel {
|
|
|
159
168
|
__onSubmitSuccess;
|
|
160
169
|
_fieldProps: any;
|
|
161
170
|
_onOk: any;
|
|
171
|
+
_dataScopeFilter: Record<string, any> | undefined;
|
|
162
172
|
|
|
163
173
|
get form() {
|
|
164
174
|
return this.context.form;
|
|
@@ -212,6 +222,7 @@ export class QuickEditFormModel extends FlowModel {
|
|
|
212
222
|
},
|
|
213
223
|
sourceFieldModel ? { delegate: sourceFieldModel.context } : undefined,
|
|
214
224
|
) as QuickEditFormModel;
|
|
225
|
+
model._dataScopeFilter = getQuickEditDataScopeFilter(sourceFieldModel);
|
|
215
226
|
|
|
216
227
|
const bodyStyles = {
|
|
217
228
|
maxHeight: QUICK_EDIT_POPOVER_MAX_HEIGHT,
|
|
@@ -410,6 +421,13 @@ QuickEditFormModel.registerFlow({
|
|
|
410
421
|
resource.setDataSourceKey(dataSourceKey);
|
|
411
422
|
resource.setResourceName(collectionName);
|
|
412
423
|
ctx.model.resource = resource;
|
|
424
|
+
// Seed the edited row before dispatching the field model's flows. An association data scope resolves
|
|
425
|
+
// `ctx.record` while the field renders, and so does the foreign key filter that one-to-one and one-to-many
|
|
426
|
+
// editors build, so the record has to be in place first.
|
|
427
|
+
if (ctx.inputArgs.filterByTk || ctx.inputArgs.record) {
|
|
428
|
+
resource.setFilterByTk(ctx.inputArgs.filterByTk);
|
|
429
|
+
resource.setData(ctx.inputArgs.record);
|
|
430
|
+
}
|
|
413
431
|
const collectionField = ctx.model.collection.getField(fieldPath) as CollectionField;
|
|
414
432
|
if (collectionField) {
|
|
415
433
|
const binding = FormItemModel.getDefaultBindingByField(ctx, collectionField);
|
|
@@ -417,24 +435,42 @@ QuickEditFormModel.registerFlow({
|
|
|
417
435
|
return;
|
|
418
436
|
}
|
|
419
437
|
const use = binding.modelName;
|
|
438
|
+
const stepParams: Record<string, Record<string, Record<string, unknown>>> = {
|
|
439
|
+
fieldSettings: {
|
|
440
|
+
init: {
|
|
441
|
+
dataSourceKey,
|
|
442
|
+
collectionName,
|
|
443
|
+
fieldPath,
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
const dataScopeFilter = ctx.model._dataScopeFilter;
|
|
448
|
+
if (dataScopeFilter) {
|
|
449
|
+
const dataScopeStep = findDataScopeStep(ctx.engine.getModelClass(use));
|
|
450
|
+
if (dataScopeStep) {
|
|
451
|
+
stepParams[dataScopeStep.flowKey] = {
|
|
452
|
+
...stepParams[dataScopeStep.flowKey],
|
|
453
|
+
[dataScopeStep.stepKey]: { filter: dataScopeFilter },
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
420
457
|
const fieldModel = ctx.model.addSubModel<FieldModel>('fields', {
|
|
421
458
|
use,
|
|
422
459
|
props:
|
|
423
460
|
typeof binding.defaultProps === 'function'
|
|
424
461
|
? binding.defaultProps(ctx, collectionField)
|
|
425
462
|
: binding.defaultProps,
|
|
426
|
-
stepParams
|
|
427
|
-
fieldSettings: {
|
|
428
|
-
init: {
|
|
429
|
-
dataSourceKey,
|
|
430
|
-
collectionName,
|
|
431
|
-
fieldPath,
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
},
|
|
463
|
+
stepParams,
|
|
435
464
|
});
|
|
436
465
|
fieldModel.setProps(getQuickEditFieldProps(collectionField, ctx.model._fieldProps));
|
|
437
466
|
fieldModel.setProps({ sourceFieldModelUid: ctx.inputArgs.sourceFieldModelUid });
|
|
467
|
+
if (
|
|
468
|
+
!ctx.model.context.isMobileLayout &&
|
|
469
|
+
QUICK_EDIT_DROPDOWN_UP_MODELS.includes(use) &&
|
|
470
|
+
fieldModel.props.placement == null
|
|
471
|
+
) {
|
|
472
|
+
fieldModel.setProps({ placement: 'topLeft' });
|
|
473
|
+
}
|
|
438
474
|
ctx.model.context.defineProperty('collectionField', {
|
|
439
475
|
get: () => collectionField,
|
|
440
476
|
});
|
|
@@ -442,8 +478,6 @@ QuickEditFormModel.registerFlow({
|
|
|
442
478
|
await fieldModel.dispatchEvent('beforeRender');
|
|
443
479
|
}
|
|
444
480
|
if (ctx.inputArgs.filterByTk || ctx.inputArgs.record) {
|
|
445
|
-
resource.setFilterByTk(ctx.inputArgs.filterByTk);
|
|
446
|
-
resource.setData(ctx.inputArgs.record);
|
|
447
481
|
ctx.model.form?.setFieldsValue(resource.getData());
|
|
448
482
|
}
|
|
449
483
|
},
|