@dxos/react-ui-table 0.8.3 → 0.8.4-main.1f223c7
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-63UUF4IG.mjs +66 -0
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +7 -0
- package/dist/lib/browser/chunk-BBXDTWCX.mjs +1822 -0
- package/dist/lib/browser/chunk-BBXDTWCX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +814 -2152
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +124 -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-K734DJB7.mjs +67 -0
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs +1823 -0
- package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +814 -2152
- 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 +125 -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 +50 -2
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +44 -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 +3 -2
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +42 -3
- package/dist/types/src/components/Table/Table.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 +8 -3
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +9 -15
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.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/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +14 -0
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -0
- 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 +1 -2
- 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 +59 -21
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +10 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +3 -4
- 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 +22 -0
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +5 -6
- 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 +28 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/util/dynamic-table.d.ts +4 -5
- 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/table-buttons.d.ts +15 -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 -44
- package/src/components/Table/ColumnActionsMenu.tsx +1 -1
- package/src/components/Table/ColumnSettings.tsx +15 -11
- package/src/components/Table/CreateRefPanel.tsx +30 -11
- package/src/components/Table/DynamicTable.stories.tsx +8 -5
- package/src/components/Table/DynamicTable.tsx +17 -10
- package/src/components/Table/{relations.stories.tsx → Relations.stories.tsx} +56 -47
- package/src/components/Table/RowActionsMenu.tsx +3 -3
- package/src/components/Table/Table.stories.tsx +126 -159
- package/src/components/Table/Table.tsx +167 -123
- package/src/components/TableCellEditor/CellValidationMessage.tsx +7 -2
- package/src/components/TableCellEditor/FormCellEditor.tsx +158 -48
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +31 -47
- package/src/components/TableCellEditor/TableCellEditor.tsx +106 -111
- package/src/components/TableToolbar/TableToolbar.tsx +2 -2
- package/src/components/testing.ts +7 -24
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useAddRow.ts +38 -0
- package/src/hooks/useTableModel.ts +21 -17
- package/src/index.ts +1 -2
- package/src/model/modal-controller.ts +1 -1
- package/src/model/selection-model.ts +6 -3
- package/src/model/table-model.test.ts +12 -9
- package/src/model/table-model.ts +288 -88
- package/src/model/table-presentation.test.ts +12 -8
- package/src/model/table-presentation.ts +263 -138
- package/src/model/table-sorting.ts +22 -13
- package/src/playwright/playwright.config.ts +17 -0
- package/src/playwright/smoke.spec.ts +137 -44
- package/src/testing/index.ts +5 -0
- package/src/testing/useTestTableModel.ts +124 -0
- package/src/translations.ts +7 -5
- package/src/types/index.ts +2 -2
- package/src/types/schema.ts +73 -0
- package/src/util/dynamic-table.ts +24 -21
- package/src/util/index.ts +0 -1
- package/src/util/schema.ts +1 -1
- package/src/util/table-buttons.ts +28 -4
- package/src/util/table-controls.ts +4 -1
- 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/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/table.d.ts +0 -56
- package/dist/types/src/types/table.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -14
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/playwright/playwright.config.cts +0 -18
- package/src/types/table.ts +0 -27
- package/src/util/table.ts +0 -127
|
@@ -3,94 +3,204 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Schema } from 'effect';
|
|
6
|
-
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
6
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Filter, Obj } from '@dxos/echo';
|
|
9
|
+
import { Ref, type TypeAnnotation, getValue } from '@dxos/echo-schema';
|
|
9
10
|
import { invariant } from '@dxos/invariant';
|
|
11
|
+
import { getSnapshot } from '@dxos/live-object';
|
|
12
|
+
import { type Client } from '@dxos/react-client';
|
|
13
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
10
14
|
import { Popover } from '@dxos/react-ui';
|
|
11
|
-
import { Form } from '@dxos/react-ui-form';
|
|
12
|
-
import { parseCellIndex, useGridContext } from '@dxos/react-ui-grid';
|
|
15
|
+
import { Form, type FormProps } from '@dxos/react-ui-form';
|
|
16
|
+
import { cellQuery, parseCellIndex, useGridContext } from '@dxos/react-ui-grid';
|
|
13
17
|
import { type FieldProjection } from '@dxos/schema';
|
|
14
|
-
import { getDeep, setDeep } from '@dxos/util';
|
|
18
|
+
import { getDeep, isNotFalsy, setDeep } from '@dxos/util';
|
|
15
19
|
|
|
16
|
-
import { type TableModel } from '../../model';
|
|
20
|
+
import { type ModalController, type TableModel } from '../../model';
|
|
21
|
+
import { translationKey } from '../../translations';
|
|
17
22
|
import { narrowSchema } from '../../util';
|
|
18
23
|
|
|
19
24
|
type FormCellEditorProps = {
|
|
20
25
|
fieldProjection: FieldProjection;
|
|
21
26
|
model?: TableModel;
|
|
22
27
|
schema?: Schema.Schema.AnyNoContext;
|
|
28
|
+
onSave?: () => void;
|
|
29
|
+
client?: Client;
|
|
30
|
+
modals?: ModalController;
|
|
23
31
|
__gridScope: any;
|
|
24
|
-
}
|
|
32
|
+
} & Omit<FormProps<any>, 'values' | 'schema'>;
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
const { editing, setEditing } = useGridContext('ArrayEditor', __gridScope);
|
|
28
|
-
const cellRef = useRef<HTMLButtonElement | null>(null);
|
|
34
|
+
const createOptionLabel = ['create new object label', { ns: translationKey }] as [string, { ns: string }];
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
export const FormCellEditor = ({
|
|
37
|
+
fieldProjection,
|
|
38
|
+
model,
|
|
39
|
+
schema,
|
|
40
|
+
onSave,
|
|
41
|
+
client,
|
|
42
|
+
modals,
|
|
43
|
+
__gridScope,
|
|
44
|
+
...formProps
|
|
45
|
+
}: FormCellEditorProps) => {
|
|
46
|
+
const { editing: contextEditing, setEditing, id: gridId } = useGridContext('ArrayEditor', __gridScope);
|
|
47
|
+
const [editing, setLocalEditing] = useState(false);
|
|
48
|
+
const anchorRef = useRef<HTMLButtonElement | null>(null);
|
|
35
49
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
const getSchema = useCallback(
|
|
51
|
+
(typeAnnotation: TypeAnnotation) => {
|
|
52
|
+
const space = getSpace(model!.view);
|
|
53
|
+
invariant(space);
|
|
54
|
+
|
|
55
|
+
let schema;
|
|
56
|
+
if (client) {
|
|
57
|
+
schema = client.graph.schemaRegistry.getSchema(typeAnnotation.typename);
|
|
58
|
+
}
|
|
59
|
+
if (!schema) {
|
|
60
|
+
schema = space.db.schemaRegistry.getSchema(typeAnnotation.typename);
|
|
61
|
+
}
|
|
62
|
+
return { space, schema };
|
|
63
|
+
},
|
|
64
|
+
[client, model],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const handleQueryRefOptions = useCallback(
|
|
68
|
+
async (typeAnnotation: TypeAnnotation) => {
|
|
69
|
+
const { schema, space } = getSchema(typeAnnotation);
|
|
70
|
+
if (model && schema && space) {
|
|
71
|
+
const { objects } = await space.db.query(Filter.type(schema)).run();
|
|
72
|
+
return objects
|
|
73
|
+
.map((obj) => {
|
|
74
|
+
return {
|
|
75
|
+
dxn: Obj.getDXN(obj),
|
|
76
|
+
label: getValue(obj, fieldProjection.field.referencePath!) || obj.id.toString(),
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
.filter(isNotFalsy);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return [];
|
|
83
|
+
},
|
|
84
|
+
[client, model],
|
|
85
|
+
);
|
|
42
86
|
|
|
43
87
|
const originalRow = useMemo(() => {
|
|
44
|
-
if (model &&
|
|
45
|
-
const cell = parseCellIndex(
|
|
46
|
-
const row = model.getRowAt(cell.row);
|
|
47
|
-
invariant(row);
|
|
88
|
+
if (model && contextEditing) {
|
|
89
|
+
const cell = parseCellIndex(contextEditing.index);
|
|
48
90
|
|
|
49
|
-
|
|
91
|
+
// Check if this is a draft cell and get the appropriate row data
|
|
92
|
+
if (model.isDraftCell(cell)) {
|
|
93
|
+
const draftRow = model.draftRows.value[cell.row];
|
|
94
|
+
invariant(draftRow);
|
|
95
|
+
return draftRow.data;
|
|
96
|
+
} else {
|
|
97
|
+
const row = model.getRowAt(cell.row);
|
|
98
|
+
invariant(row);
|
|
99
|
+
return row;
|
|
100
|
+
}
|
|
50
101
|
}
|
|
51
102
|
|
|
52
103
|
return undefined;
|
|
53
|
-
}, [model,
|
|
54
|
-
|
|
55
|
-
const formValues = useMemo(() => {
|
|
56
|
-
if (originalRow) {
|
|
57
|
-
// NOTE(ZaymonFC): Important to get a snapshot to eject from the live object.
|
|
58
|
-
return getSnapshot(originalRow);
|
|
59
|
-
}
|
|
60
|
-
}, [originalRow]);
|
|
104
|
+
}, [model, contextEditing]);
|
|
61
105
|
|
|
62
106
|
const handleSave = useCallback(
|
|
63
107
|
(values: any) => {
|
|
64
108
|
const path = fieldProjection.field.path;
|
|
65
109
|
const value = getDeep(values, [path]);
|
|
66
110
|
setDeep(originalRow, [path], value);
|
|
111
|
+
contextEditing?.cellElement?.focus();
|
|
112
|
+
setEditing(null);
|
|
113
|
+
setLocalEditing(false);
|
|
114
|
+
onSave?.();
|
|
115
|
+
},
|
|
116
|
+
[fieldProjection.field.path, onSave, contextEditing, originalRow],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const handleCreate = useCallback(
|
|
120
|
+
(object: any) => {
|
|
121
|
+
const ref = Ref.make(object);
|
|
122
|
+
const path = fieldProjection.field.path;
|
|
123
|
+
setDeep(originalRow, [path], ref);
|
|
124
|
+
contextEditing?.cellElement?.focus();
|
|
67
125
|
setEditing(null);
|
|
126
|
+
setLocalEditing(false);
|
|
127
|
+
onSave?.();
|
|
68
128
|
},
|
|
69
|
-
[fieldProjection.field.path, originalRow],
|
|
129
|
+
[fieldProjection.field.path, onSave, contextEditing, originalRow],
|
|
70
130
|
);
|
|
71
131
|
|
|
72
|
-
const
|
|
73
|
-
(
|
|
74
|
-
if (
|
|
75
|
-
|
|
132
|
+
const handleCreateFromQuery = useCallback(
|
|
133
|
+
async (typeAnnotation: TypeAnnotation, query: string) => {
|
|
134
|
+
if (model && modals && contextEditing?.index) {
|
|
135
|
+
setLocalEditing(false);
|
|
136
|
+
modals.openCreateRef(
|
|
137
|
+
typeAnnotation.typename,
|
|
138
|
+
document.querySelector(cellQuery(contextEditing.index, gridId)),
|
|
139
|
+
{
|
|
140
|
+
[fieldProjection.field.referencePath!]: query,
|
|
141
|
+
},
|
|
142
|
+
handleCreate,
|
|
143
|
+
);
|
|
76
144
|
}
|
|
77
145
|
},
|
|
78
|
-
[
|
|
146
|
+
[model, modals, client, contextEditing?.index, gridId, fieldProjection, handleSave],
|
|
79
147
|
);
|
|
80
148
|
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (contextEditing && contextEditing.cellElement) {
|
|
151
|
+
anchorRef.current = (contextEditing.cellElement as HTMLElement).querySelector(
|
|
152
|
+
'.dx-grid__cell__content',
|
|
153
|
+
) as HTMLButtonElement;
|
|
154
|
+
setLocalEditing(true);
|
|
155
|
+
} else {
|
|
156
|
+
anchorRef.current = null;
|
|
157
|
+
setLocalEditing(false);
|
|
158
|
+
}
|
|
159
|
+
}, [contextEditing]);
|
|
160
|
+
|
|
161
|
+
const narrowedSchema = useMemo(() => {
|
|
162
|
+
if (!schema) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
return narrowSchema(schema, [fieldProjection.field.path]);
|
|
166
|
+
}, [JSON.stringify(schema), fieldProjection.field.path]); // TODO(burdon): Avoid stringify.
|
|
167
|
+
|
|
168
|
+
// NOTE: Important to get a snapshot to eject from the live object.
|
|
169
|
+
const formValues = useMemo(() => (originalRow ? getSnapshot(originalRow) : {}), [originalRow]);
|
|
170
|
+
|
|
171
|
+
const handleOpenChange = useCallback((nextOpen: boolean) => {
|
|
172
|
+
if (nextOpen === false) {
|
|
173
|
+
setEditing(null);
|
|
174
|
+
onSave?.();
|
|
175
|
+
}
|
|
176
|
+
setLocalEditing(nextOpen);
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
81
179
|
if (!editing) {
|
|
82
180
|
return null;
|
|
83
181
|
}
|
|
84
182
|
|
|
85
183
|
return (
|
|
86
|
-
<Popover.Root open={editing
|
|
87
|
-
<Popover.VirtualTrigger virtualRef={
|
|
88
|
-
<Popover.
|
|
89
|
-
<Popover.
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
184
|
+
<Popover.Root open={editing} onOpenChange={handleOpenChange}>
|
|
185
|
+
<Popover.VirtualTrigger virtualRef={anchorRef} />
|
|
186
|
+
<Popover.Portal>
|
|
187
|
+
<Popover.Content tabIndex={-1} classNames='popover-card-width density-fine'>
|
|
188
|
+
<Popover.Arrow />
|
|
189
|
+
<Popover.Viewport>
|
|
190
|
+
<Form
|
|
191
|
+
autoFocus
|
|
192
|
+
values={formValues}
|
|
193
|
+
schema={narrowedSchema as any}
|
|
194
|
+
onSave={handleSave}
|
|
195
|
+
{...formProps}
|
|
196
|
+
onQueryRefOptions={handleQueryRefOptions}
|
|
197
|
+
onCreateFromQuery={handleCreateFromQuery}
|
|
198
|
+
createOptionIcon='ph--plus--regular'
|
|
199
|
+
createOptionLabel={createOptionLabel}
|
|
200
|
+
/>
|
|
201
|
+
</Popover.Viewport>
|
|
202
|
+
</Popover.Content>
|
|
203
|
+
</Popover.Portal>
|
|
94
204
|
</Popover.Root>
|
|
95
205
|
);
|
|
96
206
|
};
|
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type Meta, type StoryObj } from '@storybook/react';
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
8
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { Obj } from '@dxos/echo';
|
|
11
11
|
import { type EchoSchema, isMutable } from '@dxos/echo-schema';
|
|
12
12
|
import { invariant } from '@dxos/invariant';
|
|
13
13
|
import { faker } from '@dxos/random';
|
|
14
|
-
import { Filter, useQuery
|
|
14
|
+
import { Filter, useQuery } from '@dxos/react-client/echo';
|
|
15
15
|
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { Grid, type GridEditing, defaultRowSize } from '@dxos/react-ui-grid';
|
|
17
|
+
import { DataType, createDefaultSchema, typenameFromQuery } from '@dxos/schema';
|
|
18
18
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
19
19
|
|
|
20
|
-
import { TableCellEditor, type TableCellEditorProps } from './TableCellEditor';
|
|
21
20
|
import { useTableModel } from '../../hooks';
|
|
22
21
|
import { type TableFeatures } from '../../model';
|
|
23
|
-
import translations from '../../translations';
|
|
24
|
-
import {
|
|
25
|
-
|
|
22
|
+
import { translations } from '../../translations';
|
|
23
|
+
import { Table } from '../../types';
|
|
24
|
+
|
|
25
|
+
import { TableCellEditor } from './TableCellEditor';
|
|
26
26
|
|
|
27
27
|
type StoryProps = {
|
|
28
28
|
editing: GridEditing;
|
|
@@ -32,23 +32,16 @@ const DefaultStory = ({ editing }: StoryProps) => {
|
|
|
32
32
|
const { space } = useClientProvider();
|
|
33
33
|
invariant(space);
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
const [
|
|
35
|
+
const views = useQuery(space, Filter.type(DataType.View));
|
|
36
|
+
const [view, setView] = useState<DataType.View>();
|
|
37
37
|
const [schema, setSchema] = useState<EchoSchema>();
|
|
38
38
|
useEffect(() => {
|
|
39
|
-
if (space &&
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
setSchema(space.db.schemaRegistry.getSchema(table.view.target!.query.typename!));
|
|
44
|
-
}
|
|
45
|
-
}, [space, tables]);
|
|
46
|
-
|
|
47
|
-
const projection = useMemo(() => {
|
|
48
|
-
if (schema && table?.view) {
|
|
49
|
-
return new ViewProjection(schema.jsonSchema, table.view.target!);
|
|
39
|
+
if (space && views.length && !view) {
|
|
40
|
+
const view = views[0];
|
|
41
|
+
setView(view);
|
|
42
|
+
setSchema(space.db.schemaRegistry.getSchema(typenameFromQuery(view.query)!));
|
|
50
43
|
}
|
|
51
|
-
}, [
|
|
44
|
+
}, [space, views, view]);
|
|
52
45
|
|
|
53
46
|
const features: Partial<TableFeatures> = useMemo(
|
|
54
47
|
() => ({
|
|
@@ -59,50 +52,41 @@ const DefaultStory = ({ editing }: StoryProps) => {
|
|
|
59
52
|
[schema],
|
|
60
53
|
);
|
|
61
54
|
|
|
62
|
-
const model = useTableModel({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// TODO(dmaretskyi): If no schema query nothing
|
|
66
|
-
const { objects } = await space.db.query(schema ? Filter.type(schema) : Filter.everything()).run();
|
|
67
|
-
return objects.map((obj) => {
|
|
68
|
-
const label = obj[field.referencePath ?? 'id'];
|
|
69
|
-
return {
|
|
70
|
-
label,
|
|
71
|
-
data: obj,
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
if (!model || !schema || !table) {
|
|
55
|
+
const model = useTableModel({ view, schema: schema?.jsonSchema, features });
|
|
56
|
+
|
|
57
|
+
if (!model || !schema || !view) {
|
|
77
58
|
return <div />;
|
|
78
59
|
}
|
|
79
60
|
|
|
80
61
|
return (
|
|
81
62
|
<div className='flex w-[300px] border border-separator' style={{ height: defaultRowSize }}>
|
|
82
63
|
<Grid.Root id='test' editing={editing}>
|
|
83
|
-
<TableCellEditor model={model}
|
|
64
|
+
<TableCellEditor model={model} schema={schema} />
|
|
84
65
|
</Grid.Root>
|
|
85
66
|
</div>
|
|
86
67
|
);
|
|
87
68
|
};
|
|
88
69
|
|
|
89
|
-
const meta
|
|
90
|
-
title: '
|
|
70
|
+
const meta = {
|
|
71
|
+
title: 'ui/react-ui-table/TableCellEditor',
|
|
91
72
|
component: DefaultStory,
|
|
92
73
|
render: DefaultStory,
|
|
93
74
|
parameters: { translations, layout: 'centered' },
|
|
94
75
|
decorators: [
|
|
95
76
|
withClientProvider({
|
|
96
|
-
types: [
|
|
77
|
+
types: [DataType.View, Table.Table],
|
|
97
78
|
createIdentity: true,
|
|
98
79
|
createSpace: true,
|
|
99
80
|
onSpaceCreated: async ({ client, space }) => {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
81
|
+
const schema = createDefaultSchema();
|
|
82
|
+
const { view } = await Table.makeView({ client, space, typename: schema.typename });
|
|
83
|
+
space.db.add(view);
|
|
102
84
|
Array.from({ length: 10 }).forEach(() => {
|
|
103
85
|
space.db.add(
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
Obj.make(schema, {
|
|
87
|
+
title: faker.person.fullName(),
|
|
88
|
+
status: faker.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
|
|
89
|
+
description: faker.lorem.sentence(),
|
|
106
90
|
}),
|
|
107
91
|
);
|
|
108
92
|
});
|
|
@@ -111,11 +95,11 @@ const meta: Meta<StoryProps> = {
|
|
|
111
95
|
withTheme,
|
|
112
96
|
withLayout(),
|
|
113
97
|
],
|
|
114
|
-
}
|
|
98
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
115
99
|
|
|
116
100
|
export default meta;
|
|
117
101
|
|
|
118
|
-
type Story = StoryObj<
|
|
102
|
+
type Story = StoryObj<typeof meta>;
|
|
119
103
|
|
|
120
104
|
export const Default: Story = {
|
|
121
105
|
args: {
|