@dxos/react-ui-table 0.8.3 → 0.8.4-main.5acf9ea
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-5XLSHLOG.mjs +1751 -0
- package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +7 -0
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +18 -0
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +246 -1641
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +121 -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-Y66YLSTC.mjs +1752 -0
- package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +246 -1641
- 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 +122 -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/ColumnSettings.d.ts +3 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +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/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/Table/relations.stories.d.ts +1 -1
- package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +2 -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 +3 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.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/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +13 -0
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +7 -6
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.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 +56 -20
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +8 -0
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +2 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts +3 -0
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
- 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 +3 -4
- package/dist/types/src/translations.d.ts.map +1 -1
- 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 +15 -1
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +8 -11
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +55 -43
- package/src/components/Table/ColumnSettings.tsx +14 -10
- package/src/components/Table/CreateRefPanel.tsx +5 -3
- package/src/components/Table/DynamicTable.stories.tsx +2 -2
- package/src/components/Table/DynamicTable.tsx +13 -7
- package/src/components/Table/Table.stories.tsx +104 -148
- package/src/components/Table/Table.tsx +57 -34
- package/src/components/Table/relations.stories.tsx +27 -35
- package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +30 -21
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +24 -28
- package/src/components/TableCellEditor/TableCellEditor.tsx +79 -21
- package/src/components/testing.ts +7 -24
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useAddRow.ts +36 -0
- package/src/hooks/useTableModel.ts +20 -16
- package/src/index.ts +1 -2
- package/src/model/selection-model.ts +4 -2
- package/src/model/table-model.test.ts +7 -8
- package/src/model/table-model.ts +267 -78
- package/src/model/table-presentation.test.ts +6 -7
- package/src/model/table-presentation.ts +215 -132
- package/src/model/table-sorting.ts +9 -9
- package/src/playwright/playwright.config.ts +17 -0
- package/src/playwright/smoke.spec.ts +21 -20
- package/src/testing/index.ts +5 -0
- package/src/testing/useTestTableModel.ts +122 -0
- package/src/translations.ts +5 -3
- package/src/types/index.ts +2 -2
- package/src/types/schema.ts +16 -0
- package/src/util/dynamic-table.ts +19 -17
- package/src/util/table-buttons.ts +24 -1
- package/src/util/table.ts +33 -111
- package/dist/lib/browser/chunk-TL7CKQQV.mjs +0 -27
- package/dist/lib/browser/chunk-TL7CKQQV.mjs.map +0 -7
- package/dist/lib/node/chunk-O2VPBNS5.cjs +0 -50
- package/dist/lib/node/chunk-O2VPBNS5.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -2739
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/types/index.cjs +0 -31
- package/dist/lib/node/types/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-GBT6GD4G.mjs +0 -29
- package/dist/lib/node-esm/chunk-GBT6GD4G.mjs.map +0 -7
- package/dist/types/src/types/table.d.ts +0 -56
- package/dist/types/src/types/table.d.ts.map +0 -1
- package/src/playwright/playwright.config.cts +0 -18
- 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.
|
|
3
|
+
"version": "0.8.4-main.5acf9ea",
|
|
4
4
|
"description": "A table component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -12,17 +12,26 @@
|
|
|
12
12
|
"./deprecated": {
|
|
13
13
|
"types": "./dist/types/src/deprecated/index.d.ts",
|
|
14
14
|
"browser": "./dist/lib/browser/deprecated/index.mjs",
|
|
15
|
-
"node": "./dist/lib/node-esm/deprecated/index.mjs"
|
|
15
|
+
"node": "./dist/lib/node-esm/deprecated/index.mjs",
|
|
16
|
+
"source": "./src/deprecated/index.ts"
|
|
16
17
|
},
|
|
17
18
|
".": {
|
|
18
19
|
"types": "./dist/types/src/index.d.ts",
|
|
19
20
|
"browser": "./dist/lib/browser/index.mjs",
|
|
20
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
21
|
+
"node": "./dist/lib/node-esm/index.mjs",
|
|
22
|
+
"source": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"./testing": {
|
|
25
|
+
"types": "./dist/types/src/testing/index.d.ts",
|
|
26
|
+
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
27
|
+
"node": "./dist/lib/node-esm/testing/index.mjs",
|
|
28
|
+
"source": "./src/testing/index.ts"
|
|
21
29
|
},
|
|
22
30
|
"./types": {
|
|
23
31
|
"types": "./dist/types/src/types/index.d.ts",
|
|
24
32
|
"browser": "./dist/lib/browser/types/index.mjs",
|
|
25
|
-
"node": "./dist/lib/node-esm/types/index.mjs"
|
|
33
|
+
"node": "./dist/lib/node-esm/types/index.mjs",
|
|
34
|
+
"source": "./src/types/index.ts"
|
|
26
35
|
}
|
|
27
36
|
},
|
|
28
37
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -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,60 +65,60 @@
|
|
|
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.
|
|
57
|
-
"@dxos/debug": "0.8.
|
|
58
|
-
"@dxos/echo": "0.8.
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/effect": "0.8.
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/react-ui-
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/react-ui-grid": "0.8.
|
|
73
|
-
"@dxos/react-ui-menu": "0.8.
|
|
74
|
-
"@dxos/react-ui-searchlist": "0.8.
|
|
75
|
-
"@dxos/react-ui-
|
|
76
|
-
"@dxos/react-ui-
|
|
77
|
-
"@dxos/react-ui-
|
|
78
|
-
"@dxos/react-ui-
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/
|
|
68
|
+
"@dxos/context": "0.8.4-main.5acf9ea",
|
|
69
|
+
"@dxos/debug": "0.8.4-main.5acf9ea",
|
|
70
|
+
"@dxos/echo": "0.8.4-main.5acf9ea",
|
|
71
|
+
"@dxos/echo-schema": "0.8.4-main.5acf9ea",
|
|
72
|
+
"@dxos/echo-db": "0.8.4-main.5acf9ea",
|
|
73
|
+
"@dxos/effect": "0.8.4-main.5acf9ea",
|
|
74
|
+
"@dxos/invariant": "0.8.4-main.5acf9ea",
|
|
75
|
+
"@dxos/keys": "0.8.4-main.5acf9ea",
|
|
76
|
+
"@dxos/lit-grid": "0.8.4-main.5acf9ea",
|
|
77
|
+
"@dxos/live-object": "0.8.4-main.5acf9ea",
|
|
78
|
+
"@dxos/log": "0.8.4-main.5acf9ea",
|
|
79
|
+
"@dxos/plugin-search": "0.8.4-main.5acf9ea",
|
|
80
|
+
"@dxos/random": "0.8.4-main.5acf9ea",
|
|
81
|
+
"@dxos/react-client": "0.8.4-main.5acf9ea",
|
|
82
|
+
"@dxos/react-ui-attention": "0.8.4-main.5acf9ea",
|
|
83
|
+
"@dxos/react-ui-editor": "0.8.4-main.5acf9ea",
|
|
84
|
+
"@dxos/react-ui-grid": "0.8.4-main.5acf9ea",
|
|
85
|
+
"@dxos/react-ui-menu": "0.8.4-main.5acf9ea",
|
|
86
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.5acf9ea",
|
|
87
|
+
"@dxos/react-ui-stack": "0.8.4-main.5acf9ea",
|
|
88
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.5acf9ea",
|
|
89
|
+
"@dxos/react-ui-form": "0.8.4-main.5acf9ea",
|
|
90
|
+
"@dxos/react-ui-tag-picker": "0.8.4-main.5acf9ea",
|
|
91
|
+
"@dxos/schema": "0.8.4-main.5acf9ea",
|
|
92
|
+
"@dxos/react-ui-types": "0.8.4-main.5acf9ea",
|
|
93
|
+
"@dxos/util": "0.8.4-main.5acf9ea"
|
|
81
94
|
},
|
|
82
95
|
"devDependencies": {
|
|
83
|
-
"@effect-rx/rx-react": "
|
|
84
|
-
"@effect/platform": "0.
|
|
85
|
-
"@phosphor-icons/react": "^2.1.5",
|
|
96
|
+
"@effect-rx/rx-react": "0.38.0",
|
|
97
|
+
"@effect/platform": "0.89.0",
|
|
86
98
|
"@types/lodash.orderby": "^4.6.9",
|
|
87
99
|
"@types/react": "~18.2.0",
|
|
88
100
|
"@types/react-dom": "~18.2.0",
|
|
89
|
-
"effect": "3.
|
|
101
|
+
"effect": "3.17.0",
|
|
90
102
|
"fast-check": "^3.19.0",
|
|
91
103
|
"react": "~18.2.0",
|
|
92
104
|
"react-dom": "~18.2.0",
|
|
93
105
|
"vite": "5.4.7",
|
|
94
|
-
"@dxos/
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/
|
|
97
|
-
"@dxos/react-ui": "0.8.
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/
|
|
106
|
+
"@dxos/echo-signals": "0.8.4-main.5acf9ea",
|
|
107
|
+
"@dxos/plugin-search": "0.8.4-main.5acf9ea",
|
|
108
|
+
"@dxos/random": "0.8.4-main.5acf9ea",
|
|
109
|
+
"@dxos/react-ui": "0.8.4-main.5acf9ea",
|
|
110
|
+
"@dxos/storybook-utils": "0.8.4-main.5acf9ea",
|
|
111
|
+
"@dxos/react-ui-theme": "0.8.4-main.5acf9ea",
|
|
112
|
+
"@dxos/test-utils": "0.8.4-main.5acf9ea"
|
|
100
113
|
},
|
|
101
114
|
"peerDependencies": {
|
|
102
115
|
"@effect-rx/rx-react": "^0.34.1",
|
|
103
|
-
"@effect/platform": "0.80.12",
|
|
104
|
-
"@phosphor-icons/react": "^2.1.5",
|
|
116
|
+
"@effect/platform": "^0.80.12",
|
|
105
117
|
"effect": "^3.13.3",
|
|
106
118
|
"react": "~18.2.0",
|
|
107
119
|
"react-dom": "~18.2.0",
|
|
108
|
-
"@dxos/react-ui": "0.8.
|
|
109
|
-
"@dxos/react-ui-theme": "0.8.
|
|
120
|
+
"@dxos/react-ui": "0.8.4-main.5acf9ea",
|
|
121
|
+
"@dxos/react-ui-theme": "0.8.4-main.5acf9ea"
|
|
110
122
|
},
|
|
111
123
|
"publishConfig": {
|
|
112
124
|
"access": "public"
|
|
@@ -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
13
|
import { type TableModel, type ModalController } 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,7 +5,9 @@
|
|
|
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';
|
|
@@ -17,7 +19,7 @@ export type CreateRefPanelProps = { model?: TableModel; modals: ModalController
|
|
|
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 StoryObj, type Meta } from '@storybook/react';
|
|
7
|
+
import { type StoryObj, type Meta } from '@storybook/react-vite';
|
|
8
8
|
import React, { useMemo, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { Obj } from '@dxos/echo';
|
|
@@ -19,7 +19,7 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
|
19
19
|
|
|
20
20
|
import { DynamicTable } from './DynamicTable';
|
|
21
21
|
import { type TableFeatures } from '../../model';
|
|
22
|
-
import translations from '../../translations';
|
|
22
|
+
import { translations } from '../../translations';
|
|
23
23
|
|
|
24
24
|
faker.seed(0);
|
|
25
25
|
|
|
@@ -36,18 +36,23 @@ export const DynamicTable = ({
|
|
|
36
36
|
name = 'example.com/dynamic-table', // Rmove default or make random; this will lead to type collisions.
|
|
37
37
|
rows,
|
|
38
38
|
properties,
|
|
39
|
-
jsonSchema,
|
|
39
|
+
jsonSchema: _jsonSchema,
|
|
40
40
|
schema,
|
|
41
41
|
rowActions,
|
|
42
42
|
onRowClick,
|
|
43
43
|
onRowAction,
|
|
44
44
|
...props
|
|
45
45
|
}: DynamicTableProps) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
47
|
+
const { typename, jsonSchema } = useMemo(
|
|
48
|
+
() => getBaseSchema({ typename: name, properties, jsonSchema: _jsonSchema, schema }),
|
|
49
|
+
[name, properties, _jsonSchema, schema],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const { projection, view } = useMemo(
|
|
53
|
+
() => makeDynamicTable({ typename, jsonSchema, properties }),
|
|
54
|
+
[typename, jsonSchema, properties],
|
|
55
|
+
);
|
|
51
56
|
|
|
52
57
|
const tableRef = useRef<TableController>(null);
|
|
53
58
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -68,8 +73,9 @@ export const DynamicTable = ({
|
|
|
68
73
|
);
|
|
69
74
|
|
|
70
75
|
const model = useTableModel({
|
|
71
|
-
table,
|
|
72
76
|
rows,
|
|
77
|
+
view,
|
|
78
|
+
schema: jsonSchema,
|
|
73
79
|
projection,
|
|
74
80
|
features,
|
|
75
81
|
rowActions,
|
|
@@ -4,150 +4,86 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type StoryObj, type Meta } from '@storybook/react';
|
|
7
|
+
import { type StoryObj, type Meta } from '@storybook/react-vite';
|
|
8
8
|
import { Schema } from 'effect';
|
|
9
|
-
import React, { useCallback
|
|
9
|
+
import React, { useCallback } from 'react';
|
|
10
10
|
|
|
11
11
|
import { Obj, Type } from '@dxos/echo';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
FormatEnum,
|
|
14
|
+
EchoObject,
|
|
15
|
+
GeneratorAnnotation,
|
|
16
|
+
FormatAnnotation,
|
|
17
|
+
PropertyMetaAnnotationId,
|
|
18
|
+
} from '@dxos/echo-schema';
|
|
13
19
|
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
15
20
|
import { faker } from '@dxos/random';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
21
|
+
import { PublicKey } from '@dxos/react-client';
|
|
22
|
+
import { live, type Space } from '@dxos/react-client/echo';
|
|
23
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
19
24
|
import { ViewEditor } from '@dxos/react-ui-form';
|
|
20
25
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
21
|
-
import { getSchemaFromPropertyDefinitions,
|
|
26
|
+
import { getSchemaFromPropertyDefinitions, DataType } from '@dxos/schema';
|
|
22
27
|
import { Testing, createObjectFactory } from '@dxos/schema/testing';
|
|
23
28
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
24
29
|
|
|
25
|
-
import { Table
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
import {
|
|
30
|
-
import { initializeTable } from '../../util';
|
|
30
|
+
import { Table } from './Table';
|
|
31
|
+
import { useTestTableModel } from '../../testing';
|
|
32
|
+
import { translations } from '../../translations';
|
|
33
|
+
import { TableView } from '../../types';
|
|
34
|
+
import { createTable } from '../../util';
|
|
31
35
|
import { TableToolbar } from '../TableToolbar';
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const handleRowOrderChange = useCallback(() => {
|
|
72
|
-
tableRef.current?.update?.();
|
|
73
|
-
}, []);
|
|
74
|
-
|
|
75
|
-
const handleInsertRow = useCallback(() => {
|
|
76
|
-
if (space && schema) {
|
|
77
|
-
space.db.add(live(schema, {}));
|
|
78
|
-
}
|
|
79
|
-
}, [space, schema]);
|
|
80
|
-
|
|
81
|
-
const handleDeleteRows = useCallback(
|
|
82
|
-
(_: number, objects: any[]) => {
|
|
83
|
-
for (const object of objects) {
|
|
84
|
-
space?.db.remove(object);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
[space],
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const handleDeleteColumn = useCallback(
|
|
91
|
-
(fieldId: string) => {
|
|
92
|
-
if (projection) {
|
|
93
|
-
projection.deleteFieldProjection(fieldId);
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
[projection],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const model = useTableModel({
|
|
100
|
-
table,
|
|
101
|
-
projection,
|
|
102
|
-
features,
|
|
103
|
-
rows: filteredObjects,
|
|
104
|
-
onInsertRow: handleInsertRow,
|
|
105
|
-
onDeleteRows: handleDeleteRows,
|
|
106
|
-
onDeleteColumn: handleDeleteColumn,
|
|
107
|
-
onCellUpdate: handleCellUpdate,
|
|
108
|
-
onRowOrderChange: handleRowOrderChange,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const handleSaveView = useCallback(() => {
|
|
112
|
-
model?.saveView();
|
|
113
|
-
}, [model]);
|
|
114
|
-
|
|
115
|
-
const presentation = useMemo(() => {
|
|
116
|
-
if (model) {
|
|
117
|
-
return new TablePresentation(model);
|
|
118
|
-
}
|
|
119
|
-
}, [model]);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
schema,
|
|
123
|
-
table,
|
|
124
|
-
tableRef,
|
|
125
|
-
model,
|
|
126
|
-
presentation,
|
|
127
|
-
space,
|
|
128
|
-
client,
|
|
129
|
-
handleInsertRow,
|
|
130
|
-
handleSaveView,
|
|
131
|
-
handleDeleteRows,
|
|
132
|
-
handleDeleteColumn,
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const StoryViewEditor = () => {
|
|
137
|
-
const { table, space, schema, handleDeleteColumn } = useTestTableModel();
|
|
138
|
-
|
|
37
|
+
const TestSchema = Schema.Struct({
|
|
38
|
+
// TODO(wittjosiah): Should be title. Currently name to work with default label.
|
|
39
|
+
name: Schema.optional(Schema.String).annotations({ title: 'Title' }),
|
|
40
|
+
urgent: Schema.optional(Schema.Boolean).annotations({ title: 'Urgent' }),
|
|
41
|
+
status: Schema.optional(
|
|
42
|
+
Schema.Literal('todo', 'in-progress', 'done')
|
|
43
|
+
.pipe(FormatAnnotation.set(FormatEnum.SingleSelect))
|
|
44
|
+
.annotations({
|
|
45
|
+
title: 'Status',
|
|
46
|
+
[PropertyMetaAnnotationId]: {
|
|
47
|
+
singleSelect: {
|
|
48
|
+
options: [
|
|
49
|
+
{ id: 'todo', title: 'Todo', color: 'indigo' },
|
|
50
|
+
{ id: 'in-progress', title: 'In Progress', color: 'purple' },
|
|
51
|
+
{ id: 'done', title: 'Done', color: 'amber' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
),
|
|
57
|
+
description: Schema.optional(Schema.String).annotations({ title: 'Description' }),
|
|
58
|
+
parent: Schema.optional(Schema.suspend((): Type.Ref<TestSchema> => Type.Ref(TestSchema))).annotations({
|
|
59
|
+
title: 'Parent',
|
|
60
|
+
}),
|
|
61
|
+
}).pipe(Type.Obj({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }));
|
|
62
|
+
interface TestSchema extends Schema.Schema.Type<typeof TestSchema> {}
|
|
63
|
+
|
|
64
|
+
const StoryViewEditor = ({
|
|
65
|
+
view,
|
|
66
|
+
schema,
|
|
67
|
+
space,
|
|
68
|
+
handleDeleteColumn,
|
|
69
|
+
}: {
|
|
70
|
+
view?: DataType.View;
|
|
71
|
+
schema?: Schema.Schema.AnyNoContext;
|
|
72
|
+
space?: Space;
|
|
73
|
+
handleDeleteColumn: (fieldId: string) => void;
|
|
74
|
+
}) => {
|
|
139
75
|
const handleTypenameChanged = useCallback(
|
|
140
76
|
(typename: string) => {
|
|
141
77
|
invariant(schema);
|
|
142
78
|
invariant(Type.isMutable(schema));
|
|
143
79
|
schema.updateTypename(typename);
|
|
144
|
-
invariant(
|
|
145
|
-
|
|
80
|
+
invariant(view);
|
|
81
|
+
view.query.typename = typename;
|
|
146
82
|
},
|
|
147
|
-
[schema,
|
|
83
|
+
[schema, view],
|
|
148
84
|
);
|
|
149
85
|
|
|
150
|
-
if (!
|
|
86
|
+
if (!view || !schema) {
|
|
151
87
|
return null;
|
|
152
88
|
}
|
|
153
89
|
|
|
@@ -155,7 +91,7 @@ const StoryViewEditor = () => {
|
|
|
155
91
|
<ViewEditor
|
|
156
92
|
registry={space?.db.schemaRegistry}
|
|
157
93
|
schema={schema}
|
|
158
|
-
view={
|
|
94
|
+
view={view}
|
|
159
95
|
onTypenameChanged={handleTypenameChanged}
|
|
160
96
|
onDelete={handleDeleteColumn}
|
|
161
97
|
/>
|
|
@@ -167,9 +103,20 @@ const StoryViewEditor = () => {
|
|
|
167
103
|
//
|
|
168
104
|
|
|
169
105
|
const DefaultStory = () => {
|
|
170
|
-
const {
|
|
106
|
+
const {
|
|
107
|
+
space,
|
|
108
|
+
schema,
|
|
109
|
+
view,
|
|
110
|
+
tableRef,
|
|
111
|
+
model,
|
|
112
|
+
presentation,
|
|
113
|
+
client,
|
|
114
|
+
handleInsertRow,
|
|
115
|
+
handleSaveView,
|
|
116
|
+
handleDeleteColumn,
|
|
117
|
+
} = useTestTableModel();
|
|
171
118
|
|
|
172
|
-
if (!schema || !
|
|
119
|
+
if (!schema || !view) {
|
|
173
120
|
return <div />;
|
|
174
121
|
}
|
|
175
122
|
|
|
@@ -189,9 +136,9 @@ const DefaultStory = () => {
|
|
|
189
136
|
</Table.Root>
|
|
190
137
|
</div>
|
|
191
138
|
<div className='flex flex-col h-full border-l border-separator overflow-y-auto'>
|
|
192
|
-
<StoryViewEditor />
|
|
139
|
+
<StoryViewEditor view={view} schema={schema} space={space} handleDeleteColumn={handleDeleteColumn} />
|
|
193
140
|
<SyntaxHighlighter language='json' className='w-full text-xs'>
|
|
194
|
-
{JSON.stringify({ view
|
|
141
|
+
{JSON.stringify({ view, schema }, null, 2)}
|
|
195
142
|
</SyntaxHighlighter>
|
|
196
143
|
</div>
|
|
197
144
|
</div>
|
|
@@ -209,26 +156,36 @@ type StoryProps = { rows?: number };
|
|
|
209
156
|
const meta: Meta<StoryProps> = {
|
|
210
157
|
title: 'ui/react-ui-table/Table',
|
|
211
158
|
render: DefaultStory,
|
|
212
|
-
parameters: {
|
|
159
|
+
parameters: {
|
|
160
|
+
translations,
|
|
161
|
+
layout: 'fullscreen',
|
|
162
|
+
controls: {
|
|
163
|
+
disable: true,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
213
166
|
decorators: [
|
|
167
|
+
withTheme,
|
|
168
|
+
withLayout({ fullscreen: true }),
|
|
214
169
|
withClientProvider({
|
|
215
|
-
types: [
|
|
170
|
+
types: [DataType.View, TableView],
|
|
216
171
|
createIdentity: true,
|
|
217
172
|
createSpace: true,
|
|
218
173
|
onSpaceCreated: async ({ client, space }) => {
|
|
219
|
-
const
|
|
220
|
-
const
|
|
174
|
+
const [schema] = await space.db.schemaRegistry.register([TestSchema]);
|
|
175
|
+
const { view } = await createTable({ client, space, typename: schema.typename });
|
|
176
|
+
space.db.add(view);
|
|
177
|
+
|
|
221
178
|
Array.from({ length: 10 }).map(() => {
|
|
222
179
|
return space.db.add(
|
|
223
|
-
|
|
224
|
-
name: faker.
|
|
180
|
+
Obj.make(schema, {
|
|
181
|
+
name: faker.lorem.sentence(),
|
|
182
|
+
status: faker.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
|
|
183
|
+
description: faker.lorem.paragraph(),
|
|
225
184
|
}),
|
|
226
185
|
);
|
|
227
186
|
});
|
|
228
187
|
},
|
|
229
188
|
}),
|
|
230
|
-
withLayout({ fullscreen: true }),
|
|
231
|
-
withTheme,
|
|
232
189
|
],
|
|
233
190
|
};
|
|
234
191
|
|
|
@@ -241,18 +198,17 @@ export const StaticSchema: StoryObj = {
|
|
|
241
198
|
parameters: { translations },
|
|
242
199
|
decorators: [
|
|
243
200
|
withClientProvider({
|
|
244
|
-
types: [
|
|
201
|
+
types: [DataType.View, TableView, Testing.Contact, Testing.Organization],
|
|
245
202
|
createIdentity: true,
|
|
246
203
|
createSpace: true,
|
|
247
204
|
onSpaceCreated: async ({ client, space }) => {
|
|
248
|
-
const
|
|
249
|
-
|
|
205
|
+
const { view } = await createTable({ client, space, typename: Testing.Contact.typename });
|
|
206
|
+
space.db.add(view);
|
|
250
207
|
|
|
251
208
|
const factory = createObjectFactory(space.db, faker as any);
|
|
252
209
|
await factory([
|
|
253
|
-
|
|
210
|
+
{ type: Testing.Contact, count: 10 },
|
|
254
211
|
// { type: Testing.Organization, count: 1 },
|
|
255
|
-
{ type: ContactWithArrayOfEmails, count: 10 },
|
|
256
212
|
]);
|
|
257
213
|
},
|
|
258
214
|
}),
|
|
@@ -283,12 +239,12 @@ export const ArrayOfObjects: StoryObj = {
|
|
|
283
239
|
parameters: { translations },
|
|
284
240
|
decorators: [
|
|
285
241
|
withClientProvider({
|
|
286
|
-
types: [
|
|
242
|
+
types: [DataType.View, TableView, Testing.Contact, Testing.Organization, ContactWithArrayOfEmails],
|
|
287
243
|
createIdentity: true,
|
|
288
244
|
createSpace: true,
|
|
289
245
|
onSpaceCreated: async ({ client, space }) => {
|
|
290
|
-
const
|
|
291
|
-
|
|
246
|
+
const { view } = await createTable({ client, space, typename: ContactWithArrayOfEmails.typename });
|
|
247
|
+
space.db.add(view);
|
|
292
248
|
|
|
293
249
|
const factory = createObjectFactory(space.db, faker as any);
|
|
294
250
|
await factory([
|
|
@@ -309,7 +265,7 @@ export const Tags: Meta<StoryProps> = {
|
|
|
309
265
|
parameters: { translations },
|
|
310
266
|
decorators: [
|
|
311
267
|
withClientProvider({
|
|
312
|
-
types: [
|
|
268
|
+
types: [DataType.View, TableView],
|
|
313
269
|
createIdentity: true,
|
|
314
270
|
createSpace: true,
|
|
315
271
|
onSpaceCreated: async ({ client, space }) => {
|
|
@@ -340,8 +296,8 @@ export const Tags: Meta<StoryProps> = {
|
|
|
340
296
|
const [storedSchema] = await space.db.schemaRegistry.register([schema]);
|
|
341
297
|
|
|
342
298
|
// Initialize table.
|
|
343
|
-
const
|
|
344
|
-
|
|
299
|
+
const { view } = await createTable({ client, space, typename });
|
|
300
|
+
space.db.add(view);
|
|
345
301
|
|
|
346
302
|
// Populate.
|
|
347
303
|
Array.from({ length: 10 }).map(() => {
|