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