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