@dxos/react-ui-table 0.8.4-main.c1de068 → 0.8.4-main.c85a9c8dae
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/dist/lib/browser/chunk-DSR2MRZB.mjs +80 -0
- package/dist/lib/browser/chunk-DSR2MRZB.mjs.map +7 -0
- package/dist/lib/browser/chunk-PTHMYAAM.mjs +1751 -0
- package/dist/lib/browser/chunk-PTHMYAAM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1190 -1139
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +31 -38
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/chunk-GI72MQSG.mjs +1753 -0
- package/dist/lib/node-esm/chunk-GI72MQSG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HTZJSULI.mjs +81 -0
- package/dist/lib/node-esm/chunk-HTZJSULI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1190 -1139
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +31 -38
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -3
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +37 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +17 -13
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +13 -9
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +11 -18
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +5 -5
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +23 -16
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +6 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +10 -10
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -8
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -8
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +112 -30
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +5 -2
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +18 -34
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +4 -4
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +31 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +14 -12
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +61 -56
- package/src/components/Table/ColumnActionsMenu.tsx +11 -7
- package/src/components/Table/ColumnSettings.tsx +9 -10
- package/src/components/Table/DynamicTable.stories.tsx +28 -24
- package/src/components/Table/DynamicTable.tsx +33 -27
- package/src/components/Table/Relations.stories.tsx +240 -0
- package/src/components/Table/RowActionsMenu.tsx +26 -17
- package/src/components/Table/Table.stories.tsx +146 -116
- package/src/components/Table/Table.tsx +353 -297
- package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -6
- package/src/components/TableCellEditor/FormCellEditor.tsx +134 -40
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +31 -66
- package/src/components/TableCellEditor/TableCellEditor.tsx +88 -238
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +54 -38
- package/src/components/testing.ts +39 -13
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +14 -14
- package/src/hooks/useProjectionModel.ts +39 -0
- package/src/hooks/useTableModel.ts +36 -34
- package/src/model/modal-controller.ts +24 -41
- package/src/model/selection-model.ts +75 -43
- package/src/model/table-model.test.ts +92 -55
- package/src/model/table-model.ts +453 -175
- package/src/model/table-presentation.test.ts +70 -58
- package/src/model/table-presentation.ts +111 -64
- package/src/playwright/TableManager.ts +13 -6
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +171 -33
- package/src/testing/useTestTableModel.ts +46 -35
- package/src/translations.ts +3 -3
- package/src/types/Table.ts +95 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +46 -33
- package/src/util/index.ts +2 -1
- package/src/util/query-ast.ts +22 -0
- package/src/util/schema.ts +4 -4
- package/src/util/sort.ts +90 -0
- package/src/util/table-buttons.ts +4 -3
- package/src/util/table-controls.ts +6 -3
- package/dist/lib/browser/chunk-5XLSHLOG.mjs +0 -1751
- package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y66YLSTC.mjs +0 -1752
- package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
- package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -53
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -8
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -11
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/Table/relations.stories.tsx +0 -116
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/model/table-sorting.ts +0 -216
- package/src/types/schema.ts +0 -16
- package/src/util/table.ts +0 -49
|
@@ -4,16 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import { expect, test } from '@playwright/test';
|
|
6
6
|
|
|
7
|
+
import { type DxGrid } from '@dxos/lit-grid';
|
|
8
|
+
import { faker } from '@dxos/random';
|
|
7
9
|
import { setupPage, storybookUrl } from '@dxos/test-utils/playwright';
|
|
8
10
|
|
|
9
11
|
import { TableManager } from './TableManager';
|
|
10
12
|
|
|
11
13
|
const storyUrl = storybookUrl('ui-react-ui-table-table--default', 9004);
|
|
14
|
+
const relationsStoryUrl = storybookUrl('ui-react-ui-table-relations--default', 9004);
|
|
12
15
|
|
|
13
16
|
// NOTE(ZaymonFC): This test suite relies on the faker seed being set to 0 in the story.
|
|
14
17
|
test.describe('Table', () => {
|
|
15
18
|
test('Loads', async ({ browser, browserName }) => {
|
|
16
19
|
test.skip(browserName === 'webkit');
|
|
20
|
+
test.skip(browserName === 'firefox');
|
|
17
21
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
18
22
|
const table = new TableManager(page);
|
|
19
23
|
|
|
@@ -23,6 +27,7 @@ test.describe('Table', () => {
|
|
|
23
27
|
|
|
24
28
|
test('sort', async ({ browser, browserName }) => {
|
|
25
29
|
test.skip(browserName === 'webkit');
|
|
30
|
+
test.skip(browserName === 'firefox');
|
|
26
31
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
27
32
|
const table = new TableManager(page);
|
|
28
33
|
|
|
@@ -39,6 +44,7 @@ test.describe('Table', () => {
|
|
|
39
44
|
|
|
40
45
|
test('selection', async ({ browser, browserName }) => {
|
|
41
46
|
test.skip(browserName === 'webkit');
|
|
47
|
+
test.skip(browserName === 'firefox');
|
|
42
48
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
43
49
|
const table = new TableManager(page);
|
|
44
50
|
|
|
@@ -60,10 +66,12 @@ test.describe('Table', () => {
|
|
|
60
66
|
|
|
61
67
|
test('delete row', async ({ browser, browserName }) => {
|
|
62
68
|
test.skip(browserName === 'webkit');
|
|
69
|
+
test.skip(browserName === 'firefox');
|
|
63
70
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
64
71
|
const table = new TableManager(page);
|
|
65
72
|
|
|
66
73
|
await table.grid.ready();
|
|
74
|
+
await expect(page.getByRole('gridcell', { name: 'Sapiente.' })).toHaveCount(1);
|
|
67
75
|
await table.deleteRow(0);
|
|
68
76
|
await expect(page.getByRole('gridcell', { name: 'Sapiente.' })).toHaveCount(0);
|
|
69
77
|
await page.close();
|
|
@@ -71,6 +79,7 @@ test.describe('Table', () => {
|
|
|
71
79
|
|
|
72
80
|
test('delete row--select all', async ({ browser, browserName }) => {
|
|
73
81
|
test.skip(browserName === 'webkit');
|
|
82
|
+
test.skip(browserName === 'firefox');
|
|
74
83
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
75
84
|
const table = new TableManager(page);
|
|
76
85
|
|
|
@@ -80,7 +89,7 @@ test.describe('Table', () => {
|
|
|
80
89
|
// Delete action affects all selected rows.
|
|
81
90
|
await table.deleteRow(0);
|
|
82
91
|
|
|
83
|
-
await expect(page.getByRole('gridcell', { name: '
|
|
92
|
+
await expect(page.getByRole('gridcell', { name: 'Aut.' })).toHaveCount(0);
|
|
84
93
|
await expect(page.getByRole('gridcell', { name: 'Beatae.' })).toHaveCount(0);
|
|
85
94
|
await expect(table.grid.cellsWithinPlane('grid')).toHaveCount(0);
|
|
86
95
|
await page.close();
|
|
@@ -88,6 +97,7 @@ test.describe('Table', () => {
|
|
|
88
97
|
|
|
89
98
|
test('delete column', async ({ browser, browserName }) => {
|
|
90
99
|
test.skip(browserName === 'webkit');
|
|
100
|
+
test.skip(browserName === 'firefox');
|
|
91
101
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
92
102
|
const table = new TableManager(page);
|
|
93
103
|
|
|
@@ -111,59 +121,39 @@ test.describe('Table', () => {
|
|
|
111
121
|
await page.close();
|
|
112
122
|
});
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
test('add column', async ({ browser, browserName }) => {
|
|
124
|
+
test('add column without changing format', async ({ browser, browserName }) => {
|
|
116
125
|
test.skip(browserName === 'webkit');
|
|
126
|
+
test.skip(browserName === 'firefox');
|
|
117
127
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
118
128
|
const table = new TableManager(page);
|
|
119
129
|
|
|
120
130
|
await table.grid.ready();
|
|
121
|
-
const newColumnLabel = '
|
|
131
|
+
const newColumnLabel = 'DEFAULT FORMAT COL';
|
|
122
132
|
|
|
123
|
-
await table.addColumn({ label: newColumnLabel
|
|
133
|
+
await table.addColumn({ label: newColumnLabel });
|
|
124
134
|
|
|
125
135
|
await expect(page.getByRole('gridcell', { name: newColumnLabel })).toBeVisible();
|
|
126
136
|
await page.close();
|
|
127
137
|
});
|
|
128
138
|
|
|
129
|
-
test('
|
|
139
|
+
test('add column with format', async ({ browser, browserName }) => {
|
|
130
140
|
test.skip(browserName === 'webkit');
|
|
141
|
+
test.skip(browserName === 'firefox');
|
|
131
142
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
132
143
|
const table = new TableManager(page);
|
|
133
144
|
|
|
134
145
|
await table.grid.ready();
|
|
146
|
+
const newColumnLabel = 'TEST LABEL';
|
|
135
147
|
|
|
136
|
-
|
|
137
|
-
// Scroll over to the manager column.
|
|
138
|
-
await table.grid.panByWheel(10000, 0);
|
|
139
|
-
|
|
140
|
-
await table.grid.cell(4, 0, 'grid').click();
|
|
141
|
-
// TODO(wittjosiah): Surprisingly long delay needed here.
|
|
142
|
-
await page.keyboard.press('A', { delay: 1_000 });
|
|
143
|
-
await page.keyboard.press('u', { delay: 1_000 });
|
|
144
|
-
await page.getByRole('option', { name: 'Aut.' }).click();
|
|
145
|
-
|
|
146
|
-
// Assert that the value is shown in the cell.
|
|
147
|
-
await expect(page.getByRole('gridcell', { name: 'Aut.' }).first()).toBeVisible();
|
|
148
|
-
|
|
149
|
-
// Create new object.
|
|
150
|
-
await table.grid.cell(4, 1, 'grid').click();
|
|
151
|
-
// TODO(wittjosiah): Surprisingly long delay needed here.
|
|
152
|
-
await page.keyboard.type('t', { delay: 1_000 });
|
|
153
|
-
await page.keyboard.type('e', { delay: 1_000 });
|
|
154
|
-
await page.keyboard.type('s', { delay: 1_000 });
|
|
155
|
-
await page.keyboard.type('t', { delay: 1_000 });
|
|
156
|
-
await page.getByText('Create new object', { exact: false }).click();
|
|
157
|
-
await page.getByTestId('save-button').click();
|
|
158
|
-
|
|
159
|
-
// Scroll to the left.
|
|
160
|
-
await page.getByRole('gridcell', { name: 'test' }).first().click();
|
|
148
|
+
await table.addColumn({ label: newColumnLabel, format: 'Number' });
|
|
161
149
|
|
|
150
|
+
await expect(page.getByRole('gridcell', { name: newColumnLabel })).toBeVisible();
|
|
162
151
|
await page.close();
|
|
163
152
|
});
|
|
164
153
|
|
|
165
|
-
test('test toggles', async ({ browser, browserName }) => {
|
|
154
|
+
test.skip('test toggles', async ({ browser, browserName }) => {
|
|
166
155
|
test.skip(browserName === 'webkit');
|
|
156
|
+
test.skip(browserName === 'firefox');
|
|
167
157
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
168
158
|
const table = new TableManager(page);
|
|
169
159
|
|
|
@@ -178,9 +168,157 @@ test.describe('Table', () => {
|
|
|
178
168
|
// Assert the first two switch checkboxes are checked.
|
|
179
169
|
await expect(page.getByTestId('table-switch').first()).toBeChecked();
|
|
180
170
|
await expect(page.getByTestId('table-switch').nth(1)).toBeChecked();
|
|
181
|
-
await expect(table.grid.cell(0, 0, 'grid')).toHaveText('
|
|
171
|
+
await expect(table.grid.cell(0, 0, 'grid')).toHaveText('Aut.');
|
|
182
172
|
await expect(table.grid.cell(0, 1, 'grid')).toHaveText('Beatae.');
|
|
183
173
|
|
|
184
174
|
await page.close();
|
|
185
175
|
});
|
|
176
|
+
|
|
177
|
+
test('add row and edit cell', async ({ browser, browserName }) => {
|
|
178
|
+
test.skip(browserName === 'webkit');
|
|
179
|
+
test.skip(browserName === 'firefox');
|
|
180
|
+
const { page } = await setupPage(browser, { url: storyUrl });
|
|
181
|
+
const table = new TableManager(page);
|
|
182
|
+
|
|
183
|
+
await table.grid.ready();
|
|
184
|
+
|
|
185
|
+
// Click the CTA row at the bottom to add a new row.
|
|
186
|
+
await table.grid.cell(0, 0, 'frozenRowsEnd').click();
|
|
187
|
+
|
|
188
|
+
// All schema fields are optional so the row is added directly to the grid (not as a draft).
|
|
189
|
+
const newCell = table.grid.cell(0, 10, 'grid');
|
|
190
|
+
await newCell.waitFor({ state: 'visible' });
|
|
191
|
+
|
|
192
|
+
// Focus should already be on the new row; engage edit mode.
|
|
193
|
+
await page.keyboard.press('Enter');
|
|
194
|
+
await page.getByTestId('grid.cell-editor').waitFor({ state: 'visible' });
|
|
195
|
+
|
|
196
|
+
// Type text and confirm.
|
|
197
|
+
const cellContent = 'New row content';
|
|
198
|
+
await page.keyboard.type(cellContent);
|
|
199
|
+
await page.keyboard.press('Enter');
|
|
200
|
+
|
|
201
|
+
// Assert the cell content is saved.
|
|
202
|
+
await expect(newCell).toHaveText(cellContent);
|
|
203
|
+
await page.close();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// TODO(wittjosiah): Remove? Conflicts with story play function which is run as a unit test anyways.
|
|
207
|
+
test.skip('extant relations work as expected', async ({ browser, browserName }) => {
|
|
208
|
+
test.skip(browserName === 'webkit');
|
|
209
|
+
test.skip(browserName === 'firefox');
|
|
210
|
+
const { page } = await setupPage(browser, { url: relationsStoryUrl });
|
|
211
|
+
|
|
212
|
+
// Wait for the page to load
|
|
213
|
+
await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
|
|
214
|
+
|
|
215
|
+
// Find the dx-grid element for the contactModel (second table)
|
|
216
|
+
// The contactModel is used in the second Table.Main component in the story
|
|
217
|
+
const dxGrid = page.locator('dx-grid').nth(1);
|
|
218
|
+
await dxGrid.waitFor({ state: 'visible' });
|
|
219
|
+
|
|
220
|
+
// Scroll to the last column (column 4)
|
|
221
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
222
|
+
dxGridElement.scrollToColumn(4);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Click on the cell at aria-rowindex=0 aria-colindex=4 to focus it
|
|
226
|
+
const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
|
|
227
|
+
await targetCell.click();
|
|
228
|
+
|
|
229
|
+
// Click again to engage edit mode
|
|
230
|
+
await page.keyboard.press('Enter');
|
|
231
|
+
|
|
232
|
+
// Click on the combobox to open options
|
|
233
|
+
await page.getByRole('combobox').click();
|
|
234
|
+
await page.pause();
|
|
235
|
+
await page.getByPlaceholder('Search…').focus();
|
|
236
|
+
|
|
237
|
+
// Type the first few letters of an org name.
|
|
238
|
+
const orgName =
|
|
239
|
+
(await page
|
|
240
|
+
.locator('dx-grid')
|
|
241
|
+
.nth(0)
|
|
242
|
+
.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="0"] .dx-grid__cell__content')
|
|
243
|
+
.textContent()) ?? 'never';
|
|
244
|
+
await page.keyboard.type(orgName.substring(0, 4), { delay: 500 });
|
|
245
|
+
|
|
246
|
+
// Assert that there is an element with aria-selected on the page
|
|
247
|
+
await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
|
|
248
|
+
|
|
249
|
+
// Type the enter key
|
|
250
|
+
await page.keyboard.press('Enter');
|
|
251
|
+
|
|
252
|
+
// Save the result
|
|
253
|
+
await page.getByTestId('save-button').click();
|
|
254
|
+
|
|
255
|
+
// Assert that the cell element has the org name
|
|
256
|
+
await expect(targetCell).toHaveText(orgName);
|
|
257
|
+
|
|
258
|
+
await page.close();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// TODO(wittjosiah): Remove? Conflicts with story play function which is run as a unit test anyways.
|
|
262
|
+
test.skip('new relations work as expected', async ({ browser, browserName }) => {
|
|
263
|
+
test.skip(browserName === 'webkit');
|
|
264
|
+
test.skip(browserName === 'firefox');
|
|
265
|
+
const { page } = await setupPage(browser, { url: relationsStoryUrl });
|
|
266
|
+
|
|
267
|
+
// Wait for the page to load
|
|
268
|
+
await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
|
|
269
|
+
|
|
270
|
+
// Find the dx-grid element for the contactModel (second table)
|
|
271
|
+
// The contactModel is used in the second Table.Main component in the story
|
|
272
|
+
const dxGrid = page.locator('dx-grid').nth(1);
|
|
273
|
+
await dxGrid.waitFor({ state: 'visible' });
|
|
274
|
+
|
|
275
|
+
// Scroll to the last column (column 4)
|
|
276
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
277
|
+
dxGridElement.scrollToColumn(4);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Click on the cell at aria-rowindex=0 aria-colindex=8 to focus it
|
|
281
|
+
const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
|
|
282
|
+
await targetCell.click();
|
|
283
|
+
|
|
284
|
+
// Click again to engage edit mode
|
|
285
|
+
await page.keyboard.press('Enter');
|
|
286
|
+
|
|
287
|
+
// Click on the combobox to open options
|
|
288
|
+
await page.getByRole('combobox').click();
|
|
289
|
+
await page.getByPlaceholder('Search…').focus();
|
|
290
|
+
|
|
291
|
+
// Type the first few letters of an org name.
|
|
292
|
+
const orgName = 'Sally';
|
|
293
|
+
await page.keyboard.type(orgName, { delay: 500 });
|
|
294
|
+
|
|
295
|
+
// Assert that there is an element with aria-selected on the page
|
|
296
|
+
await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
|
|
297
|
+
|
|
298
|
+
// Type the enter key
|
|
299
|
+
await page.keyboard.press('Enter');
|
|
300
|
+
await page.pause();
|
|
301
|
+
|
|
302
|
+
// Click the save button in the popover
|
|
303
|
+
await page.getByTestId('create-referenced-object-form').getByTestId('save-button').click();
|
|
304
|
+
|
|
305
|
+
// Assert that the cell element has the org name
|
|
306
|
+
await expect(targetCell).toHaveText(orgName);
|
|
307
|
+
|
|
308
|
+
// Make a change to a non-ref cell to check that populated refs don’t cause problems with snapshots or schemas.
|
|
309
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
310
|
+
dxGridElement.scrollToColumn(6);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const nonRefContent = faker.lorem.words(3);
|
|
314
|
+
const nonRefCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="6"]');
|
|
315
|
+
await nonRefCell.click();
|
|
316
|
+
await page.keyboard.press('Enter');
|
|
317
|
+
await page.getByTestId('grid.cell-editor').waitFor({ state: 'visible' });
|
|
318
|
+
await page.keyboard.type(nonRefContent, { delay: 500 });
|
|
319
|
+
await page.keyboard.press('Enter');
|
|
320
|
+
await expect(nonRefCell).toHaveText(nonRefContent);
|
|
321
|
+
|
|
322
|
+
await page.close();
|
|
323
|
+
});
|
|
186
324
|
});
|
|
@@ -2,40 +2,52 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type RefObject, useCallback, useContext, useMemo, useRef } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { type Database, type Type } from '@dxos/echo';
|
|
9
|
+
import { isMutable } from '@dxos/echo/internal';
|
|
9
10
|
import { faker } from '@dxos/random';
|
|
10
|
-
import { useClient } from '@dxos/react-client';
|
|
11
11
|
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { useClientStory } from '@dxos/react-client/testing';
|
|
13
|
+
import { useGlobalFilteredObjects } from '@dxos/react-ui-searchlist';
|
|
14
|
+
import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
14
15
|
|
|
15
16
|
import { type TableController } from '../components';
|
|
16
|
-
import {
|
|
17
|
-
import { TablePresentation } from '../model';
|
|
17
|
+
import { useAddRow, useProjectionModel, useTableModel } from '../hooks';
|
|
18
|
+
import { type TableModel, TablePresentation } from '../model';
|
|
19
|
+
import { Table } from '../types';
|
|
18
20
|
|
|
19
21
|
faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
|
|
20
22
|
|
|
23
|
+
export type TestTableModel<T extends Type.AnyObj = Type.AnyObj> = {
|
|
24
|
+
schema: T | undefined;
|
|
25
|
+
table: Table.Table | undefined;
|
|
26
|
+
projection: ProjectionModel | undefined;
|
|
27
|
+
tableRef: RefObject<TableController | null>;
|
|
28
|
+
model: TableModel | undefined;
|
|
29
|
+
presentation: TablePresentation | undefined;
|
|
30
|
+
db: Database.Database | undefined;
|
|
31
|
+
handleInsertRow: () => void;
|
|
32
|
+
handleSaveView: () => void;
|
|
33
|
+
handleDeleteRows: (rowIndex: number, objects: any[]) => void;
|
|
34
|
+
handleDeleteColumn: (fieldId: string) => void;
|
|
35
|
+
};
|
|
36
|
+
|
|
21
37
|
/**
|
|
22
38
|
* Custom hook to create and manage a test table model for storybook demonstrations.
|
|
23
39
|
* Provides table data, schema, and handlers for table operations.
|
|
24
40
|
*/
|
|
25
|
-
export const useTestTableModel = () => {
|
|
26
|
-
const
|
|
27
|
-
const { space } =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const projection =
|
|
35
|
-
if (schema && view?.projection) {
|
|
36
|
-
return new ProjectionModel(toJsonSchema(schema), view.projection);
|
|
37
|
-
}
|
|
38
|
-
}, [schema, view?.projection]);
|
|
41
|
+
export const useTestTableModel = <T extends Type.AnyObj = Type.AnyObj>(): TestTableModel<T> => {
|
|
42
|
+
const registry = useContext(RegistryContext);
|
|
43
|
+
const { space } = useClientStory();
|
|
44
|
+
const db = space?.db;
|
|
45
|
+
|
|
46
|
+
const tables = useQuery(space?.db, Filter.type(Table.Table));
|
|
47
|
+
const table = tables.at(0);
|
|
48
|
+
const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
|
|
49
|
+
const schema = useSchema<T>(space?.db, typename);
|
|
50
|
+
const projection = useProjectionModel(schema, table, registry);
|
|
39
51
|
|
|
40
52
|
const features = useMemo(
|
|
41
53
|
() => ({
|
|
@@ -46,7 +58,7 @@ export const useTestTableModel = () => {
|
|
|
46
58
|
[schema],
|
|
47
59
|
);
|
|
48
60
|
|
|
49
|
-
const objects = useQuery(
|
|
61
|
+
const objects = useQuery(db, schema ? Filter.type(schema) : Filter.nothing());
|
|
50
62
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
51
63
|
|
|
52
64
|
const tableRef = useRef<TableController>(null);
|
|
@@ -58,15 +70,15 @@ export const useTestTableModel = () => {
|
|
|
58
70
|
tableRef.current?.update?.();
|
|
59
71
|
}, []);
|
|
60
72
|
|
|
61
|
-
const addRow = useAddRow({
|
|
73
|
+
const addRow = useAddRow({ db, schema });
|
|
62
74
|
|
|
63
75
|
const handleDeleteRows = useCallback(
|
|
64
76
|
(_: number, objects: any[]) => {
|
|
65
77
|
for (const object of objects) {
|
|
66
|
-
|
|
78
|
+
db?.remove(object);
|
|
67
79
|
}
|
|
68
80
|
},
|
|
69
|
-
[
|
|
81
|
+
[db],
|
|
70
82
|
);
|
|
71
83
|
|
|
72
84
|
const handleDeleteColumn = useCallback(
|
|
@@ -79,20 +91,20 @@ export const useTestTableModel = () => {
|
|
|
79
91
|
);
|
|
80
92
|
|
|
81
93
|
const model = useTableModel({
|
|
82
|
-
|
|
83
|
-
schema: jsonSchema,
|
|
94
|
+
object: table,
|
|
84
95
|
projection,
|
|
85
96
|
features,
|
|
86
97
|
rows: filteredObjects,
|
|
87
98
|
onInsertRow: addRow,
|
|
88
99
|
onDeleteRows: handleDeleteRows,
|
|
89
|
-
|
|
100
|
+
onColumnDelete: handleDeleteColumn,
|
|
90
101
|
onCellUpdate: handleCellUpdate,
|
|
91
102
|
onRowOrderChange: handleRowOrderChange,
|
|
92
103
|
});
|
|
93
104
|
|
|
94
105
|
const handleInsertRow = useCallback(() => {
|
|
95
|
-
model?.insertRow();
|
|
106
|
+
const insertResult = model?.insertRow();
|
|
107
|
+
tableRef.current?.handleInsertRowResult?.(insertResult);
|
|
96
108
|
}, [model]);
|
|
97
109
|
|
|
98
110
|
const handleSaveView = useCallback(() => {
|
|
@@ -101,19 +113,18 @@ export const useTestTableModel = () => {
|
|
|
101
113
|
|
|
102
114
|
const presentation = useMemo(() => {
|
|
103
115
|
if (model) {
|
|
104
|
-
return new TablePresentation(model);
|
|
116
|
+
return new TablePresentation(registry, model);
|
|
105
117
|
}
|
|
106
|
-
}, [model]);
|
|
118
|
+
}, [registry, model]);
|
|
107
119
|
|
|
108
120
|
return {
|
|
109
121
|
schema,
|
|
110
|
-
|
|
122
|
+
table,
|
|
111
123
|
projection,
|
|
112
124
|
tableRef,
|
|
113
125
|
model,
|
|
114
126
|
presentation,
|
|
115
|
-
|
|
116
|
-
client,
|
|
127
|
+
db,
|
|
117
128
|
handleInsertRow,
|
|
118
129
|
handleSaveView,
|
|
119
130
|
handleDeleteRows,
|
package/src/translations.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
export const translationKey = 'react-ui-table';
|
|
7
|
+
export const translationKey = '@dxos/react-ui-table';
|
|
8
8
|
|
|
9
9
|
export const translations = [
|
|
10
10
|
{
|
|
@@ -14,8 +14,8 @@ export const translations = [
|
|
|
14
14
|
'create object label': 'Create table',
|
|
15
15
|
'table name placeholder': 'Table name',
|
|
16
16
|
'settings title': 'Table settings',
|
|
17
|
-
'table schema label': '
|
|
18
|
-
'new schema': 'New
|
|
17
|
+
'table schema label': 'Type',
|
|
18
|
+
'new schema': 'New type',
|
|
19
19
|
'continue label': 'Continue',
|
|
20
20
|
'create stack section label': 'Create table',
|
|
21
21
|
'add row label': 'Add row',
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { View } from '@dxos/echo';
|
|
11
|
+
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
12
|
+
import { ViewAnnotation } from '@dxos/schema';
|
|
13
|
+
|
|
14
|
+
export const Table = Schema.Struct({
|
|
15
|
+
name: Schema.String.pipe(Schema.optional),
|
|
16
|
+
|
|
17
|
+
view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
18
|
+
|
|
19
|
+
sizes: Schema.Record({
|
|
20
|
+
// TODO(wittjosiah): Should be JsonPath.
|
|
21
|
+
key: Schema.String,
|
|
22
|
+
value: Schema.Number,
|
|
23
|
+
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
24
|
+
}).pipe(
|
|
25
|
+
Type.object({
|
|
26
|
+
typename: 'dxos.org/type/Table',
|
|
27
|
+
version: '0.2.0',
|
|
28
|
+
}),
|
|
29
|
+
LabelAnnotation.set(['name']),
|
|
30
|
+
ViewAnnotation.set(true),
|
|
31
|
+
Annotation.IconAnnotation.set({
|
|
32
|
+
icon: 'ph--table--regular',
|
|
33
|
+
hue: 'green',
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export interface Table extends Schema.Schema.Type<typeof Table> {}
|
|
38
|
+
|
|
39
|
+
type MakeProps = {
|
|
40
|
+
name?: string;
|
|
41
|
+
sizes?: Record<string, number>;
|
|
42
|
+
view: View.View;
|
|
43
|
+
/** Required to auto-size columns. */
|
|
44
|
+
jsonSchema?: JsonSchemaType;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Make a table as a view of a data set.
|
|
49
|
+
*/
|
|
50
|
+
export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
|
|
51
|
+
const table = Obj.make(Table, { name, view: Ref.make(view), sizes } as Obj.MakeProps<typeof Table>);
|
|
52
|
+
|
|
53
|
+
// Preset sizes.
|
|
54
|
+
if (jsonSchema) {
|
|
55
|
+
const schema = JsonSchema.toEffectSchema(jsonSchema);
|
|
56
|
+
const properties = SchemaAST.getPropertySignatures(schema.ast);
|
|
57
|
+
for (const property of properties) {
|
|
58
|
+
const name = property.name.toString() as JsonPath;
|
|
59
|
+
if (sizes?.[name]) {
|
|
60
|
+
table.sizes[name] = sizes[name];
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Match.type<SchemaAST.AST>().pipe(
|
|
65
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => {
|
|
66
|
+
table.sizes[name] = 100;
|
|
67
|
+
}),
|
|
68
|
+
Match.when({ _tag: 'NumberKeyword' }, () => {
|
|
69
|
+
table.sizes[name] = 100;
|
|
70
|
+
}),
|
|
71
|
+
Match.orElse(() => {
|
|
72
|
+
// Noop.
|
|
73
|
+
}),
|
|
74
|
+
)(property.type);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return table;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
// V1
|
|
83
|
+
//
|
|
84
|
+
|
|
85
|
+
export const TableV1 = Schema.Struct({
|
|
86
|
+
sizes: Schema.Record({
|
|
87
|
+
key: Schema.String,
|
|
88
|
+
value: Schema.Number,
|
|
89
|
+
}).pipe(Schema.mutable),
|
|
90
|
+
}).pipe(
|
|
91
|
+
Type.object({
|
|
92
|
+
typename: 'dxos.org/type/Table',
|
|
93
|
+
version: '0.1.0',
|
|
94
|
+
}),
|
|
95
|
+
);
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { Format } from '@dxos/echo';
|
|
9
|
+
|
|
10
|
+
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from './dynamic-table';
|
|
11
|
+
|
|
12
|
+
describe('makeDynamicTable', () => {
|
|
13
|
+
/**
|
|
14
|
+
* Base case: plain jsonSchema (not from Echo / JsonSchema.toJsonSchema). Does not exercise the path
|
|
15
|
+
* where projection or schema are reactive, so this does not reproduce the Obj.change regression.
|
|
16
|
+
* Confirms makeDynamicTable + setProperties (title) works with plain objects.
|
|
17
|
+
*/
|
|
18
|
+
test('makeDynamicTable with plain jsonSchema and properties with title does not throw', () => {
|
|
19
|
+
const registry = Registry.make();
|
|
20
|
+
const jsonSchema = {
|
|
21
|
+
type: 'object' as const,
|
|
22
|
+
properties: {
|
|
23
|
+
id: { type: 'string' as const },
|
|
24
|
+
name: { type: 'string' as const },
|
|
25
|
+
},
|
|
26
|
+
required: ['id'],
|
|
27
|
+
};
|
|
28
|
+
const properties: TablePropertyDefinition[] = [
|
|
29
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
30
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
expect(() => {
|
|
34
|
+
const { projection, object } = makeDynamicTable({
|
|
35
|
+
registry,
|
|
36
|
+
jsonSchema,
|
|
37
|
+
properties,
|
|
38
|
+
});
|
|
39
|
+
expect(projection).toBeDefined();
|
|
40
|
+
expect(object).toBeDefined();
|
|
41
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
42
|
+
}).not.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Regression test for the path where jsonSchema comes from getBaseSchema(typename, properties).
|
|
47
|
+
* That path uses Echo (ViewModel.make, JsonSchema.toJsonSchema); mutations must run inside Obj.change and on a
|
|
48
|
+
* cloned schema. This test ensures that flow does not throw.
|
|
49
|
+
*/
|
|
50
|
+
test('makeDynamicTable with jsonSchema from getBaseSchema(typename, properties) and properties with title does not throw', () => {
|
|
51
|
+
const registry = Registry.make();
|
|
52
|
+
const typename = 'example.com/type/DynamicTableTest';
|
|
53
|
+
const properties: TablePropertyDefinition[] = [
|
|
54
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
55
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
56
|
+
];
|
|
57
|
+
const { jsonSchema } = getBaseSchema({ typename, properties });
|
|
58
|
+
|
|
59
|
+
expect(() => {
|
|
60
|
+
const { projection, object } = makeDynamicTable({
|
|
61
|
+
registry,
|
|
62
|
+
jsonSchema,
|
|
63
|
+
properties,
|
|
64
|
+
});
|
|
65
|
+
expect(projection).toBeDefined();
|
|
66
|
+
expect(object).toBeDefined();
|
|
67
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
68
|
+
}).not.toThrow();
|
|
69
|
+
});
|
|
70
|
+
});
|