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