@dxos/react-ui-table 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d
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-L2LSB6KV.mjs +18 -0
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs +1814 -0
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +658 -2359
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +123 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -5
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +20 -0
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs +1815 -0
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +658 -2359
- 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 +124 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +3 -5
- 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 +4 -2
- 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 +1 -1
- 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 → Relations.stories.d.ts} +2 -2
- 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 +1 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +1 -1
- 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 +2 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +8 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -40
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +8 -7
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.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 +2 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +17 -16
- 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 +4 -4
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/useTestTableModel.d.ts +41 -0
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
- 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 +8 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/util/dynamic-table.d.ts +3 -4
- package/dist/types/src/util/dynamic-table.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/src/util/table.d.ts +9 -11
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +50 -36
- package/src/components/Table/ColumnActionsMenu.tsx +1 -1
- package/src/components/Table/ColumnSettings.tsx +15 -11
- package/src/components/Table/CreateRefPanel.tsx +6 -4
- package/src/components/Table/DynamicTable.stories.tsx +3 -2
- package/src/components/Table/DynamicTable.tsx +17 -10
- package/src/components/Table/{relations.stories.tsx → Relations.stories.tsx} +36 -35
- package/src/components/Table/RowActionsMenu.tsx +3 -3
- package/src/components/Table/Table.stories.tsx +99 -144
- package/src/components/Table/Table.tsx +87 -71
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +30 -21
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +24 -27
- package/src/components/TableCellEditor/TableCellEditor.tsx +42 -27
- package/src/components/TableCellEditor/extension.ts +2 -2
- package/src/components/TableToolbar/TableToolbar.tsx +2 -2
- package/src/components/testing.ts +7 -24
- package/src/hooks/useTableModel.ts +21 -17
- package/src/index.ts +0 -1
- package/src/model/modal-controller.ts +1 -1
- package/src/model/selection-model.ts +6 -3
- package/src/model/table-model.test.ts +8 -8
- package/src/model/table-model.ts +68 -62
- package/src/model/table-presentation.test.ts +8 -8
- package/src/model/table-presentation.ts +35 -13
- package/src/model/table-sorting.ts +11 -11
- package/src/playwright/smoke.spec.ts +105 -14
- package/src/testing/index.ts +5 -0
- package/src/testing/useTestTableModel.ts +123 -0
- package/src/translations.ts +2 -2
- package/src/types/index.ts +2 -2
- package/src/types/schema.ts +16 -0
- package/src/util/dynamic-table.ts +20 -18
- package/src/util/schema.ts +1 -1
- package/src/util/table-buttons.ts +2 -1
- package/src/util/table-controls.ts +4 -1
- package/src/util/table.ts +37 -111
- package/dist/lib/browser/chunk-Q5QQXJUO.mjs +0 -27
- package/dist/lib/browser/chunk-Q5QQXJUO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs +0 -29
- package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs.map +0 -7
- package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
- package/dist/types/src/types/table.d.ts +0 -56
- package/dist/types/src/types/table.d.ts.map +0 -1
- package/src/types/table.ts +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-table",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.fd6878d",
|
|
4
4
|
"description": "A table component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,16 +10,25 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
"./deprecated": {
|
|
13
|
+
"source": "./src/deprecated/index.ts",
|
|
13
14
|
"types": "./dist/types/src/deprecated/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/deprecated/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/deprecated/index.mjs"
|
|
16
17
|
},
|
|
17
18
|
".": {
|
|
19
|
+
"source": "./src/index.ts",
|
|
18
20
|
"types": "./dist/types/src/index.d.ts",
|
|
19
21
|
"browser": "./dist/lib/browser/index.mjs",
|
|
20
22
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
21
23
|
},
|
|
24
|
+
"./testing": {
|
|
25
|
+
"source": "./src/testing/index.ts",
|
|
26
|
+
"types": "./dist/types/src/testing/index.d.ts",
|
|
27
|
+
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
28
|
+
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
29
|
+
},
|
|
22
30
|
"./types": {
|
|
31
|
+
"source": "./src/types/index.ts",
|
|
23
32
|
"types": "./dist/types/src/types/index.d.ts",
|
|
24
33
|
"browser": "./dist/lib/browser/types/index.mjs",
|
|
25
34
|
"node": "./dist/lib/node-esm/types/index.mjs"
|
|
@@ -31,6 +40,9 @@
|
|
|
31
40
|
"deprecated": [
|
|
32
41
|
"dist/types/src/deprecated/index.d.ts"
|
|
33
42
|
],
|
|
43
|
+
"testing": [
|
|
44
|
+
"dist/types/src/testing/index.d.ts"
|
|
45
|
+
],
|
|
34
46
|
"types": [
|
|
35
47
|
"dist/types/src/types/index.d.ts"
|
|
36
48
|
]
|
|
@@ -53,49 +65,51 @@
|
|
|
53
65
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
54
66
|
"date-fns": "^3.3.1",
|
|
55
67
|
"lodash.orderby": "^4.6.0",
|
|
56
|
-
"@dxos/context": "0.8.4-main.
|
|
57
|
-
"@dxos/debug": "0.8.4-main.
|
|
58
|
-
"@dxos/echo": "0.8.4-main.
|
|
59
|
-
"@dxos/echo-
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/invariant": "0.8.4-main.
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/live-object": "0.8.4-main.
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/plugin-
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/react-
|
|
70
|
-
"@dxos/react-ui-editor": "0.8.4-main.
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/react-ui-
|
|
73
|
-
"@dxos/react-ui-
|
|
74
|
-
"@dxos/react-ui-
|
|
75
|
-
"@dxos/react-ui-
|
|
76
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
77
|
-
"@dxos/react-ui-tag-picker": "0.8.4-main.
|
|
78
|
-
"@dxos/react-ui-types": "0.8.4-main.
|
|
79
|
-
"@dxos/schema": "0.8.4-main.
|
|
80
|
-
"@dxos/
|
|
68
|
+
"@dxos/context": "0.8.4-main.fd6878d",
|
|
69
|
+
"@dxos/debug": "0.8.4-main.fd6878d",
|
|
70
|
+
"@dxos/echo": "0.8.4-main.fd6878d",
|
|
71
|
+
"@dxos/echo-db": "0.8.4-main.fd6878d",
|
|
72
|
+
"@dxos/echo-schema": "0.8.4-main.fd6878d",
|
|
73
|
+
"@dxos/invariant": "0.8.4-main.fd6878d",
|
|
74
|
+
"@dxos/effect": "0.8.4-main.fd6878d",
|
|
75
|
+
"@dxos/keys": "0.8.4-main.fd6878d",
|
|
76
|
+
"@dxos/lit-grid": "0.8.4-main.fd6878d",
|
|
77
|
+
"@dxos/live-object": "0.8.4-main.fd6878d",
|
|
78
|
+
"@dxos/log": "0.8.4-main.fd6878d",
|
|
79
|
+
"@dxos/plugin-search": "0.8.4-main.fd6878d",
|
|
80
|
+
"@dxos/random": "0.8.4-main.fd6878d",
|
|
81
|
+
"@dxos/react-client": "0.8.4-main.fd6878d",
|
|
82
|
+
"@dxos/react-ui-editor": "0.8.4-main.fd6878d",
|
|
83
|
+
"@dxos/react-ui-grid": "0.8.4-main.fd6878d",
|
|
84
|
+
"@dxos/react-ui-attention": "0.8.4-main.fd6878d",
|
|
85
|
+
"@dxos/react-ui-form": "0.8.4-main.fd6878d",
|
|
86
|
+
"@dxos/react-ui-stack": "0.8.4-main.fd6878d",
|
|
87
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.fd6878d",
|
|
88
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.fd6878d",
|
|
89
|
+
"@dxos/react-ui-tag-picker": "0.8.4-main.fd6878d",
|
|
90
|
+
"@dxos/react-ui-types": "0.8.4-main.fd6878d",
|
|
91
|
+
"@dxos/schema": "0.8.4-main.fd6878d",
|
|
92
|
+
"@dxos/react-ui-menu": "0.8.4-main.fd6878d",
|
|
93
|
+
"@dxos/util": "0.8.4-main.fd6878d"
|
|
81
94
|
},
|
|
82
95
|
"devDependencies": {
|
|
83
96
|
"@effect-rx/rx-react": "0.38.0",
|
|
84
|
-
"@effect/platform": "0.
|
|
97
|
+
"@effect/platform": "0.90.2",
|
|
85
98
|
"@types/lodash.orderby": "^4.6.9",
|
|
86
99
|
"@types/react": "~18.2.0",
|
|
87
100
|
"@types/react-dom": "~18.2.0",
|
|
88
|
-
"effect": "3.
|
|
101
|
+
"effect": "3.17.7",
|
|
89
102
|
"fast-check": "^3.19.0",
|
|
90
103
|
"react": "~18.2.0",
|
|
91
104
|
"react-dom": "~18.2.0",
|
|
92
105
|
"vite": "5.4.7",
|
|
93
|
-
"@dxos/echo-signals": "0.8.4-main.
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
97
|
-
"@dxos/
|
|
98
|
-
"@dxos/
|
|
106
|
+
"@dxos/echo-signals": "0.8.4-main.fd6878d",
|
|
107
|
+
"@dxos/plugin-search": "0.8.4-main.fd6878d",
|
|
108
|
+
"@dxos/random": "0.8.4-main.fd6878d",
|
|
109
|
+
"@dxos/react-ui-theme": "0.8.4-main.fd6878d",
|
|
110
|
+
"@dxos/test-utils": "0.8.4-main.fd6878d",
|
|
111
|
+
"@dxos/react-ui": "0.8.4-main.fd6878d",
|
|
112
|
+
"@dxos/storybook-utils": "0.8.4-main.fd6878d"
|
|
99
113
|
},
|
|
100
114
|
"peerDependencies": {
|
|
101
115
|
"@effect-rx/rx-react": "^0.34.1",
|
|
@@ -103,8 +117,8 @@
|
|
|
103
117
|
"effect": "^3.13.3",
|
|
104
118
|
"react": "~18.2.0",
|
|
105
119
|
"react-dom": "~18.2.0",
|
|
106
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
107
|
-
"@dxos/react-ui
|
|
120
|
+
"@dxos/react-ui-theme": "0.8.4-main.fd6878d",
|
|
121
|
+
"@dxos/react-ui": "0.8.4-main.fd6878d"
|
|
108
122
|
},
|
|
109
123
|
"publishConfig": {
|
|
110
124
|
"access": "public"
|
|
@@ -6,7 +6,7 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { DropdownMenu, useTranslation } from '@dxos/react-ui';
|
|
8
8
|
|
|
9
|
-
import { type
|
|
9
|
+
import { type ModalController, type TableModel } from '../../model';
|
|
10
10
|
import { translationKey } from '../../translations';
|
|
11
11
|
|
|
12
12
|
type ColumnActionsMenuProps = { model: TableModel; modals: ModalController };
|
|
@@ -4,20 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
// TODO(burdon): Remove dependency on echo-db.
|
|
8
|
+
import { type SchemaRegistry } from '@dxos/echo-db';
|
|
7
9
|
import { Popover } from '@dxos/react-ui';
|
|
8
10
|
import { FieldEditor } from '@dxos/react-ui-form';
|
|
9
11
|
import { type FieldType } from '@dxos/schema';
|
|
10
12
|
|
|
11
|
-
import { type
|
|
13
|
+
import { type ModalController, type TableModel } from '../../model';
|
|
12
14
|
|
|
13
|
-
type ColumnSettingsProps = {
|
|
15
|
+
type ColumnSettingsProps = {
|
|
16
|
+
registry?: SchemaRegistry;
|
|
17
|
+
model?: TableModel;
|
|
18
|
+
modals: ModalController;
|
|
19
|
+
onNewColumn: () => void;
|
|
20
|
+
};
|
|
14
21
|
|
|
15
|
-
export const ColumnSettings = ({ model, modals, onNewColumn }: ColumnSettingsProps) => {
|
|
22
|
+
export const ColumnSettings = ({ registry, model, modals, onNewColumn }: ColumnSettingsProps) => {
|
|
16
23
|
const [newField, setNewField] = useState<FieldType>();
|
|
17
24
|
const state = modals.state.value;
|
|
18
25
|
|
|
19
|
-
const space = model?.space;
|
|
20
|
-
|
|
21
26
|
useEffect(() => {
|
|
22
27
|
if (state?.type === 'columnSettings' && state.mode.type === 'create' && model?.projection) {
|
|
23
28
|
setNewField(model.projection.createFieldProjection());
|
|
@@ -33,11 +38,11 @@ export const ColumnSettings = ({ model, modals, onNewColumn }: ColumnSettingsPro
|
|
|
33
38
|
if (state?.type === 'columnSettings') {
|
|
34
39
|
const { mode } = state;
|
|
35
40
|
if (mode.type === 'edit') {
|
|
36
|
-
return model?.
|
|
41
|
+
return model?.projection?.fields.find((f) => f.id === mode.fieldId);
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
return undefined;
|
|
40
|
-
}, [model?.
|
|
45
|
+
}, [model?.projection?.fields, state]);
|
|
41
46
|
|
|
42
47
|
const field = existingField ?? newField;
|
|
43
48
|
|
|
@@ -47,11 +52,11 @@ export const ColumnSettings = ({ model, modals, onNewColumn }: ColumnSettingsPro
|
|
|
47
52
|
|
|
48
53
|
const handleCancel = useCallback(() => {
|
|
49
54
|
if (state?.type === 'columnSettings' && state.mode.type === 'create' && newField) {
|
|
50
|
-
model?.projection
|
|
55
|
+
model?.projection.deleteFieldProjection(newField.id);
|
|
51
56
|
}
|
|
52
57
|
}, [model?.projection, state, newField]);
|
|
53
58
|
|
|
54
|
-
if (!model?.
|
|
59
|
+
if (!model?.projection || !field) {
|
|
55
60
|
return null;
|
|
56
61
|
}
|
|
57
62
|
|
|
@@ -62,10 +67,9 @@ export const ColumnSettings = ({ model, modals, onNewColumn }: ColumnSettingsPro
|
|
|
62
67
|
<Popover.Content classNames='md:is-64'>
|
|
63
68
|
<Popover.Viewport>
|
|
64
69
|
<FieldEditor
|
|
65
|
-
view={model.view!}
|
|
66
70
|
projection={model.projection}
|
|
67
71
|
field={field}
|
|
68
|
-
registry={
|
|
72
|
+
registry={registry}
|
|
69
73
|
onSave={handleSave}
|
|
70
74
|
onCancel={handleCancel}
|
|
71
75
|
/>
|
|
@@ -5,19 +5,21 @@
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
import React, { useCallback, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import { live } from '@dxos/
|
|
8
|
+
import { live } from '@dxos/live-object';
|
|
9
|
+
// TODO(wittjosiah): Remove dependency on react-client.
|
|
10
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
9
11
|
import { Popover } from '@dxos/react-ui';
|
|
10
12
|
import { Form } from '@dxos/react-ui-form';
|
|
11
13
|
import { type GridScopedProps, useGridContext } from '@dxos/react-ui-grid';
|
|
12
14
|
|
|
13
|
-
import { type
|
|
15
|
+
import { type ModalController, type TableModel } from '../../model';
|
|
14
16
|
|
|
15
17
|
export type CreateRefPanelProps = { model?: TableModel; modals: ModalController };
|
|
16
18
|
|
|
17
19
|
// TODO(burdon): Factor out Space dependency (to plugin?)
|
|
18
20
|
export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<CreateRefPanelProps>) => {
|
|
19
21
|
const { id: gridId } = useGridContext('TableCellEditor', __gridScope);
|
|
20
|
-
const space = model?.
|
|
22
|
+
const space = model && getSpace(model?.view);
|
|
21
23
|
const state = modals.state.value;
|
|
22
24
|
|
|
23
25
|
const schema = useMemo<Schema.Schema<any> | undefined>(() => {
|
|
@@ -54,7 +56,7 @@ export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<C
|
|
|
54
56
|
}
|
|
55
57
|
}, [modals]);
|
|
56
58
|
|
|
57
|
-
if (!model?.
|
|
59
|
+
if (!model?.projection) {
|
|
58
60
|
return null;
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
8
|
import React, { useMemo, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { Obj } from '@dxos/echo';
|
|
@@ -17,10 +17,11 @@ import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
|
17
17
|
import { Testing } from '@dxos/schema/testing';
|
|
18
18
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
19
19
|
|
|
20
|
-
import { DynamicTable } from './DynamicTable';
|
|
21
20
|
import { type TableFeatures } from '../../model';
|
|
22
21
|
import { translations } from '../../translations';
|
|
23
22
|
|
|
23
|
+
import { DynamicTable } from './DynamicTable';
|
|
24
|
+
|
|
24
25
|
faker.seed(0);
|
|
25
26
|
|
|
26
27
|
const useTestPropertiesAndObjects = () => {
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Schema } from 'effect';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, { useCallback, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
8
|
import { type JsonSchemaType } from '@dxos/echo-schema';
|
|
9
9
|
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
10
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import { Table, type TableController } from './Table';
|
|
13
12
|
import { useTableModel } from '../../hooks';
|
|
14
13
|
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
15
|
-
import { getBaseSchema, makeDynamicTable
|
|
14
|
+
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '../../util';
|
|
15
|
+
|
|
16
|
+
import { Table, type TableController } from './Table';
|
|
16
17
|
|
|
17
18
|
type DynamicTableProps = ThemedClassName<{
|
|
18
19
|
name?: string; // TODO(burdon): Remove?
|
|
@@ -36,18 +37,23 @@ export const DynamicTable = ({
|
|
|
36
37
|
name = 'example.com/dynamic-table', // Rmove default or make random; this will lead to type collisions.
|
|
37
38
|
rows,
|
|
38
39
|
properties,
|
|
39
|
-
jsonSchema,
|
|
40
|
+
jsonSchema: _jsonSchema,
|
|
40
41
|
schema,
|
|
41
42
|
rowActions,
|
|
42
43
|
onRowClick,
|
|
43
44
|
onRowAction,
|
|
44
45
|
...props
|
|
45
46
|
}: DynamicTableProps) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
48
|
+
const { typename, jsonSchema } = useMemo(
|
|
49
|
+
() => getBaseSchema({ typename: name, properties, jsonSchema: _jsonSchema, schema }),
|
|
50
|
+
[name, properties, _jsonSchema, schema],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const { projection, view } = useMemo(
|
|
54
|
+
() => makeDynamicTable({ typename, jsonSchema, properties }),
|
|
55
|
+
[typename, jsonSchema, properties],
|
|
56
|
+
);
|
|
51
57
|
|
|
52
58
|
const tableRef = useRef<TableController>(null);
|
|
53
59
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -68,8 +74,9 @@ export const DynamicTable = ({
|
|
|
68
74
|
);
|
|
69
75
|
|
|
70
76
|
const model = useTableModel({
|
|
71
|
-
table,
|
|
72
77
|
rows,
|
|
78
|
+
view,
|
|
79
|
+
schema: jsonSchema,
|
|
73
80
|
projection,
|
|
74
81
|
features,
|
|
75
82
|
rowActions,
|
|
@@ -4,26 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import { getSchemaTypename, toJsonSchema } from '@dxos/echo-schema';
|
|
13
|
-
import { getAnnotation } from '@dxos/effect';
|
|
14
|
-
import { invariant } from '@dxos/invariant';
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { Type } from '@dxos/echo';
|
|
11
|
+
import { type JsonSchemaType } from '@dxos/echo-schema';
|
|
15
12
|
import { faker } from '@dxos/random';
|
|
16
13
|
import { useClient } from '@dxos/react-client';
|
|
17
14
|
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
18
|
-
import { DataType
|
|
19
|
-
import {
|
|
15
|
+
import { DataType } from '@dxos/schema';
|
|
16
|
+
import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
|
|
20
17
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
21
18
|
|
|
22
|
-
import { Table } from './Table';
|
|
23
19
|
import { useTableModel } from '../../hooks';
|
|
24
20
|
import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
|
|
25
21
|
import { translations } from '../../translations';
|
|
26
|
-
import {
|
|
22
|
+
import { TableView } from '../../types';
|
|
23
|
+
import { createTable } from '../../util';
|
|
24
|
+
|
|
25
|
+
import { Table } from './Table';
|
|
27
26
|
|
|
28
27
|
faker.seed(1);
|
|
29
28
|
const generator: ValueGenerator = faker as any;
|
|
@@ -33,35 +32,37 @@ const generator: ValueGenerator = faker as any;
|
|
|
33
32
|
// TODO(burdon): Reconcile schemas types and utils (see API PR).
|
|
34
33
|
// TODO(burdon): Base type for T (with id); see ECHO API PR?
|
|
35
34
|
const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
35
|
+
const client = useClient();
|
|
36
36
|
const { space } = useClientProvider();
|
|
37
|
-
|
|
38
|
-
const jsonSchema =
|
|
39
|
-
const table = useMemo(() => {
|
|
40
|
-
if (!space) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
const typename = getSchemaTypename(schema);
|
|
44
|
-
invariant(typename);
|
|
45
|
-
const name = getAnnotation<string>(SchemaAST.TitleAnnotationId)(schema.ast) ?? typename;
|
|
46
|
-
const view = createView({ name, typename, jsonSchema });
|
|
47
|
-
return space.db.add(Obj.make(TableType, { view: Ref.make(view) }));
|
|
48
|
-
}, [schema, space, jsonSchema]);
|
|
49
|
-
|
|
50
|
-
const projection = useMemo(() => {
|
|
51
|
-
if (!table?.view?.target) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// TODO(burdon): Just pass in view? Reuse same jsonSchema instance? View determines if mutable, etc.
|
|
56
|
-
return new ViewProjection(jsonSchema, table.view.target);
|
|
57
|
-
}, [jsonSchema, table]);
|
|
37
|
+
const [view, setView] = useState<DataType.View>();
|
|
38
|
+
const [jsonSchema, setJsonSchema] = useState<JsonSchemaType>();
|
|
58
39
|
|
|
59
40
|
const features = useMemo<TableFeatures>(
|
|
60
41
|
() => ({ schemaEditable: false, dataEditable: true, selection: { enabled: false } }),
|
|
61
42
|
[],
|
|
62
43
|
);
|
|
63
44
|
|
|
64
|
-
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!space) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const timeout = setTimeout(async () => {
|
|
51
|
+
const {
|
|
52
|
+
jsonSchema,
|
|
53
|
+
schema: effectSchema,
|
|
54
|
+
view,
|
|
55
|
+
} = await createTable({ client, space, typename: Type.getTypename(schema) });
|
|
56
|
+
setJsonSchema(jsonSchema);
|
|
57
|
+
setView(view);
|
|
58
|
+
space.db.add(view);
|
|
59
|
+
await space.db.schemaRegistry.register([effectSchema]);
|
|
60
|
+
});
|
|
61
|
+
return () => clearTimeout(timeout);
|
|
62
|
+
}, [client, space, schema]);
|
|
63
|
+
|
|
64
|
+
const model = useTableModel<TableRow>({ view, schema: jsonSchema, rows: [], features });
|
|
65
|
+
|
|
65
66
|
useEffect(() => {
|
|
66
67
|
if (!model || !space) {
|
|
67
68
|
return;
|
|
@@ -107,7 +108,7 @@ const meta: Meta<typeof DefaultStory> = {
|
|
|
107
108
|
parameters: { translations, controls: { disable: true } },
|
|
108
109
|
decorators: [
|
|
109
110
|
withClientProvider({
|
|
110
|
-
types: [
|
|
111
|
+
types: [DataType.View, DataType.Organization, DataType.Person, TableView],
|
|
111
112
|
createIdentity: true,
|
|
112
113
|
createSpace: true,
|
|
113
114
|
}),
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { DropdownMenu, useTranslation } from '@dxos/react-ui';
|
|
7
|
+
import { DropdownMenu, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
8
|
|
|
9
|
-
import { type
|
|
9
|
+
import { type ModalController, type TableModel } from '../../model';
|
|
10
10
|
import { translationKey } from '../../translations';
|
|
11
11
|
|
|
12
12
|
type RowActionsMenuProps = { model: TableModel; modals: ModalController };
|
|
@@ -38,7 +38,7 @@ export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
|
38
38
|
model.handleRowAction(action.id, state.rowIndex);
|
|
39
39
|
}}
|
|
40
40
|
>
|
|
41
|
-
{
|
|
41
|
+
{toLocalizedString(action.label, t)}
|
|
42
42
|
</DropdownMenu.Item>
|
|
43
43
|
))}
|
|
44
44
|
</DropdownMenu.Viewport>
|