@nocobase/client-v2 2.4.0-alpha.2 → 2.4.0-alpha.20
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/README.md +4 -4
- 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/components/form/VariableInput.d.ts +1 -0
- package/es/flow/FlowModelRepository.d.ts +4 -1
- package/es/flow/FlowPage.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/MobileTopbarActionsContext.d.ts +10 -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/actions/LinkActionUtils.d.ts +1 -0
- package/es/flow/models/actions/getHasManyDeleteFilterByTk.d.ts +12 -0
- package/es/flow/models/base/PageModel/closeGuard.d.ts +8 -1
- package/es/flow/models/blocks/assign-form/assignFormValue.d.ts +29 -0
- package/es/flow/models/blocks/form/EditFormModel.d.ts +2 -0
- package/es/flow/models/blocks/form/QuickEditFormModel.d.ts +1 -0
- package/es/flow/models/blocks/table/sortUtils.d.ts +3 -0
- package/es/flow/models/topbar/UserCenterTopbarActionModel.d.ts +2 -0
- package/es/flow/useRouteContentRequest.d.ts +20 -0
- package/es/index.mjs +141 -104
- package/lib/index.js +178 -141
- 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/components/form/VariableInput.tsx +1 -0
- package/src/flow/FlowModelRepository.ts +47 -1
- package/src/flow/FlowPage.tsx +25 -10
- package/src/flow/__tests__/FlowModelRepository.test.ts +38 -1
- package/src/flow/__tests__/FlowPage.test.tsx +78 -46
- package/src/flow/actions/__tests__/validation.test.ts +48 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +8 -1
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +5 -1
- package/src/flow/admin-shell/admin-layout/MobileTopbarActionsContext.ts +13 -0
- package/src/flow/admin-shell/admin-layout/TopbarActionsBar.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.mobile.test.tsx +259 -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/flows/editMarkdownFlow.tsx +1 -1
- 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/BulkDeleteActionModel.tsx +13 -2
- package/src/flow/models/actions/DeleteActionModel.tsx +16 -2
- package/src/flow/models/actions/JSItemActionModel.tsx +19 -3
- package/src/flow/models/actions/LinkActionModel.tsx +11 -9
- package/src/flow/models/actions/LinkActionUtils.ts +4 -2
- package/src/flow/models/actions/__tests__/DeleteActionModel.test.ts +256 -0
- package/src/flow/models/actions/__tests__/JSItemActionModel.test.tsx +47 -1
- package/src/flow/models/actions/__tests__/LinkActionModel.test.ts +14 -0
- package/src/flow/models/actions/getHasManyDeleteFilterByTk.ts +40 -0
- package/src/flow/models/base/GridModel.tsx +0 -1
- package/src/flow/models/base/PageModel/PageTabModel.tsx +27 -12
- package/src/flow/models/base/PageModel/closeGuard.ts +9 -8
- package/src/flow/models/blocks/assign-form/AssignFormGridModel.tsx +22 -1
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +40 -12
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.editor.test.tsx +140 -0
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.multipleSelect.test.tsx +216 -0
- package/src/flow/models/blocks/assign-form/__tests__/assignFormValue.test.ts +41 -0
- package/src/flow/models/blocks/assign-form/assignFormValue.ts +64 -0
- package/src/flow/models/blocks/details/DetailsItemModel.tsx +62 -1
- package/src/flow/models/blocks/details/__tests__/DetailsItemModel.spacing.test.tsx +77 -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/EditFormModel.tsx +23 -1
- 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__/EditFormModel.pagination.test.tsx +77 -0
- 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/TableBlockModel.tsx +4 -10
- 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/blocks/table/__tests__/sortUtils.test.ts +11 -1
- package/src/flow/models/blocks/table/sortUtils.ts +10 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +11 -2
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +4 -3
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +13 -1
- 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/AssociationFieldModel/__tests__/associationSelect.search.test.ts +113 -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/InputFieldModel.tsx +1 -1
- package/src/flow/models/fields/SelectFieldModel.tsx +5 -0
- package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +16 -0
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +29 -1
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +1 -0
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +20 -0
- package/src/flow/models/topbar/UserCenterTopbarActionModel.tsx +64 -30
- package/src/flow/useRouteContentRequest.tsx +46 -0
package/src/flow/models/fields/AssociationFieldModel/__tests__/associationSelect.search.test.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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 { CollectionField } from '@nocobase/flow-engine';
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
+
import '../../../index';
|
|
13
|
+
import { createTypedFilterable } from '../../../../../collection-manager/filter-operators';
|
|
14
|
+
import { CascadeSelectInnerFieldModel } from '../CascadeSelectFieldModel';
|
|
15
|
+
import { RecordSelectFieldModel } from '../RecordSelectFieldModel';
|
|
16
|
+
|
|
17
|
+
function createContext(fieldOptions: Record<string, unknown>, searchText = ' 3 ') {
|
|
18
|
+
const field = new CollectionField({ name: 'display_name', ...fieldOptions });
|
|
19
|
+
const filterable = createTypedFilterable<{ dataType?: string }>(
|
|
20
|
+
[
|
|
21
|
+
{ types: ['boolean'], operators: 'boolean' },
|
|
22
|
+
{ types: ['string'], operators: 'string' },
|
|
23
|
+
{ types: ['integer'], operators: 'number' },
|
|
24
|
+
],
|
|
25
|
+
(meta) => meta.dataType || 'string',
|
|
26
|
+
);
|
|
27
|
+
vi.spyOn(field, 'getInterfaceOptions').mockReturnValue({ filterable });
|
|
28
|
+
const records = [{ id: 3, display_name: '3 Jackson Hughes' }];
|
|
29
|
+
const resource = {
|
|
30
|
+
setPage: vi.fn(),
|
|
31
|
+
addFilterGroup: vi.fn(),
|
|
32
|
+
removeFilterGroup: vi.fn(),
|
|
33
|
+
refresh: vi.fn().mockResolvedValue(undefined),
|
|
34
|
+
getData: vi.fn(() => records),
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
field,
|
|
38
|
+
inputArgs: { searchText },
|
|
39
|
+
model: {
|
|
40
|
+
collectionField: { targetCollection: { getField: vi.fn(() => field) } },
|
|
41
|
+
props: { fieldNames: { label: 'display_name', value: 'id' } },
|
|
42
|
+
resource,
|
|
43
|
+
setDataSource: vi.fn(),
|
|
44
|
+
setProps: vi.fn(),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe.each([
|
|
50
|
+
{ name: 'RecordSelect', model: RecordSelectFieldModel, searchGroup: '__search__display_name' },
|
|
51
|
+
{ name: 'CascadeSelect', model: CascadeSelectInnerFieldModel, searchGroup: 'display_name' },
|
|
52
|
+
])('$name search', ({ model, searchGroup }) => {
|
|
53
|
+
beforeEach(() => vi.useFakeTimers());
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
vi.clearAllTimers();
|
|
56
|
+
vi.useRealTimers();
|
|
57
|
+
vi.restoreAllMocks();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
async function search(ctx: ReturnType<typeof createContext>) {
|
|
61
|
+
const handler = model.globalFlowRegistry.getFlow('searchSettings').getStep('step1').serialize().handler as (
|
|
62
|
+
ctx: ReturnType<typeof createContext>,
|
|
63
|
+
params: Record<string, unknown>,
|
|
64
|
+
) => unknown;
|
|
65
|
+
handler(ctx, {});
|
|
66
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
it.each([{ type: 'formula', dataType: 'string' }, { type: 'string' }])(
|
|
70
|
+
'uses partial text matching for $type labels',
|
|
71
|
+
async (options) => {
|
|
72
|
+
const ctx = createContext(options);
|
|
73
|
+
|
|
74
|
+
await search(ctx);
|
|
75
|
+
|
|
76
|
+
expect(ctx.model.resource.addFilterGroup).toHaveBeenCalledWith(searchGroup, { 'display_name.$includes': '3' });
|
|
77
|
+
expect(ctx.model.resource.setPage).toHaveBeenCalledWith(1);
|
|
78
|
+
expect(ctx.model.resource.refresh).toHaveBeenCalledOnce();
|
|
79
|
+
expect(ctx.model.setDataSource).toHaveBeenCalledWith([
|
|
80
|
+
expect.objectContaining({ display_name: '3 Jackson Hughes' }),
|
|
81
|
+
]);
|
|
82
|
+
expect(ctx.model.setProps).toHaveBeenCalledWith({ searchText: '3' });
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
it('preserves the interface operator for non-string labels', async () => {
|
|
87
|
+
const ctx = createContext({ type: 'integer' });
|
|
88
|
+
vi.spyOn(ctx.field, 'getInterfaceOptions').mockReturnValue({ filterable: { operators: [{ value: '$eq' }] } });
|
|
89
|
+
|
|
90
|
+
await search(ctx);
|
|
91
|
+
|
|
92
|
+
expect(ctx.model.resource.addFilterGroup).toHaveBeenCalledWith(searchGroup, { 'display_name.$eq': '3' });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('falls back to partial text matching without an interface', async () => {
|
|
96
|
+
const ctx = createContext({ type: 'string' });
|
|
97
|
+
vi.spyOn(ctx.field, 'getInterfaceOptions').mockReturnValue(undefined);
|
|
98
|
+
|
|
99
|
+
await search(ctx);
|
|
100
|
+
|
|
101
|
+
expect(ctx.model.resource.addFilterGroup).toHaveBeenCalledWith(searchGroup, { 'display_name.$includes': '3' });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('removes the search filter when the search is cleared', async () => {
|
|
105
|
+
const ctx = createContext({ type: 'formula', dataType: 'string' }, ' ');
|
|
106
|
+
|
|
107
|
+
await search(ctx);
|
|
108
|
+
|
|
109
|
+
expect(ctx.model.resource.removeFilterGroup).toHaveBeenCalledWith(searchGroup);
|
|
110
|
+
expect(ctx.model.resource.addFilterGroup).not.toHaveBeenCalled();
|
|
111
|
+
expect(ctx.model.resource.refresh).toHaveBeenCalledOnce();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -58,7 +58,7 @@ export class InputFieldModel extends FieldModel {
|
|
|
58
58
|
return <ScanInput {...this.props} />;
|
|
59
59
|
}
|
|
60
60
|
const { enableScan, disableManualInput, ...inputProps } = this.props;
|
|
61
|
-
return <IMESafeInput {...inputProps} />;
|
|
61
|
+
return <IMESafeInput {...inputProps} style={{ verticalAlign: 'top', ...inputProps.style }} />;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -13,6 +13,7 @@ import React from 'react';
|
|
|
13
13
|
import { FieldModel } from '../base/FieldModel';
|
|
14
14
|
import { MobileSelect } from './mobile-components/MobileSelect';
|
|
15
15
|
import { enumToOptions, getSelectedEnumLabels, translateOptionLabel } from '../../internal/utils/enumOptionsUtils';
|
|
16
|
+
import { syncQuickEditPreventClose } from '../../internal/utils/quickEditViewContainer';
|
|
16
17
|
|
|
17
18
|
const getOriginalEnumOptions = (model: SelectFieldModel) => {
|
|
18
19
|
const fromEnum = enumToOptions(model.context.collectionField?.uiSchema?.enum, model.translate) || [];
|
|
@@ -62,6 +63,10 @@ export class SelectFieldModel extends FieldModel {
|
|
|
62
63
|
this.props.onChange?.(nextValue?.value);
|
|
63
64
|
}}
|
|
64
65
|
options={options}
|
|
66
|
+
onDropdownVisibleChange={(open) => {
|
|
67
|
+
syncQuickEditPreventClose(this, open);
|
|
68
|
+
this.props.onDropdownVisibleChange?.(open);
|
|
69
|
+
}}
|
|
65
70
|
labelRender={(item) => item.label}
|
|
66
71
|
maxTagCount="responsive"
|
|
67
72
|
maxTagPlaceholder={(omittedValues) => (
|
|
@@ -27,6 +27,22 @@ function createInputFieldModel(props?: Record<string, unknown>) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
describe('InputFieldModel', () => {
|
|
30
|
+
it('aligns plain inputs with the top of other filter form controls', () => {
|
|
31
|
+
const model = createInputFieldModel();
|
|
32
|
+
|
|
33
|
+
render(<>{model.render()}</>);
|
|
34
|
+
|
|
35
|
+
expect(screen.getByRole('textbox')).toHaveStyle({ verticalAlign: 'top' });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('preserves explicitly configured input styles', () => {
|
|
39
|
+
const model = createInputFieldModel({ style: { verticalAlign: 'middle', width: 200 } });
|
|
40
|
+
|
|
41
|
+
render(<>{model.render()}</>);
|
|
42
|
+
|
|
43
|
+
expect(screen.getByRole('textbox')).toHaveStyle({ verticalAlign: 'middle', width: '200px' });
|
|
44
|
+
});
|
|
45
|
+
|
|
30
46
|
it('renders the normal input when scan input is disabled', () => {
|
|
31
47
|
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
32
48
|
const model = createInputFieldModel({ disableManualInput: true, enableScan: false });
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import React from 'react';
|
|
11
|
-
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
12
12
|
import { SelectFieldModel } from '../SelectFieldModel';
|
|
13
13
|
|
|
14
14
|
function mockT(text: string) {
|
|
@@ -40,4 +40,32 @@ describe('SelectFieldModel', () => {
|
|
|
40
40
|
|
|
41
41
|
expect(element.props.value).toEqual({ label: '是', value: true });
|
|
42
42
|
});
|
|
43
|
+
|
|
44
|
+
it('keeps the quick edit popover open while the dropdown is open', () => {
|
|
45
|
+
vi.useFakeTimers();
|
|
46
|
+
try {
|
|
47
|
+
const update = vi.fn();
|
|
48
|
+
const onDropdownVisibleChange = vi.fn();
|
|
49
|
+
const model = {
|
|
50
|
+
props: { value: undefined, onDropdownVisibleChange },
|
|
51
|
+
parent: { use: 'QuickEditFormModel', viewContainer: { update } },
|
|
52
|
+
context: { collectionField: { uiSchema: { enum: [] } } },
|
|
53
|
+
translate: mockT,
|
|
54
|
+
} as unknown as SelectFieldModel;
|
|
55
|
+
|
|
56
|
+
const element = SelectFieldModel.prototype.render.call(model) as React.ReactElement;
|
|
57
|
+
|
|
58
|
+
element.props.onDropdownVisibleChange(true);
|
|
59
|
+
expect(update).toHaveBeenCalledWith({ preventClose: true });
|
|
60
|
+
expect(onDropdownVisibleChange).toHaveBeenCalledWith(true);
|
|
61
|
+
|
|
62
|
+
element.props.onDropdownVisibleChange(false);
|
|
63
|
+
expect(onDropdownVisibleChange).toHaveBeenCalledWith(false);
|
|
64
|
+
expect(update).toHaveBeenCalledTimes(1);
|
|
65
|
+
vi.runAllTimers();
|
|
66
|
+
expect(update).toHaveBeenLastCalledWith({ preventClose: false });
|
|
67
|
+
} finally {
|
|
68
|
+
vi.useRealTimers();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
43
71
|
});
|