@dxos/react-ui-table 0.8.4-main.66e292d → 0.8.4-main.69d29f4
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-I5IFW7UF.mjs} +597 -634
- package/dist/lib/browser/chunk-I5IFW7UF.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-DDJKYJFY.mjs} +597 -633
- package/dist/lib/node-esm/chunk-DDJKYJFY.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 +28 -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
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.69d29f4",
|
|
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.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/async": "0.8.4-main.
|
|
69
|
-
"@dxos/context": "0.8.4-main.
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/effect": "0.8.4-main.
|
|
73
|
-
"@dxos/invariant": "0.8.4-main.
|
|
74
|
-
"@dxos/keys": "0.8.4-main.
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/react-ui-
|
|
82
|
-
"@dxos/react-
|
|
83
|
-
"@dxos/react-ui-
|
|
84
|
-
"@dxos/react-
|
|
85
|
-
"@dxos/react-ui-
|
|
86
|
-
"@dxos/react-ui-
|
|
87
|
-
"@dxos/react-ui-
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/
|
|
92
|
-
"@dxos/util": "0.8.4-main.
|
|
93
|
-
"@dxos/react-ui-searchlist": "0.8.4-main.66e292d",
|
|
94
|
-
"@dxos/types": "0.8.4-main.66e292d"
|
|
71
|
+
"@dxos/async": "0.8.4-main.69d29f4",
|
|
72
|
+
"@dxos/context": "0.8.4-main.69d29f4",
|
|
73
|
+
"@dxos/echo": "0.8.4-main.69d29f4",
|
|
74
|
+
"@dxos/debug": "0.8.4-main.69d29f4",
|
|
75
|
+
"@dxos/effect": "0.8.4-main.69d29f4",
|
|
76
|
+
"@dxos/invariant": "0.8.4-main.69d29f4",
|
|
77
|
+
"@dxos/keys": "0.8.4-main.69d29f4",
|
|
78
|
+
"@dxos/lit-grid": "0.8.4-main.69d29f4",
|
|
79
|
+
"@dxos/log": "0.8.4-main.69d29f4",
|
|
80
|
+
"@dxos/echo-atom": "0.8.4-main.69d29f4",
|
|
81
|
+
"@dxos/random": "0.8.4-main.69d29f4",
|
|
82
|
+
"@dxos/react-ui-components": "0.8.4-main.69d29f4",
|
|
83
|
+
"@dxos/react-ui-attention": "0.8.4-main.69d29f4",
|
|
84
|
+
"@dxos/react-ui-editor": "0.8.4-main.69d29f4",
|
|
85
|
+
"@dxos/react-client": "0.8.4-main.69d29f4",
|
|
86
|
+
"@dxos/react-ui-form": "0.8.4-main.69d29f4",
|
|
87
|
+
"@dxos/react-ui-grid": "0.8.4-main.69d29f4",
|
|
88
|
+
"@dxos/react-ui-menu": "0.8.4-main.69d29f4",
|
|
89
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.69d29f4",
|
|
90
|
+
"@dxos/react-ui-stack": "0.8.4-main.69d29f4",
|
|
91
|
+
"@dxos/types": "0.8.4-main.69d29f4",
|
|
92
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.69d29f4",
|
|
93
|
+
"@dxos/schema": "0.8.4-main.69d29f4",
|
|
94
|
+
"@dxos/ui-types": "0.8.4-main.69d29f4",
|
|
95
|
+
"@dxos/util": "0.8.4-main.69d29f4"
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
|
97
|
-
"@effect
|
|
98
|
-
"@effect/platform": "0.92.1",
|
|
98
|
+
"@effect/platform": "0.93.6",
|
|
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.11",
|
|
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/
|
|
114
|
-
"@dxos/test-utils": "0.8.4-main.66e292d"
|
|
107
|
+
"@dxos/random": "0.8.4-main.69d29f4",
|
|
108
|
+
"@dxos/lit-ui": "0.8.4-main.69d29f4",
|
|
109
|
+
"@dxos/react-client": "0.8.4-main.69d29f4",
|
|
110
|
+
"@dxos/storybook-utils": "0.8.4-main.69d29f4",
|
|
111
|
+
"@dxos/ui-theme": "0.8.4-main.69d29f4",
|
|
112
|
+
"@dxos/test-utils": "0.8.4-main.69d29f4",
|
|
113
|
+
"@dxos/react-ui": "0.8.4-main.69d29f4"
|
|
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.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/react-ui": "0.8.4-main.69d29f4",
|
|
122
|
+
"@dxos/ui-theme": "0.8.4-main.69d29f4"
|
|
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';
|
|
@@ -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
|
|
|
@@ -8,12 +8,12 @@ import React, { useMemo, useState } from 'react';
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
9
|
import { Format, type JsonSchemaType } from '@dxos/echo/internal';
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
|
-
import { useClient } from '@dxos/react-client';
|
|
12
11
|
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
13
|
-
import {
|
|
12
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
14
13
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
14
|
import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
16
15
|
import { TestSchema } from '@dxos/schema/testing';
|
|
16
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
17
17
|
|
|
18
18
|
import { type TableFeatures } from '../../model';
|
|
19
19
|
import { translations } from '../../translations';
|
|
@@ -58,7 +58,7 @@ const DynamicTableStory = () => {
|
|
|
58
58
|
const meta = {
|
|
59
59
|
title: 'ui/react-ui-table/DynamicTable',
|
|
60
60
|
component: DynamicTable,
|
|
61
|
-
decorators: [withTheme],
|
|
61
|
+
decorators: [withTheme, withRegistry],
|
|
62
62
|
parameters: {
|
|
63
63
|
layout: 'fullscreen',
|
|
64
64
|
translations,
|
|
@@ -130,10 +130,9 @@ export const WithJsonSchema: StoryObj = {
|
|
|
130
130
|
|
|
131
131
|
export const WithEchoSchema: StoryObj = {
|
|
132
132
|
render: () => {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
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());
|
|
137
136
|
if (!schema) {
|
|
138
137
|
return <div>Loading schema...</div>;
|
|
139
138
|
}
|
|
@@ -2,26 +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 Type } from '@dxos/echo';
|
|
8
9
|
import { type JsonSchemaType } from '@dxos/echo/internal';
|
|
9
10
|
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { type ProjectionModel } from '@dxos/schema';
|
|
12
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
13
|
|
|
13
14
|
import { useTableModel } from '../../hooks';
|
|
14
15
|
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
16
|
+
import { type Table as TableType } from '../../types';
|
|
15
17
|
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '../../util';
|
|
16
18
|
|
|
17
19
|
import { Table, type TableController } from './Table';
|
|
18
20
|
|
|
19
|
-
type DynamicTableProps = ThemedClassName<{
|
|
21
|
+
export type DynamicTableProps<T extends Type.Entity.Any = Type.Entity.Any> = ThemedClassName<{
|
|
22
|
+
schema?: T;
|
|
20
23
|
name?: string; // TODO(burdon): Remove?
|
|
21
24
|
rows: any[];
|
|
22
25
|
properties?: TablePropertyDefinition[];
|
|
23
26
|
jsonSchema?: JsonSchemaType;
|
|
24
|
-
schema?: Schema.Schema.AnyNoContext;
|
|
25
27
|
features?: Partial<TableFeatures>;
|
|
26
28
|
rowActions?: TableRowAction[];
|
|
27
29
|
onRowClick?: (row: any) => void;
|
|
@@ -33,25 +35,30 @@ type DynamicTableProps = ThemedClassName<{
|
|
|
33
35
|
*/
|
|
34
36
|
// TODO(burdon): Instead of creating component variants, create helpers/hooks that normalize the props.
|
|
35
37
|
// TODO(burdon): Warning: Cannot update a component (`DynamicTable`) while rendering a different component (`DynamicTable`).
|
|
36
|
-
export const DynamicTable = ({
|
|
38
|
+
export const DynamicTable = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
37
39
|
classNames,
|
|
40
|
+
schema,
|
|
38
41
|
name = 'example.com/dynamic-table', // Rmove default or make random; this will lead to type collisions.
|
|
39
42
|
rows,
|
|
40
43
|
properties,
|
|
41
44
|
jsonSchema: _jsonSchema,
|
|
42
|
-
schema,
|
|
43
45
|
rowActions,
|
|
44
46
|
onRowClick,
|
|
45
47
|
onRowAction,
|
|
46
48
|
...props
|
|
47
|
-
}: DynamicTableProps) => {
|
|
49
|
+
}: DynamicTableProps<T>) => {
|
|
50
|
+
const registry = useContext(RegistryContext);
|
|
51
|
+
const [dynamicTable, setDynamicTable] = useState<{ object: TableType.Table; projection: ProjectionModel }>();
|
|
52
|
+
|
|
48
53
|
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
49
54
|
const { jsonSchema } = useMemo(
|
|
50
55
|
() => getBaseSchema({ typename: name, properties, jsonSchema: _jsonSchema, schema }),
|
|
51
56
|
[name, properties, _jsonSchema, schema],
|
|
52
57
|
);
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setDynamicTable(makeDynamicTable({ registry, jsonSchema, properties }));
|
|
61
|
+
}, [registry, jsonSchema, properties]);
|
|
55
62
|
|
|
56
63
|
const tableRef = useRef<TableController>(null);
|
|
57
64
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -71,18 +78,10 @@ export const DynamicTable = ({
|
|
|
71
78
|
}) as const,
|
|
72
79
|
);
|
|
73
80
|
|
|
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
81
|
const model = useTableModel({
|
|
83
82
|
rows,
|
|
84
|
-
object,
|
|
85
|
-
projection:
|
|
83
|
+
object: dynamicTable?.object,
|
|
84
|
+
projection: dynamicTable?.projection,
|
|
86
85
|
features,
|
|
87
86
|
rowActions,
|
|
88
87
|
onCellUpdate: handleCellUpdate,
|
|
@@ -92,9 +91,9 @@ export const DynamicTable = ({
|
|
|
92
91
|
|
|
93
92
|
const presentation = useMemo(() => {
|
|
94
93
|
if (model) {
|
|
95
|
-
return new TablePresentation(model);
|
|
94
|
+
return new TablePresentation(registry, model);
|
|
96
95
|
}
|
|
97
|
-
}, [model]);
|
|
96
|
+
}, [registry, model]);
|
|
98
97
|
|
|
99
98
|
// TODO(burdon): Do we need the outer divs?
|
|
100
99
|
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,8 +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 { space } =
|
|
39
|
+
const registry = useContext(RegistryContext);
|
|
40
|
+
const { space } = useClientStory();
|
|
40
41
|
const [object, setObject] = useState<Table.Table>();
|
|
41
42
|
|
|
42
43
|
const features = useMemo<TableFeatures>(
|
|
@@ -49,15 +50,14 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
const { view, jsonSchema } = await View.
|
|
53
|
+
const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename: Type.getTypename(schema) });
|
|
53
54
|
const object = Table.make({ view, jsonSchema });
|
|
54
55
|
setObject(object);
|
|
55
56
|
space.db.add(object);
|
|
56
|
-
|
|
57
|
-
}, [client, space, schema]);
|
|
57
|
+
}, [space, schema]);
|
|
58
58
|
|
|
59
|
-
const projection = useProjectionModel(schema, object);
|
|
60
|
-
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 });
|
|
61
61
|
|
|
62
62
|
useEffect(() => {
|
|
63
63
|
if (!model || !space) {
|
|
@@ -75,21 +75,22 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
return new TablePresentation(model);
|
|
79
|
-
}, [model]);
|
|
78
|
+
return new TablePresentation(registry, model);
|
|
79
|
+
}, [registry, model]);
|
|
80
80
|
|
|
81
81
|
return { model, presentation };
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
const DefaultStory = () => {
|
|
85
|
-
const client = useClient();
|
|
86
85
|
const { model: orgModel, presentation: orgPresentation } = useTestModel(Organization.Organization, 50);
|
|
87
86
|
const { model: contactModel, presentation: contactPresentation } = useTestModel(Person.Person, 50);
|
|
88
|
-
const { space } =
|
|
87
|
+
const { space } = useClientStory();
|
|
89
88
|
|
|
90
89
|
const handleCreate = useCallback(
|
|
91
|
-
(schema:
|
|
92
|
-
|
|
90
|
+
(schema: Type.Entity.Any, values: any) => {
|
|
91
|
+
invariant(Type.isObjectSchema(schema));
|
|
92
|
+
invariant(space);
|
|
93
|
+
return space.db.add(Obj.make(schema, values));
|
|
93
94
|
},
|
|
94
95
|
[space],
|
|
95
96
|
);
|
|
@@ -102,7 +103,6 @@ const DefaultStory = () => {
|
|
|
102
103
|
schema={Organization.Organization}
|
|
103
104
|
presentation={orgPresentation}
|
|
104
105
|
onCreate={handleCreate}
|
|
105
|
-
client={client}
|
|
106
106
|
ignoreAttention
|
|
107
107
|
testId='relations-0'
|
|
108
108
|
/>
|
|
@@ -113,7 +113,6 @@ const DefaultStory = () => {
|
|
|
113
113
|
schema={Person.Person}
|
|
114
114
|
presentation={contactPresentation}
|
|
115
115
|
onCreate={handleCreate}
|
|
116
|
-
client={client}
|
|
117
116
|
ignoreAttention
|
|
118
117
|
testId='relations-1'
|
|
119
118
|
/>
|
|
@@ -127,7 +126,8 @@ const meta = {
|
|
|
127
126
|
render: DefaultStory,
|
|
128
127
|
decorators: [
|
|
129
128
|
withTheme,
|
|
130
|
-
|
|
129
|
+
withRegistry,
|
|
130
|
+
// TODO(thure): Shouldn't `layout: 'fullscreen'` below make this unnecessary?
|
|
131
131
|
withLayout({ classNames: 'fixed inset-0' }),
|
|
132
132
|
withClientProvider({
|
|
133
133
|
types: [View.View, Organization.Organization, Person.Person, Table.Table],
|
|
@@ -219,9 +219,9 @@ export const Default: Story = {
|
|
|
219
219
|
const newOrgName = 'Salieri LLC';
|
|
220
220
|
await userEvent.type(newSearchField, newOrgName);
|
|
221
221
|
|
|
222
|
-
//
|
|
223
|
-
const
|
|
224
|
-
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();
|
|
225
225
|
|
|
226
226
|
// Press Enter to select/create
|
|
227
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
|
}
|