@dxos/react-ui-table 0.8.4-main.c1de068 → 0.8.4-main.e098934
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-63UUF4IG.mjs +66 -0
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-BBXDTWCX.mjs} +537 -466
- package/dist/lib/browser/chunk-BBXDTWCX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +730 -669
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +9 -6
- 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-K734DJB7.mjs +67 -0
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-Y66YLSTC.mjs → chunk-RNQDU7IQ.mjs} +537 -466
- package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +730 -669
- 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 +9 -6
- 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 +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +50 -2
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +44 -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 +3 -2
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +42 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -3
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +8 -15
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +2 -1
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +9 -7
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +2 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +2 -3
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +2 -21
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- 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/types/schema.d.ts +24 -4
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +2 -2
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- 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 +47 -42
- package/src/components/Table/ColumnActionsMenu.tsx +1 -1
- package/src/components/Table/ColumnSettings.tsx +1 -1
- package/src/components/Table/CreateRefPanel.tsx +25 -8
- package/src/components/Table/DynamicTable.stories.tsx +7 -4
- package/src/components/Table/DynamicTable.tsx +4 -3
- package/src/components/Table/{relations.stories.tsx → Relations.stories.tsx} +40 -23
- package/src/components/Table/RowActionsMenu.tsx +3 -3
- package/src/components/Table/Table.stories.tsx +39 -28
- package/src/components/Table/Table.tsx +138 -112
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +143 -42
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +12 -24
- package/src/components/TableCellEditor/TableCellEditor.tsx +74 -137
- package/src/components/TableToolbar/TableToolbar.tsx +2 -2
- package/src/components/testing.ts +1 -1
- package/src/hooks/useAddRow.ts +6 -4
- package/src/hooks/useTableModel.ts +1 -1
- package/src/model/modal-controller.ts +1 -1
- package/src/model/selection-model.ts +3 -2
- package/src/model/table-model.test.ts +9 -5
- package/src/model/table-model.ts +35 -24
- package/src/model/table-presentation.test.ts +10 -5
- package/src/model/table-presentation.ts +72 -30
- package/src/model/table-sorting.ts +16 -7
- package/src/playwright/smoke.spec.ts +129 -37
- package/src/testing/useTestTableModel.ts +7 -5
- package/src/translations.ts +2 -2
- package/src/types/index.ts +1 -1
- package/src/types/schema.ts +62 -5
- package/src/util/dynamic-table.ts +10 -9
- package/src/util/index.ts +0 -1
- package/src/util/schema.ts +1 -1
- package/src/util/table-buttons.ts +4 -3
- package/src/util/table-controls.ts +4 -1
- 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.map +0 -7
- 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/util/table.d.ts +0 -11
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/util/table.ts +0 -49
package/src/model/table-model.ts
CHANGED
|
@@ -2,40 +2,47 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { computed, effect, signal
|
|
5
|
+
import { type ReadonlySignal, computed, effect, signal } from '@preact/signals-core';
|
|
6
6
|
|
|
7
7
|
import { Resource } from '@dxos/context';
|
|
8
8
|
import { Obj, Ref } from '@dxos/echo';
|
|
9
9
|
import {
|
|
10
|
-
type FieldSortType,
|
|
11
10
|
FormatEnum,
|
|
12
|
-
getValue,
|
|
13
|
-
setValue,
|
|
14
11
|
type JsonProp,
|
|
15
|
-
|
|
12
|
+
type JsonSchemaType,
|
|
16
13
|
getSchema,
|
|
14
|
+
getValue,
|
|
15
|
+
setValue,
|
|
17
16
|
toEffectSchema,
|
|
18
|
-
type JsonSchemaType,
|
|
19
17
|
} from '@dxos/echo-schema';
|
|
20
18
|
import { invariant } from '@dxos/invariant';
|
|
21
19
|
import { ObjectId } from '@dxos/keys';
|
|
22
|
-
import { isLiveObject } from '@dxos/live-object';
|
|
20
|
+
import { getSnapshot, isLiveObject } from '@dxos/live-object';
|
|
23
21
|
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
22
|
+
import { type Label } from '@dxos/react-ui';
|
|
24
23
|
import { formatForEditing, parseValue } from '@dxos/react-ui-form';
|
|
25
24
|
import {
|
|
26
25
|
type DxGridAxisMeta,
|
|
27
|
-
type DxGridPlaneRange,
|
|
28
26
|
type DxGridPlanePosition,
|
|
27
|
+
type DxGridPlaneRange,
|
|
29
28
|
type DxGridPosition,
|
|
30
29
|
} from '@dxos/react-ui-grid';
|
|
31
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
type DataType,
|
|
32
|
+
type FieldSortType,
|
|
33
|
+
ProjectionModel,
|
|
34
|
+
type PropertyType,
|
|
35
|
+
type ValidationError,
|
|
36
|
+
validateSchema,
|
|
37
|
+
} from '@dxos/schema';
|
|
32
38
|
|
|
33
|
-
import {
|
|
34
|
-
import { TableSorting } from './table-sorting';
|
|
35
|
-
import { TableView } from '../types';
|
|
39
|
+
import { Table } from '../types';
|
|
36
40
|
import { touch } from '../util';
|
|
37
41
|
import { extractTagIds } from '../util/tag';
|
|
38
42
|
|
|
43
|
+
import { type SelectionMode, SelectionModel } from './selection-model';
|
|
44
|
+
import { TableSorting } from './table-sorting';
|
|
45
|
+
|
|
39
46
|
// Domain types for cell classification
|
|
40
47
|
export type TableCellType = 'standard' | 'draft' | 'header';
|
|
41
48
|
|
|
@@ -53,7 +60,7 @@ export type TableRow = Record<JsonProp, any> & { id: string };
|
|
|
53
60
|
|
|
54
61
|
export type TableRowAction = {
|
|
55
62
|
id: string;
|
|
56
|
-
|
|
63
|
+
label: Label;
|
|
57
64
|
};
|
|
58
65
|
|
|
59
66
|
export type TableFeatures = {
|
|
@@ -68,6 +75,8 @@ const defaultFeatures: TableFeatures = {
|
|
|
68
75
|
schemaEditable: false,
|
|
69
76
|
};
|
|
70
77
|
|
|
78
|
+
export type InsertRowResult = 'draft' | 'final';
|
|
79
|
+
|
|
71
80
|
export type TableModelProps<T extends TableRow = TableRow> = {
|
|
72
81
|
view: DataType.View;
|
|
73
82
|
schema: JsonSchemaType;
|
|
@@ -78,7 +87,7 @@ export type TableModelProps<T extends TableRow = TableRow> = {
|
|
|
78
87
|
pinnedRows?: { top: number[]; bottom: number[] };
|
|
79
88
|
rowActions?: TableRowAction[];
|
|
80
89
|
onResolveSchema?: (typename: string) => Promise<JsonSchemaType>;
|
|
81
|
-
onInsertRow?: (data?: any) =>
|
|
90
|
+
onInsertRow?: (data?: any) => InsertRowResult;
|
|
82
91
|
onDeleteRows?: (index: number, obj: T[]) => void;
|
|
83
92
|
onDeleteColumn?: (fieldId: string) => void;
|
|
84
93
|
onCellUpdate?: (cell: DxGridPosition) => void;
|
|
@@ -89,14 +98,14 @@ export type TableModelProps<T extends TableRow = TableRow> = {
|
|
|
89
98
|
export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
90
99
|
private readonly _view: DataType.View;
|
|
91
100
|
private readonly _projection: ProjectionModel;
|
|
92
|
-
private _table?:
|
|
101
|
+
private _table?: Table.Table;
|
|
93
102
|
|
|
94
103
|
private readonly _visibleRange = signal<DxGridPlaneRange>({
|
|
95
104
|
start: { row: 0, col: 0 },
|
|
96
105
|
end: { row: 0, col: 0 },
|
|
97
106
|
});
|
|
98
107
|
|
|
99
|
-
private readonly _onInsertRow?: (data?: any) =>
|
|
108
|
+
private readonly _onInsertRow?: (data?: any) => InsertRowResult;
|
|
100
109
|
private readonly _onDeleteRows?: TableModelProps<T>['onDeleteRows'];
|
|
101
110
|
private readonly _onDeleteColumn?: TableModelProps<T>['onDeleteColumn'];
|
|
102
111
|
private readonly _onCellUpdate?: TableModelProps<T>['onCellUpdate'];
|
|
@@ -173,7 +182,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
173
182
|
return this._view;
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
public get table():
|
|
185
|
+
public get table(): Table.Table {
|
|
177
186
|
invariant(this._table, 'Model not initialized');
|
|
178
187
|
return this._table;
|
|
179
188
|
}
|
|
@@ -236,7 +245,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
236
245
|
|
|
237
246
|
protected override async _open(): Promise<void> {
|
|
238
247
|
const presentation = this._view.presentation.target ?? (await this._view.presentation.load());
|
|
239
|
-
invariant(Obj.instanceOf(
|
|
248
|
+
invariant(Obj.instanceOf(Table.Table, presentation));
|
|
240
249
|
this._table = presentation;
|
|
241
250
|
|
|
242
251
|
this.initializeColumnMeta();
|
|
@@ -254,7 +263,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
254
263
|
return {
|
|
255
264
|
grid: meta,
|
|
256
265
|
frozenColsStart: { 0: { size: 30, resizeable: false } },
|
|
257
|
-
frozenColsEnd: { 0: { size:
|
|
266
|
+
frozenColsEnd: { 0: { size: 32, resizeable: false } },
|
|
258
267
|
};
|
|
259
268
|
});
|
|
260
269
|
}
|
|
@@ -334,11 +343,12 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
334
343
|
|
|
335
344
|
public getColumnCount = (): number => this._projection?.fields.length ?? 0;
|
|
336
345
|
|
|
337
|
-
public insertRow = ():
|
|
346
|
+
public insertRow = (): InsertRowResult => {
|
|
338
347
|
const result = this._onInsertRow?.();
|
|
339
|
-
if (result ===
|
|
348
|
+
if (result === 'draft' && this._draftRows.value.length === 0) {
|
|
340
349
|
this.createDraftRow();
|
|
341
350
|
}
|
|
351
|
+
return result ?? 'final';
|
|
342
352
|
};
|
|
343
353
|
|
|
344
354
|
private createDraftRow(): void {
|
|
@@ -393,14 +403,14 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
393
403
|
return false;
|
|
394
404
|
}
|
|
395
405
|
|
|
396
|
-
const
|
|
406
|
+
const insertRowResult = this._onInsertRow?.(draftRow.data);
|
|
397
407
|
|
|
398
|
-
if (
|
|
408
|
+
if (insertRowResult === 'final') {
|
|
399
409
|
const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
|
|
400
410
|
this._draftRows.value = newDraftRows;
|
|
401
411
|
}
|
|
402
412
|
|
|
403
|
-
return
|
|
413
|
+
return insertRowResult === 'final';
|
|
404
414
|
};
|
|
405
415
|
|
|
406
416
|
public deleteRow = (rowIndex: number): void => {
|
|
@@ -497,6 +507,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
497
507
|
setValue(snapshot, field.path, transformedValue);
|
|
498
508
|
|
|
499
509
|
const validationErrors = this.validateDraftRowData(snapshot);
|
|
510
|
+
// TODO(thure): These errors sometimes result in a useless message like “is missing” (what is missing?)
|
|
500
511
|
if (validationErrors.length > 0) {
|
|
501
512
|
const error = validationErrors.find((err) => err.path === field.path);
|
|
502
513
|
if (error) {
|
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
|
-
import { describe, expect, it
|
|
6
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Filter, Query } from '@dxos/echo';
|
|
9
9
|
import { TypedObject } from '@dxos/echo-schema';
|
|
10
10
|
import { live } from '@dxos/live-object';
|
|
11
11
|
import { createEchoSchema } from '@dxos/live-object/testing';
|
|
12
12
|
import { createView } from '@dxos/schema';
|
|
13
13
|
|
|
14
|
+
import { Table } from '../types';
|
|
15
|
+
|
|
14
16
|
import { TableModel, type TableModelProps } from './table-model';
|
|
15
17
|
import { TablePresentation } from './table-presentation';
|
|
16
|
-
import { TableView } from '../types';
|
|
17
18
|
|
|
18
19
|
describe('TablePresentation', () => {
|
|
19
20
|
describe('row reactivity', () => {
|
|
@@ -97,7 +98,11 @@ class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.
|
|
|
97
98
|
|
|
98
99
|
const createTableModel = (props: Partial<TableModelProps> = {}): TableModel => {
|
|
99
100
|
const schema = createEchoSchema(Test);
|
|
100
|
-
const table =
|
|
101
|
-
const view = createView({
|
|
101
|
+
const table = Table.make();
|
|
102
|
+
const view = createView({
|
|
103
|
+
query: Query.select(Filter.type(schema)),
|
|
104
|
+
jsonSchema: schema.jsonSchema,
|
|
105
|
+
presentation: table,
|
|
106
|
+
});
|
|
102
107
|
return new TableModel({ view, schema: schema.jsonSchema, ...props });
|
|
103
108
|
};
|
|
@@ -6,7 +6,7 @@ import { signal } from '@preact/signals-core';
|
|
|
6
6
|
import { isNotNullable } from 'effect/Predicate';
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { FormatEnum,
|
|
9
|
+
import { FormatEnum, TypeEnum, getValue } from '@dxos/echo-schema';
|
|
10
10
|
import { cellClassesForFieldType, formatForDisplay } from '@dxos/react-ui-form';
|
|
11
11
|
import {
|
|
12
12
|
type DxGridCellValue,
|
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
toPlaneCellIndex,
|
|
17
17
|
} from '@dxos/react-ui-grid';
|
|
18
18
|
import { mx } from '@dxos/react-ui-theme';
|
|
19
|
-
import {
|
|
19
|
+
import { type FieldType, VIEW_FIELD_LIMIT } from '@dxos/schema';
|
|
20
20
|
|
|
21
|
-
import { type SelectionMode } from './selection-model';
|
|
22
|
-
import { type TableRow, type TableModel } from './table-model';
|
|
23
21
|
import { tableButtons, tableControls } from '../util';
|
|
24
22
|
|
|
23
|
+
import { type SelectionMode } from './selection-model';
|
|
24
|
+
import { type TableModel, type TableRow } from './table-model';
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* Presentation layer for a table component, handling cell rendering and grid display logic.
|
|
27
28
|
* Manages rendering of table cells, headers, selection columns, and action columns across
|
|
@@ -67,6 +68,9 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
67
68
|
case 'frozenRowsEnd':
|
|
68
69
|
cells = this.getDraftRowCells(range);
|
|
69
70
|
break;
|
|
71
|
+
case 'fixedEndStart':
|
|
72
|
+
cells = this.getDraftIconCells(range);
|
|
73
|
+
break;
|
|
70
74
|
case 'fixedEndEnd':
|
|
71
75
|
cells = this.getDraftActionCells(range);
|
|
72
76
|
break;
|
|
@@ -137,20 +141,22 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
137
141
|
};
|
|
138
142
|
|
|
139
143
|
const classes = [];
|
|
140
|
-
const formatClasses = cellClassesForFieldType(
|
|
144
|
+
const formatClasses = cellClassesForFieldType(props);
|
|
145
|
+
|
|
141
146
|
if (formatClasses) {
|
|
142
147
|
classes.push(formatClasses);
|
|
143
148
|
}
|
|
149
|
+
|
|
144
150
|
const rowSelectionClasses = cellClassesForRowSelection(
|
|
145
151
|
this.model.selection.isObjectSelected(obj),
|
|
146
152
|
this.model.selection.selectionMode,
|
|
147
153
|
);
|
|
154
|
+
|
|
148
155
|
if (rowSelectionClasses) {
|
|
149
156
|
classes.push(rowSelectionClasses);
|
|
150
157
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
158
|
+
|
|
159
|
+
cell.className = mx(classes);
|
|
154
160
|
|
|
155
161
|
// Arrays.
|
|
156
162
|
if (props.type === TypeEnum.Array) {
|
|
@@ -199,7 +205,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
199
205
|
const targetObj = getValue(obj, field.path)?.target;
|
|
200
206
|
if (targetObj) {
|
|
201
207
|
const dxn = Obj.getDXN(targetObj)?.toString();
|
|
202
|
-
cell.accessoryHtml = `<dx-
|
|
208
|
+
cell.accessoryHtml = `<dx-anchor refId=${dxn} class="dx-button is-6 pli-[3px] pbe-[2px] min-bs-0 absolute inline-end-2 block-start-[.2rem]" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor>`;
|
|
203
209
|
}
|
|
204
210
|
}
|
|
205
211
|
|
|
@@ -275,23 +281,34 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
275
281
|
const fields = this.model.projection?.fields ?? [];
|
|
276
282
|
const draftRows = this.model.draftRows.value;
|
|
277
283
|
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
// Return cells of the CTA row if no draft row is active
|
|
285
|
+
if (draftRows.length === 0) {
|
|
280
286
|
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
cells[toPlaneCellIndex({ col, row: 0 })] = {
|
|
288
|
+
value: '',
|
|
289
|
+
readonly: true,
|
|
290
|
+
className: 'dx-grid__row--cta__cell',
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
|
|
295
|
+
const draftRow = draftRows[row];
|
|
296
|
+
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
297
|
+
const cellIndex = toPlaneCellIndex({ col, row });
|
|
298
|
+
const field = fields[col];
|
|
299
|
+
if (!field) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
285
302
|
|
|
286
|
-
|
|
303
|
+
this.createDataCell(cells, draftRow.data, field, col, row);
|
|
287
304
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
305
|
+
if (this.model.hasDraftRowValidationError(row, field.path)) {
|
|
306
|
+
const cellValue = cells[cellIndex];
|
|
307
|
+
if (cellValue) {
|
|
308
|
+
const existingClasses = cellValue.className || '';
|
|
309
|
+
const draftClasses = 'dx-grid__cell--flagged';
|
|
310
|
+
cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
|
|
311
|
+
}
|
|
295
312
|
}
|
|
296
313
|
}
|
|
297
314
|
}
|
|
@@ -310,14 +327,14 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
310
327
|
|
|
311
328
|
cells[toPlaneCellIndex({ col, row: 0 })] = {
|
|
312
329
|
// TODO(burdon): Use same logic as form for fallback title.
|
|
313
|
-
value:
|
|
314
|
-
readonly: true,
|
|
330
|
+
value: '',
|
|
315
331
|
resizeHandle: 'col',
|
|
316
332
|
accessoryHtml: `
|
|
333
|
+
<span class="grow min-is-0 truncate">${props.title ?? field.path}</span>
|
|
317
334
|
${direction !== undefined ? tableButtons.sort.render({ fieldId: field.id, direction }) : ''}
|
|
318
335
|
${tableButtons.columnSettings.render({ fieldId: field.id })}
|
|
319
336
|
`,
|
|
320
|
-
className: '!bg-toolbarSurface',
|
|
337
|
+
className: '!bg-toolbarSurface !text-description [&>div]:flex [&>div]:items-stretch',
|
|
321
338
|
};
|
|
322
339
|
}
|
|
323
340
|
|
|
@@ -400,14 +417,39 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
400
417
|
const cells: DxGridPlaneCells = {};
|
|
401
418
|
const draftRows = this.model.draftRows.value;
|
|
402
419
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
420
|
+
// Return cells of the CTA row if no draft row is active
|
|
421
|
+
if (draftRows.length === 0) {
|
|
422
|
+
cells[toPlaneCellIndex({ col: 0, row: 0 })] = {
|
|
423
|
+
value: '',
|
|
424
|
+
className: 'dx-grid__row--cta__cell',
|
|
425
|
+
readonly: true,
|
|
426
|
+
};
|
|
427
|
+
} else {
|
|
428
|
+
for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
|
|
429
|
+
const draftRow = draftRows[row];
|
|
430
|
+
const disabled = !draftRow.valid;
|
|
431
|
+
|
|
432
|
+
cells[toPlaneCellIndex({ col: 0, row })] = {
|
|
433
|
+
value: '',
|
|
434
|
+
readonly: true,
|
|
435
|
+
accessoryHtml: tableButtons.saveDraftRow.render({ rowIndex: row, disabled }),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return cells;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
private getDraftIconCells(range: DxGridPlaneRange): DxGridPlaneCells {
|
|
444
|
+
const cells: DxGridPlaneCells = {};
|
|
445
|
+
const draftRows = this.model.draftRows.value;
|
|
406
446
|
|
|
447
|
+
for (let row = range.start.row; row <= range.end.row; row++) {
|
|
407
448
|
cells[toPlaneCellIndex({ col: 0, row })] = {
|
|
408
449
|
value: '',
|
|
409
450
|
readonly: true,
|
|
410
|
-
accessoryHtml:
|
|
451
|
+
accessoryHtml: '<dx-icon icon="ph--plus--regular" class="contents"></dx-icon>',
|
|
452
|
+
className: mx('[&>div]:grid [&>div]:place-content-center', draftRows.length < 1 && 'dx-grid__row--cta__cell'),
|
|
411
453
|
};
|
|
412
454
|
}
|
|
413
455
|
|
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type ReadonlySignal, type Signal, computed, signal } from '@preact/signals-core';
|
|
6
6
|
import orderBy from 'lodash.orderby';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { FormatEnum, TypeEnum, getValue } from '@dxos/echo-schema';
|
|
9
9
|
import { formatForDisplay } from '@dxos/react-ui-form';
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
DataType,
|
|
12
|
+
FieldSortType,
|
|
13
|
+
FieldType,
|
|
14
|
+
ProjectionModel,
|
|
15
|
+
PropertyType,
|
|
16
|
+
SortDirectionType,
|
|
17
|
+
} from '@dxos/schema';
|
|
11
18
|
|
|
12
19
|
import { type TableRow } from './table-model';
|
|
13
20
|
|
|
21
|
+
// TODO(wittjosiah): Remove. Use ordering in queries instead.
|
|
22
|
+
|
|
14
23
|
/**
|
|
15
24
|
* Represents the local sort state.
|
|
16
25
|
* - undefined: No local sort set, fallback to view sort.
|
|
@@ -55,7 +64,7 @@ export class TableSorting<T extends TableRow> {
|
|
|
55
64
|
this._rows = rows;
|
|
56
65
|
this._isDirty = computed(() => {
|
|
57
66
|
const local = this._localSort.value;
|
|
58
|
-
const viewSort = this._view.
|
|
67
|
+
const viewSort = this._view.sort?.[0];
|
|
59
68
|
if (local?.type === 'cleared') {
|
|
60
69
|
return viewSort !== undefined;
|
|
61
70
|
}
|
|
@@ -83,7 +92,7 @@ export class TableSorting<T extends TableRow> {
|
|
|
83
92
|
return local.sort;
|
|
84
93
|
}
|
|
85
94
|
|
|
86
|
-
return this._view.
|
|
95
|
+
return this._view.sort?.[0];
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
/**
|
|
@@ -129,9 +138,9 @@ export class TableSorting<T extends TableRow> {
|
|
|
129
138
|
public save(): void {
|
|
130
139
|
if (this._localSort.value !== undefined) {
|
|
131
140
|
if (this._localSort.value.type === 'active') {
|
|
132
|
-
this._view.
|
|
141
|
+
this._view.sort = [this._localSort.value.sort];
|
|
133
142
|
} else {
|
|
134
|
-
this._view.
|
|
143
|
+
this._view.sort = [];
|
|
135
144
|
}
|
|
136
145
|
this._localSort.value = undefined;
|
|
137
146
|
}
|
|
@@ -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,6 +66,7 @@ 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
|
|
|
@@ -71,6 +78,7 @@ test.describe('Table', () => {
|
|
|
71
78
|
|
|
72
79
|
test('delete row--select all', async ({ browser, browserName }) => {
|
|
73
80
|
test.skip(browserName === 'webkit');
|
|
81
|
+
test.skip(browserName === 'firefox');
|
|
74
82
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
75
83
|
const table = new TableManager(page);
|
|
76
84
|
|
|
@@ -88,6 +96,7 @@ test.describe('Table', () => {
|
|
|
88
96
|
|
|
89
97
|
test('delete column', async ({ browser, browserName }) => {
|
|
90
98
|
test.skip(browserName === 'webkit');
|
|
99
|
+
test.skip(browserName === 'firefox');
|
|
91
100
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
92
101
|
const table = new TableManager(page);
|
|
93
102
|
|
|
@@ -114,6 +123,7 @@ test.describe('Table', () => {
|
|
|
114
123
|
// Rest of add column test remains the same as it's a more complex flow.
|
|
115
124
|
test('add column', 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
|
|
|
@@ -126,44 +136,9 @@ test.describe('Table', () => {
|
|
|
126
136
|
await page.close();
|
|
127
137
|
});
|
|
128
138
|
|
|
129
|
-
test('
|
|
130
|
-
test.skip(browserName === 'webkit');
|
|
131
|
-
const { page } = await setupPage(browser, { url: storyUrl });
|
|
132
|
-
const table = new TableManager(page);
|
|
133
|
-
|
|
134
|
-
await table.grid.ready();
|
|
135
|
-
|
|
136
|
-
// Reference existing object.
|
|
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();
|
|
161
|
-
|
|
162
|
-
await page.close();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('test toggles', async ({ browser, browserName }) => {
|
|
139
|
+
test.skip('test toggles', async ({ browser, browserName }) => {
|
|
166
140
|
test.skip(browserName === 'webkit');
|
|
141
|
+
test.skip(browserName === 'firefox');
|
|
167
142
|
const { page } = await setupPage(browser, { url: storyUrl });
|
|
168
143
|
const table = new TableManager(page);
|
|
169
144
|
|
|
@@ -183,4 +158,121 @@ test.describe('Table', () => {
|
|
|
183
158
|
|
|
184
159
|
await page.close();
|
|
185
160
|
});
|
|
161
|
+
|
|
162
|
+
test('extant relations work as expected', async ({ browser, browserName }) => {
|
|
163
|
+
test.skip(browserName === 'webkit');
|
|
164
|
+
test.skip(browserName === 'firefox');
|
|
165
|
+
const { page } = await setupPage(browser, { url: relationsStoryUrl });
|
|
166
|
+
|
|
167
|
+
// Wait for the page to load
|
|
168
|
+
await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
|
|
169
|
+
|
|
170
|
+
// Find the dx-grid element for the contactModel (second table)
|
|
171
|
+
// The contactModel is used in the second Table.Main component in the story
|
|
172
|
+
const dxGrid = page.locator('dx-grid').nth(1);
|
|
173
|
+
await dxGrid.waitFor({ state: 'visible' });
|
|
174
|
+
|
|
175
|
+
// Scroll to the last column (column 4)
|
|
176
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
177
|
+
dxGridElement.scrollToColumn(4);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Click on the cell at aria-rowindex=0 aria-colindex=4 to focus it
|
|
181
|
+
const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
|
|
182
|
+
await targetCell.click();
|
|
183
|
+
|
|
184
|
+
// Click again to engage edit mode
|
|
185
|
+
await page.keyboard.press('Enter');
|
|
186
|
+
|
|
187
|
+
// Click on the combobox to open options
|
|
188
|
+
await page.getByRole('combobox').click();
|
|
189
|
+
await page.pause();
|
|
190
|
+
await page.getByPlaceholder('Search...').focus();
|
|
191
|
+
|
|
192
|
+
// Type the first few letters of an org name.
|
|
193
|
+
const orgName =
|
|
194
|
+
(await page
|
|
195
|
+
.locator('dx-grid')
|
|
196
|
+
.nth(0)
|
|
197
|
+
.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="0"] .dx-grid__cell__content')
|
|
198
|
+
.textContent()) ?? 'never';
|
|
199
|
+
await page.keyboard.type(orgName.substring(0, 4), { delay: 500 });
|
|
200
|
+
|
|
201
|
+
// Assert that there is an element with aria-selected on the page
|
|
202
|
+
await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
|
|
203
|
+
|
|
204
|
+
// Type the enter key
|
|
205
|
+
await page.keyboard.press('Enter');
|
|
206
|
+
|
|
207
|
+
// Save the result
|
|
208
|
+
await page.getByTestId('save-button').click();
|
|
209
|
+
|
|
210
|
+
// Assert that the cell element has the org name
|
|
211
|
+
await expect(targetCell).toHaveText(orgName);
|
|
212
|
+
|
|
213
|
+
await page.close();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('new relations work as expected', async ({ browser, browserName }) => {
|
|
217
|
+
test.skip(browserName === 'webkit');
|
|
218
|
+
test.skip(browserName === 'firefox');
|
|
219
|
+
const { page } = await setupPage(browser, { url: relationsStoryUrl });
|
|
220
|
+
|
|
221
|
+
// Wait for the page to load
|
|
222
|
+
await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
|
|
223
|
+
|
|
224
|
+
// Find the dx-grid element for the contactModel (second table)
|
|
225
|
+
// The contactModel is used in the second Table.Main component in the story
|
|
226
|
+
const dxGrid = page.locator('dx-grid').nth(1);
|
|
227
|
+
await dxGrid.waitFor({ state: 'visible' });
|
|
228
|
+
|
|
229
|
+
// Scroll to the last column (column 4)
|
|
230
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
231
|
+
dxGridElement.scrollToColumn(4);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Click on the cell at aria-rowindex=0 aria-colindex=8 to focus it
|
|
235
|
+
const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
|
|
236
|
+
await targetCell.click();
|
|
237
|
+
|
|
238
|
+
// Click again to engage edit mode
|
|
239
|
+
await page.keyboard.press('Enter');
|
|
240
|
+
|
|
241
|
+
// Click on the combobox to open options
|
|
242
|
+
await page.getByRole('combobox').click();
|
|
243
|
+
await page.getByPlaceholder('Search...').focus();
|
|
244
|
+
|
|
245
|
+
// Type the first few letters of an org name.
|
|
246
|
+
const orgName = 'Sally';
|
|
247
|
+
await page.keyboard.type(orgName, { delay: 500 });
|
|
248
|
+
|
|
249
|
+
// Assert that there is an element with aria-selected on the page
|
|
250
|
+
await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
|
|
251
|
+
|
|
252
|
+
// Type the enter key
|
|
253
|
+
await page.keyboard.press('Enter');
|
|
254
|
+
await page.pause();
|
|
255
|
+
|
|
256
|
+
// Click the save button in the popover
|
|
257
|
+
await page.getByTestId('save-button').click();
|
|
258
|
+
|
|
259
|
+
// Assert that the cell element has the org name
|
|
260
|
+
await expect(targetCell).toHaveText(orgName);
|
|
261
|
+
|
|
262
|
+
// Make a change to a non-ref cell to check that populated refs don’t cause problems with snapshots or schemas.
|
|
263
|
+
await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
|
|
264
|
+
dxGridElement.scrollToColumn(6);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const nonRefContent = faker.lorem.words(3);
|
|
268
|
+
const nonRefCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="6"]');
|
|
269
|
+
await nonRefCell.click();
|
|
270
|
+
await page.keyboard.press('Enter');
|
|
271
|
+
await page.getByTestId('grid.cell-editor').waitFor({ state: 'visible' });
|
|
272
|
+
await page.keyboard.type(nonRefContent, { delay: 500 });
|
|
273
|
+
await page.keyboard.press('Enter');
|
|
274
|
+
await expect(nonRefCell).toHaveText(nonRefContent);
|
|
275
|
+
|
|
276
|
+
await page.close();
|
|
277
|
+
});
|
|
186
278
|
});
|