@dxos/react-ui-table 0.8.4-main.1da679c → 0.8.4-main.21d9917
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-MNZKOFMA.mjs +1746 -0
- package/dist/lib/browser/chunk-MNZKOFMA.mjs.map +7 -0
- package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
- package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1134 -1150
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +29 -39
- 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-2ATAIIAO.mjs +1748 -0
- package/dist/lib/node-esm/chunk-2ATAIIAO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1134 -1150
- 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 +29 -39
- 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 -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 +5 -6
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +6 -20
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +77 -10
- 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 +11 -8
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +76 -11
- 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 +12 -12
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +7 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +5 -6
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +4 -4
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +23 -16
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +5 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +8 -8
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -8
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -8
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +103 -24
- 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 +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +4 -4
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +31 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +13 -12
- 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/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +56 -56
- package/src/components/Table/ColumnActionsMenu.tsx +10 -6
- package/src/components/Table/ColumnSettings.tsx +6 -6
- package/src/components/Table/DynamicTable.stories.tsx +18 -18
- package/src/components/Table/DynamicTable.tsx +23 -19
- package/src/components/Table/Relations.stories.tsx +143 -39
- package/src/components/Table/RowActionsMenu.tsx +24 -15
- package/src/components/Table/Table.stories.tsx +92 -95
- package/src/components/Table/Table.tsx +339 -307
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +116 -129
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +23 -47
- package/src/components/TableCellEditor/TableCellEditor.tsx +35 -122
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +47 -31
- package/src/components/testing.ts +39 -13
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +40 -0
- package/src/hooks/useTableModel.ts +35 -33
- package/src/model/modal-controller.ts +23 -40
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +91 -58
- package/src/model/table-model.ts +429 -163
- package/src/model/table-presentation.test.ts +64 -57
- package/src/model/table-presentation.ts +34 -30
- package/src/playwright/TableManager.ts +5 -5
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +11 -8
- package/src/testing/useTestTableModel.ts +44 -35
- package/src/translations.ts +3 -3
- package/src/types/Table.ts +90 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +41 -30
- package/src/util/index.ts +2 -0
- package/src/util/query-ast.ts +19 -0
- package/src/util/schema.ts +4 -4
- package/src/util/sort.ts +90 -0
- package/dist/lib/browser/chunk-63UUF4IG.mjs +0 -66
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-BBXDTWCX.mjs +0 -1822
- package/dist/lib/browser/chunk-BBXDTWCX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K734DJB7.mjs +0 -67
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs +0 -1823
- package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -52
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -28
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -103
- package/src/model/table-sorting.ts +0 -225
- package/src/types/schema.ts +0 -73
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.21d9917",
|
|
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": {
|
|
@@ -53,73 +57,69 @@
|
|
|
53
57
|
"src"
|
|
54
58
|
],
|
|
55
59
|
"dependencies": {
|
|
56
|
-
"@codemirror/autocomplete": "^6.
|
|
60
|
+
"@codemirror/autocomplete": "^6.19.0",
|
|
57
61
|
"@codemirror/state": "^6.5.2",
|
|
58
|
-
"@codemirror/view": "^6.38.
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@preact/signals-core": "^1.9.0",
|
|
62
|
+
"@codemirror/view": "^6.38.4",
|
|
63
|
+
"@effect-atom/atom-react": "^0.4.6",
|
|
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/echo": "0.8.4-main.
|
|
72
|
-
"@dxos/echo
|
|
73
|
-
"@dxos/effect": "0.8.4-main.
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
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/
|
|
86
|
-
"@dxos/
|
|
87
|
-
"@dxos/react-ui-
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/react-ui-
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/
|
|
92
|
-
"@dxos/
|
|
93
|
-
"@dxos/util": "0.8.4-main.1da679c",
|
|
94
|
-
"@dxos/react-ui-types": "0.8.4-main.1da679c"
|
|
71
|
+
"@dxos/context": "0.8.4-main.21d9917",
|
|
72
|
+
"@dxos/debug": "0.8.4-main.21d9917",
|
|
73
|
+
"@dxos/async": "0.8.4-main.21d9917",
|
|
74
|
+
"@dxos/echo-atom": "0.8.4-main.21d9917",
|
|
75
|
+
"@dxos/echo": "0.8.4-main.21d9917",
|
|
76
|
+
"@dxos/effect": "0.8.4-main.21d9917",
|
|
77
|
+
"@dxos/invariant": "0.8.4-main.21d9917",
|
|
78
|
+
"@dxos/keys": "0.8.4-main.21d9917",
|
|
79
|
+
"@dxos/lit-grid": "0.8.4-main.21d9917",
|
|
80
|
+
"@dxos/random": "0.8.4-main.21d9917",
|
|
81
|
+
"@dxos/log": "0.8.4-main.21d9917",
|
|
82
|
+
"@dxos/react-client": "0.8.4-main.21d9917",
|
|
83
|
+
"@dxos/react-ui-attention": "0.8.4-main.21d9917",
|
|
84
|
+
"@dxos/react-ui-components": "0.8.4-main.21d9917",
|
|
85
|
+
"@dxos/react-ui-form": "0.8.4-main.21d9917",
|
|
86
|
+
"@dxos/react-ui-grid": "0.8.4-main.21d9917",
|
|
87
|
+
"@dxos/react-ui-menu": "0.8.4-main.21d9917",
|
|
88
|
+
"@dxos/react-ui-stack": "0.8.4-main.21d9917",
|
|
89
|
+
"@dxos/schema": "0.8.4-main.21d9917",
|
|
90
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.21d9917",
|
|
91
|
+
"@dxos/types": "0.8.4-main.21d9917",
|
|
92
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.21d9917",
|
|
93
|
+
"@dxos/util": "0.8.4-main.21d9917",
|
|
94
|
+
"@dxos/ui-types": "0.8.4-main.21d9917",
|
|
95
|
+
"@dxos/react-ui-editor": "0.8.4-main.21d9917"
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
|
97
|
-
"@effect
|
|
98
|
-
"@effect/platform": "0.90.2",
|
|
98
|
+
"@effect/platform": "0.93.6",
|
|
99
99
|
"@types/lodash.orderby": "^4.6.9",
|
|
100
|
-
"@types/react": "~
|
|
101
|
-
"@types/react-dom": "~
|
|
102
|
-
"effect": "3.
|
|
100
|
+
"@types/react": "~19.2.7",
|
|
101
|
+
"@types/react-dom": "~19.2.3",
|
|
102
|
+
"effect": "3.19.11",
|
|
103
103
|
"fast-check": "^3.19.0",
|
|
104
|
-
"react": "~
|
|
105
|
-
"react-dom": "~
|
|
106
|
-
"vite": "7.1.
|
|
107
|
-
"@dxos/
|
|
108
|
-
"@dxos/
|
|
109
|
-
"@dxos/react-
|
|
110
|
-
"@dxos/
|
|
111
|
-
"@dxos/
|
|
112
|
-
"@dxos/
|
|
113
|
-
"@dxos/test-utils": "0.8.4-main.
|
|
104
|
+
"react": "~19.2.3",
|
|
105
|
+
"react-dom": "~19.2.3",
|
|
106
|
+
"vite": "7.1.9",
|
|
107
|
+
"@dxos/lit-ui": "0.8.4-main.21d9917",
|
|
108
|
+
"@dxos/random": "0.8.4-main.21d9917",
|
|
109
|
+
"@dxos/react-client": "0.8.4-main.21d9917",
|
|
110
|
+
"@dxos/react-ui": "0.8.4-main.21d9917",
|
|
111
|
+
"@dxos/storybook-utils": "0.8.4-main.21d9917",
|
|
112
|
+
"@dxos/ui-theme": "0.8.4-main.21d9917",
|
|
113
|
+
"@dxos/test-utils": "0.8.4-main.21d9917"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
|
-
"@effect-
|
|
117
|
-
"@effect/platform": "
|
|
118
|
-
"effect": "
|
|
119
|
-
"react": "~
|
|
120
|
-
"react-dom": "~
|
|
121
|
-
"@dxos/
|
|
122
|
-
"@dxos/react-ui
|
|
116
|
+
"@effect-atom/atom-react": "^0.4.6",
|
|
117
|
+
"@effect/platform": "0.93.6",
|
|
118
|
+
"effect": "3.19.11",
|
|
119
|
+
"react": "~19.2.3",
|
|
120
|
+
"react-dom": "~19.2.3",
|
|
121
|
+
"@dxos/ui-theme": "0.8.4-main.21d9917",
|
|
122
|
+
"@dxos/react-ui": "0.8.4-main.21d9917"
|
|
123
123
|
},
|
|
124
124
|
"publishConfig": {
|
|
125
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';
|
|
@@ -9,16 +10,19 @@ import { DropdownMenu, useTranslation } from '@dxos/react-ui';
|
|
|
9
10
|
import { type ModalController, type TableModel } from '../../model';
|
|
10
11
|
import { translationKey } from '../../translations';
|
|
11
12
|
|
|
12
|
-
type ColumnActionsMenuProps = {
|
|
13
|
+
export type ColumnActionsMenuProps = {
|
|
14
|
+
model: TableModel;
|
|
15
|
+
modals: ModalController;
|
|
16
|
+
};
|
|
13
17
|
|
|
14
18
|
export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) => {
|
|
15
19
|
const { t } = useTranslation(translationKey);
|
|
16
|
-
const state = modals.state
|
|
20
|
+
const state = useAtomValue(modals.state);
|
|
17
21
|
if (state?.type !== 'column') {
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
const currentSort = model.
|
|
25
|
+
const currentSort = model.getSorting();
|
|
22
26
|
const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
|
|
23
27
|
|
|
24
28
|
return (
|
|
@@ -30,7 +34,7 @@ export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) =>
|
|
|
30
34
|
{(!isCurrentColumnSorted || currentSort?.direction === 'asc') && (
|
|
31
35
|
<DropdownMenu.Item
|
|
32
36
|
data-testid='column-sort-descending'
|
|
33
|
-
onClick={() => model.
|
|
37
|
+
onClick={() => model.setSort(state.fieldId, 'desc')}
|
|
34
38
|
>
|
|
35
39
|
{t('column action sort descending')}
|
|
36
40
|
</DropdownMenu.Item>
|
|
@@ -38,13 +42,13 @@ export const ColumnActionsMenu = ({ model, modals }: ColumnActionsMenuProps) =>
|
|
|
38
42
|
{(!isCurrentColumnSorted || currentSort?.direction === 'desc') && (
|
|
39
43
|
<DropdownMenu.Item
|
|
40
44
|
data-testid='column-sort-ascending'
|
|
41
|
-
onClick={() => model.
|
|
45
|
+
onClick={() => model.setSort(state.fieldId, 'asc')}
|
|
42
46
|
>
|
|
43
47
|
{t('column action sort ascending')}
|
|
44
48
|
</DropdownMenu.Item>
|
|
45
49
|
)}
|
|
46
50
|
{isCurrentColumnSorted && (
|
|
47
|
-
<DropdownMenu.Item data-testid='column-clear-sort' onClick={() => model.
|
|
51
|
+
<DropdownMenu.Item data-testid='column-clear-sort' onClick={() => model.clearSort()}>
|
|
48
52
|
{t('column action clear sorting')}
|
|
49
53
|
</DropdownMenu.Item>
|
|
50
54
|
)}
|
|
@@ -2,10 +2,10 @@
|
|
|
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-db';
|
|
8
|
+
import { type SchemaRegistry } from '@dxos/echo';
|
|
9
9
|
import { Popover } from '@dxos/react-ui';
|
|
10
10
|
import { FieldEditor } from '@dxos/react-ui-form';
|
|
11
11
|
import { type FieldType } from '@dxos/schema';
|
|
@@ -13,7 +13,7 @@ import { type FieldType } from '@dxos/schema';
|
|
|
13
13
|
import { type ModalController, type TableModel } from '../../model';
|
|
14
14
|
|
|
15
15
|
type ColumnSettingsProps = {
|
|
16
|
-
registry?: SchemaRegistry;
|
|
16
|
+
registry?: SchemaRegistry.SchemaRegistry;
|
|
17
17
|
model?: TableModel;
|
|
18
18
|
modals: ModalController;
|
|
19
19
|
onNewColumn: () => void;
|
|
@@ -21,7 +21,7 @@ type ColumnSettingsProps = {
|
|
|
21
21
|
|
|
22
22
|
export const ColumnSettings = ({ registry, model, modals, onNewColumn }: ColumnSettingsProps) => {
|
|
23
23
|
const [newField, setNewField] = useState<FieldType>();
|
|
24
|
-
const state = modals.state
|
|
24
|
+
const state = useAtomValue(modals.state);
|
|
25
25
|
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
if (state?.type === 'columnSettings' && state.mode.type === 'create' && model?.projection) {
|
|
@@ -38,11 +38,11 @@ export const ColumnSettings = ({ registry, model, modals, onNewColumn }: ColumnS
|
|
|
38
38
|
if (state?.type === 'columnSettings') {
|
|
39
39
|
const { mode } = state;
|
|
40
40
|
if (mode.type === 'edit') {
|
|
41
|
-
return model?.projection?.
|
|
41
|
+
return model?.projection?.getFields().find((f) => f.id === mode.fieldId);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return undefined;
|
|
45
|
-
}, [model?.projection
|
|
45
|
+
}, [model?.projection, state]);
|
|
46
46
|
|
|
47
47
|
const field = existingField ?? newField;
|
|
48
48
|
|
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useMemo, useState } from 'react';
|
|
9
7
|
|
|
10
8
|
import { Obj } from '@dxos/echo';
|
|
11
|
-
import {
|
|
9
|
+
import { Format, type JsonSchemaType } from '@dxos/echo/internal';
|
|
12
10
|
import { faker } from '@dxos/random';
|
|
13
|
-
import { useClient } from '@dxos/react-client';
|
|
14
11
|
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
15
|
-
import {
|
|
12
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
13
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
16
14
|
import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
16
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
19
17
|
|
|
20
18
|
import { type TableFeatures } from '../../model';
|
|
21
19
|
import { translations } from '../../translations';
|
|
@@ -27,8 +25,8 @@ faker.seed(0);
|
|
|
27
25
|
const useTestPropertiesAndObjects = () => {
|
|
28
26
|
const properties = useMemo<SchemaPropertyDefinition[]>(
|
|
29
27
|
() => [
|
|
30
|
-
{ name: 'name', format:
|
|
31
|
-
{ name: 'age', format:
|
|
28
|
+
{ name: 'name', format: Format.TypeFormat.String },
|
|
29
|
+
{ name: 'age', format: Format.TypeFormat.Number },
|
|
32
30
|
],
|
|
33
31
|
[],
|
|
34
32
|
);
|
|
@@ -60,8 +58,11 @@ const DynamicTableStory = () => {
|
|
|
60
58
|
const meta = {
|
|
61
59
|
title: 'ui/react-ui-table/DynamicTable',
|
|
62
60
|
component: DynamicTable,
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
decorators: [withTheme, withRegistry],
|
|
62
|
+
parameters: {
|
|
63
|
+
layout: 'fullscreen',
|
|
64
|
+
translations,
|
|
65
|
+
},
|
|
65
66
|
} satisfies Meta<typeof DynamicTable>;
|
|
66
67
|
|
|
67
68
|
export default meta;
|
|
@@ -129,10 +130,9 @@ export const WithJsonSchema: StoryObj = {
|
|
|
129
130
|
|
|
130
131
|
export const WithEchoSchema: StoryObj = {
|
|
131
132
|
render: () => {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
|
|
133
|
+
const { space } = useClientStory();
|
|
134
|
+
const schema = useSchema(space?.db, TestSchema.Person.typename);
|
|
135
|
+
const objects = useQuery(space?.db, schema ? Filter.type(schema) : Filter.nothing());
|
|
136
136
|
if (!schema) {
|
|
137
137
|
return <div>Loading schema...</div>;
|
|
138
138
|
}
|
|
@@ -141,13 +141,13 @@ export const WithEchoSchema: StoryObj = {
|
|
|
141
141
|
},
|
|
142
142
|
decorators: [
|
|
143
143
|
withClientProvider({
|
|
144
|
-
types: [
|
|
144
|
+
types: [TestSchema.Person],
|
|
145
145
|
createIdentity: true,
|
|
146
146
|
createSpace: true,
|
|
147
|
-
|
|
147
|
+
onCreateSpace: async ({ space }) => {
|
|
148
148
|
Array.from({ length: 10 }).forEach(() => {
|
|
149
149
|
space.db.add(
|
|
150
|
-
Obj.make(
|
|
150
|
+
Obj.make(TestSchema.Person, {
|
|
151
151
|
name: faker.person.fullName(),
|
|
152
152
|
email: faker.internet.email(),
|
|
153
153
|
}),
|
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import React, { useCallback, useMemo, useRef } from 'react';
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { type
|
|
8
|
+
import { type Type } from '@dxos/echo';
|
|
9
|
+
import { type JsonSchemaType } from '@dxos/echo/internal';
|
|
9
10
|
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
11
|
+
import { type ProjectionModel } from '@dxos/schema';
|
|
12
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
13
|
|
|
12
14
|
import { useTableModel } from '../../hooks';
|
|
13
15
|
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
16
|
+
import { type Table as TableType } from '../../types';
|
|
14
17
|
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '../../util';
|
|
15
18
|
|
|
16
19
|
import { Table, type TableController } from './Table';
|
|
17
20
|
|
|
18
|
-
type DynamicTableProps = ThemedClassName<{
|
|
21
|
+
export type DynamicTableProps<T extends Type.Entity.Any = Type.Entity.Any> = ThemedClassName<{
|
|
22
|
+
schema?: T;
|
|
19
23
|
name?: string; // TODO(burdon): Remove?
|
|
20
24
|
rows: any[];
|
|
21
25
|
properties?: TablePropertyDefinition[];
|
|
22
26
|
jsonSchema?: JsonSchemaType;
|
|
23
|
-
schema?: Schema.Schema.AnyNoContext;
|
|
24
27
|
features?: Partial<TableFeatures>;
|
|
25
28
|
rowActions?: TableRowAction[];
|
|
26
29
|
onRowClick?: (row: any) => void;
|
|
@@ -32,28 +35,30 @@ type DynamicTableProps = ThemedClassName<{
|
|
|
32
35
|
*/
|
|
33
36
|
// TODO(burdon): Instead of creating component variants, create helpers/hooks that normalize the props.
|
|
34
37
|
// TODO(burdon): Warning: Cannot update a component (`DynamicTable`) while rendering a different component (`DynamicTable`).
|
|
35
|
-
export const DynamicTable = ({
|
|
38
|
+
export const DynamicTable = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
36
39
|
classNames,
|
|
40
|
+
schema,
|
|
37
41
|
name = 'example.com/dynamic-table', // Rmove default or make random; this will lead to type collisions.
|
|
38
42
|
rows,
|
|
39
43
|
properties,
|
|
40
44
|
jsonSchema: _jsonSchema,
|
|
41
|
-
schema,
|
|
42
45
|
rowActions,
|
|
43
46
|
onRowClick,
|
|
44
47
|
onRowAction,
|
|
45
48
|
...props
|
|
46
|
-
}: DynamicTableProps) => {
|
|
49
|
+
}: DynamicTableProps<T>) => {
|
|
50
|
+
const registry = useContext(RegistryContext);
|
|
51
|
+
const [dynamicTable, setDynamicTable] = useState<{ object: TableType.Table; projection: ProjectionModel }>();
|
|
52
|
+
|
|
47
53
|
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
48
|
-
const {
|
|
54
|
+
const { jsonSchema } = useMemo(
|
|
49
55
|
() => getBaseSchema({ typename: name, properties, jsonSchema: _jsonSchema, schema }),
|
|
50
56
|
[name, properties, _jsonSchema, schema],
|
|
51
57
|
);
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setDynamicTable(makeDynamicTable({ registry, jsonSchema, properties }));
|
|
61
|
+
}, [registry, jsonSchema, properties]);
|
|
57
62
|
|
|
58
63
|
const tableRef = useRef<TableController>(null);
|
|
59
64
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -75,9 +80,8 @@ export const DynamicTable = ({
|
|
|
75
80
|
|
|
76
81
|
const model = useTableModel({
|
|
77
82
|
rows,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
projection,
|
|
83
|
+
object: dynamicTable?.object,
|
|
84
|
+
projection: dynamicTable?.projection,
|
|
81
85
|
features,
|
|
82
86
|
rowActions,
|
|
83
87
|
onCellUpdate: handleCellUpdate,
|
|
@@ -87,9 +91,9 @@ export const DynamicTable = ({
|
|
|
87
91
|
|
|
88
92
|
const presentation = useMemo(() => {
|
|
89
93
|
if (model) {
|
|
90
|
-
return new TablePresentation(model);
|
|
94
|
+
return new TablePresentation(registry, model);
|
|
91
95
|
}
|
|
92
|
-
}, [model]);
|
|
96
|
+
}, [registry, model]);
|
|
93
97
|
|
|
94
98
|
// TODO(burdon): Do we need the outer divs?
|
|
95
99
|
return (
|