@dxos/react-ui-table 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
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-KNC7XYT6.mjs → chunk-MNZKOFMA.mjs} +597 -634
- package/dist/lib/browser/chunk-MNZKOFMA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5XWSB3JP.mjs → chunk-OZBLY7XM.mjs} +18 -13
- package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1096 -980
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -18
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-CWSGS3Y2.mjs → chunk-2ATAIIAO.mjs} +597 -633
- package/dist/lib/node-esm/chunk-2ATAIIAO.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MKTMOY46.mjs → chunk-WNZSKIRF.mjs} +18 -13
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1096 -980
- 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 +19 -18
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +4 -5
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -16
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +6 -3
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +8 -8
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +6 -3
- 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/FormCellEditor.d.ts +10 -12
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +22 -13
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +5 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +2 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +5 -4
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -1
- 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 +97 -16
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +3 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +5 -8
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +17 -14
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +8 -7
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +2 -0
- 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/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +53 -54
- package/src/components/Table/ColumnActionsMenu.tsx +10 -6
- package/src/components/Table/ColumnSettings.tsx +6 -6
- package/src/components/Table/DynamicTable.stories.tsx +6 -7
- package/src/components/Table/DynamicTable.tsx +21 -22
- package/src/components/Table/Relations.stories.tsx +23 -23
- package/src/components/Table/RowActionsMenu.tsx +3 -2
- package/src/components/Table/Table.stories.tsx +34 -43
- package/src/components/Table/Table.tsx +335 -305
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +111 -134
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +7 -5
- package/src/components/TableCellEditor/TableCellEditor.tsx +27 -27
- package/src/components/TableToolbar/TableToolbar.tsx +18 -12
- package/src/components/testing.ts +37 -11
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +29 -8
- package/src/hooks/useTableModel.ts +26 -22
- package/src/model/modal-controller.ts +23 -12
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +80 -52
- package/src/model/table-model.ts +402 -131
- package/src/model/table-presentation.test.ts +57 -47
- package/src/model/table-presentation.ts +22 -17
- package/src/playwright/TableManager.ts +2 -2
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +3 -2
- package/src/testing/useTestTableModel.ts +23 -24
- package/src/translations.ts +1 -1
- package/src/types/Table.ts +19 -18
- package/src/util/dynamic-table.ts +28 -12
- package/src/util/index.ts +2 -0
- package/src/util/query-ast.ts +19 -0
- package/src/util/sort.ts +90 -0
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +0 -7
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +0 -7
- package/dist/types/src/model/table-sorting.d.ts +0 -56
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/src/model/table-sorting.ts +0 -234
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Registry } from '@effect-atom/atom-react';
|
|
5
6
|
import * as Schema from 'effect/Schema';
|
|
6
7
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
7
8
|
|
|
8
|
-
import { Filter, Query } from '@dxos/echo';
|
|
9
|
-
import { TypedObject } from '@dxos/echo/internal';
|
|
9
|
+
import { Filter, Query, Type } from '@dxos/echo';
|
|
10
10
|
import { createEchoSchema } from '@dxos/echo/testing';
|
|
11
|
-
import {
|
|
12
|
-
import { ProjectionModel, View } from '@dxos/schema';
|
|
11
|
+
import { ProjectionModel, View, createDirectChangeCallback } from '@dxos/schema';
|
|
13
12
|
|
|
14
13
|
import { Table } from '../types';
|
|
15
14
|
|
|
@@ -17,48 +16,53 @@ import { TableModel, type TableModelProps } from './table-model';
|
|
|
17
16
|
import { TablePresentation } from './table-presentation';
|
|
18
17
|
|
|
19
18
|
describe('TablePresentation', () => {
|
|
20
|
-
describe('
|
|
19
|
+
describe('getCells', () => {
|
|
20
|
+
let registry: Registry.Registry;
|
|
21
21
|
let data: any[];
|
|
22
|
-
let updateCount: number;
|
|
23
22
|
let model: any;
|
|
24
23
|
let presentation: TablePresentation;
|
|
25
24
|
|
|
26
25
|
beforeEach(async () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
model = createTableModel({
|
|
36
|
-
onCellUpdate: () => updateCount++,
|
|
37
|
-
});
|
|
38
|
-
model.setRows(data);
|
|
26
|
+
registry = Registry.make();
|
|
27
|
+
data = [
|
|
28
|
+
{ id: '1', title: 'A', count: 1 },
|
|
29
|
+
{ id: '2', title: 'B', count: 2 },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
model = createTableModel(registry, {});
|
|
39
33
|
await model.open();
|
|
40
|
-
|
|
34
|
+
model.setRows(data);
|
|
35
|
+
presentation = new TablePresentation(registry, model);
|
|
41
36
|
});
|
|
42
37
|
|
|
43
|
-
it('should
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
it('should return cells for the visible range', () => {
|
|
39
|
+
const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 1, col: 2 } }, 'grid');
|
|
40
|
+
|
|
41
|
+
// Verify that cells are returned for the range. The exact column indices depend on the projection.
|
|
42
|
+
const cellKeys = Object.keys(cells);
|
|
43
|
+
expect(cellKeys.length).toBeGreaterThan(0);
|
|
44
|
+
|
|
45
|
+
// Check that values from the data are present in the cells.
|
|
46
|
+
const values = Object.values(cells).map((c) => c.value);
|
|
47
|
+
expect(values).toContain('A');
|
|
48
|
+
expect(values).toContain('B');
|
|
49
|
+
});
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
it('should reflect row data changes', () => {
|
|
52
|
+
// Update the row data and refresh.
|
|
48
53
|
data[0].title = 'New Value';
|
|
49
|
-
|
|
54
|
+
model.setRows(data);
|
|
50
55
|
|
|
51
56
|
// Verify the new value through getCells.
|
|
52
|
-
const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 0, col:
|
|
53
|
-
|
|
57
|
+
const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 0, col: 2 } }, 'grid');
|
|
58
|
+
const values = Object.values(cells).map((c) => c.value);
|
|
59
|
+
expect(values).toContain('New Value');
|
|
54
60
|
});
|
|
55
61
|
|
|
56
|
-
it('should
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
data.push({ title: 'C', count: 3 });
|
|
61
|
-
expect(updateCount).toBe(2);
|
|
62
|
+
it('should reflect new rows', () => {
|
|
63
|
+
// Add a new row.
|
|
64
|
+
data.push({ id: '3', title: 'C', count: 3 });
|
|
65
|
+
model.setRows(data);
|
|
62
66
|
|
|
63
67
|
const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 2, col: 2 } }, 'grid');
|
|
64
68
|
|
|
@@ -67,17 +71,12 @@ describe('TablePresentation', () => {
|
|
|
67
71
|
expect(cells['1,2']?.value).toBe('3');
|
|
68
72
|
});
|
|
69
73
|
|
|
70
|
-
it('should handle
|
|
71
|
-
//
|
|
72
|
-
presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 2, col: 2 } }, 'grid');
|
|
73
|
-
|
|
74
|
-
// Multiple operations.
|
|
74
|
+
it('should handle row modifications', () => {
|
|
75
|
+
// Modify the data.
|
|
75
76
|
data[0].title = 'Updated A';
|
|
76
|
-
data.push({ title: 'C', count: 3
|
|
77
|
+
data.push({ id: '3', title: 'C', count: 3 });
|
|
77
78
|
data.splice(1, 1);
|
|
78
|
-
|
|
79
|
-
// We expect one update per operation affecting visible rows.
|
|
80
|
-
expect(updateCount).toBe(4);
|
|
79
|
+
model.setRows(data);
|
|
81
80
|
|
|
82
81
|
const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 1, col: 2 } }, 'grid');
|
|
83
82
|
|
|
@@ -88,18 +87,29 @@ describe('TablePresentation', () => {
|
|
|
88
87
|
});
|
|
89
88
|
});
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
const Test = Schema.Struct({
|
|
92
91
|
title: Schema.String,
|
|
93
92
|
count: Schema.Number,
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
}).pipe(
|
|
94
|
+
Type.object({
|
|
95
|
+
typename: 'example.com/type/Test',
|
|
96
|
+
version: '0.1.0',
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const createTableModel = (registry: Registry.Registry, props: Partial<TableModelProps> = {}): TableModel => {
|
|
97
101
|
const schema = createEchoSchema(Test);
|
|
98
102
|
const view = View.make({
|
|
99
103
|
query: Query.select(Filter.type(schema)),
|
|
100
104
|
jsonSchema: schema.jsonSchema,
|
|
101
105
|
});
|
|
102
106
|
const object = Table.make({ view });
|
|
103
|
-
const projection = new ProjectionModel(
|
|
104
|
-
|
|
107
|
+
const projection = new ProjectionModel({
|
|
108
|
+
registry,
|
|
109
|
+
view,
|
|
110
|
+
baseSchema: schema.jsonSchema,
|
|
111
|
+
change: createDirectChangeCallback(view.projection, schema.jsonSchema),
|
|
112
|
+
});
|
|
113
|
+
projection.normalizeView();
|
|
114
|
+
return new TableModel({ registry, object, projection, ...props });
|
|
105
115
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Atom, type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
import * as Predicate from 'effect/Predicate';
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
type DxGridPlaneRange,
|
|
16
16
|
toPlaneCellIndex,
|
|
17
17
|
} from '@dxos/react-ui-grid';
|
|
18
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
19
18
|
import { type FieldType, VIEW_FIELD_LIMIT } from '@dxos/schema';
|
|
19
|
+
import { mx } from '@dxos/ui-theme';
|
|
20
20
|
|
|
21
21
|
import { tableButtons, tableControls } from '../util';
|
|
22
22
|
|
|
@@ -29,15 +29,20 @@ import { type TableModel, type TableRow } from './table-model';
|
|
|
29
29
|
* different grid planes.
|
|
30
30
|
*/
|
|
31
31
|
export class TablePresentation<T extends TableRow = TableRow> {
|
|
32
|
+
private readonly _registry: Registry.Registry;
|
|
33
|
+
private readonly _visibleRange: Atom.Writable<DxGridPlaneRange>;
|
|
32
34
|
private fieldProjectionCache = new Map<string, ReturnType<typeof this.model.projection.getFieldProjection>>();
|
|
33
35
|
|
|
34
36
|
constructor(
|
|
37
|
+
registry: Registry.Registry,
|
|
35
38
|
private readonly model: TableModel<T>,
|
|
36
|
-
|
|
39
|
+
) {
|
|
40
|
+
this._registry = registry;
|
|
41
|
+
this._visibleRange = Atom.make<DxGridPlaneRange>({
|
|
37
42
|
start: { row: 0, col: 0 },
|
|
38
43
|
end: { row: 0, col: 0 },
|
|
39
|
-
})
|
|
40
|
-
|
|
44
|
+
});
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
public getCells(range: DxGridPlaneRange, plane: DxGridPlane): DxGridPlaneCells {
|
|
43
48
|
// Clear cache at the start of each render pass
|
|
@@ -47,7 +52,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
47
52
|
|
|
48
53
|
switch (plane) {
|
|
49
54
|
case 'grid':
|
|
50
|
-
this._visibleRange
|
|
55
|
+
this._registry.set(this._visibleRange, range);
|
|
51
56
|
cells = this.getMainGridCells(range);
|
|
52
57
|
break;
|
|
53
58
|
case 'frozenRowsStart':
|
|
@@ -260,7 +265,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
260
265
|
|
|
261
266
|
private getMainGridCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
262
267
|
const cells: DxGridPlaneCells = {};
|
|
263
|
-
const fields = this.model.projection?.
|
|
268
|
+
const fields = this.model.projection?.getFields() ?? [];
|
|
264
269
|
|
|
265
270
|
for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
|
|
266
271
|
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
@@ -269,7 +274,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
269
274
|
continue;
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
this.createDataCell(cells, this.model.
|
|
277
|
+
this.createDataCell(cells, this.model.getRows()[row], field, col, row);
|
|
273
278
|
}
|
|
274
279
|
}
|
|
275
280
|
|
|
@@ -278,8 +283,8 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
278
283
|
|
|
279
284
|
private getDraftRowCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
280
285
|
const cells: DxGridPlaneCells = {};
|
|
281
|
-
const fields = this.model.projection?.
|
|
282
|
-
const draftRows = this.model.
|
|
286
|
+
const fields = this.model.projection?.getFields() ?? [];
|
|
287
|
+
const draftRows = this.model.getDraftRows();
|
|
283
288
|
|
|
284
289
|
// Return cells of the CTA row if no draft row is active
|
|
285
290
|
if (draftRows.length === 0) {
|
|
@@ -319,11 +324,11 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
319
324
|
|
|
320
325
|
private getHeaderCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
321
326
|
const cells: DxGridPlaneCells = {};
|
|
322
|
-
const fields = this.model.projection?.
|
|
327
|
+
const fields = this.model.projection?.getFields() ?? [];
|
|
328
|
+
const currentSort = this.model.getSorting();
|
|
323
329
|
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
324
330
|
const { field, props } = this.model.projection.getFieldProjection(fields[col].id);
|
|
325
|
-
const
|
|
326
|
-
const direction = sorting?.fieldId === field.id ? sorting.direction : undefined;
|
|
331
|
+
const direction = currentSort?.fieldId === field.id ? currentSort.direction : undefined;
|
|
327
332
|
|
|
328
333
|
cells[toPlaneCellIndex({ col, row: 0 })] = {
|
|
329
334
|
// TODO(burdon): Use same logic as form for fallback title.
|
|
@@ -389,7 +394,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
389
394
|
accessoryHtml: tableControls.checkbox.render({
|
|
390
395
|
rowIndex: 0,
|
|
391
396
|
header: true,
|
|
392
|
-
checked: this.model.selection.
|
|
397
|
+
checked: this.model.selection.allRowsSelected,
|
|
393
398
|
}),
|
|
394
399
|
className: '!bg-toolbarSurface',
|
|
395
400
|
readonly: true,
|
|
@@ -403,7 +408,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
403
408
|
[toPlaneCellIndex({ col: 0, row: 0 })]: {
|
|
404
409
|
accessoryHtml: this.model.features.schemaEditable
|
|
405
410
|
? tableButtons.addColumn.render({
|
|
406
|
-
disabled: (this.model.projection?.
|
|
411
|
+
disabled: (this.model.projection?.getFields()?.length ?? 0) >= VIEW_FIELD_LIMIT,
|
|
407
412
|
})
|
|
408
413
|
: undefined,
|
|
409
414
|
className: '!bg-toolbarSurface',
|
|
@@ -415,7 +420,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
415
420
|
|
|
416
421
|
private getDraftActionCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
417
422
|
const cells: DxGridPlaneCells = {};
|
|
418
|
-
const draftRows = this.model.
|
|
423
|
+
const draftRows = this.model.getDraftRows();
|
|
419
424
|
|
|
420
425
|
// Return cells of the CTA row if no draft row is active
|
|
421
426
|
if (draftRows.length === 0) {
|
|
@@ -442,7 +447,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
442
447
|
|
|
443
448
|
private getDraftIconCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
444
449
|
const cells: DxGridPlaneCells = {};
|
|
445
|
-
const draftRows = this.model.
|
|
450
|
+
const draftRows = this.model.getDraftRows();
|
|
446
451
|
|
|
447
452
|
for (let row = range.start.row; row <= range.end.row; row++) {
|
|
448
453
|
cells[toPlaneCellIndex({ col: 0, row })] = {
|
|
@@ -57,8 +57,8 @@ export class TableManager {
|
|
|
57
57
|
await this.page.getByTestId(TABLE_SELECTORS.newColumnButton).click();
|
|
58
58
|
await this.page.getByRole('combobox').click();
|
|
59
59
|
await this.page.getByLabel(format).click();
|
|
60
|
-
await this.page.getByPlaceholder('Property label
|
|
61
|
-
await this.page.getByPlaceholder('Property label
|
|
60
|
+
await this.page.getByPlaceholder('Property label').click();
|
|
61
|
+
await this.page.getByPlaceholder('Property label').fill(label);
|
|
62
62
|
await this.page.getByRole('button', { name: 'Save' }).click();
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -10,7 +10,7 @@ export default defineConfig({
|
|
|
10
10
|
...e2ePreset(import.meta.dirname),
|
|
11
11
|
// TODO(wittjosiah): Avoid hard-coding ports.
|
|
12
12
|
webServer: {
|
|
13
|
-
command: 'moon run storybook:serve-e2e -- --port=9004',
|
|
13
|
+
command: 'moon run storybook-react:serve-e2e -- --port=9004',
|
|
14
14
|
port: 9004,
|
|
15
15
|
reuseExistingServer: false,
|
|
16
16
|
},
|
|
@@ -71,6 +71,7 @@ test.describe('Table', () => {
|
|
|
71
71
|
const table = new TableManager(page);
|
|
72
72
|
|
|
73
73
|
await table.grid.ready();
|
|
74
|
+
await expect(page.getByRole('gridcell', { name: 'Sapiente.' })).toHaveCount(1);
|
|
74
75
|
await table.deleteRow(0);
|
|
75
76
|
await expect(page.getByRole('gridcell', { name: 'Sapiente.' })).toHaveCount(0);
|
|
76
77
|
await page.close();
|
|
@@ -88,7 +89,7 @@ test.describe('Table', () => {
|
|
|
88
89
|
// Delete action affects all selected rows.
|
|
89
90
|
await table.deleteRow(0);
|
|
90
91
|
|
|
91
|
-
await expect(page.getByRole('gridcell', { name: '
|
|
92
|
+
await expect(page.getByRole('gridcell', { name: 'Aut.' })).toHaveCount(0);
|
|
92
93
|
await expect(page.getByRole('gridcell', { name: 'Beatae.' })).toHaveCount(0);
|
|
93
94
|
await expect(table.grid.cellsWithinPlane('grid')).toHaveCount(0);
|
|
94
95
|
await page.close();
|
|
@@ -153,7 +154,7 @@ test.describe('Table', () => {
|
|
|
153
154
|
// Assert the first two switch checkboxes are checked.
|
|
154
155
|
await expect(page.getByTestId('table-switch').first()).toBeChecked();
|
|
155
156
|
await expect(page.getByTestId('table-switch').nth(1)).toBeChecked();
|
|
156
|
-
await expect(table.grid.cell(0, 0, 'grid')).toHaveText('
|
|
157
|
+
await expect(table.grid.cell(0, 0, 'grid')).toHaveText('Aut.');
|
|
157
158
|
await expect(table.grid.cell(0, 1, 'grid')).toHaveText('Beatae.');
|
|
158
159
|
|
|
159
160
|
await page.close();
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import { type RefObject, useCallback, useMemo, useRef } from 'react';
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type RefObject, useCallback, useContext, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
|
+
import { type Database, type Type } from '@dxos/echo';
|
|
8
9
|
import { isMutable } from '@dxos/echo/internal';
|
|
9
|
-
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
12
|
+
import { useClientStory } from '@dxos/react-client/testing';
|
|
13
|
+
import { useGlobalFilteredObjects } from '@dxos/react-ui-searchlist';
|
|
14
14
|
import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
15
15
|
|
|
16
16
|
import { type TableController } from '../components';
|
|
@@ -20,15 +20,14 @@ import { Table } from '../types';
|
|
|
20
20
|
|
|
21
21
|
faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
|
|
22
22
|
|
|
23
|
-
export type TestTableModel = {
|
|
24
|
-
schema:
|
|
23
|
+
export type TestTableModel<T extends Type.Obj.Any = Type.Obj.Any> = {
|
|
24
|
+
schema: T | undefined;
|
|
25
25
|
table: Table.Table | undefined;
|
|
26
26
|
projection: ProjectionModel | undefined;
|
|
27
27
|
tableRef: RefObject<TableController | null>;
|
|
28
28
|
model: TableModel | undefined;
|
|
29
29
|
presentation: TablePresentation | undefined;
|
|
30
|
-
|
|
31
|
-
client: Client | undefined;
|
|
30
|
+
db: Database.Database | undefined;
|
|
32
31
|
handleInsertRow: () => void;
|
|
33
32
|
handleSaveView: () => void;
|
|
34
33
|
handleDeleteRows: (rowIndex: number, objects: any[]) => void;
|
|
@@ -39,15 +38,16 @@ export type TestTableModel = {
|
|
|
39
38
|
* Custom hook to create and manage a test table model for storybook demonstrations.
|
|
40
39
|
* Provides table data, schema, and handlers for table operations.
|
|
41
40
|
*/
|
|
42
|
-
export const useTestTableModel = (): TestTableModel => {
|
|
43
|
-
const
|
|
44
|
-
const { space } =
|
|
41
|
+
export const useTestTableModel = <T extends Type.Obj.Any = Type.Obj.Any>(): TestTableModel<T> => {
|
|
42
|
+
const registry = useContext(RegistryContext);
|
|
43
|
+
const { space } = useClientStory();
|
|
44
|
+
const db = space?.db;
|
|
45
45
|
|
|
46
|
-
const tables = useQuery(space, Filter.type(Table.Table));
|
|
46
|
+
const tables = useQuery(space?.db, Filter.type(Table.Table));
|
|
47
47
|
const table = tables.at(0);
|
|
48
48
|
const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
|
|
49
|
-
const schema = useSchema(
|
|
50
|
-
const projection = useProjectionModel(schema, table);
|
|
49
|
+
const schema = useSchema<T>(space?.db, typename);
|
|
50
|
+
const projection = useProjectionModel(schema, table, registry);
|
|
51
51
|
|
|
52
52
|
const features = useMemo(
|
|
53
53
|
() => ({
|
|
@@ -58,7 +58,7 @@ export const useTestTableModel = (): TestTableModel => {
|
|
|
58
58
|
[schema],
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
const objects = useQuery(
|
|
61
|
+
const objects = useQuery(db, schema ? Filter.type(schema) : Filter.nothing());
|
|
62
62
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
63
63
|
|
|
64
64
|
const tableRef = useRef<TableController>(null);
|
|
@@ -70,15 +70,15 @@ export const useTestTableModel = (): TestTableModel => {
|
|
|
70
70
|
tableRef.current?.update?.();
|
|
71
71
|
}, []);
|
|
72
72
|
|
|
73
|
-
const addRow = useAddRow({
|
|
73
|
+
const addRow = useAddRow({ db, schema });
|
|
74
74
|
|
|
75
75
|
const handleDeleteRows = useCallback(
|
|
76
76
|
(_: number, objects: any[]) => {
|
|
77
77
|
for (const object of objects) {
|
|
78
|
-
|
|
78
|
+
db?.remove(object);
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
[
|
|
81
|
+
[db],
|
|
82
82
|
);
|
|
83
83
|
|
|
84
84
|
const handleDeleteColumn = useCallback(
|
|
@@ -113,9 +113,9 @@ export const useTestTableModel = (): TestTableModel => {
|
|
|
113
113
|
|
|
114
114
|
const presentation = useMemo(() => {
|
|
115
115
|
if (model) {
|
|
116
|
-
return new TablePresentation(model);
|
|
116
|
+
return new TablePresentation(registry, model);
|
|
117
117
|
}
|
|
118
|
-
}, [model]);
|
|
118
|
+
}, [registry, model]);
|
|
119
119
|
|
|
120
120
|
return {
|
|
121
121
|
schema,
|
|
@@ -124,8 +124,7 @@ export const useTestTableModel = (): TestTableModel => {
|
|
|
124
124
|
tableRef,
|
|
125
125
|
model,
|
|
126
126
|
presentation,
|
|
127
|
-
|
|
128
|
-
client,
|
|
127
|
+
db,
|
|
129
128
|
handleInsertRow,
|
|
130
129
|
handleSaveView,
|
|
131
130
|
handleDeleteRows,
|
package/src/translations.ts
CHANGED
package/src/types/Table.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Match from 'effect/Match';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
8
|
|
|
8
9
|
import { Obj, Ref, Type } from '@dxos/echo';
|
|
9
10
|
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
10
|
-
import {
|
|
11
|
-
import { View, ViewAnnotation, getSchemaProperties } from '@dxos/schema';
|
|
11
|
+
import { View, ViewAnnotation } from '@dxos/schema';
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
export const Table = Schema.Struct({
|
|
14
14
|
name: Schema.String.pipe(Schema.optional),
|
|
15
15
|
|
|
16
16
|
view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
@@ -21,7 +21,7 @@ const TableSchema = Schema.Struct({
|
|
|
21
21
|
value: Schema.Number,
|
|
22
22
|
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
23
23
|
}).pipe(
|
|
24
|
-
Type.
|
|
24
|
+
Type.object({
|
|
25
25
|
typename: 'dxos.org/type/Table',
|
|
26
26
|
version: '0.2.0',
|
|
27
27
|
}),
|
|
@@ -29,11 +29,11 @@ const TableSchema = Schema.Struct({
|
|
|
29
29
|
ViewAnnotation.set(true),
|
|
30
30
|
);
|
|
31
31
|
|
|
32
|
-
export interface Table extends Schema.Schema.Type<typeof
|
|
33
|
-
export interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}
|
|
34
|
-
export const Table: Schema.Schema<Table, TableEncoded> = TableSchema;
|
|
32
|
+
export interface Table extends Schema.Schema.Type<typeof Table> {}
|
|
35
33
|
|
|
36
|
-
type MakeProps =
|
|
34
|
+
type MakeProps = {
|
|
35
|
+
name?: string;
|
|
36
|
+
sizes?: Record<string, number>;
|
|
37
37
|
view: View.View;
|
|
38
38
|
/** Required to auto-size columns. */
|
|
39
39
|
jsonSchema?: JsonSchemaType;
|
|
@@ -43,24 +43,25 @@ type MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {
|
|
|
43
43
|
* Make a table as a view of a data set.
|
|
44
44
|
*/
|
|
45
45
|
export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
|
|
46
|
-
const table = Obj.make(Table, { name, view: Ref.make(view), sizes });
|
|
46
|
+
const table = Obj.make(Table, { name, view: Ref.make(view), sizes } as Obj.MakeProps<typeof Table>);
|
|
47
47
|
|
|
48
48
|
// Preset sizes.
|
|
49
49
|
if (jsonSchema) {
|
|
50
50
|
const schema = Type.toEffectSchema(jsonSchema);
|
|
51
|
-
const properties =
|
|
51
|
+
const properties = SchemaAST.getPropertySignatures(schema.ast);
|
|
52
52
|
for (const property of properties) {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const name = property.name.toString() as JsonPath;
|
|
54
|
+
if (sizes?.[name]) {
|
|
55
|
+
table.sizes[name] = sizes[name];
|
|
55
56
|
continue;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
Match.type<
|
|
59
|
-
Match.when('
|
|
60
|
-
table.sizes[
|
|
59
|
+
Match.type<SchemaAST.AST>().pipe(
|
|
60
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => {
|
|
61
|
+
table.sizes[name] = 100;
|
|
61
62
|
}),
|
|
62
|
-
Match.when('
|
|
63
|
-
table.sizes[
|
|
63
|
+
Match.when({ _tag: 'NumberKeyword' }, () => {
|
|
64
|
+
table.sizes[name] = 100;
|
|
64
65
|
}),
|
|
65
66
|
Match.orElse(() => {
|
|
66
67
|
// Noop.
|
|
@@ -82,7 +83,7 @@ export const TableV1 = Schema.Struct({
|
|
|
82
83
|
value: Schema.Number,
|
|
83
84
|
}).pipe(Schema.mutable),
|
|
84
85
|
}).pipe(
|
|
85
|
-
Type.
|
|
86
|
+
Type.object({
|
|
86
87
|
typename: 'dxos.org/type/Table',
|
|
87
88
|
version: '0.1.0',
|
|
88
89
|
}),
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
|
|
7
|
-
import { Filter, type JsonSchema, Obj, Query, Ref, Type } from '@dxos/echo';
|
|
7
|
+
import { Filter, type JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type } from '@dxos/echo';
|
|
8
8
|
import {
|
|
9
9
|
ProjectionModel,
|
|
10
10
|
type SchemaPropertyDefinition,
|
|
11
|
-
type SortDirectionType,
|
|
12
11
|
View,
|
|
12
|
+
createDirectChangeCallback,
|
|
13
13
|
getSchemaFromPropertyDefinitions,
|
|
14
14
|
} from '@dxos/schema';
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ import { Table } from '../types';
|
|
|
19
19
|
type PropertyDisplayProps = {
|
|
20
20
|
size: number;
|
|
21
21
|
title: string;
|
|
22
|
-
sort:
|
|
22
|
+
sort: QueryAST.OrderDirection;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<PropertyDisplayProps>;
|
|
@@ -29,15 +29,15 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
|
|
|
29
29
|
*/
|
|
30
30
|
// TODO(burdon): Remove variance.
|
|
31
31
|
export const getBaseSchema = ({
|
|
32
|
+
schema,
|
|
32
33
|
typename,
|
|
33
34
|
properties,
|
|
34
35
|
jsonSchema,
|
|
35
|
-
schema,
|
|
36
36
|
}: {
|
|
37
|
+
schema?: Type.Entity.Any;
|
|
37
38
|
typename?: string;
|
|
38
39
|
properties?: TablePropertyDefinition[];
|
|
39
40
|
jsonSchema?: JsonSchema.JsonSchema;
|
|
40
|
-
schema?: Schema.Schema.AnyNoContext;
|
|
41
41
|
}): { typename: string; jsonSchema: JsonSchema.JsonSchema } => {
|
|
42
42
|
if (typename && properties) {
|
|
43
43
|
const schema = getSchemaFromPropertyDefinitions(typename, properties);
|
|
@@ -52,9 +52,11 @@ export const getBaseSchema = ({
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
export const makeDynamicTable = ({
|
|
55
|
+
registry,
|
|
55
56
|
jsonSchema,
|
|
56
57
|
properties,
|
|
57
58
|
}: {
|
|
59
|
+
registry: Registry.Registry;
|
|
58
60
|
jsonSchema: JsonSchema.JsonSchema;
|
|
59
61
|
properties?: TablePropertyDefinition[];
|
|
60
62
|
}): { projection: ProjectionModel; object: Table.Table } => {
|
|
@@ -65,9 +67,15 @@ export const makeDynamicTable = ({
|
|
|
65
67
|
});
|
|
66
68
|
const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
// Use direct change callback for in-memory objects (non-ECHO backed).
|
|
71
|
+
const projection = new ProjectionModel({
|
|
72
|
+
registry,
|
|
73
|
+
view,
|
|
74
|
+
baseSchema: jsonSchema,
|
|
75
|
+
change: createDirectChangeCallback(view.projection, jsonSchema),
|
|
76
|
+
});
|
|
69
77
|
projection.normalizeView();
|
|
70
|
-
if (properties && projection.
|
|
78
|
+
if (properties && projection.getFields()) {
|
|
71
79
|
setProperties(view, projection, object, properties);
|
|
72
80
|
}
|
|
73
81
|
|
|
@@ -81,10 +89,12 @@ const setProperties = (
|
|
|
81
89
|
properties: TablePropertyDefinition[],
|
|
82
90
|
) => {
|
|
83
91
|
for (const property of properties) {
|
|
84
|
-
const field = projection.
|
|
92
|
+
const field = projection.getFields().find((field) => field.path === property.name);
|
|
85
93
|
if (field) {
|
|
86
94
|
if (property.size !== undefined) {
|
|
87
|
-
table
|
|
95
|
+
Obj.change(table, (t) => {
|
|
96
|
+
t.sizes[field.path] = property.size!;
|
|
97
|
+
});
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
if (property.title !== undefined) {
|
|
@@ -96,8 +106,14 @@ const setProperties = (
|
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
if (property.sort) {
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
// Apply sort to query instead of deprecated view.sort
|
|
110
|
+
const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
|
|
111
|
+
// Use any type parameter since we're working with dynamic field paths
|
|
112
|
+
const newQuery = currentQuery.orderBy(Order.property<any>(field.path as string, property.sort));
|
|
113
|
+
Obj.change(view, (v) => {
|
|
114
|
+
// Type assertion needed because Query AST types have some variance issues.
|
|
115
|
+
v.query.ast = newQuery.ast as typeof v.query.ast;
|
|
116
|
+
});
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
}
|