@nocobase/client-v2 3.0.0-alpha.6 → 3.0.0-alpha.8
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/flow/actions/linkageRules.d.ts +24 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +4 -30
- package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
- package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
- package/es/flow/components/field-value-variable/index.d.ts +11 -0
- package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +6 -0
- package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
- package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
- package/es/index.mjs +106 -106
- package/lib/index.js +97 -97
- package/package.json +7 -7
- package/src/__tests__/app.test.tsx +122 -3
- package/src/__tests__/browserChecker.test.ts +37 -0
- package/src/__tests__/settings-shell.test.tsx +27 -1
- package/src/components/AppComponents.tsx +16 -7
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
- package/src/flow/actions/linkageRules.tsx +25 -7
- package/src/flow/components/FieldAssignValueInput.tsx +38 -621
- package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
- package/src/flow/components/field-value-variable/dateValue.ts +223 -0
- package/src/flow/components/field-value-variable/index.ts +12 -0
- package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
- package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
- package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
- package/src/flow/models/blocks/form/FormBlockModel.tsx +4 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
- package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
- package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +8 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +46 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +1 -0
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +20 -2
- package/src/settings-app/SettingsShell.tsx +19 -4
|
@@ -0,0 +1,433 @@
|
|
|
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 { fireEvent, render } from '@testing-library/react';
|
|
11
|
+
import { css } from '@emotion/css';
|
|
12
|
+
import { ConfigProvider, Table as AntdTable } from 'antd';
|
|
13
|
+
import type { ColumnsType } from 'antd/es/table/interface';
|
|
14
|
+
import type { RenderedCell } from 'rc-table/lib/interface';
|
|
15
|
+
import React from 'react';
|
|
16
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
17
|
+
import { Table, type TableProps } from '../Table';
|
|
18
|
+
|
|
19
|
+
type Row = {
|
|
20
|
+
id: number;
|
|
21
|
+
name: string;
|
|
22
|
+
note: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const row: Row = {
|
|
26
|
+
id: 1,
|
|
27
|
+
name: 'Long unbroken content',
|
|
28
|
+
note: 'Secondary content',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const defaultColumnMaxWidth = 400;
|
|
32
|
+
const defaultColumnContentClassName = 'nb-table-default-column-content';
|
|
33
|
+
|
|
34
|
+
function getMatchingStyleValues(element: Element, property: string) {
|
|
35
|
+
return Array.from(document.styleSheets).flatMap((styleSheet) => {
|
|
36
|
+
try {
|
|
37
|
+
return Array.from(styleSheet.cssRules).flatMap((rule) => {
|
|
38
|
+
if (!(rule instanceof CSSStyleRule)) return [];
|
|
39
|
+
try {
|
|
40
|
+
return element.matches(rule.selectorText) ? [rule.style.getPropertyValue(property)] : [];
|
|
41
|
+
} catch {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
} catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function renderTable(columns: ColumnsType<Row>, props: Partial<TableProps<Row>> = {}) {
|
|
52
|
+
return render(
|
|
53
|
+
<ConfigProvider
|
|
54
|
+
theme={{
|
|
55
|
+
token: {
|
|
56
|
+
screenXS: 500,
|
|
57
|
+
paddingXL: 40,
|
|
58
|
+
padding: 10,
|
|
59
|
+
},
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<Table<Row> rowKey="id" columns={columns} dataSource={[row]} pagination={false} {...props} />
|
|
63
|
+
</ConfigProvider>,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getResolvedMaxWidth(element: HTMLElement) {
|
|
68
|
+
const style = window.getComputedStyle(element);
|
|
69
|
+
const variableName = style.maxWidth.match(/^var\((--[^)]+)\)$/)?.[1];
|
|
70
|
+
return variableName ? style.getPropertyValue(variableName).trim() : style.maxWidth;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function expectDefaultWrappingStyle(element: Element | null) {
|
|
74
|
+
expect(element).not.toBeNull();
|
|
75
|
+
const htmlElement = element as HTMLElement;
|
|
76
|
+
const style = window.getComputedStyle(htmlElement);
|
|
77
|
+
expect(htmlElement.classList).toContain(defaultColumnContentClassName);
|
|
78
|
+
expect(getResolvedMaxWidth(htmlElement)).toBe(`${defaultColumnMaxWidth}px`);
|
|
79
|
+
expect(style.whiteSpace).toBe('normal');
|
|
80
|
+
expect(style.overflowWrap).toBe('break-word');
|
|
81
|
+
expect(style.wordBreak).toBe('break-word');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function expectNoDefaultWrappingStyle(element: Element | null) {
|
|
85
|
+
expect(element).not.toBeNull();
|
|
86
|
+
const htmlElement = element as HTMLElement;
|
|
87
|
+
expect(htmlElement.classList).not.toContain(defaultColumnContentClassName);
|
|
88
|
+
expect(getResolvedMaxWidth(htmlElement)).not.toBe(`${defaultColumnMaxWidth}px`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
describe('Table default column content width', () => {
|
|
92
|
+
it('adds token-derived wrapping styles to unconstrained leaf headers and cells', () => {
|
|
93
|
+
const { getByRole } = renderTable([{ title: 'Name', dataIndex: 'name' }]);
|
|
94
|
+
|
|
95
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Name' }));
|
|
96
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: row.name }));
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('leaves columns with explicit width, ellipsis, or fixed positioning unchanged', () => {
|
|
100
|
+
const columns: ColumnsType<Row> = [
|
|
101
|
+
{ title: 'Width', dataIndex: 'name', width: 240 },
|
|
102
|
+
{ title: 'Ellipsis', dataIndex: 'note', ellipsis: true },
|
|
103
|
+
{ title: 'Fixed', dataIndex: 'id', fixed: 'left' },
|
|
104
|
+
];
|
|
105
|
+
const { getByRole } = renderTable(columns, { scroll: { x: 800 } });
|
|
106
|
+
|
|
107
|
+
for (const title of ['Width', 'Ellipsis', 'Fixed']) {
|
|
108
|
+
expectNoDefaultWrappingStyle(getByRole('columnheader', { name: title }));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const widthCell = getByRole('cell', { name: row.name });
|
|
112
|
+
const ellipsisCell = getByRole('cell', { name: row.note });
|
|
113
|
+
const fixedCell = getByRole('cell', { name: String(row.id) });
|
|
114
|
+
for (const cell of [widthCell, ellipsisCell, fixedCell]) {
|
|
115
|
+
expectNoDefaultWrappingStyle(cell);
|
|
116
|
+
}
|
|
117
|
+
expect(ellipsisCell.classList).toContain('ant-table-cell-ellipsis');
|
|
118
|
+
expect(window.getComputedStyle(ellipsisCell).whiteSpace).toBe('nowrap');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('preserves cell callbacks and lets caller styles override the defaults', () => {
|
|
122
|
+
const handleClick = vi.fn();
|
|
123
|
+
const onCell = vi.fn(() => ({
|
|
124
|
+
colSpan: 2,
|
|
125
|
+
className: 'custom-body-cell',
|
|
126
|
+
onClick: handleClick,
|
|
127
|
+
style: {
|
|
128
|
+
maxWidth: 120,
|
|
129
|
+
whiteSpace: 'pre' as const,
|
|
130
|
+
},
|
|
131
|
+
}));
|
|
132
|
+
const onHeaderCell = vi.fn(() => ({
|
|
133
|
+
colSpan: 2,
|
|
134
|
+
className: 'custom-header-cell',
|
|
135
|
+
style: {
|
|
136
|
+
maxWidth: 180,
|
|
137
|
+
overflowWrap: 'normal' as const,
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
const columns: ColumnsType<Row> = [
|
|
141
|
+
{ title: 'Name', dataIndex: 'name', onCell, onHeaderCell },
|
|
142
|
+
{ title: 'Note', dataIndex: 'note', width: 100 },
|
|
143
|
+
];
|
|
144
|
+
const { container } = renderTable(columns);
|
|
145
|
+
|
|
146
|
+
const header = container.querySelector<HTMLElement>('th.custom-header-cell');
|
|
147
|
+
expect(header?.getAttribute('colspan')).toBe('2');
|
|
148
|
+
const headerStyle = window.getComputedStyle(header as HTMLElement);
|
|
149
|
+
expect(headerStyle.maxWidth).toBe('180px');
|
|
150
|
+
expect(headerStyle.whiteSpace).toBe('normal');
|
|
151
|
+
expect(headerStyle.overflowWrap).toBe('normal');
|
|
152
|
+
expect(headerStyle.wordBreak).toBe('break-word');
|
|
153
|
+
|
|
154
|
+
const cell = container.querySelector<HTMLElement>('td.custom-body-cell');
|
|
155
|
+
expect(cell?.getAttribute('colspan')).toBe('2');
|
|
156
|
+
const cellStyle = window.getComputedStyle(cell as HTMLElement);
|
|
157
|
+
expect(cellStyle.maxWidth).toBe('120px');
|
|
158
|
+
expect(cellStyle.whiteSpace).toBe('pre');
|
|
159
|
+
expect(cellStyle.overflowWrap).toBe('break-word');
|
|
160
|
+
expect(cellStyle.wordBreak).toBe('break-word');
|
|
161
|
+
|
|
162
|
+
fireEvent.click(cell as HTMLElement);
|
|
163
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
164
|
+
expect(onCell).toHaveBeenCalledWith(row, 0);
|
|
165
|
+
expect(onHeaderCell).toHaveBeenCalledWith(expect.objectContaining({ title: 'Name' }));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('keeps the default wrapping behavior when caller classNames have no styles', () => {
|
|
169
|
+
const columns: ColumnsType<Row> = [
|
|
170
|
+
{
|
|
171
|
+
title: 'Name',
|
|
172
|
+
dataIndex: 'name',
|
|
173
|
+
className: 'column-marker',
|
|
174
|
+
onCell: () => ({ className: 'body-marker' }),
|
|
175
|
+
onHeaderCell: () => ({ className: 'header-marker' }),
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
title: 'Note',
|
|
179
|
+
dataIndex: 'note',
|
|
180
|
+
render: () => ({ children: 'Rendered marker', props: { className: 'render-marker' } }),
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
const { getByRole } = renderTable(columns);
|
|
184
|
+
|
|
185
|
+
const nameHeader = getByRole('columnheader', { name: 'Name' });
|
|
186
|
+
const nameCell = getByRole('cell', { name: row.name });
|
|
187
|
+
const renderedCell = getByRole('cell', { name: 'Rendered marker' });
|
|
188
|
+
expect(nameHeader.classList).toContain('column-marker');
|
|
189
|
+
expect(nameHeader.classList).toContain('header-marker');
|
|
190
|
+
expect(nameCell.classList).toContain('column-marker');
|
|
191
|
+
expect(nameCell.classList).toContain('body-marker');
|
|
192
|
+
expect(renderedCell.classList).toContain('render-marker');
|
|
193
|
+
for (const element of [nameHeader, nameCell, renderedCell]) {
|
|
194
|
+
expectDefaultWrappingStyle(element);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('lets caller className styles override the defaults', () => {
|
|
199
|
+
const callerClassName = css`
|
|
200
|
+
max-width: 135px;
|
|
201
|
+
white-space: pre;
|
|
202
|
+
overflow-wrap: normal;
|
|
203
|
+
word-break: normal;
|
|
204
|
+
`;
|
|
205
|
+
const columns: ColumnsType<Row> = [
|
|
206
|
+
{
|
|
207
|
+
title: 'Name',
|
|
208
|
+
dataIndex: 'name',
|
|
209
|
+
onCell: () => ({ className: callerClassName }),
|
|
210
|
+
onHeaderCell: () => ({ className: callerClassName }),
|
|
211
|
+
},
|
|
212
|
+
{ title: 'Note', dataIndex: 'note', className: callerClassName },
|
|
213
|
+
];
|
|
214
|
+
// Use a distinct token value so this render creates its default Emotion class after the caller class. This
|
|
215
|
+
// catches source-order regressions that would be hidden if a previous test had already inserted the default rule.
|
|
216
|
+
const { getByRole } = render(
|
|
217
|
+
<ConfigProvider theme={{ token: { screenXS: 501, paddingXL: 40, padding: 10 } }}>
|
|
218
|
+
<Table<Row> rowKey="id" columns={columns} dataSource={[row]} pagination={false} />
|
|
219
|
+
</ConfigProvider>,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
for (const element of [
|
|
223
|
+
getByRole('columnheader', { name: 'Name' }),
|
|
224
|
+
getByRole('columnheader', { name: 'Note' }),
|
|
225
|
+
getByRole('cell', { name: row.name }),
|
|
226
|
+
getByRole('cell', { name: row.note }),
|
|
227
|
+
]) {
|
|
228
|
+
const style = window.getComputedStyle(element);
|
|
229
|
+
expect(getResolvedMaxWidth(element)).toBe('135px');
|
|
230
|
+
expect(style.whiteSpace).toBe('pre');
|
|
231
|
+
expect(style.overflowWrap).not.toBe('anywhere');
|
|
232
|
+
expect(getMatchingStyleValues(element, 'overflow-wrap')).toContain('normal');
|
|
233
|
+
expect(style.wordBreak).toBe('normal');
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('lets className returned from render override the defaults on first mount', () => {
|
|
238
|
+
const callerClassName = css`
|
|
239
|
+
max-width: 136px;
|
|
240
|
+
white-space: pre;
|
|
241
|
+
overflow-wrap: normal;
|
|
242
|
+
word-break: normal;
|
|
243
|
+
`;
|
|
244
|
+
const renderedCell: RenderedCell<Row> = {
|
|
245
|
+
props: { className: callerClassName },
|
|
246
|
+
};
|
|
247
|
+
const { container } = render(
|
|
248
|
+
<ConfigProvider theme={{ token: { screenXS: 502, paddingXL: 40, padding: 10 } }}>
|
|
249
|
+
<Table<Row>
|
|
250
|
+
rowKey="id"
|
|
251
|
+
columns={[{ title: 'Name', dataIndex: 'name', render: () => renderedCell }]}
|
|
252
|
+
dataSource={[row]}
|
|
253
|
+
pagination={false}
|
|
254
|
+
/>
|
|
255
|
+
</ConfigProvider>,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const cell = container.querySelector<HTMLElement>('.ant-table-tbody td');
|
|
259
|
+
expect(cell).not.toBeNull();
|
|
260
|
+
const htmlCell = cell as HTMLElement;
|
|
261
|
+
const style = window.getComputedStyle(htmlCell);
|
|
262
|
+
expect(getResolvedMaxWidth(htmlCell)).toBe('136px');
|
|
263
|
+
expect(style.whiteSpace).toBe('pre');
|
|
264
|
+
expect(style.overflowWrap).not.toBe('anywhere');
|
|
265
|
+
expect(getMatchingStyleValues(cell as HTMLElement, 'overflow-wrap')).toContain('normal');
|
|
266
|
+
expect(style.wordBreak).toBe('normal');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('lets static caller className styles override defaults inserted later', () => {
|
|
270
|
+
const callerClassName = 'caller-static-table-column';
|
|
271
|
+
const callerStyle = document.createElement('style');
|
|
272
|
+
callerStyle.textContent = `
|
|
273
|
+
.${callerClassName} {
|
|
274
|
+
max-width: 137px;
|
|
275
|
+
white-space: pre;
|
|
276
|
+
overflow-wrap: normal;
|
|
277
|
+
word-break: normal;
|
|
278
|
+
}
|
|
279
|
+
`;
|
|
280
|
+
document.head.prepend(callerStyle);
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
const columns: ColumnsType<Row> = [
|
|
284
|
+
{
|
|
285
|
+
title: 'Name',
|
|
286
|
+
dataIndex: 'name',
|
|
287
|
+
onCell: () => ({ className: callerClassName }),
|
|
288
|
+
onHeaderCell: () => ({ className: callerClassName }),
|
|
289
|
+
},
|
|
290
|
+
{ title: 'Note', dataIndex: 'note', className: callerClassName },
|
|
291
|
+
{
|
|
292
|
+
title: 'Rendered',
|
|
293
|
+
dataIndex: 'id',
|
|
294
|
+
render: () => ({ props: { className: callerClassName } }),
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
const { container, getByRole } = render(
|
|
298
|
+
<ConfigProvider theme={{ token: { screenXS: 503, paddingXL: 40, padding: 10 } }}>
|
|
299
|
+
<Table<Row> rowKey="id" columns={columns} dataSource={[row]} pagination={false} />
|
|
300
|
+
</ConfigProvider>,
|
|
301
|
+
);
|
|
302
|
+
const cells = Array.from(container.querySelectorAll<HTMLElement>('.ant-table-tbody td'));
|
|
303
|
+
|
|
304
|
+
for (const element of [
|
|
305
|
+
getByRole('columnheader', { name: 'Name' }),
|
|
306
|
+
getByRole('columnheader', { name: 'Note' }),
|
|
307
|
+
cells[0],
|
|
308
|
+
cells[1],
|
|
309
|
+
cells[2],
|
|
310
|
+
]) {
|
|
311
|
+
expect(element).toBeDefined();
|
|
312
|
+
const htmlElement = element as HTMLElement;
|
|
313
|
+
const style = window.getComputedStyle(htmlElement);
|
|
314
|
+
expect(getResolvedMaxWidth(htmlElement)).toBe('137px');
|
|
315
|
+
expect(style.whiteSpace).toBe('pre');
|
|
316
|
+
expect(style.overflowWrap).not.toBe('anywhere');
|
|
317
|
+
expect(getMatchingStyleValues(htmlElement, 'overflow-wrap')).toContain('normal');
|
|
318
|
+
expect(style.wordBreak).toBe('normal');
|
|
319
|
+
}
|
|
320
|
+
} finally {
|
|
321
|
+
callerStyle.remove();
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('lets styles returned from render override the defaults', () => {
|
|
326
|
+
const renderedCell: RenderedCell<Row> = {
|
|
327
|
+
children: 'Rendered cell',
|
|
328
|
+
props: {
|
|
329
|
+
className: 'rendered-cell',
|
|
330
|
+
style: {
|
|
331
|
+
maxWidth: 123,
|
|
332
|
+
whiteSpace: 'pre',
|
|
333
|
+
overflowWrap: 'normal',
|
|
334
|
+
wordBreak: 'normal',
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
const { getByRole } = renderTable([{ title: 'Name', dataIndex: 'name', render: () => renderedCell }]);
|
|
339
|
+
|
|
340
|
+
const style = window.getComputedStyle(getByRole('cell', { name: 'Rendered cell' }));
|
|
341
|
+
expect(style.maxWidth).toBe('123px');
|
|
342
|
+
expect(style.whiteSpace).toBe('pre');
|
|
343
|
+
expect(style.overflowWrap).toBe('normal');
|
|
344
|
+
expect(style.wordBreak).toBe('normal');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('processes only leaves in nested columns without mutating the input', () => {
|
|
348
|
+
const nameColumn = { title: 'Name', dataIndex: 'name' as const };
|
|
349
|
+
const noteColumn = { title: 'Note', dataIndex: 'note' as const };
|
|
350
|
+
const children = [nameColumn, noteColumn];
|
|
351
|
+
const groupColumn = { title: 'Details', children };
|
|
352
|
+
const columns: ColumnsType<Row> = [groupColumn];
|
|
353
|
+
|
|
354
|
+
const { getByRole } = renderTable(columns);
|
|
355
|
+
|
|
356
|
+
expectNoDefaultWrappingStyle(getByRole('columnheader', { name: 'Details' }));
|
|
357
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Name' }));
|
|
358
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Note' }));
|
|
359
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: row.name }));
|
|
360
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: row.note }));
|
|
361
|
+
|
|
362
|
+
expect(columns[0]).toBe(groupColumn);
|
|
363
|
+
expect(groupColumn.children).toBe(children);
|
|
364
|
+
expect(children[0]).toBe(nameColumn);
|
|
365
|
+
expect(children[1]).toBe(noteColumn);
|
|
366
|
+
expect(nameColumn).not.toHaveProperty('onCell');
|
|
367
|
+
expect(nameColumn).not.toHaveProperty('onHeaderCell');
|
|
368
|
+
expect(noteColumn).not.toHaveProperty('onCell');
|
|
369
|
+
expect(noteColumn).not.toHaveProperty('onHeaderCell');
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('does not apply the default boundary to selection or drag-handle columns', () => {
|
|
373
|
+
const columns: ColumnsType<Row> = [{ title: 'Name', dataIndex: 'name' }];
|
|
374
|
+
const selectionTable = renderTable(columns, { rowSelection: {} });
|
|
375
|
+
|
|
376
|
+
expectNoDefaultWrappingStyle(selectionTable.container.querySelector<HTMLElement>('th.ant-table-selection-column'));
|
|
377
|
+
expectNoDefaultWrappingStyle(selectionTable.container.querySelector<HTMLElement>('td.ant-table-selection-column'));
|
|
378
|
+
expectDefaultWrappingStyle(selectionTable.getByRole('columnheader', { name: 'Name' }));
|
|
379
|
+
selectionTable.unmount();
|
|
380
|
+
|
|
381
|
+
const dragTable = renderTable(columns, { isDraggable: true, onSortEnd: vi.fn() });
|
|
382
|
+
const dragHeader = dragTable.container.querySelector<HTMLElement>('.ant-table-thead th:first-child');
|
|
383
|
+
const dragCell = dragTable.container.querySelector<HTMLElement>('.ant-table-tbody td:first-child');
|
|
384
|
+
|
|
385
|
+
expectNoDefaultWrappingStyle(dragHeader);
|
|
386
|
+
expectNoDefaultWrappingStyle(dragCell);
|
|
387
|
+
expectDefaultWrappingStyle(dragTable.getByRole('columnheader', { name: 'Name' }));
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('preserves Ant Design sentinels used to position expand and selection columns', () => {
|
|
391
|
+
const columns: ColumnsType<Row> = [
|
|
392
|
+
{ title: 'Name', dataIndex: 'name' },
|
|
393
|
+
AntdTable.EXPAND_COLUMN,
|
|
394
|
+
AntdTable.SELECTION_COLUMN,
|
|
395
|
+
{ title: 'Note', dataIndex: 'note' },
|
|
396
|
+
];
|
|
397
|
+
const { container } = renderTable(columns, {
|
|
398
|
+
expandable: { expandedRowRender: (record) => <span>{record.note}</span> },
|
|
399
|
+
rowSelection: {},
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
const headers = Array.from(container.querySelectorAll<HTMLElement>('.ant-table-thead th'));
|
|
403
|
+
expect(headers).toHaveLength(4);
|
|
404
|
+
expect(headers[0].textContent).toBe('Name');
|
|
405
|
+
expect(headers[1].classList).toContain('ant-table-row-expand-icon-cell');
|
|
406
|
+
expect(headers[2].classList).toContain('ant-table-selection-column');
|
|
407
|
+
expect(headers[3].textContent).toBe('Note');
|
|
408
|
+
expectNoDefaultWrappingStyle(headers[1]);
|
|
409
|
+
expectNoDefaultWrappingStyle(headers[2]);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('treats empty, undefined, or null children as leaves like antd', () => {
|
|
413
|
+
const columns = [
|
|
414
|
+
{ title: 'Empty children', dataIndex: 'name', children: [] },
|
|
415
|
+
{ title: 'Undefined children', dataIndex: 'note', children: undefined },
|
|
416
|
+
{ title: 'Null children', dataIndex: 'id', children: null },
|
|
417
|
+
] as unknown as ColumnsType<Row>;
|
|
418
|
+
const { getByRole } = renderTable(columns);
|
|
419
|
+
|
|
420
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Empty children' }));
|
|
421
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Undefined children' }));
|
|
422
|
+
expectDefaultWrappingStyle(getByRole('columnheader', { name: 'Null children' }));
|
|
423
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: row.name }));
|
|
424
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: row.note }));
|
|
425
|
+
expectDefaultWrappingStyle(getByRole('cell', { name: String(row.id) }));
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('does not force fixed table layout', () => {
|
|
429
|
+
const { container } = renderTable([{ title: 'Name', dataIndex: 'name' }]);
|
|
430
|
+
|
|
431
|
+
expect(container.querySelector<HTMLTableElement>('table')?.style.tableLayout).not.toBe('fixed');
|
|
432
|
+
});
|
|
433
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { describe, expect, it } from 'vitest';
|
|
11
|
+
import { getActionLinkageStateOptions } from '../linkageRules';
|
|
12
|
+
|
|
13
|
+
describe('getActionLinkageStateOptions', () => {
|
|
14
|
+
const t = (key: string) => key;
|
|
15
|
+
|
|
16
|
+
it('returns all states for regular action models', () => {
|
|
17
|
+
expect(getActionLinkageStateOptions({}, t).map((option) => option.value)).toEqual([
|
|
18
|
+
'visible',
|
|
19
|
+
'hidden',
|
|
20
|
+
'hiddenText',
|
|
21
|
+
'enabled',
|
|
22
|
+
'disabled',
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('filters states declared unsupported by the action model', () => {
|
|
27
|
+
expect(
|
|
28
|
+
getActionLinkageStateOptions({ supportedActionLinkageStates: ['visible', 'hidden'] }, t).map(
|
|
29
|
+
(option) => option.value,
|
|
30
|
+
),
|
|
31
|
+
).toEqual(['visible', 'hidden']);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -660,6 +660,30 @@ export const linkageSetBlockProps = defineAction({
|
|
|
660
660
|
},
|
|
661
661
|
});
|
|
662
662
|
|
|
663
|
+
const ACTION_LINKAGE_STATE_OPTIONS = [
|
|
664
|
+
{ label: 'Visible', value: 'visible' },
|
|
665
|
+
{ label: 'Hidden', value: 'hidden' },
|
|
666
|
+
{ label: 'Hidden text', value: 'hiddenText' },
|
|
667
|
+
{ label: 'Enabled', value: 'enabled' },
|
|
668
|
+
{ label: 'Disabled', value: 'disabled' },
|
|
669
|
+
] as const;
|
|
670
|
+
|
|
671
|
+
type ActionLinkageState = (typeof ACTION_LINKAGE_STATE_OPTIONS)[number]['value'];
|
|
672
|
+
|
|
673
|
+
export function getActionLinkageStateOptions(
|
|
674
|
+
model: { supportedActionLinkageStates?: readonly ActionLinkageState[] },
|
|
675
|
+
t: (key: string) => string,
|
|
676
|
+
) {
|
|
677
|
+
const supportedStates = model.supportedActionLinkageStates ? new Set(model.supportedActionLinkageStates) : undefined;
|
|
678
|
+
|
|
679
|
+
return ACTION_LINKAGE_STATE_OPTIONS.filter((option) => !supportedStates || supportedStates.has(option.value)).map(
|
|
680
|
+
(option) => ({
|
|
681
|
+
label: t(option.label),
|
|
682
|
+
value: option.value,
|
|
683
|
+
}),
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
|
|
663
687
|
export const linkageSetActionProps = defineAction({
|
|
664
688
|
name: 'linkageSetActionProps',
|
|
665
689
|
title: tExpr('Set button state'),
|
|
@@ -680,13 +704,7 @@ export const linkageSetActionProps = defineAction({
|
|
|
680
704
|
onChange={onChange}
|
|
681
705
|
placeholder={t('Please select state')}
|
|
682
706
|
style={{ width: '100%' }}
|
|
683
|
-
options={
|
|
684
|
-
{ label: t('Visible'), value: 'visible' },
|
|
685
|
-
{ label: t('Hidden'), value: 'hidden' },
|
|
686
|
-
{ label: t('Hidden text'), value: 'hiddenText' },
|
|
687
|
-
{ label: t('Enabled'), value: 'enabled' },
|
|
688
|
-
{ label: t('Disabled'), value: 'disabled' },
|
|
689
|
-
]}
|
|
707
|
+
options={getActionLinkageStateOptions(ctx.model, t)}
|
|
690
708
|
allowClear
|
|
691
709
|
/>
|
|
692
710
|
);
|