@dxos/react-ui-table 0.8.4-main.3c1ae3b → 0.8.4-main.52d7546f51
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-V7A7ZA5E.mjs → chunk-GTGYBRJA.mjs} +606 -641
- package/dist/lib/browser/chunk-GTGYBRJA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-CJQ6T4LL.mjs → chunk-OZBLY7XM.mjs} +4 -5
- package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1082 -969
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -16
- 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-P73ALX3N.mjs → chunk-DPNSZHU5.mjs} +606 -640
- package/dist/lib/node-esm/chunk-DPNSZHU5.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-T6PXZQ6W.mjs → chunk-WNZSKIRF.mjs} +4 -5
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1082 -969
- 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 +20 -16
- 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.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +3 -2
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +2 -2
- 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.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +2 -2
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +1 -2
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +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 +6 -5
- 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 +99 -18
- 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/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 +4 -5
- 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 +10 -7
- 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 -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 +6 -5
- package/src/components/Table/ColumnSettings.tsx +4 -3
- package/src/components/Table/DynamicTable.stories.tsx +10 -8
- package/src/components/Table/DynamicTable.tsx +18 -18
- package/src/components/Table/Relations.stories.tsx +23 -19
- package/src/components/Table/RowActionsMenu.tsx +3 -2
- package/src/components/Table/Table.stories.tsx +47 -31
- package/src/components/Table/Table.tsx +34 -17
- package/src/components/TableCellEditor/FormCellEditor.tsx +49 -65
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +3 -3
- package/src/components/TableCellEditor/TableCellEditor.tsx +2 -2
- 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 +28 -8
- package/src/hooks/useTableModel.ts +27 -23
- 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 +409 -138
- package/src/model/table-presentation.test.ts +57 -47
- package/src/model/table-presentation.ts +23 -18
- package/src/playwright/TableManager.ts +10 -3
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +48 -4
- package/src/testing/useTestTableModel.ts +23 -20
- package/src/translations.ts +1 -1
- package/src/types/Table.ts +8 -8
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +31 -13
- 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-CJQ6T4LL.mjs.map +0 -7
- package/dist/lib/browser/chunk-V7A7ZA5E.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P73ALX3N.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-T6PXZQ6W.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
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-table",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.52d7546f51",
|
|
4
4
|
"description": "A table component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
"./deprecated": {
|
|
@@ -56,71 +60,66 @@
|
|
|
56
60
|
"@codemirror/autocomplete": "^6.19.0",
|
|
57
61
|
"@codemirror/state": "^6.5.2",
|
|
58
62
|
"@codemirror/view": "^6.38.4",
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@preact/signals-core": "^1.12.1",
|
|
63
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
64
|
+
"@fluentui/react-tabster": "9.26.11",
|
|
62
65
|
"@radix-ui/react-context": "1.1.1",
|
|
63
66
|
"@radix-ui/react-primitive": "2.0.2",
|
|
64
67
|
"@radix-ui/react-slot": "1.1.2",
|
|
65
68
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
66
69
|
"date-fns": "^3.3.1",
|
|
67
70
|
"lodash.orderby": "^4.6.0",
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/invariant": "0.8.4-main.
|
|
75
|
-
"@dxos/keys": "0.8.4-main.
|
|
76
|
-
"@dxos/lit-grid": "0.8.4-main.
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/react-
|
|
82
|
-
"@dxos/react-ui-
|
|
83
|
-
"@dxos/react-ui-
|
|
84
|
-
"@dxos/react-ui-
|
|
85
|
-
"@dxos/react-ui-
|
|
86
|
-
"@dxos/react-ui-
|
|
87
|
-
"@dxos/react-ui-
|
|
88
|
-
"@dxos/react-ui-
|
|
89
|
-
"@dxos/
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/
|
|
92
|
-
"@dxos/
|
|
93
|
-
"@dxos/types": "0.8.4-main.3c1ae3b",
|
|
94
|
-
"@dxos/util": "0.8.4-main.3c1ae3b"
|
|
71
|
+
"@dxos/context": "0.8.4-main.52d7546f51",
|
|
72
|
+
"@dxos/debug": "0.8.4-main.52d7546f51",
|
|
73
|
+
"@dxos/echo": "0.8.4-main.52d7546f51",
|
|
74
|
+
"@dxos/effect": "0.8.4-main.52d7546f51",
|
|
75
|
+
"@dxos/async": "0.8.4-main.52d7546f51",
|
|
76
|
+
"@dxos/echo-atom": "0.8.4-main.52d7546f51",
|
|
77
|
+
"@dxos/invariant": "0.8.4-main.52d7546f51",
|
|
78
|
+
"@dxos/keys": "0.8.4-main.52d7546f51",
|
|
79
|
+
"@dxos/lit-grid": "0.8.4-main.52d7546f51",
|
|
80
|
+
"@dxos/random": "0.8.4-main.52d7546f51",
|
|
81
|
+
"@dxos/log": "0.8.4-main.52d7546f51",
|
|
82
|
+
"@dxos/react-client": "0.8.4-main.52d7546f51",
|
|
83
|
+
"@dxos/react-ui-components": "0.8.4-main.52d7546f51",
|
|
84
|
+
"@dxos/react-ui-editor": "0.8.4-main.52d7546f51",
|
|
85
|
+
"@dxos/react-ui-grid": "0.8.4-main.52d7546f51",
|
|
86
|
+
"@dxos/react-ui-menu": "0.8.4-main.52d7546f51",
|
|
87
|
+
"@dxos/react-ui-form": "0.8.4-main.52d7546f51",
|
|
88
|
+
"@dxos/react-ui-attention": "0.8.4-main.52d7546f51",
|
|
89
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.52d7546f51",
|
|
90
|
+
"@dxos/react-ui-stack": "0.8.4-main.52d7546f51",
|
|
91
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.52d7546f51",
|
|
92
|
+
"@dxos/schema": "0.8.4-main.52d7546f51",
|
|
93
|
+
"@dxos/types": "0.8.4-main.52d7546f51",
|
|
94
|
+
"@dxos/util": "0.8.4-main.52d7546f51",
|
|
95
|
+
"@dxos/ui-types": "0.8.4-main.52d7546f51"
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
|
97
|
-
"@effect
|
|
98
|
-
"@effect/platform": "0.92.1",
|
|
98
|
+
"@effect/platform": "0.94.4",
|
|
99
99
|
"@types/lodash.orderby": "^4.6.9",
|
|
100
|
-
"@types/react": "~19.2.
|
|
101
|
-
"@types/react-dom": "~19.2.
|
|
102
|
-
"effect": "3.
|
|
100
|
+
"@types/react": "~19.2.7",
|
|
101
|
+
"@types/react-dom": "~19.2.3",
|
|
102
|
+
"effect": "3.19.16",
|
|
103
103
|
"fast-check": "^3.19.0",
|
|
104
|
-
"react": "~19.2.
|
|
105
|
-
"react-dom": "~19.2.
|
|
104
|
+
"react": "~19.2.3",
|
|
105
|
+
"react-dom": "~19.2.3",
|
|
106
106
|
"vite": "7.1.9",
|
|
107
|
-
"@dxos/
|
|
108
|
-
"@dxos/
|
|
109
|
-
"@dxos/
|
|
110
|
-
"@dxos/
|
|
111
|
-
"@dxos/
|
|
112
|
-
"@dxos/
|
|
113
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
114
|
-
"@dxos/test-utils": "0.8.4-main.3c1ae3b"
|
|
107
|
+
"@dxos/lit-ui": "0.8.4-main.52d7546f51",
|
|
108
|
+
"@dxos/react-ui": "0.8.4-main.52d7546f51",
|
|
109
|
+
"@dxos/react-client": "0.8.4-main.52d7546f51",
|
|
110
|
+
"@dxos/random": "0.8.4-main.52d7546f51",
|
|
111
|
+
"@dxos/test-utils": "0.8.4-main.52d7546f51",
|
|
112
|
+
"@dxos/ui-theme": "0.8.4-main.52d7546f51",
|
|
113
|
+
"@dxos/storybook-utils": "0.8.4-main.52d7546f51"
|
|
115
114
|
},
|
|
116
115
|
"peerDependencies": {
|
|
117
|
-
"@effect-atom/atom-react": "^0.
|
|
118
|
-
"@effect/platform": "
|
|
119
|
-
"effect": "
|
|
120
|
-
"react": "
|
|
121
|
-
"react-dom": "
|
|
122
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
123
|
-
"@dxos/
|
|
116
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
117
|
+
"@effect/platform": "0.94.4",
|
|
118
|
+
"effect": "3.19.16",
|
|
119
|
+
"react": "~19.2.3",
|
|
120
|
+
"react-dom": "~19.2.3",
|
|
121
|
+
"@dxos/react-ui": "0.8.4-main.52d7546f51",
|
|
122
|
+
"@dxos/ui-theme": "0.8.4-main.52d7546f51"
|
|
124
123
|
},
|
|
125
124
|
"publishConfig": {
|
|
126
125
|
"access": "public"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { DropdownMenu, useTranslation } from '@dxos/react-ui';
|
|
@@ -16,12 +17,12 @@ export type ColumnActionsMenuProps = {
|
|
|
16
17
|
|
|
17
18
|
export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) => {
|
|
18
19
|
const { t } = useTranslation(translationKey);
|
|
19
|
-
const state = modals.state
|
|
20
|
+
const state = useAtomValue(modals.state);
|
|
20
21
|
if (state?.type !== 'column') {
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const currentSort = model.
|
|
25
|
+
const currentSort = model.getSorting();
|
|
25
26
|
const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
|
|
26
27
|
|
|
27
28
|
return (
|
|
@@ -33,7 +34,7 @@ export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) =>
|
|
|
33
34
|
{(!isCurrentColumnSorted || currentSort?.direction === 'asc') && (
|
|
34
35
|
<DropdownMenu.Item
|
|
35
36
|
data-testid='column-sort-descending'
|
|
36
|
-
onClick={() => model.
|
|
37
|
+
onClick={() => model.setSort(state.fieldId, 'desc')}
|
|
37
38
|
>
|
|
38
39
|
{t('column action sort descending')}
|
|
39
40
|
</DropdownMenu.Item>
|
|
@@ -41,13 +42,13 @@ export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) =>
|
|
|
41
42
|
{(!isCurrentColumnSorted || currentSort?.direction === 'desc') && (
|
|
42
43
|
<DropdownMenu.Item
|
|
43
44
|
data-testid='column-sort-ascending'
|
|
44
|
-
onClick={() => model.
|
|
45
|
+
onClick={() => model.setSort(state.fieldId, 'asc')}
|
|
45
46
|
>
|
|
46
47
|
{t('column action sort ascending')}
|
|
47
48
|
</DropdownMenu.Item>
|
|
48
49
|
)}
|
|
49
50
|
{isCurrentColumnSorted && (
|
|
50
|
-
<DropdownMenu.Item data-testid='column-clear-sort' onClick={() => model.
|
|
51
|
+
<DropdownMenu.Item data-testid='column-clear-sort' onClick={() => model.clearSort()}>
|
|
51
52
|
{t('column action clear sorting')}
|
|
52
53
|
</DropdownMenu.Item>
|
|
53
54
|
)}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
5
6
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
import { type SchemaRegistry } from '@dxos/echo';
|
|
@@ -20,7 +21,7 @@ type ColumnSettingsProps = {
|
|
|
20
21
|
|
|
21
22
|
export const ColumnSettings = ({ registry, model, modals, onNewColumn }: ColumnSettingsProps) => {
|
|
22
23
|
const [newField, setNewField] = useState<FieldType>();
|
|
23
|
-
const state = modals.state
|
|
24
|
+
const state = useAtomValue(modals.state);
|
|
24
25
|
|
|
25
26
|
useEffect(() => {
|
|
26
27
|
if (state?.type === 'columnSettings' && state.mode.type === 'create' && model?.projection) {
|
|
@@ -37,11 +38,11 @@ export const ColumnSettings = ({ registry, model, modals, onNewColumn }: ColumnS
|
|
|
37
38
|
if (state?.type === 'columnSettings') {
|
|
38
39
|
const { mode } = state;
|
|
39
40
|
if (mode.type === 'edit') {
|
|
40
|
-
return model?.projection?.
|
|
41
|
+
return model?.projection?.getFields().find((f) => f.id === mode.fieldId);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
return undefined;
|
|
44
|
-
}, [model?.projection
|
|
45
|
+
}, [model?.projection, state]);
|
|
45
46
|
|
|
46
47
|
const field = existingField ?? newField;
|
|
47
48
|
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import type * as Types from 'effect/Types';
|
|
6
7
|
import React, { useMemo, useState } from 'react';
|
|
7
8
|
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { Format
|
|
9
|
+
import { type JsonSchema, Obj } from '@dxos/echo';
|
|
10
|
+
import { Format } from '@dxos/echo/internal';
|
|
10
11
|
import { faker } from '@dxos/random';
|
|
11
12
|
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
12
|
-
import {
|
|
13
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
13
14
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
15
|
import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
15
16
|
import { TestSchema } from '@dxos/schema/testing';
|
|
17
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
18
|
|
|
17
19
|
import { type TableFeatures } from '../../model';
|
|
18
20
|
import { translations } from '../../translations';
|
|
@@ -57,7 +59,7 @@ const DynamicTableStory = () => {
|
|
|
57
59
|
const meta = {
|
|
58
60
|
title: 'ui/react-ui-table/DynamicTable',
|
|
59
61
|
component: DynamicTable,
|
|
60
|
-
decorators: [withTheme],
|
|
62
|
+
decorators: [withTheme(), withRegistry],
|
|
61
63
|
parameters: {
|
|
62
64
|
layout: 'fullscreen',
|
|
63
65
|
translations,
|
|
@@ -100,7 +102,7 @@ export const WithClickToSelect: StoryObj = {
|
|
|
100
102
|
|
|
101
103
|
export const WithJsonSchema: StoryObj = {
|
|
102
104
|
render: () => {
|
|
103
|
-
const schema = useMemo<
|
|
105
|
+
const schema = useMemo<Types.DeepMutable<JsonSchema.JsonSchema>>(
|
|
104
106
|
() => ({
|
|
105
107
|
type: 'object',
|
|
106
108
|
properties: {
|
|
@@ -129,9 +131,9 @@ export const WithJsonSchema: StoryObj = {
|
|
|
129
131
|
|
|
130
132
|
export const WithEchoSchema: StoryObj = {
|
|
131
133
|
render: () => {
|
|
132
|
-
const { space } =
|
|
133
|
-
const schema = useSchema(space, TestSchema.Person.typename);
|
|
134
|
-
const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
|
|
134
|
+
const { space } = useClientStory();
|
|
135
|
+
const schema = useSchema(space?.db, TestSchema.Person.typename);
|
|
136
|
+
const objects = useQuery(space?.db, schema ? Filter.type(schema) : Filter.nothing());
|
|
135
137
|
if (!schema) {
|
|
136
138
|
return <div>Loading schema...</div>;
|
|
137
139
|
}
|
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import type * as Types from 'effect/Types';
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
8
|
|
|
7
9
|
import { type Type } from '@dxos/echo';
|
|
8
|
-
import { type
|
|
10
|
+
import { type JsonSchema } from '@dxos/echo';
|
|
9
11
|
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
+
import { type ProjectionModel } from '@dxos/schema';
|
|
13
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
14
|
|
|
13
15
|
import { useTableModel } from '../../hooks';
|
|
14
16
|
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
17
|
+
import { type Table as TableType } from '../../types';
|
|
15
18
|
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '../../util';
|
|
16
19
|
|
|
17
20
|
import { Table, type TableController } from './Table';
|
|
@@ -21,7 +24,7 @@ export type DynamicTableProps<T extends Type.Entity.Any = Type.Entity.Any> = The
|
|
|
21
24
|
name?: string; // TODO(burdon): Remove?
|
|
22
25
|
rows: any[];
|
|
23
26
|
properties?: TablePropertyDefinition[];
|
|
24
|
-
jsonSchema?:
|
|
27
|
+
jsonSchema?: Types.DeepMutable<JsonSchema.JsonSchema>;
|
|
25
28
|
features?: Partial<TableFeatures>;
|
|
26
29
|
rowActions?: TableRowAction[];
|
|
27
30
|
onRowClick?: (row: any) => void;
|
|
@@ -45,13 +48,18 @@ export const DynamicTable = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
|
45
48
|
onRowAction,
|
|
46
49
|
...props
|
|
47
50
|
}: DynamicTableProps<T>) => {
|
|
51
|
+
const registry = useContext(RegistryContext);
|
|
52
|
+
const [dynamicTable, setDynamicTable] = useState<{ object: TableType.Table; projection: ProjectionModel }>();
|
|
53
|
+
|
|
48
54
|
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
49
55
|
const { jsonSchema } = useMemo(
|
|
50
56
|
() => getBaseSchema({ typename: name, properties, jsonSchema: _jsonSchema, schema }),
|
|
51
57
|
[name, properties, _jsonSchema, schema],
|
|
52
58
|
);
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setDynamicTable(makeDynamicTable({ registry, jsonSchema, properties }));
|
|
62
|
+
}, [registry, jsonSchema, properties]);
|
|
55
63
|
|
|
56
64
|
const tableRef = useRef<TableController>(null);
|
|
57
65
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -71,18 +79,10 @@ export const DynamicTable = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
|
71
79
|
}) as const,
|
|
72
80
|
);
|
|
73
81
|
|
|
74
|
-
const projectionModel = useMemo(() => {
|
|
75
|
-
if (jsonSchema && projection) {
|
|
76
|
-
const model = new ProjectionModel(jsonSchema, projection);
|
|
77
|
-
model.normalizeView();
|
|
78
|
-
return model;
|
|
79
|
-
}
|
|
80
|
-
}, [jsonSchema, projection]);
|
|
81
|
-
|
|
82
82
|
const model = useTableModel({
|
|
83
83
|
rows,
|
|
84
|
-
object,
|
|
85
|
-
projection:
|
|
84
|
+
object: dynamicTable?.object,
|
|
85
|
+
projection: dynamicTable?.projection,
|
|
86
86
|
features,
|
|
87
87
|
rowActions,
|
|
88
88
|
onCellUpdate: handleCellUpdate,
|
|
@@ -92,9 +92,9 @@ export const DynamicTable = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
|
92
92
|
|
|
93
93
|
const presentation = useMemo(() => {
|
|
94
94
|
if (model) {
|
|
95
|
-
return new TablePresentation(model);
|
|
95
|
+
return new TablePresentation(registry, model);
|
|
96
96
|
}
|
|
97
|
-
}, [model]);
|
|
97
|
+
}, [registry, model]);
|
|
98
98
|
|
|
99
99
|
// TODO(burdon): Do we need the outer divs?
|
|
100
100
|
return (
|
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
5
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import
|
|
7
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
8
8
|
import { expect, userEvent, within } from 'storybook/test';
|
|
9
9
|
|
|
10
10
|
import { Obj, Type } from '@dxos/echo';
|
|
11
|
+
import { invariant } from '@dxos/invariant';
|
|
11
12
|
import { type DxGrid } from '@dxos/lit-grid';
|
|
12
13
|
import '@dxos/lit-ui/dx-tag-picker.pcss';
|
|
13
14
|
import { faker } from '@dxos/random';
|
|
14
|
-
import {
|
|
15
|
-
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
15
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
16
16
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
17
17
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
18
18
|
import { translations as formTranslations } from '@dxos/react-ui-form';
|
|
19
19
|
import { View } from '@dxos/schema';
|
|
20
20
|
import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
|
|
21
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
21
22
|
import { Organization, Person } from '@dxos/types';
|
|
22
23
|
|
|
23
24
|
import { useProjectionModel, useTableModel } from '../../hooks';
|
|
@@ -35,7 +36,8 @@ const generator: ValueGenerator = faker as any;
|
|
|
35
36
|
// TODO(burdon): Reconcile schemas types and utils (see API PR).
|
|
36
37
|
// TODO(burdon): Base type for T (with id); see ECHO API PR?
|
|
37
38
|
const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
38
|
-
const
|
|
39
|
+
const registry = useContext(RegistryContext);
|
|
40
|
+
const { space } = useClientStory();
|
|
39
41
|
const [object, setObject] = useState<Table.Table>();
|
|
40
42
|
|
|
41
43
|
const features = useMemo<TableFeatures>(
|
|
@@ -48,14 +50,14 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const { view, jsonSchema } = await View.
|
|
53
|
+
const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename: Type.getTypename(schema) });
|
|
52
54
|
const object = Table.make({ view, jsonSchema });
|
|
53
55
|
setObject(object);
|
|
54
56
|
space.db.add(object);
|
|
55
57
|
}, [space, schema]);
|
|
56
58
|
|
|
57
|
-
const projection = useProjectionModel(schema, object);
|
|
58
|
-
const model = useTableModel<TableRow>({ object, projection, features });
|
|
59
|
+
const projection = useProjectionModel(schema, object, registry);
|
|
60
|
+
const model = useTableModel<TableRow>({ object, projection, db: space?.db, features });
|
|
59
61
|
|
|
60
62
|
useEffect(() => {
|
|
61
63
|
if (!model || !space) {
|
|
@@ -73,21 +75,22 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
return new TablePresentation(model);
|
|
77
|
-
}, [model]);
|
|
78
|
+
return new TablePresentation(registry, model);
|
|
79
|
+
}, [registry, model]);
|
|
78
80
|
|
|
79
81
|
return { model, presentation };
|
|
80
82
|
};
|
|
81
83
|
|
|
82
84
|
const DefaultStory = () => {
|
|
83
|
-
const client = useClient();
|
|
84
85
|
const { model: orgModel, presentation: orgPresentation } = useTestModel(Organization.Organization, 50);
|
|
85
86
|
const { model: contactModel, presentation: contactPresentation } = useTestModel(Person.Person, 50);
|
|
86
|
-
const { space } =
|
|
87
|
+
const { space } = useClientStory();
|
|
87
88
|
|
|
88
89
|
const handleCreate = useCallback(
|
|
89
|
-
(schema:
|
|
90
|
-
|
|
90
|
+
(schema: Type.Entity.Any, values: any) => {
|
|
91
|
+
invariant(Type.isObjectSchema(schema));
|
|
92
|
+
invariant(space);
|
|
93
|
+
return space.db.add(Obj.make(schema, values));
|
|
91
94
|
},
|
|
92
95
|
[space],
|
|
93
96
|
);
|
|
@@ -122,8 +125,9 @@ const meta = {
|
|
|
122
125
|
title: 'ui/react-ui-table/Relations',
|
|
123
126
|
render: DefaultStory,
|
|
124
127
|
decorators: [
|
|
125
|
-
withTheme,
|
|
126
|
-
|
|
128
|
+
withTheme(),
|
|
129
|
+
withRegistry,
|
|
130
|
+
// TODO(thure): Shouldn't `layout: 'fullscreen'` below make this unnecessary?
|
|
127
131
|
withLayout({ classNames: 'fixed inset-0' }),
|
|
128
132
|
withClientProvider({
|
|
129
133
|
types: [View.View, Organization.Organization, Person.Person, Table.Table],
|
|
@@ -215,9 +219,9 @@ export const Default: Story = {
|
|
|
215
219
|
const newOrgName = 'Salieri LLC';
|
|
216
220
|
await userEvent.type(newSearchField, newOrgName);
|
|
217
221
|
|
|
218
|
-
//
|
|
219
|
-
const
|
|
220
|
-
await expect(
|
|
222
|
+
// Wait for the create option to appear (debounce is 200ms, allow time for render)
|
|
223
|
+
const createOption = await body.findByRole('option', undefined, { timeout: 500 });
|
|
224
|
+
await expect(createOption).toBeVisible();
|
|
221
225
|
|
|
222
226
|
// Press Enter to select/create
|
|
223
227
|
await userEvent.keyboard('{Enter}');
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { DropdownMenu, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
@@ -13,8 +14,8 @@ type RowActionsMenuProps = { model: TableModel; modals: ModalController };
|
|
|
13
14
|
|
|
14
15
|
export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
15
16
|
const { t } = useTranslation(translationKey);
|
|
16
|
-
const hasSelection = model.selection.hasSelection
|
|
17
|
-
const state = modals.state
|
|
17
|
+
const hasSelection = model.selection.hasSelection;
|
|
18
|
+
const state = useAtomValue(modals.state);
|
|
18
19
|
if (state?.type !== 'row') {
|
|
19
20
|
return null;
|
|
20
21
|
}
|