@nocobase/client-v2 2.3.0-beta.8 → 2.3.0-beta.9
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/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/index.mjs +19 -19
- package/lib/index.js +38 -38
- package/package.json +9 -8
- 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/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +42 -23
- 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/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/__tests__/FormBlockModel.test.tsx +145 -0
- package/src/flow/models/blocks/form/__tests__/popupLinkage.test.tsx +175 -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/topbar/TopbarActionModel.tsx +5 -5
|
@@ -17,14 +17,16 @@ import {
|
|
|
17
17
|
observer,
|
|
18
18
|
} from '@nocobase/flow-engine';
|
|
19
19
|
import { Table } from 'antd';
|
|
20
|
+
import type { TableProps } from 'antd';
|
|
20
21
|
import classNames from 'classnames';
|
|
21
22
|
import { DragEndEvent } from '@dnd-kit/core';
|
|
22
23
|
import { css } from '@emotion/css';
|
|
23
|
-
import { isEmpty } from 'lodash';
|
|
24
|
+
import { get, isEmpty, orderBy } from 'lodash';
|
|
24
25
|
import React, { useEffect, useMemo, useState, useCallback } from 'react';
|
|
25
26
|
import { useTranslation } from 'react-i18next';
|
|
26
27
|
import { FieldModel } from '../../base';
|
|
27
28
|
import { DetailsItemModel } from '../../blocks/details/DetailsItemModel';
|
|
29
|
+
import { FormAssociationItemModel } from '../../blocks/form/FormAssociationItemModel';
|
|
28
30
|
import { adjustColumnOrder } from '../../blocks/table/utils';
|
|
29
31
|
|
|
30
32
|
const HeaderWrapperComponent = React.memo((props) => {
|
|
@@ -65,11 +67,31 @@ const AddFieldColumn = ({ model }) => {
|
|
|
65
67
|
};
|
|
66
68
|
|
|
67
69
|
const DisplayTable = (props) => {
|
|
68
|
-
const { pageSize, value, size, collection, baseColumns, enableIndexColumn = true, model } = props;
|
|
70
|
+
const { pageSize, value: rawValue, size, collection, baseColumns, enableIndexColumn = true, model } = props;
|
|
71
|
+
const isFormAssociation = model.parent instanceof FormAssociationItemModel;
|
|
69
72
|
const [currentPage, setCurrentPage] = useState(1);
|
|
70
73
|
const [currentPageSize, setCurrentPageSize] = useState(pageSize);
|
|
74
|
+
const [localSort, setLocalSort] = useState<{ field: string; order: 'asc' | 'desc' }>();
|
|
71
75
|
const { t } = useTranslation();
|
|
72
76
|
|
|
77
|
+
const value = useMemo(() => {
|
|
78
|
+
if (!isFormAssociation || Array.isArray(rawValue)) return rawValue;
|
|
79
|
+
if (rawValue && Array.isArray(rawValue.rows)) return rawValue.rows;
|
|
80
|
+
return rawValue && typeof rawValue === 'object' ? [rawValue] : [];
|
|
81
|
+
}, [isFormAssociation, rawValue]);
|
|
82
|
+
|
|
83
|
+
const sortedValue = useMemo(
|
|
84
|
+
() =>
|
|
85
|
+
isFormAssociation && localSort
|
|
86
|
+
? orderBy(value, [(record) => get(record, localSort.field)], [localSort.order])
|
|
87
|
+
: value,
|
|
88
|
+
[isFormAssociation, localSort, value],
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (isFormAssociation) setCurrentPage(1);
|
|
93
|
+
}, [isFormAssociation, rawValue]);
|
|
94
|
+
|
|
73
95
|
useEffect(() => {
|
|
74
96
|
setCurrentPageSize(pageSize);
|
|
75
97
|
}, [pageSize]);
|
|
@@ -89,7 +111,7 @@ const DisplayTable = (props) => {
|
|
|
89
111
|
return t('Total {{count}} items', { count: total });
|
|
90
112
|
},
|
|
91
113
|
} as any;
|
|
92
|
-
}, [currentPage, currentPageSize, value]);
|
|
114
|
+
}, [currentPage, currentPageSize, value, t]);
|
|
93
115
|
|
|
94
116
|
const getColumns = () => {
|
|
95
117
|
const cols = adjustColumnOrder(
|
|
@@ -119,8 +141,20 @@ const DisplayTable = (props) => {
|
|
|
119
141
|
}
|
|
120
142
|
return cols;
|
|
121
143
|
};
|
|
122
|
-
const handleChange = useCallback(
|
|
123
|
-
async (pagination, filters,
|
|
144
|
+
const handleChange = useCallback<NonNullable<TableProps<Record<string, unknown>>['onChange']>>(
|
|
145
|
+
async (pagination, filters, sorters, extra) => {
|
|
146
|
+
const sorter = Array.isArray(sorters) ? sorters[0] : sorters;
|
|
147
|
+
if (isFormAssociation) {
|
|
148
|
+
if (extra.action !== 'sort') return;
|
|
149
|
+
const column = sorter?.column as { sortField?: string } | undefined;
|
|
150
|
+
const sortField = column?.sortField || sorter?.field;
|
|
151
|
+
const fullPath = Array.isArray(sortField) ? sortField.join('.') : String(sortField ?? '');
|
|
152
|
+
const prefix = `${model.context.fieldPath}.`;
|
|
153
|
+
const field = fullPath.startsWith(prefix) ? fullPath.slice(prefix.length) : fullPath;
|
|
154
|
+
setLocalSort(sorter?.order && field ? { field, order: sorter.order === 'ascend' ? 'asc' : 'desc' } : undefined);
|
|
155
|
+
setCurrentPage(1);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
124
158
|
//支持列点击排序
|
|
125
159
|
if (!isEmpty(sorter)) {
|
|
126
160
|
const resource = model.context.blockModel.resource;
|
|
@@ -138,7 +172,7 @@ const DisplayTable = (props) => {
|
|
|
138
172
|
await resource.refresh();
|
|
139
173
|
}
|
|
140
174
|
},
|
|
141
|
-
[model],
|
|
175
|
+
[isFormAssociation, model],
|
|
142
176
|
);
|
|
143
177
|
|
|
144
178
|
return (
|
|
@@ -147,7 +181,7 @@ const DisplayTable = (props) => {
|
|
|
147
181
|
size={size}
|
|
148
182
|
rowKey={collection.filterTargetKey}
|
|
149
183
|
scroll={{ x: 'max-content' }}
|
|
150
|
-
dataSource={
|
|
184
|
+
dataSource={sortedValue}
|
|
151
185
|
columns={getColumns()}
|
|
152
186
|
pagination={pagination}
|
|
153
187
|
onChange={handleChange}
|
|
@@ -269,3 +303,4 @@ DisplaySubTableFieldModel.define({
|
|
|
269
303
|
});
|
|
270
304
|
|
|
271
305
|
DetailsItemModel.bindModelToInterface('DisplaySubTableFieldModel', ['m2m', 'o2m', 'mbm']);
|
|
306
|
+
FormAssociationItemModel.bindModelToInterface('DisplaySubTableFieldModel', ['m2m', 'o2m', 'mbm']);
|
package/src/flow/models/fields/DisplayAssociationField/__tests__/DisplaySubTableFieldModel.test.tsx
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
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 { Form, type FormInstance, type TableProps } from 'antd';
|
|
12
|
+
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
13
|
+
import { DisplayItemModel, FlowEngine, FlowEngineProvider, FlowModelProvider } from '@nocobase/flow-engine';
|
|
14
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
15
|
+
import {
|
|
16
|
+
DetailsItemModel,
|
|
17
|
+
DisplaySubTableFieldModel,
|
|
18
|
+
DisplayTextFieldModel,
|
|
19
|
+
FormAssociationItemModel,
|
|
20
|
+
FormItemModel,
|
|
21
|
+
TableColumnModel,
|
|
22
|
+
aclCheck,
|
|
23
|
+
displayFieldComponent,
|
|
24
|
+
fixed,
|
|
25
|
+
overflowMode,
|
|
26
|
+
titleField,
|
|
27
|
+
} from '../../../../index';
|
|
28
|
+
import { buildAssociationOptions } from '../../../../actions/displayFieldComponent';
|
|
29
|
+
import { rebuildFieldSubModel } from '../../../../internal/utils/rebuildFieldSubModel';
|
|
30
|
+
|
|
31
|
+
type Row = Record<string, unknown>;
|
|
32
|
+
type TableOptions = TableProps<Row>;
|
|
33
|
+
|
|
34
|
+
const { tableRender } = vi.hoisted(() => ({ tableRender: vi.fn() }));
|
|
35
|
+
|
|
36
|
+
vi.mock('react-i18next', async (importOriginal) => ({
|
|
37
|
+
...(await importOriginal<typeof import('react-i18next')>()),
|
|
38
|
+
useTranslation: () => ({ t: (value: string) => value }),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock('antd', async (importOriginal) => ({
|
|
42
|
+
...(await importOriginal<typeof import('antd')>()),
|
|
43
|
+
Table: (props: TableOptions) => {
|
|
44
|
+
tableRender(props);
|
|
45
|
+
return <div data-testid="rows">{JSON.stringify(props.dataSource)}</div>;
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
cleanup();
|
|
51
|
+
vi.restoreAllMocks();
|
|
52
|
+
tableRender.mockClear();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function setup(parentUse = 'FormAssociationItemModel') {
|
|
56
|
+
const engine = new FlowEngine();
|
|
57
|
+
engine.registerActions({ aclCheck, displayFieldComponent, fixed, overflowMode, titleField });
|
|
58
|
+
engine.registerModels({
|
|
59
|
+
DetailsItemModel,
|
|
60
|
+
DisplaySubTableFieldModel,
|
|
61
|
+
DisplayTextFieldModel,
|
|
62
|
+
FormAssociationItemModel,
|
|
63
|
+
FormItemModel,
|
|
64
|
+
TableColumnModel,
|
|
65
|
+
});
|
|
66
|
+
const dataSource = engine.dataSourceManager.getDataSource('main');
|
|
67
|
+
dataSource.addCollection({
|
|
68
|
+
name: 'users',
|
|
69
|
+
filterTargetKey: 'id',
|
|
70
|
+
titleField: 'name',
|
|
71
|
+
fields: [
|
|
72
|
+
{ name: 'id', type: 'integer', interface: 'integer' },
|
|
73
|
+
{ name: 'name', type: 'string', interface: 'input' },
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
dataSource.addCollection({
|
|
77
|
+
name: 'orgs',
|
|
78
|
+
fields: [
|
|
79
|
+
{ name: 'staff', type: 'belongsToMany', interface: 'm2m', target: 'users' },
|
|
80
|
+
{ name: 'reports', type: 'hasMany', interface: 'o2m', target: 'users' },
|
|
81
|
+
{ name: 'members', type: 'belongsToArray', interface: 'mbm', target: 'users' },
|
|
82
|
+
{ name: 'manager', type: 'belongsTo', interface: 'm2o', target: 'users' },
|
|
83
|
+
{ name: 'name', type: 'string', interface: 'input' },
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
dataSource.addCollection({
|
|
87
|
+
name: 'posts',
|
|
88
|
+
fields: [{ name: 'org', type: 'belongsTo', interface: 'm2o', target: 'orgs' }],
|
|
89
|
+
});
|
|
90
|
+
const parent = engine.createModel<FormAssociationItemModel>({
|
|
91
|
+
use: parentUse,
|
|
92
|
+
stepParams: {
|
|
93
|
+
fieldSettings: {
|
|
94
|
+
init: { dataSourceKey: 'main', collectionName: 'posts', fieldPath: 'org.staff' },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
const resource = { getAppends: vi.fn(() => ['staff']), setAppends: vi.fn(), refresh: vi.fn() };
|
|
99
|
+
parent.context.defineProperty('blockModel', {
|
|
100
|
+
value: { collection: dataSource.getCollection('posts'), resource, addAppends: vi.fn() },
|
|
101
|
+
});
|
|
102
|
+
parent.context.defineProperty('flowSettingsEnabled', { value: false });
|
|
103
|
+
parent.context.defineProperty('aclCheck', { value: vi.fn().mockResolvedValue(true) });
|
|
104
|
+
const field = parent.setSubModel('field', { use: 'DisplaySubTableFieldModel', props: { pageSize: 10 } });
|
|
105
|
+
return { engine, parent, field: field as DisplaySubTableFieldModel, resource, dataSource };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function tableProps(): TableOptions {
|
|
109
|
+
return tableRender.mock.lastCall[0] as TableOptions;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe('DisplaySubTableFieldModel in association display fields', () => {
|
|
113
|
+
it.each(['staff', 'reports', 'members'])('offers a subtable for the to-many field %s', (fieldName) => {
|
|
114
|
+
const { parent, dataSource } = setup();
|
|
115
|
+
const collectionField = dataSource.getCollection('orgs').getField(fieldName);
|
|
116
|
+
const bindings = FormAssociationItemModel.getBindingsByField(parent.context, collectionField);
|
|
117
|
+
expect(bindings.map((binding) => binding.modelName)).toContain('DisplaySubTableFieldModel');
|
|
118
|
+
expect(buildAssociationOptions(parent.context, FormAssociationItemModel)).toContainEqual({
|
|
119
|
+
label: expect.any(String),
|
|
120
|
+
value: 'DisplaySubTableFieldModel',
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('keeps the binding scoped and preserves the default title-field display', () => {
|
|
125
|
+
const { parent, dataSource } = setup();
|
|
126
|
+
const collection = dataSource.getCollection('orgs');
|
|
127
|
+
for (const itemModel of [DisplayItemModel, TableColumnModel, FormItemModel]) {
|
|
128
|
+
expect(itemModel.getBindingsByField(parent.context, collection.getField('staff'))).not.toEqual(
|
|
129
|
+
expect.arrayContaining([expect.objectContaining({ modelName: 'DisplaySubTableFieldModel' })]),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
for (const fieldName of ['manager', 'name']) {
|
|
133
|
+
expect(FormAssociationItemModel.getBindingsByField(parent.context, collection.getField(fieldName))).not.toEqual(
|
|
134
|
+
expect.arrayContaining([expect.objectContaining({ modelName: 'DisplaySubTableFieldModel' })]),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
expect(DetailsItemModel.getBindingsByField(parent.context, collection.getField('staff'))).toEqual(
|
|
138
|
+
expect.arrayContaining([expect.objectContaining({ modelName: 'DisplaySubTableFieldModel' })]),
|
|
139
|
+
);
|
|
140
|
+
expect(
|
|
141
|
+
FormAssociationItemModel.getDefaultBindingByField(parent.context, collection.getField('staff'), {
|
|
142
|
+
fallbackToTargetTitleField: true,
|
|
143
|
+
})?.modelName,
|
|
144
|
+
).toBe('DisplayTextFieldModel');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it.each([undefined, null, [], { rows: [] }])('renders an empty table for %j', (value) => {
|
|
148
|
+
const { field } = setup();
|
|
149
|
+
field.setProps({ value });
|
|
150
|
+
render(field.render());
|
|
151
|
+
expect(tableProps().dataSource).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('updates rows and resets pagination when the association changes or is cleared', async () => {
|
|
155
|
+
const { field, resource } = setup();
|
|
156
|
+
field.setProps({ value: [{ id: 1, name: 'Alice' }] });
|
|
157
|
+
const view = render(field.render());
|
|
158
|
+
await act(async () => {
|
|
159
|
+
const pagination = tableProps().pagination;
|
|
160
|
+
if (pagination) pagination.onChange?.(3, 10);
|
|
161
|
+
});
|
|
162
|
+
expect(tableProps().pagination).toMatchObject({ current: 3 });
|
|
163
|
+
act(() => {
|
|
164
|
+
field.setProps({ value: { rows: [{ id: 2, name: 'Bob' }] } });
|
|
165
|
+
view.rerender(field.render());
|
|
166
|
+
});
|
|
167
|
+
expect(screen.getByTestId('rows').textContent).toContain('Bob');
|
|
168
|
+
expect(screen.getByTestId('rows').textContent).not.toContain('Alice');
|
|
169
|
+
expect(tableProps().pagination).toMatchObject({ current: 1 });
|
|
170
|
+
act(() => {
|
|
171
|
+
field.setProps({ value: null });
|
|
172
|
+
view.rerender(field.render());
|
|
173
|
+
});
|
|
174
|
+
expect(tableProps().dataSource).toEqual([]);
|
|
175
|
+
expect(resource.refresh).not.toHaveBeenCalled();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('sorts nested columns locally without mutating form values or refreshing the form resource', async () => {
|
|
179
|
+
const { field, resource } = setup();
|
|
180
|
+
const rows = [
|
|
181
|
+
{ id: 1, name: 'Bob' },
|
|
182
|
+
{ id: 2, name: 'Alice' },
|
|
183
|
+
];
|
|
184
|
+
const original = structuredClone(rows);
|
|
185
|
+
field.setProps({ value: rows });
|
|
186
|
+
render(field.render());
|
|
187
|
+
await act(async () => {
|
|
188
|
+
await tableProps().onChange?.(
|
|
189
|
+
{},
|
|
190
|
+
{},
|
|
191
|
+
{ field: 'org.staff.name', order: 'ascend' },
|
|
192
|
+
{
|
|
193
|
+
action: 'sort',
|
|
194
|
+
currentDataSource: rows,
|
|
195
|
+
},
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
expect(tableProps().dataSource).toEqual([rows[1], rows[0]]);
|
|
199
|
+
await act(async () => {
|
|
200
|
+
await tableProps().onChange?.(
|
|
201
|
+
{},
|
|
202
|
+
{},
|
|
203
|
+
{ field: 'org.staff.name', order: 'descend' },
|
|
204
|
+
{
|
|
205
|
+
action: 'sort',
|
|
206
|
+
currentDataSource: rows,
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
expect(tableProps().dataSource).toEqual(rows);
|
|
211
|
+
await act(async () => {
|
|
212
|
+
await tableProps().onChange?.(
|
|
213
|
+
{},
|
|
214
|
+
{},
|
|
215
|
+
{ field: 'org.staff.name' },
|
|
216
|
+
{
|
|
217
|
+
action: 'sort',
|
|
218
|
+
currentDataSource: rows,
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
expect(tableProps().dataSource).toEqual(rows);
|
|
223
|
+
expect(rows).toEqual(original);
|
|
224
|
+
expect(resource.setAppends).not.toHaveBeenCalled();
|
|
225
|
+
expect(resource.refresh).not.toHaveBeenCalled();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('retains resource-based sorting in details fields', async () => {
|
|
229
|
+
const { field, resource } = setup('DetailsItemModel');
|
|
230
|
+
field.setProps({ value: [{ id: 1 }] });
|
|
231
|
+
render(field.render());
|
|
232
|
+
await act(async () => {
|
|
233
|
+
await tableProps().onChange?.(
|
|
234
|
+
{},
|
|
235
|
+
{},
|
|
236
|
+
{ field: 'name', order: 'ascend' },
|
|
237
|
+
{
|
|
238
|
+
action: 'sort',
|
|
239
|
+
currentDataSource: [],
|
|
240
|
+
},
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
expect(resource.setAppends).toHaveBeenCalledWith(['staff(sort=name)']);
|
|
244
|
+
expect(resource.refresh).toHaveBeenCalledOnce();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('uses the configured sort field and keeps local ordering when paginating', async () => {
|
|
248
|
+
const { field, resource } = setup();
|
|
249
|
+
const rows = [{ id: 10 }, { id: 2 }];
|
|
250
|
+
field.setProps({ value: rows });
|
|
251
|
+
render(field.render());
|
|
252
|
+
const column: NonNullable<TableOptions['columns']>[number] & { sortField: string } = {
|
|
253
|
+
sortField: 'org.staff.id',
|
|
254
|
+
};
|
|
255
|
+
await act(async () => {
|
|
256
|
+
await tableProps().onChange?.(
|
|
257
|
+
{},
|
|
258
|
+
{},
|
|
259
|
+
{ field: 'other', column, order: 'ascend' },
|
|
260
|
+
{
|
|
261
|
+
action: 'sort',
|
|
262
|
+
currentDataSource: rows,
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
expect(tableProps().dataSource).toEqual([rows[1], rows[0]]);
|
|
267
|
+
await act(async () => {
|
|
268
|
+
await tableProps().onChange?.(
|
|
269
|
+
{ current: 2 },
|
|
270
|
+
{},
|
|
271
|
+
{},
|
|
272
|
+
{
|
|
273
|
+
action: 'paginate',
|
|
274
|
+
currentDataSource: rows,
|
|
275
|
+
},
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
expect(tableProps().dataSource).toEqual([rows[1], rows[0]]);
|
|
279
|
+
expect(resource.refresh).not.toHaveBeenCalled();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('follows form association changes without writing displayed records into the form', async () => {
|
|
283
|
+
vi.spyOn(window, 'matchMedia').mockImplementation((query) => ({
|
|
284
|
+
matches: false,
|
|
285
|
+
media: query,
|
|
286
|
+
onchange: null,
|
|
287
|
+
addListener: vi.fn(),
|
|
288
|
+
removeListener: vi.fn(),
|
|
289
|
+
addEventListener: vi.fn(),
|
|
290
|
+
removeEventListener: vi.fn(),
|
|
291
|
+
dispatchEvent: vi.fn(),
|
|
292
|
+
}));
|
|
293
|
+
const { engine, parent, resource } = setup();
|
|
294
|
+
let form: FormInstance;
|
|
295
|
+
const firstOrg = { id: 1, staff: [{ id: 1, name: 'Alice' }] };
|
|
296
|
+
const secondOrg = { id: 2, staff: [{ id: 2, name: 'Bob' }] };
|
|
297
|
+
function TestForm() {
|
|
298
|
+
const [formInstance] = Form.useForm();
|
|
299
|
+
form = formInstance;
|
|
300
|
+
parent.context.defineProperty('form', { value: formInstance });
|
|
301
|
+
parent.context.defineProperty('formValues', { get: () => formInstance.getFieldsValue(true), cache: false });
|
|
302
|
+
return (
|
|
303
|
+
<Form form={formInstance} initialValues={{ org: firstOrg, note: 'unsaved' }}>
|
|
304
|
+
<FlowModelProvider model={parent}>{parent.renderItem()}</FlowModelProvider>
|
|
305
|
+
</Form>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
render(
|
|
309
|
+
<FlowEngineProvider engine={engine}>
|
|
310
|
+
<TestForm />
|
|
311
|
+
</FlowEngineProvider>,
|
|
312
|
+
);
|
|
313
|
+
await waitFor(() => expect(screen.getByTestId('rows').textContent).toContain('Alice'));
|
|
314
|
+
act(() => form.setFieldValue('org', secondOrg));
|
|
315
|
+
await waitFor(() => expect(screen.getByTestId('rows').textContent).toContain('Bob'));
|
|
316
|
+
expect(form.getFieldsValue(true)).toEqual({ org: secondOrg, note: 'unsaved' });
|
|
317
|
+
act(() => form.setFieldValue('org', null));
|
|
318
|
+
await waitFor(() => expect(tableProps().dataSource).toEqual([]));
|
|
319
|
+
expect(form.getFieldsValue(true)).toEqual({ org: null, note: 'unsaved' });
|
|
320
|
+
expect(resource.refresh).not.toHaveBeenCalled();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('keeps nested column paths and column configuration when switching components', async () => {
|
|
324
|
+
const { parent, field } = setup();
|
|
325
|
+
vi.spyOn(parent, 'save').mockResolvedValue(undefined);
|
|
326
|
+
const column = field.addSubModel('columns', {
|
|
327
|
+
use: 'TableColumnModel',
|
|
328
|
+
stepParams: {
|
|
329
|
+
fieldSettings: {
|
|
330
|
+
init: { dataSourceKey: 'main', collectionName: 'posts', fieldPath: 'org.staff.name' },
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
subModels: { field: { use: 'DisplayTextFieldModel' } },
|
|
334
|
+
});
|
|
335
|
+
expect(field.context.prefixFieldPath).toBe('org.staff');
|
|
336
|
+
expect(field.collection.name).toBe('users');
|
|
337
|
+
const columnField = column.subModels.field as DisplayTextFieldModel;
|
|
338
|
+
const createFork = vi.spyOn(columnField, 'createFork');
|
|
339
|
+
(column as TableColumnModel).renderItem()(undefined, { id: 1, name: 'Alice' }, 0);
|
|
340
|
+
expect(createFork.mock.results[0].value.props.value).toBe('Alice');
|
|
341
|
+
expect(createFork.mock.results[0].value.context.record).toEqual({ id: 1, name: 'Alice' });
|
|
342
|
+
await rebuildFieldSubModel({ parentModel: parent, targetUse: 'DisplayTextFieldModel' });
|
|
343
|
+
await rebuildFieldSubModel({ parentModel: parent, targetUse: 'DisplaySubTableFieldModel' });
|
|
344
|
+
const rebuilt = parent.subModels.field as DisplaySubTableFieldModel;
|
|
345
|
+
expect(rebuilt.uid).toBe(field.uid);
|
|
346
|
+
expect(rebuilt.serialize().subModels.columns[0]).toMatchObject({
|
|
347
|
+
uid: column.uid,
|
|
348
|
+
stepParams: { fieldSettings: { init: { fieldPath: 'org.staff.name' } } },
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
});
|
|
@@ -201,12 +201,12 @@ function TopbarInternalSettingsLabel(props: { title: React.ReactNode; path?: str
|
|
|
201
201
|
adminRoutePath: getTopbarAdminRoutePath(app),
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
+
if (!shouldOpenInNewWindow) {
|
|
205
|
+
return <Link to={stripTopbarRouterBasePath(targetPathInCurrentApp, basename)}>{props.title}</Link>;
|
|
206
|
+
}
|
|
207
|
+
|
|
204
208
|
return (
|
|
205
|
-
<a
|
|
206
|
-
href={href}
|
|
207
|
-
target={shouldOpenInNewWindow ? '_blank' : undefined}
|
|
208
|
-
rel={shouldOpenInNewWindow ? 'noopener noreferrer' : undefined}
|
|
209
|
-
>
|
|
209
|
+
<a href={href} target="_blank" rel="noopener noreferrer">
|
|
210
210
|
{props.title}
|
|
211
211
|
</a>
|
|
212
212
|
);
|