@dxos/react-ui-table 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b
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-CJQ6T4LL.mjs +77 -0
- package/dist/lib/browser/chunk-CJQ6T4LL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-V7A7ZA5E.mjs} +576 -544
- package/dist/lib/browser/chunk-V7A7ZA5E.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +694 -760
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -27
- 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-Y66YLSTC.mjs → chunk-P73ALX3N.mjs} +576 -544
- package/dist/lib/node-esm/chunk-P73ALX3N.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs +78 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +694 -760
- 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 +16 -27
- 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 +2 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -3
- 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 +37 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
- 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 +13 -9
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
- 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/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +14 -9
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +11 -18
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
- 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 +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -5
- 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 +3 -2
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +5 -6
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +0 -7
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +14 -14
- 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 +9 -6
- package/dist/types/src/model/table-sorting.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 +19 -34
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts +28 -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 +10 -11
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- 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/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -51
- package/src/components/Table/ColumnActionsMenu.tsx +5 -2
- package/src/components/Table/ColumnSettings.tsx +3 -4
- package/src/components/Table/DynamicTable.stories.tsx +21 -19
- package/src/components/Table/DynamicTable.tsx +24 -18
- package/src/components/Table/Relations.stories.tsx +233 -0
- package/src/components/Table/RowActionsMenu.tsx +23 -15
- package/src/components/Table/Table.stories.tsx +104 -99
- package/src/components/Table/Table.tsx +338 -295
- package/src/components/TableCellEditor/CellValidationMessage.tsx +2 -2
- package/src/components/TableCellEditor/FormCellEditor.tsx +143 -39
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +30 -66
- package/src/components/TableCellEditor/TableCellEditor.tsx +86 -236
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +34 -24
- package/src/components/testing.ts +4 -4
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +7 -5
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +13 -15
- package/src/model/modal-controller.ts +1 -29
- package/src/model/selection-model.ts +3 -2
- package/src/model/table-model.test.ts +21 -12
- package/src/model/table-model.ts +64 -58
- package/src/model/table-presentation.test.ts +25 -23
- package/src/model/table-presentation.ts +82 -41
- package/src/model/table-sorting.ts +32 -14
- package/src/playwright/TableManager.ts +5 -5
- package/src/playwright/smoke.spec.ts +132 -38
- package/src/testing/useTestTableModel.ts +32 -24
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +90 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +21 -27
- package/src/util/index.ts +0 -1
- package/src/util/schema.ts +4 -4
- package/src/util/table-buttons.ts +4 -3
- package/src/util/table-controls.ts +4 -1
- package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y66YLSTC.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/components/Table/relations.stories.d.ts +0 -9
- package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -8
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -11
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/Table/relations.stories.tsx +0 -116
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/types/schema.ts +0 -16
- package/src/util/table.ts +0 -49
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type GridScopedProps, useGridContext } from '@dxos/react-ui-grid';
|
|
8
8
|
|
|
9
9
|
export type CellValidationMessageProps = {
|
|
10
10
|
validationError: string | null;
|
|
@@ -12,9 +12,9 @@ export type CellValidationMessageProps = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const CellValidationMessage = ({
|
|
15
|
+
__gridScope,
|
|
15
16
|
validationError,
|
|
16
17
|
variant = 'error',
|
|
17
|
-
__gridScope,
|
|
18
18
|
}: GridScopedProps<CellValidationMessageProps>) => {
|
|
19
19
|
const { editing, editBox: box } = useGridContext('GridSheetCellEditor', __gridScope);
|
|
20
20
|
|
|
@@ -2,32 +2,50 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Filter, Obj, type Type } from '@dxos/echo';
|
|
9
|
+
import { Format, Ref, getValue } from '@dxos/echo/internal';
|
|
9
10
|
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { getSnapshot } from '@dxos/live-object';
|
|
12
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
13
|
+
import { type Label, Popover } from '@dxos/react-ui';
|
|
14
|
+
import { Form, type FormRootProps, omitId } from '@dxos/react-ui-form';
|
|
12
15
|
import { parseCellIndex, useGridContext } from '@dxos/react-ui-grid';
|
|
13
16
|
import { type FieldProjection } from '@dxos/schema';
|
|
14
|
-
import { getDeep, setDeep } from '@dxos/util';
|
|
17
|
+
import { getDeep, isTruthy, setDeep } from '@dxos/util';
|
|
15
18
|
|
|
16
|
-
import { type TableModel } from '../../model';
|
|
19
|
+
import { type ModalController, type TableModel, type TableRow } from '../../model';
|
|
20
|
+
import { translationKey } from '../../translations';
|
|
17
21
|
import { narrowSchema } from '../../util';
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const createOptionLabel: Label = ['create new object label', { ns: translationKey }];
|
|
24
|
+
|
|
25
|
+
export type OnCreateHandler = (schema: Schema.Schema.AnyNoContext, values: any) => Parameters<typeof Ref.make>[0];
|
|
26
|
+
|
|
27
|
+
export type FormCellEditorProps<T extends Type.Entity.Any = Type.Entity.Any> = {
|
|
28
|
+
__gridScope: any;
|
|
29
|
+
schema?: T;
|
|
21
30
|
model?: TableModel;
|
|
22
|
-
|
|
31
|
+
fieldProjection: FieldProjection;
|
|
32
|
+
modals?: ModalController; // TODO(burdon): Not used. Remove?
|
|
23
33
|
onSave?: () => void;
|
|
24
|
-
|
|
25
|
-
}
|
|
34
|
+
onCreate?: OnCreateHandler;
|
|
35
|
+
} & Omit<FormRootProps<any>, 'values' | 'schema' | 'onCreate'>;
|
|
26
36
|
|
|
27
|
-
export const FormCellEditor =
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
export const FormCellEditor = <T extends Type.Entity.Any = Type.Entity.Any>({
|
|
38
|
+
__gridScope,
|
|
39
|
+
schema,
|
|
40
|
+
model,
|
|
41
|
+
fieldProjection,
|
|
42
|
+
onSave,
|
|
43
|
+
onCreate,
|
|
44
|
+
...formProps
|
|
45
|
+
}: FormCellEditorProps<T>) => {
|
|
30
46
|
const anchorRef = useRef<HTMLButtonElement | null>(null);
|
|
47
|
+
const { id: _gridId, editing: contextEditing, setEditing } = useGridContext('ArrayEditor', __gridScope);
|
|
48
|
+
const [editing, setLocalEditing] = useState(false);
|
|
31
49
|
|
|
32
50
|
useEffect(() => {
|
|
33
51
|
if (contextEditing && contextEditing.cellElement) {
|
|
@@ -41,51 +59,114 @@ export const FormCellEditor = ({ fieldProjection, model, schema, onSave, __gridS
|
|
|
41
59
|
}
|
|
42
60
|
}, [contextEditing]);
|
|
43
61
|
|
|
44
|
-
const narrowedSchema = useMemo(() => {
|
|
62
|
+
const narrowedSchema = useMemo<Schema.Schema.AnyNoContext | undefined>(() => {
|
|
45
63
|
if (!schema) {
|
|
46
64
|
return undefined;
|
|
47
65
|
}
|
|
66
|
+
|
|
48
67
|
return narrowSchema(schema, [fieldProjection.field.path]);
|
|
49
68
|
}, [JSON.stringify(schema), fieldProjection.field.path]); // TODO(burdon): Avoid stringify.
|
|
50
69
|
|
|
51
|
-
const
|
|
70
|
+
const getSchema = useCallback(
|
|
71
|
+
({ typename }: { typename: string }) => {
|
|
72
|
+
const space = getSpace(model!.view);
|
|
73
|
+
invariant(space);
|
|
74
|
+
const schema = space.db.schemaRegistry.query({ typename, location: ['database', 'runtime'] }).runSync()[0];
|
|
75
|
+
return { space, schema };
|
|
76
|
+
},
|
|
77
|
+
[model],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const refSchema = useMemo(() => {
|
|
81
|
+
if (fieldProjection.props.format === Format.TypeFormat.Ref && fieldProjection.props.referenceSchema) {
|
|
82
|
+
const { schema } = getSchema({ typename: fieldProjection.props.referenceSchema });
|
|
83
|
+
return schema;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}, [fieldProjection.props.format, fieldProjection.props.referenceSchema, getSchema]);
|
|
88
|
+
|
|
89
|
+
const createSchema = useMemo(() => (refSchema ? omitId(refSchema) : null), [refSchema]);
|
|
90
|
+
|
|
91
|
+
const originalRow = useMemo<TableRow | undefined>(() => {
|
|
52
92
|
if (model && contextEditing) {
|
|
93
|
+
// Check if this is a draft cell and get the appropriate row data
|
|
53
94
|
const cell = parseCellIndex(contextEditing.index);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
if (model.isDraftCell(cell)) {
|
|
96
|
+
const draftRow = model.draftRows.value[cell.row];
|
|
97
|
+
invariant(draftRow);
|
|
98
|
+
return draftRow.data;
|
|
99
|
+
} else {
|
|
100
|
+
const row = model.getRowAt(cell.row);
|
|
101
|
+
invariant(row);
|
|
102
|
+
return row;
|
|
103
|
+
}
|
|
58
104
|
}
|
|
59
105
|
|
|
60
106
|
return undefined;
|
|
61
107
|
}, [model, contextEditing]);
|
|
62
108
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
109
|
+
// NOTE: Important to get a snapshot to eject from the live object.
|
|
110
|
+
const formValues = useMemo(() => (originalRow ? getSnapshot(originalRow) : {}), [originalRow]);
|
|
111
|
+
|
|
112
|
+
const handleOpenChange = useCallback((nextOpen: boolean) => {
|
|
113
|
+
if (nextOpen === false) {
|
|
114
|
+
setEditing(null);
|
|
115
|
+
onSave?.();
|
|
67
116
|
}
|
|
68
|
-
|
|
117
|
+
setLocalEditing(nextOpen);
|
|
118
|
+
}, []);
|
|
69
119
|
|
|
70
|
-
const handleSave = useCallback(
|
|
71
|
-
(values
|
|
120
|
+
const handleSave = useCallback<NonNullable<FormRootProps<any>['onSave']>>(
|
|
121
|
+
(values) => {
|
|
72
122
|
const path = fieldProjection.field.path;
|
|
73
123
|
const value = getDeep(values, [path]);
|
|
74
124
|
setDeep(originalRow, [path], value);
|
|
125
|
+
contextEditing?.cellElement?.focus();
|
|
75
126
|
setEditing(null);
|
|
76
127
|
setLocalEditing(false);
|
|
77
128
|
onSave?.();
|
|
78
129
|
},
|
|
79
|
-
[fieldProjection.field.path, originalRow],
|
|
130
|
+
[fieldProjection.field.path, onSave, contextEditing, originalRow],
|
|
80
131
|
);
|
|
81
132
|
|
|
82
|
-
const
|
|
83
|
-
|
|
133
|
+
const handleCreate = useCallback<NonNullable<FormRootProps<any>['onCreate']>>(
|
|
134
|
+
(values) => {
|
|
135
|
+
if (refSchema && onCreate) {
|
|
136
|
+
const objectWithId = onCreate(refSchema, values);
|
|
137
|
+
if (objectWithId) {
|
|
138
|
+
const ref = Ref.make(objectWithId);
|
|
139
|
+
const path = fieldProjection.field.path;
|
|
140
|
+
setDeep(originalRow, [path], ref);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
contextEditing?.cellElement?.focus();
|
|
84
144
|
setEditing(null);
|
|
145
|
+
setLocalEditing(false);
|
|
85
146
|
onSave?.();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
147
|
+
},
|
|
148
|
+
[fieldProjection.field.path, onSave, contextEditing, originalRow, refSchema, onCreate],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const handleQueryRefOptions = useCallback<NonNullable<FormRootProps<any>['onQueryRefOptions']>>(
|
|
152
|
+
async ({ typename }) => {
|
|
153
|
+
const { schema, space } = getSchema({ typename });
|
|
154
|
+
if (model && schema && space) {
|
|
155
|
+
const objects = await space.db.query(Filter.type(schema)).run();
|
|
156
|
+
return objects
|
|
157
|
+
.map((obj) => {
|
|
158
|
+
return {
|
|
159
|
+
dxn: Obj.getDXN(obj),
|
|
160
|
+
label: getValue(obj, fieldProjection.field.referencePath!) || obj.id.toString(),
|
|
161
|
+
};
|
|
162
|
+
})
|
|
163
|
+
.filter(isTruthy);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return [];
|
|
167
|
+
},
|
|
168
|
+
[model],
|
|
169
|
+
);
|
|
89
170
|
|
|
90
171
|
if (!editing) {
|
|
91
172
|
return null;
|
|
@@ -94,12 +175,35 @@ export const FormCellEditor = ({ fieldProjection, model, schema, onSave, __gridS
|
|
|
94
175
|
return (
|
|
95
176
|
<Popover.Root open={editing} onOpenChange={handleOpenChange}>
|
|
96
177
|
<Popover.VirtualTrigger virtualRef={anchorRef} />
|
|
97
|
-
<Popover.
|
|
98
|
-
<Popover.
|
|
99
|
-
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
178
|
+
<Popover.Portal>
|
|
179
|
+
<Popover.Content tabIndex={-1} classNames='popover-card-width density-fine'>
|
|
180
|
+
<Popover.Arrow />
|
|
181
|
+
<Popover.Viewport>
|
|
182
|
+
<Form.Root
|
|
183
|
+
{...formProps}
|
|
184
|
+
autoFocus
|
|
185
|
+
schema={narrowedSchema}
|
|
186
|
+
values={formValues}
|
|
187
|
+
onSave={handleSave}
|
|
188
|
+
onQueryRefOptions={handleQueryRefOptions}
|
|
189
|
+
{...(createSchema && {
|
|
190
|
+
createSchema,
|
|
191
|
+
createInitialValuePath: fieldProjection.field.referencePath,
|
|
192
|
+
createOptionIcon: 'ph--plus--regular',
|
|
193
|
+
createOptionLabel,
|
|
194
|
+
onCreate: handleCreate,
|
|
195
|
+
})}
|
|
196
|
+
>
|
|
197
|
+
<Form.Viewport>
|
|
198
|
+
<Form.Content>
|
|
199
|
+
<Form.FieldSet />
|
|
200
|
+
<Form.Actions />
|
|
201
|
+
</Form.Content>
|
|
202
|
+
</Form.Viewport>
|
|
203
|
+
</Form.Root>
|
|
204
|
+
</Popover.Viewport>
|
|
205
|
+
</Popover.Content>
|
|
206
|
+
</Popover.Portal>
|
|
103
207
|
</Popover.Root>
|
|
104
208
|
);
|
|
105
209
|
};
|
|
@@ -2,100 +2,62 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
9
7
|
|
|
10
8
|
import { Obj } from '@dxos/echo';
|
|
11
|
-
import { type EchoSchema, isMutable } from '@dxos/echo-schema';
|
|
12
|
-
import { invariant } from '@dxos/invariant';
|
|
13
9
|
import { faker } from '@dxos/random';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
10
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { Grid, type GridEditing, defaultRowSize } from '@dxos/react-ui-grid';
|
|
13
|
+
import { View } from '@dxos/schema';
|
|
14
|
+
import { Task } from '@dxos/types';
|
|
19
15
|
|
|
20
|
-
import {
|
|
21
|
-
import { useTableModel } from '../../hooks';
|
|
22
|
-
import { type TableFeatures } from '../../model';
|
|
16
|
+
import { useTestTableModel } from '../../testing';
|
|
23
17
|
import { translations } from '../../translations';
|
|
24
|
-
import {
|
|
25
|
-
|
|
18
|
+
import { Table } from '../../types';
|
|
19
|
+
|
|
20
|
+
import { TableCellEditor } from './TableCellEditor';
|
|
26
21
|
|
|
27
22
|
type StoryProps = {
|
|
28
23
|
editing: GridEditing;
|
|
29
24
|
};
|
|
30
25
|
|
|
26
|
+
// TODO(burdon): Broken layout.
|
|
31
27
|
const DefaultStory = ({ editing }: StoryProps) => {
|
|
32
|
-
const {
|
|
33
|
-
invariant(space);
|
|
34
|
-
|
|
35
|
-
const views = useQuery(space, Filter.type(DataType.View));
|
|
36
|
-
const [view, setView] = useState<DataType.View>();
|
|
37
|
-
const [schema, setSchema] = useState<EchoSchema>();
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (space && views.length && !view) {
|
|
40
|
-
const view = views[0];
|
|
41
|
-
setView(view);
|
|
42
|
-
setSchema(space.db.schemaRegistry.getSchema(view.query.typename!));
|
|
43
|
-
}
|
|
44
|
-
}, [space, views, view]);
|
|
45
|
-
|
|
46
|
-
const features: Partial<TableFeatures> = useMemo(
|
|
47
|
-
() => ({
|
|
48
|
-
selection: { enabled: true, mode: 'multiple' },
|
|
49
|
-
dataEditable: true,
|
|
50
|
-
schemaEditable: schema && isMutable(schema),
|
|
51
|
-
}),
|
|
52
|
-
[schema],
|
|
53
|
-
);
|
|
28
|
+
const { model, table } = useTestTableModel();
|
|
54
29
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const handleQuery: TableCellEditorProps['onQuery'] = async ({ field }) => {
|
|
58
|
-
// TODO(dmaretskyi): If no schema query nothing
|
|
59
|
-
const { objects } = await space.db.query(schema ? Filter.type(schema) : Filter.everything()).run();
|
|
60
|
-
return objects.map((obj) => {
|
|
61
|
-
const label = obj[field.referencePath ?? 'id'];
|
|
62
|
-
return {
|
|
63
|
-
label,
|
|
64
|
-
data: obj,
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
if (!model || !schema || !view) {
|
|
30
|
+
if (!model || !table) {
|
|
70
31
|
return <div />;
|
|
71
32
|
}
|
|
72
33
|
|
|
73
34
|
return (
|
|
74
|
-
<div className='
|
|
35
|
+
<div className='border border-separator' style={{ height: defaultRowSize }}>
|
|
75
36
|
<Grid.Root id='test' editing={editing}>
|
|
76
|
-
<TableCellEditor model={model}
|
|
37
|
+
<TableCellEditor model={model} schema={Task.Task} />
|
|
77
38
|
</Grid.Root>
|
|
78
39
|
</div>
|
|
79
40
|
);
|
|
80
41
|
};
|
|
81
42
|
|
|
82
|
-
const meta
|
|
43
|
+
const meta = {
|
|
83
44
|
title: 'ui/react-ui-table/TableCellEditor',
|
|
84
45
|
component: DefaultStory,
|
|
85
46
|
render: DefaultStory,
|
|
86
|
-
parameters: { translations, layout: 'centered' },
|
|
87
47
|
decorators: [
|
|
48
|
+
withTheme,
|
|
49
|
+
withLayout({ container: 'column' }),
|
|
88
50
|
withClientProvider({
|
|
89
|
-
types: [
|
|
51
|
+
types: [View.View, Task.Task, Table.Table],
|
|
90
52
|
createIdentity: true,
|
|
91
53
|
createSpace: true,
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
space.db.add(
|
|
54
|
+
onCreateSpace: async ({ space }) => {
|
|
55
|
+
const { view, jsonSchema } = await View.makeFromSpace({ space, typename: Task.Task.typename });
|
|
56
|
+
const table = Table.make({ view, jsonSchema });
|
|
57
|
+
space.db.add(table);
|
|
96
58
|
Array.from({ length: 10 }).forEach(() => {
|
|
97
59
|
space.db.add(
|
|
98
|
-
Obj.make(
|
|
60
|
+
Obj.make(Task.Task, {
|
|
99
61
|
title: faker.person.fullName(),
|
|
100
62
|
status: faker.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
|
|
101
63
|
description: faker.lorem.sentence(),
|
|
@@ -104,14 +66,16 @@ const meta: Meta<StoryProps> = {
|
|
|
104
66
|
});
|
|
105
67
|
},
|
|
106
68
|
}),
|
|
107
|
-
withTheme,
|
|
108
|
-
withLayout(),
|
|
109
69
|
],
|
|
110
|
-
|
|
70
|
+
parameters: {
|
|
71
|
+
layout: 'fullscreen',
|
|
72
|
+
translations,
|
|
73
|
+
},
|
|
74
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
111
75
|
|
|
112
76
|
export default meta;
|
|
113
77
|
|
|
114
|
-
type Story = StoryObj<
|
|
78
|
+
type Story = StoryObj<typeof meta>;
|
|
115
79
|
|
|
116
80
|
export const Default: Story = {
|
|
117
81
|
args: {
|