@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.
Files changed (171) hide show
  1. package/dist/lib/browser/chunk-GTGYBRJA.mjs +1748 -0
  2. package/dist/lib/browser/chunk-GTGYBRJA.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
  4. package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1156 -2508
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +114 -0
  9. package/dist/lib/browser/testing/index.mjs.map +7 -0
  10. package/dist/lib/browser/types/index.mjs +3 -5
  11. package/dist/lib/node-esm/chunk-DPNSZHU5.mjs +1750 -0
  12. package/dist/lib/node-esm/chunk-DPNSZHU5.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
  14. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1156 -2508
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +115 -0
  19. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/types/index.mjs +3 -5
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +4 -2
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +37 -3
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.d.ts +13 -9
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
  36. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +2 -1
  38. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +14 -9
  40. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +12 -18
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  43. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
  44. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  46. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  47. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +4 -4
  48. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  49. package/dist/types/src/components/testing.d.ts +26 -56
  50. package/dist/types/src/components/testing.d.ts.map +1 -1
  51. package/dist/types/src/hooks/index.d.ts +2 -0
  52. package/dist/types/src/hooks/index.d.ts.map +1 -1
  53. package/dist/types/src/hooks/useAddRow.d.ts +13 -0
  54. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -0
  55. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  56. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  57. package/dist/types/src/hooks/useTableModel.d.ts +11 -10
  58. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  59. package/dist/types/src/index.d.ts +1 -2
  60. package/dist/types/src/index.d.ts.map +1 -1
  61. package/dist/types/src/model/modal-controller.d.ts +5 -8
  62. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  63. package/dist/types/src/model/selection-model.d.ts +17 -7
  64. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  65. package/dist/types/src/model/table-model.d.ts +149 -32
  66. package/dist/types/src/model/table-model.d.ts.map +1 -1
  67. package/dist/types/src/model/table-presentation.d.ts +13 -2
  68. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  69. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  70. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  71. package/dist/types/src/playwright/playwright.config.d.ts +3 -0
  72. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
  73. package/dist/types/src/testing/index.d.ts +2 -0
  74. package/dist/types/src/testing/index.d.ts.map +1 -0
  75. package/dist/types/src/testing/useTestTableModel.d.ts +25 -0
  76. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
  77. package/dist/types/src/translations.d.ts +5 -6
  78. package/dist/types/src/translations.d.ts.map +1 -1
  79. package/dist/types/src/types/Table.d.ts +31 -0
  80. package/dist/types/src/types/Table.d.ts.map +1 -0
  81. package/dist/types/src/types/index.d.ts +1 -1
  82. package/dist/types/src/types/index.d.ts.map +1 -1
  83. package/dist/types/src/util/dynamic-table.d.ts +15 -14
  84. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  85. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  86. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  87. package/dist/types/src/util/index.d.ts +2 -1
  88. package/dist/types/src/util/index.d.ts.map +1 -1
  89. package/dist/types/src/util/query-ast.d.ts +7 -0
  90. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  91. package/dist/types/src/util/schema.d.ts +1 -1
  92. package/dist/types/src/util/schema.d.ts.map +1 -1
  93. package/dist/types/src/util/sort.d.ts +12 -0
  94. package/dist/types/src/util/sort.d.ts.map +1 -0
  95. package/dist/types/src/util/table-buttons.d.ts +15 -1
  96. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  97. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  98. package/dist/types/tsconfig.tsbuildinfo +1 -1
  99. package/package.json +69 -56
  100. package/src/components/Table/ColumnActionsMenu.tsx +11 -7
  101. package/src/components/Table/ColumnSettings.tsx +16 -12
  102. package/src/components/Table/DynamicTable.stories.tsx +29 -25
  103. package/src/components/Table/DynamicTable.tsx +34 -22
  104. package/src/components/Table/Relations.stories.tsx +237 -0
  105. package/src/components/Table/RowActionsMenu.tsx +26 -17
  106. package/src/components/Table/Table.stories.tsx +171 -194
  107. package/src/components/Table/Table.tsx +364 -286
  108. package/src/components/TableCellEditor/CellValidationMessage.tsx +8 -3
  109. package/src/components/TableCellEditor/FormCellEditor.tsx +146 -49
  110. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +36 -76
  111. package/src/components/TableCellEditor/TableCellEditor.tsx +106 -198
  112. package/src/components/TableCellEditor/index.ts +1 -0
  113. package/src/components/TableToolbar/TableToolbar.tsx +49 -33
  114. package/src/components/testing.ts +41 -32
  115. package/src/hooks/index.ts +2 -0
  116. package/src/hooks/useAddRow.ts +36 -0
  117. package/src/hooks/useProjectionModel.ts +39 -0
  118. package/src/hooks/useTableModel.ts +41 -35
  119. package/src/index.ts +1 -2
  120. package/src/model/modal-controller.ts +24 -41
  121. package/src/model/selection-model.ts +75 -41
  122. package/src/model/table-model.test.ts +92 -56
  123. package/src/model/table-model.ts +628 -162
  124. package/src/model/table-presentation.test.ts +70 -59
  125. package/src/model/table-presentation.ts +278 -149
  126. package/src/playwright/TableManager.ts +13 -6
  127. package/src/playwright/playwright.config.ts +17 -0
  128. package/src/playwright/smoke.spec.ts +180 -41
  129. package/src/testing/index.ts +5 -0
  130. package/src/testing/useTestTableModel.ts +133 -0
  131. package/src/translations.ts +7 -5
  132. package/src/types/Table.ts +90 -0
  133. package/src/types/index.ts +2 -2
  134. package/src/util/dynamic-table.test.ts +70 -0
  135. package/src/util/dynamic-table.ts +50 -36
  136. package/src/util/index.ts +2 -1
  137. package/src/util/query-ast.ts +19 -0
  138. package/src/util/schema.ts +4 -4
  139. package/src/util/sort.ts +90 -0
  140. package/src/util/table-buttons.ts +28 -4
  141. package/src/util/table-controls.ts +4 -1
  142. package/dist/lib/browser/chunk-TL7CKQQV.mjs +0 -27
  143. package/dist/lib/browser/chunk-TL7CKQQV.mjs.map +0 -7
  144. package/dist/lib/node/chunk-O2VPBNS5.cjs +0 -50
  145. package/dist/lib/node/chunk-O2VPBNS5.cjs.map +0 -7
  146. package/dist/lib/node/index.cjs +0 -2739
  147. package/dist/lib/node/index.cjs.map +0 -7
  148. package/dist/lib/node/meta.json +0 -1
  149. package/dist/lib/node/types/index.cjs +0 -31
  150. package/dist/lib/node/types/index.cjs.map +0 -7
  151. package/dist/lib/node-esm/chunk-GBT6GD4G.mjs +0 -29
  152. package/dist/lib/node-esm/chunk-GBT6GD4G.mjs.map +0 -7
  153. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  154. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  155. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  156. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  157. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  158. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  159. package/dist/types/src/model/table-sorting.d.ts +0 -53
  160. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  161. package/dist/types/src/types/table.d.ts +0 -56
  162. package/dist/types/src/types/table.d.ts.map +0 -1
  163. package/dist/types/src/util/table.d.ts +0 -14
  164. package/dist/types/src/util/table.d.ts.map +0 -1
  165. package/src/components/Table/CreateRefPanel.tsx +0 -84
  166. package/src/components/Table/relations.stories.tsx +0 -124
  167. package/src/components/TableCellEditor/extension.ts +0 -61
  168. package/src/model/table-sorting.ts +0 -216
  169. package/src/playwright/playwright.config.cts +0 -18
  170. package/src/types/table.ts +0 -27
  171. package/src/util/table.ts +0 -127
@@ -2,161 +2,95 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
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 StoryObj, type Meta } from '@storybook/react';
8
- import { Schema } from 'effect';
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 { useClient } from '@dxos/react-client';
17
- import { Filter, useQuery, useSchema, live } from '@dxos/react-client/echo';
18
- import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
19
- import { ViewEditor } from '@dxos/react-ui-form';
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 { getSchemaFromPropertyDefinitions, ViewProjection, ViewType } from '@dxos/schema';
22
- import { Testing, createObjectFactory } from '@dxos/schema/testing';
23
- import { withLayout, withTheme } from '@dxos/storybook-utils';
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
- const tableRef = useRef<TableController>(null);
67
- const handleCellUpdate = useCallback((cell: any) => {
68
- tableRef.current?.update?.(cell);
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
- const handleTypenameChanged = useCallback(
140
- (typename: string) => {
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(typename);
144
- invariant(table?.view?.target);
145
- table.view.target.query.typename = typename;
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, table?.view?.target],
81
+ [schema, view],
148
82
  );
149
83
 
150
- if (!table || !schema || !table.view?.target) {
84
+ if (!view || !schema) {
151
85
  return null;
152
86
  }
153
87
 
154
88
  return (
155
89
  <ViewEditor
156
- registry={space?.db.schemaRegistry}
90
+ registry={db?.schemaRegistry}
157
91
  schema={schema}
158
- view={table.view.target!}
159
- onTypenameChanged={handleTypenameChanged}
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, client, handleInsertRow, handleSaveView } = useTestTableModel();
104
+ const { db, schema, table, tableRef, model, presentation, handleInsertRow, handleSaveView, handleDeleteColumn } =
105
+ useTestTableModel();
171
106
 
172
- if (!schema || !table) {
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
- <Table.Root>
181
- <Table.Main
124
+ <TableComponent.Root>
125
+ <TableComponent.Main
182
126
  ref={tableRef}
127
+ schema={schema}
183
128
  model={model}
184
129
  presentation={presentation}
185
- schema={schema}
186
- client={client}
130
+ onRowClick={handleRowClick}
187
131
  ignoreAttention
188
132
  />
189
- </Table.Root>
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: Meta<StoryProps> = {
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: [TableType, ViewType],
162
+ types: [View.View, Table.Table],
216
163
  createIdentity: true,
217
164
  createSpace: true,
218
- onSpaceCreated: async ({ client, space }) => {
219
- const table = space.db.add(Obj.make(TableType, {}));
220
- const schema = await initializeTable({ client, space, table, initialRow: false });
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
- live(schema, {
224
- name: faker.person.fullName(),
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
- export const Default = {};
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: [TableType, ViewType, Testing.Contact, Testing.Organization],
209
+ types: [View.View, Table.Table],
245
210
  createIdentity: true,
246
211
  createSpace: true,
247
- onSpaceCreated: async ({ client, space }) => {
248
- const table = space.db.add(Obj.make(TableType, {}));
249
- await initializeTable({ client, space, table, typename: Testing.Organization.typename });
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
- // { type: Testing.Contact, count: 10 },
254
- // { type: Testing.Organization, count: 1 },
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
- EchoObject({
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: [TableType, ViewType, Testing.Contact, Testing.Organization, ContactWithArrayOfEmails],
255
+ types: [View.View, Table.Table, TestSchema.Person, TestSchema.Organization, ContactWithArrayOfEmails],
287
256
  createIdentity: true,
288
257
  createSpace: true,
289
- onSpaceCreated: async ({ client, space }) => {
290
- const table = space.db.add(Obj.make(TableType, {}));
291
- await initializeTable({ client, space, table, typename: ContactWithArrayOfEmails.typename });
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: Testing.Contact, count: 10 },
296
- // { type: Testing.Organization, count: 1 },
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: [TableType, ViewType],
286
+ types: [View.View, Table.Table],
313
287
  createIdentity: true,
314
288
  createSpace: true,
315
- onSpaceCreated: async ({ client, space }) => {
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: FormatEnum.SingleSelect,
305
+ format: Format.TypeFormat.SingleSelect,
332
306
  config: { options: selectOptions },
333
307
  },
334
308
  {
335
309
  name: 'multiple',
336
- format: FormatEnum.MultiSelect,
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 table = space.db.add(Obj.make(TableType, {}));
344
- await initializeTable({ client, space, table, initialRow: false, typename });
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
- live(storedSchema, {
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
  };