@dxos/react-ui-table 0.8.1-main.ba2dec9 → 0.8.1-staging.31c3ee1
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-3FR6NHPD.mjs → chunk-YWNRUF4J.mjs} +8 -6
- package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +625 -225
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-NB3SFHGA.cjs → chunk-TGG6OZ54.cjs} +10 -8
- package/dist/lib/node/chunk-TGG6OZ54.cjs.map +7 -0
- package/dist/lib/node/index.cjs +618 -220
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +3 -3
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{chunk-RLVVOZW5.mjs → chunk-KKLP54L3.mjs} +8 -6
- package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +625 -225
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +24 -0
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -0
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +10 -0
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +1 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +4 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/index.d.ts +1 -0
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/components/Table/relations.stories.d.ts +9 -0
- package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +7 -7
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +8 -9
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +1 -0
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +6 -3
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +42 -16
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +4 -4
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +2 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +7 -32
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +31 -0
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +2 -2
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +5 -3
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/package.json +38 -37
- package/src/components/Table/ColumnActionsMenu.tsx +6 -4
- package/src/components/Table/ColumnSettings.tsx +5 -6
- package/src/components/Table/CreateRefPanel.tsx +3 -3
- package/src/components/Table/DynamicTable.stories.tsx +155 -0
- package/src/components/Table/DynamicTable.tsx +104 -0
- package/src/components/Table/RefPanel.tsx +3 -3
- package/src/components/Table/RowActionsMenu.tsx +18 -3
- package/src/components/Table/Table.stories.tsx +170 -115
- package/src/components/Table/Table.tsx +71 -26
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/relations.stories.tsx +113 -0
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +15 -5
- package/src/components/TableCellEditor/TableCellEditor.tsx +102 -4
- package/src/components/testing.ts +1 -1
- package/src/hooks/useTableModel.ts +35 -14
- package/src/model/index.ts +1 -0
- package/src/model/selection-model.ts +12 -2
- package/src/model/table-model.test.ts +2 -2
- package/src/model/table-model.ts +117 -32
- package/src/model/table-presentation.test.ts +2 -2
- package/src/model/table-presentation.ts +94 -22
- package/src/model/table-sorting.ts +3 -2
- package/src/playwright/smoke.spec.ts +2 -3
- package/src/types/table.ts +9 -10
- package/src/util/dynamic-table.ts +103 -0
- package/src/util/index.ts +1 -0
- package/src/util/table-controls.ts +4 -4
- package/src/util/table.ts +68 -65
- package/dist/lib/browser/_deprecated/index.mjs +0 -1483
- package/dist/lib/browser/_deprecated/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-3FR6NHPD.mjs.map +0 -7
- package/dist/lib/node/_deprecated/index.cjs +0 -1511
- package/dist/lib/node/_deprecated/index.cjs.map +0 -7
- package/dist/lib/node/chunk-NB3SFHGA.cjs.map +0 -7
- package/dist/lib/node-esm/_deprecated/index.mjs +0 -1485
- package/dist/lib/node-esm/_deprecated/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RLVVOZW5.mjs.map +0 -7
- package/dist/types/src/_deprecated/components/Cell/Cell.d.ts +0 -12
- package/dist/types/src/_deprecated/components/Cell/Cell.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts +0 -13
- package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Cell/index.d.ts +0 -2
- package/dist/types/src/_deprecated/components/Cell/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts +0 -23
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts +0 -36
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts +0 -15
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts +0 -84
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts +0 -3
- package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/Table.d.ts +0 -20
- package/dist/types/src/_deprecated/components/Table/Table.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts +0 -116
- package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableBody.d.ts +0 -12
- package/dist/types/src/_deprecated/components/Table/TableBody.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableContext.d.ts +0 -13
- package/dist/types/src/_deprecated/components/Table/TableContext.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableHead.d.ts +0 -9
- package/dist/types/src/_deprecated/components/Table/TableHead.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts +0 -17
- package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/index.d.ts +0 -5
- package/dist/types/src/_deprecated/components/Table/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/props.d.ts +0 -42
- package/dist/types/src/_deprecated/components/Table/props.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/index.d.ts +0 -4
- package/dist/types/src/_deprecated/components/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/helpers.d.ts +0 -91
- package/dist/types/src/_deprecated/helpers.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/index.d.ts +0 -5
- package/dist/types/src/_deprecated/hooks/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts +0 -12
- package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts +0 -15
- package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts +0 -3
- package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts +0 -7
- package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts.map +0 -1
- package/dist/types/src/_deprecated/index.d.ts +0 -8
- package/dist/types/src/_deprecated/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/Schema.stories.d.ts +0 -11
- package/dist/types/src/_deprecated/schema/Schema.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/column-utils.d.ts +0 -7
- package/dist/types/src/_deprecated/schema/column-utils.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/index.d.ts +0 -3
- package/dist/types/src/_deprecated/schema/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/types.d.ts +0 -27
- package/dist/types/src/_deprecated/schema/types.d.ts.map +0 -1
- package/dist/types/src/_deprecated/theme.d.ts +0 -29
- package/dist/types/src/_deprecated/theme.d.ts.map +0 -1
- package/dist/types/src/_deprecated/translations.d.ts +0 -21
- package/dist/types/src/_deprecated/translations.d.ts.map +0 -1
- package/dist/types/src/_deprecated/types.d.ts +0 -26
- package/dist/types/src/_deprecated/types.d.ts.map +0 -1
- package/src/_deprecated/components/Cell/Cell.tsx +0 -88
- package/src/_deprecated/components/Cell/CellCombobox.tsx +0 -103
- package/src/_deprecated/components/Cell/index.ts +0 -5
- package/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.tsx +0 -129
- package/src/_deprecated/components/ColumnMenu/ColumnMenu.tsx +0 -182
- package/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.tsx +0 -108
- package/src/_deprecated/components/ColumnMenu/ColumnSettings.tsx +0 -207
- package/src/_deprecated/components/ColumnMenu/index.ts +0 -6
- package/src/_deprecated/components/Table/Table.stories.tsx +0 -508
- package/src/_deprecated/components/Table/Table.tsx +0 -301
- package/src/_deprecated/components/Table/TableBody.tsx +0 -82
- package/src/_deprecated/components/Table/TableContext.tsx +0 -34
- package/src/_deprecated/components/Table/TableHead.tsx +0 -78
- package/src/_deprecated/components/Table/TableRootContext.ts +0 -39
- package/src/_deprecated/components/Table/index.ts +0 -8
- package/src/_deprecated/components/Table/props.ts +0 -60
- package/src/_deprecated/components/index.ts +0 -7
- package/src/_deprecated/helpers.tsx +0 -526
- package/src/_deprecated/hooks/index.ts +0 -8
- package/src/_deprecated/hooks/useColumnSizing.ts +0 -46
- package/src/_deprecated/hooks/useColumnSorting.ts +0 -64
- package/src/_deprecated/hooks/usePinLastRow.ts +0 -47
- package/src/_deprecated/hooks/useRowSelection.ts +0 -40
- package/src/_deprecated/index.ts +0 -12
- package/src/_deprecated/schema/Schema.stories.tsx +0 -59
- package/src/_deprecated/schema/column-utils.ts +0 -54
- package/src/_deprecated/schema/index.ts +0 -6
- package/src/_deprecated/schema/types.ts +0 -40
- package/src/_deprecated/theme.ts +0 -82
- package/src/_deprecated/translations.ts +0 -26
- package/src/_deprecated/types.ts +0 -38
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { BaseSchema, JsonSchemaType, SortDirectionType } from '@dxos/echo-schema';
|
|
6
|
+
import { create, makeRef } from '@dxos/live-object';
|
|
7
|
+
import {
|
|
8
|
+
createView,
|
|
9
|
+
getSchemaFromPropertyDefinitions,
|
|
10
|
+
ViewProjection,
|
|
11
|
+
type ViewType,
|
|
12
|
+
type SchemaPropertyDefinition,
|
|
13
|
+
} from '@dxos/schema';
|
|
14
|
+
|
|
15
|
+
import { TableType } from '../types';
|
|
16
|
+
|
|
17
|
+
// TODO(ZaymonFC): Upstream these extra fields to SchemaPropertyDefinition to enhance schema-tools schema creation.
|
|
18
|
+
type PropertyDisplayProps = {
|
|
19
|
+
size: number;
|
|
20
|
+
title: string;
|
|
21
|
+
sort: SortDirectionType;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<PropertyDisplayProps>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
29
|
+
// TODO(burdon): Remove variance.
|
|
30
|
+
export const getBaseSchems = ({
|
|
31
|
+
typename,
|
|
32
|
+
properties,
|
|
33
|
+
jsonSchema,
|
|
34
|
+
schema,
|
|
35
|
+
}: {
|
|
36
|
+
typename?: string;
|
|
37
|
+
properties?: TablePropertyDefinition[];
|
|
38
|
+
jsonSchema?: JsonSchemaType;
|
|
39
|
+
schema?: BaseSchema;
|
|
40
|
+
}): { typename: string; jsonSchema: JsonSchemaType } => {
|
|
41
|
+
if (typename && properties) {
|
|
42
|
+
const schema = getSchemaFromPropertyDefinitions(typename, properties);
|
|
43
|
+
return { typename: schema.typename, jsonSchema: schema.jsonSchema };
|
|
44
|
+
} else if (schema) {
|
|
45
|
+
return { typename: schema.typename, jsonSchema: schema.jsonSchema };
|
|
46
|
+
} else if (typename && jsonSchema) {
|
|
47
|
+
return { typename, jsonSchema };
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('invalid properties');
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const makeDynamicTable = ({
|
|
54
|
+
typename,
|
|
55
|
+
jsonSchema,
|
|
56
|
+
properties,
|
|
57
|
+
}: {
|
|
58
|
+
typename: string;
|
|
59
|
+
jsonSchema: JsonSchemaType;
|
|
60
|
+
properties?: TablePropertyDefinition[];
|
|
61
|
+
}): { table: TableType; projection: ViewProjection } => {
|
|
62
|
+
const view = createView({
|
|
63
|
+
name: 'dynamic-table',
|
|
64
|
+
typename,
|
|
65
|
+
jsonSchema,
|
|
66
|
+
...(properties && { fields: properties.map((property) => property.name) }),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const table = create(TableType, { name: 'dynamic-table', view: makeRef(view) });
|
|
70
|
+
const projection = new ViewProjection(jsonSchema, view);
|
|
71
|
+
if (properties && view.fields) {
|
|
72
|
+
setProperties(view, projection, properties);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
table,
|
|
77
|
+
projection,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const setProperties = (view: ViewType, projection: ViewProjection, properties: TablePropertyDefinition[]) => {
|
|
82
|
+
for (const property of properties) {
|
|
83
|
+
const field = view.fields.find((field) => field.path === property.name);
|
|
84
|
+
if (field) {
|
|
85
|
+
if (property.size !== undefined) {
|
|
86
|
+
field.size = property.size;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (property.title !== undefined) {
|
|
90
|
+
const fieldProjection = projection.getFieldProjection(field.id);
|
|
91
|
+
projection.setFieldProjection({
|
|
92
|
+
...fieldProjection,
|
|
93
|
+
props: { ...fieldProjection.props, title: property.title },
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (property.sort) {
|
|
98
|
+
const fieldId = field.id;
|
|
99
|
+
view.query.sort = [{ fieldId, direction: property.sort }];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
package/src/util/index.ts
CHANGED
|
@@ -44,7 +44,7 @@ const renderInput = (
|
|
|
44
44
|
return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}"/>`;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export const
|
|
47
|
+
export const CheckboxStory = ({
|
|
48
48
|
rowIndex,
|
|
49
49
|
header = false,
|
|
50
50
|
checked = false,
|
|
@@ -59,7 +59,7 @@ export const renderCheckbox = ({
|
|
|
59
59
|
return renderInput(BASE_CLASSES.checkbox, attrs, checked, disabled, true, 'table-selection');
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
export const
|
|
62
|
+
export const SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = false }: RenderSwitchProps): string => {
|
|
63
63
|
const attrs = {
|
|
64
64
|
[CONTROL_IDENTIFIERS.switch]: '',
|
|
65
65
|
'data-row-index': rowIndex.toString(),
|
|
@@ -72,7 +72,7 @@ export const renderSwitch = ({ colIndex, rowIndex, checked = false, disabled = f
|
|
|
72
72
|
export const tableControls = {
|
|
73
73
|
checkbox: {
|
|
74
74
|
attr: CONTROL_IDENTIFIERS.checkbox,
|
|
75
|
-
render:
|
|
75
|
+
render: CheckboxStory,
|
|
76
76
|
getData: (el: HTMLElement): Extract<ControlData, { type: 'checkbox' }> => ({
|
|
77
77
|
type: 'checkbox',
|
|
78
78
|
rowIndex: Number(el.getAttribute('data-row-index')),
|
|
@@ -81,7 +81,7 @@ export const tableControls = {
|
|
|
81
81
|
},
|
|
82
82
|
switch: {
|
|
83
83
|
attr: CONTROL_IDENTIFIERS.switch,
|
|
84
|
-
render:
|
|
84
|
+
render: SwitchStory,
|
|
85
85
|
getData: (el: HTMLElement): Extract<ControlData, { type: 'switch' }> => ({
|
|
86
86
|
type: 'switch',
|
|
87
87
|
rowIndex: Number(el.getAttribute('data-row-index')),
|
package/src/util/table.ts
CHANGED
|
@@ -4,47 +4,45 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
AST,
|
|
7
|
+
type EchoSchema,
|
|
7
8
|
Format,
|
|
8
9
|
FormatEnum,
|
|
9
10
|
type JsonPath,
|
|
10
11
|
type JsonProp,
|
|
11
|
-
type EchoSchema,
|
|
12
12
|
S,
|
|
13
13
|
TypedObject,
|
|
14
14
|
TypeEnum,
|
|
15
15
|
} from '@dxos/echo-schema';
|
|
16
|
-
import { PublicKey } from '@dxos/react-client';
|
|
16
|
+
import { type Client, PublicKey } from '@dxos/react-client';
|
|
17
17
|
import { create, makeRef, type Space } from '@dxos/react-client/echo';
|
|
18
|
-
import { createFieldId, createView, getSchemaProperties, ViewProjection } from '@dxos/schema';
|
|
18
|
+
import { createFieldId, createView, getSchemaProperties, ViewProjection, type ViewType } from '@dxos/schema';
|
|
19
19
|
|
|
20
20
|
import { type TableType } from '../types';
|
|
21
21
|
|
|
22
|
+
// TODO(ZaymonFC): We don't need the client anymore.
|
|
22
23
|
type InitialiseTableProps = {
|
|
24
|
+
client: Client;
|
|
23
25
|
space: Space;
|
|
24
26
|
table: TableType;
|
|
27
|
+
typename?: string;
|
|
25
28
|
initialRow?: boolean;
|
|
26
|
-
initialSchema?: string;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
|
-
// TODO(ZaymonFC): Clean up the branching in this file.
|
|
30
|
-
|
|
31
|
-
// TODO(burdon): Pass in type.
|
|
32
|
-
// TODO(burdon): User should determine typename.
|
|
33
31
|
export const initializeTable = async ({
|
|
32
|
+
client,
|
|
34
33
|
space,
|
|
35
34
|
table,
|
|
35
|
+
typename,
|
|
36
36
|
initialRow = true,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const schema = await space.db.schemaRegistry.query({ typename: initialSchema }).firstOrUndefined();
|
|
41
|
-
|
|
37
|
+
}: InitialiseTableProps): Promise<S.Schema.AnyNoContext> => {
|
|
38
|
+
if (typename) {
|
|
39
|
+
const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
|
|
42
40
|
if (!schema) {
|
|
43
|
-
throw new Error(`Schema not found: ${
|
|
41
|
+
throw new Error(`Schema not found: ${typename}`);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
// We need to get the schema properties here.
|
|
47
|
-
// are going to be supported.
|
|
44
|
+
// We need to get the schema properties here.
|
|
45
|
+
// For now, only simple types and refs, not compound types are going to be supported.
|
|
48
46
|
const fields = getSchemaProperties(schema.ast)
|
|
49
47
|
.filter((prop) => prop.format !== FormatEnum.Ref)
|
|
50
48
|
.map((prop) => prop.name);
|
|
@@ -61,66 +59,71 @@ export const initializeTable = async ({
|
|
|
61
59
|
|
|
62
60
|
return schema;
|
|
63
61
|
} else {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
version: '0.1.0',
|
|
67
|
-
})({
|
|
68
|
-
name: S.optional(S.String).annotations({
|
|
69
|
-
[AST.TitleAnnotationId]: 'Name',
|
|
70
|
-
}),
|
|
71
|
-
active: S.optional(S.Boolean),
|
|
72
|
-
email: S.optional(Format.Email),
|
|
73
|
-
salary: S.optional(Format.Currency()).annotations({
|
|
74
|
-
[AST.TitleAnnotationId]: 'Salary',
|
|
75
|
-
}), // TODO(burdon): Should default to prop name?
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const [contactSchema] = await space.db.schemaRegistry.register([ContactSchema]);
|
|
62
|
+
const [schema] = await space.db.schemaRegistry.register([ContactSchema]);
|
|
63
|
+
const fields = ContactFields;
|
|
79
64
|
|
|
80
65
|
table.view = makeRef(
|
|
81
66
|
createView({
|
|
82
67
|
name: 'View',
|
|
83
|
-
typename:
|
|
84
|
-
jsonSchema:
|
|
85
|
-
fields
|
|
68
|
+
typename: schema.typename,
|
|
69
|
+
jsonSchema: schema.jsonSchema,
|
|
70
|
+
fields,
|
|
86
71
|
}),
|
|
87
72
|
);
|
|
88
73
|
|
|
89
|
-
|
|
90
|
-
projection.setFieldProjection({
|
|
91
|
-
field: {
|
|
92
|
-
id: table.view.target!.fields.find((f) => f.path === 'salary')!.id,
|
|
93
|
-
path: 'salary' as JsonPath,
|
|
94
|
-
size: 150,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
projection.setFieldProjection({
|
|
98
|
-
field: {
|
|
99
|
-
id: table.view.target!.fields.find((f) => f.path === 'active')!.id,
|
|
100
|
-
path: 'active' as JsonPath,
|
|
101
|
-
size: 100,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
74
|
+
createProjection(schema, table.view.target!);
|
|
104
75
|
|
|
105
|
-
projection.setFieldProjection({
|
|
106
|
-
field: {
|
|
107
|
-
id: createFieldId(),
|
|
108
|
-
path: 'manager' as JsonPath,
|
|
109
|
-
referencePath: 'name' as JsonPath,
|
|
110
|
-
},
|
|
111
|
-
props: {
|
|
112
|
-
property: 'manager' as JsonProp,
|
|
113
|
-
type: TypeEnum.Ref,
|
|
114
|
-
format: FormatEnum.Ref,
|
|
115
|
-
referenceSchema: contactSchema.typename,
|
|
116
|
-
title: 'Manager',
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
76
|
if (initialRow) {
|
|
120
77
|
// TODO(burdon): Last (first) row should not be in db and should be managed by the model.
|
|
121
|
-
space.db.add(create(
|
|
78
|
+
space.db.add(create(schema, {}));
|
|
122
79
|
}
|
|
123
80
|
|
|
124
|
-
return
|
|
81
|
+
return schema;
|
|
125
82
|
}
|
|
126
83
|
};
|
|
84
|
+
|
|
85
|
+
const ContactSchema = TypedObject({
|
|
86
|
+
typename: `example.com/type/${PublicKey.random().truncate()}`,
|
|
87
|
+
version: '0.1.0',
|
|
88
|
+
})({
|
|
89
|
+
name: S.optional(S.String).annotations({ [AST.TitleAnnotationId]: 'Name' }),
|
|
90
|
+
active: S.optional(S.Boolean),
|
|
91
|
+
email: S.optional(Format.Email),
|
|
92
|
+
salary: S.optional(Format.Currency()).annotations({ [AST.TitleAnnotationId]: 'Salary' }),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const ContactFields = ['name', 'email', 'salary', 'active'];
|
|
96
|
+
|
|
97
|
+
const createProjection = (schema: EchoSchema, view: ViewType): ViewProjection => {
|
|
98
|
+
const projection = new ViewProjection(schema.jsonSchema, view);
|
|
99
|
+
projection.setFieldProjection({
|
|
100
|
+
field: {
|
|
101
|
+
id: view.fields.find((f) => f.path === 'salary')!.id,
|
|
102
|
+
path: 'salary' as JsonPath,
|
|
103
|
+
size: 150,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
projection.setFieldProjection({
|
|
107
|
+
field: {
|
|
108
|
+
id: view.fields.find((f) => f.path === 'active')!.id,
|
|
109
|
+
path: 'active' as JsonPath,
|
|
110
|
+
size: 100,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
projection.setFieldProjection({
|
|
114
|
+
field: {
|
|
115
|
+
id: createFieldId(),
|
|
116
|
+
path: 'manager' as JsonPath,
|
|
117
|
+
referencePath: 'name' as JsonPath,
|
|
118
|
+
},
|
|
119
|
+
props: {
|
|
120
|
+
property: 'manager' as JsonProp,
|
|
121
|
+
type: TypeEnum.Ref,
|
|
122
|
+
format: FormatEnum.Ref,
|
|
123
|
+
referenceSchema: schema.typename,
|
|
124
|
+
title: 'Manager',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return projection;
|
|
129
|
+
};
|