@dxos/react-ui-table 0.8.3 → 0.8.4-main.1068cf700f
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-GTGYBRJA.mjs +1748 -0
- package/dist/lib/browser/chunk-GTGYBRJA.mjs.map +7 -0
- package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
- package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1156 -2508
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +114 -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-DPNSZHU5.mjs +1750 -0
- package/dist/lib/node-esm/chunk-DPNSZHU5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1156 -2508
- 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 +115 -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 +2 -3
- 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/DynamicTable.d.ts +7 -7
- 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 +2 -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 +12 -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 +4 -4
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +26 -56
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -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/useProjectionModel.d.ts +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +11 -10
- 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 +5 -8
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -7
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +149 -32
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +13 -2
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.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 +25 -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/Table.d.ts +31 -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 +15 -14
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- 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/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- 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 +69 -56
- package/src/components/Table/ColumnActionsMenu.tsx +11 -7
- package/src/components/Table/ColumnSettings.tsx +16 -12
- package/src/components/Table/DynamicTable.stories.tsx +29 -25
- package/src/components/Table/DynamicTable.tsx +34 -22
- package/src/components/Table/Relations.stories.tsx +237 -0
- package/src/components/Table/RowActionsMenu.tsx +26 -17
- package/src/components/Table/Table.stories.tsx +171 -194
- package/src/components/Table/Table.tsx +364 -286
- package/src/components/TableCellEditor/CellValidationMessage.tsx +8 -3
- package/src/components/TableCellEditor/FormCellEditor.tsx +146 -49
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +36 -76
- package/src/components/TableCellEditor/TableCellEditor.tsx +106 -198
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +49 -33
- package/src/components/testing.ts +41 -32
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useAddRow.ts +36 -0
- package/src/hooks/useProjectionModel.ts +39 -0
- package/src/hooks/useTableModel.ts +41 -35
- package/src/index.ts +1 -2
- package/src/model/modal-controller.ts +24 -41
- package/src/model/selection-model.ts +75 -41
- package/src/model/table-model.test.ts +92 -56
- package/src/model/table-model.ts +628 -162
- package/src/model/table-presentation.test.ts +70 -59
- package/src/model/table-presentation.ts +278 -149
- package/src/playwright/TableManager.ts +13 -6
- package/src/playwright/playwright.config.ts +17 -0
- package/src/playwright/smoke.spec.ts +180 -41
- package/src/testing/index.ts +5 -0
- package/src/testing/useTestTableModel.ts +133 -0
- package/src/translations.ts +7 -5
- package/src/types/Table.ts +90 -0
- package/src/types/index.ts +2 -2
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +50 -36
- package/src/util/index.ts +2 -1
- package/src/util/query-ast.ts +19 -0
- package/src/util/schema.ts +4 -4
- package/src/util/sort.ts +90 -0
- 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/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/model/table-sorting.d.ts +0 -53
- package/dist/types/src/model/table-sorting.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/Table/CreateRefPanel.tsx +0 -84
- package/src/components/Table/relations.stories.tsx +0 -124
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/model/table-sorting.ts +0 -216
- package/src/playwright/playwright.config.cts +0 -18
- package/src/types/table.ts +0 -27
- package/src/util/table.ts +0 -127
|
@@ -2,161 +2,95 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
6
8
|
|
|
7
|
-
import { type
|
|
8
|
-
import {
|
|
9
|
-
import React, { useCallback, useMemo, useRef } from 'react';
|
|
10
|
-
|
|
11
|
-
import { Obj, Type } from '@dxos/echo';
|
|
12
|
-
import { FormatEnum, isMutable, toJsonSchema, EchoObject, GeneratorAnnotation } from '@dxos/echo-schema';
|
|
9
|
+
import { Annotation, type Database, Format, Obj, type QueryAST, Type } from '@dxos/echo';
|
|
10
|
+
import { type Mutable, PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
13
11
|
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
15
12
|
import { faker } from '@dxos/random';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
13
|
+
import { PublicKey } from '@dxos/react-client';
|
|
14
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
15
|
+
import { ScrollArea } from '@dxos/react-ui';
|
|
16
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
17
|
+
import { ViewEditor, translations as formTranslations } from '@dxos/react-ui-form';
|
|
20
18
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
import { Table, type TableController } from './Table';
|
|
26
|
-
import { useTableModel } from '../../hooks';
|
|
27
|
-
import { TablePresentation } from '../../model';
|
|
28
|
-
import translations from '../../translations';
|
|
29
|
-
import { TableType } from '../../types';
|
|
30
|
-
import { initializeTable } from '../../util';
|
|
31
|
-
import { TableToolbar } from '../TableToolbar';
|
|
32
|
-
|
|
33
|
-
faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Custom hook to create and manage a test table model for storybook demonstrations.
|
|
37
|
-
* Provides table data, schema, and handlers for table operations.
|
|
38
|
-
*/
|
|
39
|
-
const useTestTableModel = () => {
|
|
40
|
-
const client = useClient();
|
|
41
|
-
const { space } = useClientProvider();
|
|
42
|
-
|
|
43
|
-
const filter = useMemo(() => Filter.type(TableType), []);
|
|
44
|
-
const tables = useQuery(space, filter);
|
|
45
|
-
const table = useMemo(() => tables.at(0), [tables]);
|
|
46
|
-
const schema = useSchema(client, space, table?.view?.target?.query.typename);
|
|
47
|
-
|
|
48
|
-
const projection = useMemo(() => {
|
|
49
|
-
if (schema && table?.view?.target) {
|
|
50
|
-
return new ViewProjection(toJsonSchema(schema), table.view.target);
|
|
51
|
-
}
|
|
52
|
-
}, [schema, table?.view?.target]);
|
|
53
|
-
|
|
54
|
-
const features = useMemo(
|
|
55
|
-
() => ({
|
|
56
|
-
selection: { enabled: true, mode: 'multiple' as const },
|
|
57
|
-
dataEditable: true,
|
|
58
|
-
schemaEditable: schema && isMutable(schema),
|
|
59
|
-
}),
|
|
60
|
-
[schema],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
|
|
64
|
-
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
19
|
+
import { View, getSchemaFromPropertyDefinitions, getTypenameFromQuery } from '@dxos/schema';
|
|
20
|
+
import { TestSchema, createObjectFactory } from '@dxos/schema/testing';
|
|
21
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
65
22
|
|
|
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();
|
|
23
|
+
import { useTestTableModel } from '../../testing';
|
|
24
|
+
import { translations } from '../../translations';
|
|
25
|
+
import { Table } from '../../types';
|
|
26
|
+
import { TableToolbar } from '../TableToolbar';
|
|
138
27
|
|
|
139
|
-
|
|
140
|
-
|
|
28
|
+
import { Table as TableComponent } from './Table';
|
|
29
|
+
|
|
30
|
+
const Example = Schema.Struct({
|
|
31
|
+
// TODO(wittjosiah): Should be title. Currently name to work with default label.
|
|
32
|
+
name: Schema.optional(Schema.String).annotations({ title: 'Title' }),
|
|
33
|
+
urgent: Schema.optional(Schema.Boolean).annotations({ title: 'Urgent' }),
|
|
34
|
+
status: Schema.optional(
|
|
35
|
+
Schema.Literal('todo', 'in-progress', 'done')
|
|
36
|
+
.pipe(Format.FormatAnnotation.set(Format.TypeFormat.SingleSelect))
|
|
37
|
+
.annotations({
|
|
38
|
+
title: 'Status',
|
|
39
|
+
[PropertyMetaAnnotationId]: {
|
|
40
|
+
singleSelect: {
|
|
41
|
+
options: [
|
|
42
|
+
{ id: 'todo', title: 'Todo', color: 'indigo' },
|
|
43
|
+
{ id: 'in-progress', title: 'In Progress', color: 'purple' },
|
|
44
|
+
{ id: 'done', title: 'Done', color: 'amber' },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
description: Schema.optional(Schema.String).annotations({ title: 'Description' }),
|
|
51
|
+
parent: Schema.optional(Schema.suspend((): Type.Ref<Example> => Type.Ref(Example))).annotations({
|
|
52
|
+
title: 'Parent',
|
|
53
|
+
}),
|
|
54
|
+
}).pipe(
|
|
55
|
+
Type.object({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }),
|
|
56
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
57
|
+
);
|
|
58
|
+
interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
59
|
+
|
|
60
|
+
const StoryViewEditor = ({
|
|
61
|
+
view,
|
|
62
|
+
schema,
|
|
63
|
+
db,
|
|
64
|
+
handleDeleteColumn,
|
|
65
|
+
}: {
|
|
66
|
+
view?: View.View;
|
|
67
|
+
schema?: Schema.Schema.AnyNoContext;
|
|
68
|
+
db?: Database.Database;
|
|
69
|
+
handleDeleteColumn: (fieldId: string) => void;
|
|
70
|
+
}) => {
|
|
71
|
+
const handleQueryChanged = useCallback(
|
|
72
|
+
(newQuery: QueryAST.Query) => {
|
|
141
73
|
invariant(schema);
|
|
142
74
|
invariant(Type.isMutable(schema));
|
|
143
|
-
schema.updateTypename(
|
|
144
|
-
invariant(
|
|
145
|
-
|
|
75
|
+
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
76
|
+
invariant(view);
|
|
77
|
+
Obj.change(view, (v) => {
|
|
78
|
+
v.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
79
|
+
});
|
|
146
80
|
},
|
|
147
|
-
[schema,
|
|
81
|
+
[schema, view],
|
|
148
82
|
);
|
|
149
83
|
|
|
150
|
-
if (!
|
|
84
|
+
if (!view || !schema) {
|
|
151
85
|
return null;
|
|
152
86
|
}
|
|
153
87
|
|
|
154
88
|
return (
|
|
155
89
|
<ViewEditor
|
|
156
|
-
registry={
|
|
90
|
+
registry={db?.schemaRegistry}
|
|
157
91
|
schema={schema}
|
|
158
|
-
view={
|
|
159
|
-
|
|
92
|
+
view={view}
|
|
93
|
+
onQueryChanged={handleQueryChanged}
|
|
160
94
|
onDelete={handleDeleteColumn}
|
|
161
95
|
/>
|
|
162
96
|
);
|
|
@@ -167,9 +101,19 @@ const StoryViewEditor = () => {
|
|
|
167
101
|
//
|
|
168
102
|
|
|
169
103
|
const DefaultStory = () => {
|
|
170
|
-
const { schema, table, tableRef, model, presentation,
|
|
104
|
+
const { db, schema, table, tableRef, model, presentation, handleInsertRow, handleSaveView, handleDeleteColumn } =
|
|
105
|
+
useTestTableModel();
|
|
171
106
|
|
|
172
|
-
|
|
107
|
+
const handleRowClick = useCallback(
|
|
108
|
+
(row: any) => {
|
|
109
|
+
if (model?.getDraftRowCount() === 0 && ['frozenRowsEnd', 'fixedEndStart', 'fixedEndEnd'].includes(row?.plane)) {
|
|
110
|
+
handleInsertRow();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
[model, handleInsertRow],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (!schema || !table?.view.target) {
|
|
173
117
|
return <div />;
|
|
174
118
|
}
|
|
175
119
|
|
|
@@ -177,23 +121,25 @@ const DefaultStory = () => {
|
|
|
177
121
|
<div className='grow grid grid-cols-[1fr_350px]'>
|
|
178
122
|
<div className='grid grid-rows-[min-content_1fr] min-bs-0 overflow-hidden'>
|
|
179
123
|
<TableToolbar classNames='border-be border-subduedSeparator' onAdd={handleInsertRow} onSave={handleSaveView} />
|
|
180
|
-
<
|
|
181
|
-
<
|
|
124
|
+
<TableComponent.Root>
|
|
125
|
+
<TableComponent.Main
|
|
182
126
|
ref={tableRef}
|
|
127
|
+
schema={schema}
|
|
183
128
|
model={model}
|
|
184
129
|
presentation={presentation}
|
|
185
|
-
|
|
186
|
-
client={client}
|
|
130
|
+
onRowClick={handleRowClick}
|
|
187
131
|
ignoreAttention
|
|
188
132
|
/>
|
|
189
|
-
</
|
|
190
|
-
</div>
|
|
191
|
-
<div className='flex flex-col h-full border-l border-separator overflow-y-auto'>
|
|
192
|
-
<StoryViewEditor />
|
|
193
|
-
<SyntaxHighlighter language='json' className='w-full text-xs'>
|
|
194
|
-
{JSON.stringify({ view: table.view?.target, schema }, null, 2)}
|
|
195
|
-
</SyntaxHighlighter>
|
|
133
|
+
</TableComponent.Root>
|
|
196
134
|
</div>
|
|
135
|
+
<ScrollArea.Root orientation='vertical' classNames='bs-full border-l border-separator'>
|
|
136
|
+
<ScrollArea.Viewport>
|
|
137
|
+
<StoryViewEditor view={table.view.target} schema={schema} db={db} handleDeleteColumn={handleDeleteColumn} />
|
|
138
|
+
<SyntaxHighlighter language='json' className='text-xs'>
|
|
139
|
+
{JSON.stringify({ view: table.view.target, schema }, null, 2)}
|
|
140
|
+
</SyntaxHighlighter>
|
|
141
|
+
</ScrollArea.Viewport>
|
|
142
|
+
</ScrollArea.Root>
|
|
197
143
|
</div>
|
|
198
144
|
);
|
|
199
145
|
};
|
|
@@ -206,63 +152,87 @@ type StoryProps = { rows?: number };
|
|
|
206
152
|
|
|
207
153
|
// TODO(burdon): Need super simple story.
|
|
208
154
|
|
|
209
|
-
const meta
|
|
155
|
+
const meta = {
|
|
210
156
|
title: 'ui/react-ui-table/Table',
|
|
211
157
|
render: DefaultStory,
|
|
212
|
-
parameters: { translations, controls: { disable: true } },
|
|
213
158
|
decorators: [
|
|
159
|
+
withTheme(),
|
|
160
|
+
withRegistry,
|
|
214
161
|
withClientProvider({
|
|
215
|
-
types: [
|
|
162
|
+
types: [View.View, Table.Table],
|
|
216
163
|
createIdentity: true,
|
|
217
164
|
createSpace: true,
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
const
|
|
165
|
+
onCreateSpace: async ({ space }) => {
|
|
166
|
+
const [schema] = await space.db.schemaRegistry.register([Example]);
|
|
167
|
+
const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename: schema.typename });
|
|
168
|
+
const table = Table.make({ view, jsonSchema });
|
|
169
|
+
Obj.change(view, (v) => {
|
|
170
|
+
v.projection.fields = [
|
|
171
|
+
v.projection.fields.find((field) => field.path === 'name')!,
|
|
172
|
+
...v.projection.fields.filter((field) => field.path !== 'name'),
|
|
173
|
+
];
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
space.db.add(table);
|
|
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
|
+
parameters: {
|
|
191
|
+
layout: 'fullscreen',
|
|
192
|
+
controls: {
|
|
193
|
+
disable: true,
|
|
194
|
+
},
|
|
195
|
+
translations: [...translations, ...formTranslations],
|
|
196
|
+
},
|
|
197
|
+
} satisfies Meta<typeof TableComponent>;
|
|
234
198
|
|
|
235
199
|
export default meta;
|
|
236
200
|
|
|
237
|
-
|
|
201
|
+
type Story = StoryObj<typeof meta>;
|
|
202
|
+
|
|
203
|
+
export const Default: Story = {};
|
|
238
204
|
|
|
239
205
|
export const StaticSchema: StoryObj = {
|
|
240
206
|
render: DefaultStory,
|
|
241
|
-
parameters: { translations },
|
|
242
207
|
decorators: [
|
|
243
208
|
withClientProvider({
|
|
244
|
-
types: [
|
|
209
|
+
types: [View.View, Table.Table],
|
|
245
210
|
createIdentity: true,
|
|
246
211
|
createSpace: true,
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
212
|
+
onCreateSpace: async ({ space }) => {
|
|
213
|
+
const { view, jsonSchema } = await View.makeFromDatabase({
|
|
214
|
+
db: space.db,
|
|
215
|
+
typename: TestSchema.Person.typename,
|
|
216
|
+
});
|
|
217
|
+
const table = Table.make({ view, jsonSchema });
|
|
218
|
+
space.db.add(table);
|
|
250
219
|
|
|
251
220
|
const factory = createObjectFactory(space.db, faker as any);
|
|
252
221
|
await factory([
|
|
253
|
-
|
|
254
|
-
// { type:
|
|
255
|
-
{ type: ContactWithArrayOfEmails, count: 10 },
|
|
222
|
+
{ type: TestSchema.Person, count: 10 },
|
|
223
|
+
// { type: TestSchema.Organization, count: 1 },
|
|
256
224
|
]);
|
|
257
225
|
},
|
|
258
226
|
}),
|
|
259
|
-
withLayout({ fullscreen: true }),
|
|
260
|
-
withTheme,
|
|
261
227
|
],
|
|
228
|
+
parameters: {
|
|
229
|
+
layout: 'fullscreen',
|
|
230
|
+
translations: [...translations, ...formTranslations],
|
|
231
|
+
},
|
|
262
232
|
};
|
|
263
233
|
|
|
264
234
|
const ContactWithArrayOfEmails = Schema.Struct({
|
|
265
|
-
name: Schema.String.pipe(GeneratorAnnotation.set('person.fullName')),
|
|
235
|
+
name: Schema.String.pipe(Annotation.GeneratorAnnotation.set('person.fullName')),
|
|
266
236
|
emails: Schema.optional(
|
|
267
237
|
Schema.Array(
|
|
268
238
|
Schema.Struct({
|
|
@@ -272,7 +242,7 @@ const ContactWithArrayOfEmails = Schema.Struct({
|
|
|
272
242
|
),
|
|
273
243
|
),
|
|
274
244
|
}).pipe(
|
|
275
|
-
|
|
245
|
+
Type.object({
|
|
276
246
|
typename: 'dxos.org/type/ContactWithArrayOfEmails',
|
|
277
247
|
version: '0.1.0',
|
|
278
248
|
}),
|
|
@@ -280,39 +250,43 @@ const ContactWithArrayOfEmails = Schema.Struct({
|
|
|
280
250
|
|
|
281
251
|
export const ArrayOfObjects: StoryObj = {
|
|
282
252
|
render: DefaultStory,
|
|
283
|
-
parameters: { translations },
|
|
284
253
|
decorators: [
|
|
285
254
|
withClientProvider({
|
|
286
|
-
types: [
|
|
255
|
+
types: [View.View, Table.Table, TestSchema.Person, TestSchema.Organization, ContactWithArrayOfEmails],
|
|
287
256
|
createIdentity: true,
|
|
288
257
|
createSpace: true,
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
|
|
258
|
+
onCreateSpace: async ({ space }) => {
|
|
259
|
+
const { view, jsonSchema } = await View.makeFromDatabase({
|
|
260
|
+
db: space.db,
|
|
261
|
+
typename: ContactWithArrayOfEmails.typename,
|
|
262
|
+
});
|
|
263
|
+
const table = Table.make({ view, jsonSchema });
|
|
264
|
+
space.db.add(table);
|
|
292
265
|
|
|
293
266
|
const factory = createObjectFactory(space.db, faker as any);
|
|
294
267
|
await factory([
|
|
295
|
-
// { type:
|
|
296
|
-
// { type:
|
|
268
|
+
// { type: TestSchema.Person, count: 10 },
|
|
269
|
+
// { type: TestSchema.Organization, count: 1 },
|
|
297
270
|
{ type: ContactWithArrayOfEmails, count: 10 },
|
|
298
271
|
]);
|
|
299
272
|
},
|
|
300
273
|
}),
|
|
301
|
-
withLayout({ fullscreen: true }),
|
|
302
|
-
withTheme,
|
|
303
274
|
],
|
|
275
|
+
parameters: {
|
|
276
|
+
layout: 'fullscreen',
|
|
277
|
+
translations,
|
|
278
|
+
},
|
|
304
279
|
};
|
|
305
280
|
|
|
306
281
|
export const Tags: Meta<StoryProps> = {
|
|
307
282
|
title: 'ui/react-ui-table/Table',
|
|
308
283
|
render: DefaultStory,
|
|
309
|
-
parameters: { translations },
|
|
310
284
|
decorators: [
|
|
311
285
|
withClientProvider({
|
|
312
|
-
types: [
|
|
286
|
+
types: [View.View, Table.Table],
|
|
313
287
|
createIdentity: true,
|
|
314
288
|
createSpace: true,
|
|
315
|
-
|
|
289
|
+
onCreateSpace: async ({ space }) => {
|
|
316
290
|
// Configure schema.
|
|
317
291
|
const typename = 'example.com/SingleSelect';
|
|
318
292
|
const selectOptions = [
|
|
@@ -328,25 +302,26 @@ export const Tags: Meta<StoryProps> = {
|
|
|
328
302
|
const schema = getSchemaFromPropertyDefinitions(typename, [
|
|
329
303
|
{
|
|
330
304
|
name: 'single',
|
|
331
|
-
format:
|
|
305
|
+
format: Format.TypeFormat.SingleSelect,
|
|
332
306
|
config: { options: selectOptions },
|
|
333
307
|
},
|
|
334
308
|
{
|
|
335
309
|
name: 'multiple',
|
|
336
|
-
format:
|
|
310
|
+
format: Format.TypeFormat.MultiSelect,
|
|
337
311
|
config: { options: selectOptions },
|
|
338
312
|
},
|
|
339
313
|
]);
|
|
340
314
|
const [storedSchema] = await space.db.schemaRegistry.register([schema]);
|
|
341
315
|
|
|
342
316
|
// Initialize table.
|
|
343
|
-
const
|
|
344
|
-
|
|
317
|
+
const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename });
|
|
318
|
+
const table = Table.make({ view, jsonSchema });
|
|
319
|
+
space.db.add(table);
|
|
345
320
|
|
|
346
321
|
// Populate.
|
|
347
322
|
Array.from({ length: 10 }).map(() => {
|
|
348
323
|
return space.db.add(
|
|
349
|
-
|
|
324
|
+
Obj.make(storedSchema, {
|
|
350
325
|
single: faker.helpers.arrayElement([...selectOptionIds, undefined]),
|
|
351
326
|
multiple: faker.helpers.randomSubset(selectOptionIds),
|
|
352
327
|
}),
|
|
@@ -354,7 +329,9 @@ export const Tags: Meta<StoryProps> = {
|
|
|
354
329
|
});
|
|
355
330
|
},
|
|
356
331
|
}),
|
|
357
|
-
withLayout({ fullscreen: true }),
|
|
358
|
-
withTheme,
|
|
359
332
|
],
|
|
333
|
+
parameters: {
|
|
334
|
+
layout: 'fullscreen',
|
|
335
|
+
translations,
|
|
336
|
+
},
|
|
360
337
|
};
|