@dxos/react-ui-table 0.8.1-main.ae460ac → 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 +2 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +2 -1
- package/dist/types/src/components/Table/CreateRefPanel.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/RefPanel.d.ts +2 -1
- package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +2 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +2 -1
- 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 +2 -1
- 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/TableToolbar/TableToolbar.d.ts +2 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +14 -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 +16 -20
- 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 -12
- 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 -22
- 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 -35
- 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 -14
- 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 -83
- 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 -115
- 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 -11
- 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 -8
- 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 -10
- 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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { S } from '@dxos/echo-schema';
|
|
8
|
-
import { create
|
|
8
|
+
import { create } from '@dxos/react-client/echo';
|
|
9
9
|
import { Popover } from '@dxos/react-ui';
|
|
10
10
|
import { Form } from '@dxos/react-ui-form';
|
|
11
11
|
import { type GridScopedProps, useGridContext } from '@dxos/react-ui-grid';
|
|
@@ -17,7 +17,7 @@ export type CreateRefPanelProps = { model?: TableModel; modals: ModalController
|
|
|
17
17
|
// TODO(burdon): Factor out Space dependency (to plugin?)
|
|
18
18
|
export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<CreateRefPanelProps>) => {
|
|
19
19
|
const { id: gridId } = useGridContext('TableCellEditor', __gridScope);
|
|
20
|
-
const space =
|
|
20
|
+
const space = model?.space;
|
|
21
21
|
const state = modals.state.value;
|
|
22
22
|
|
|
23
23
|
const schema = useMemo<S.Schema<any> | undefined>(() => {
|
|
@@ -54,7 +54,7 @@ export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<C
|
|
|
54
54
|
}
|
|
55
55
|
}, [modals]);
|
|
56
56
|
|
|
57
|
-
if (!model?.
|
|
57
|
+
if (!model?.view || !model.projection) {
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type StoryObj, type Meta } from '@storybook/react';
|
|
8
|
+
import React, { useMemo, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { FormatEnum, type JsonSchemaType } from '@dxos/echo-schema';
|
|
11
|
+
import { faker } from '@dxos/random';
|
|
12
|
+
import { useClient } from '@dxos/react-client';
|
|
13
|
+
import { Filter, useQuery, useSchema, create } from '@dxos/react-client/echo';
|
|
14
|
+
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
15
|
+
import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
16
|
+
import { Testing } from '@dxos/schema/testing';
|
|
17
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
18
|
+
|
|
19
|
+
import { DynamicTable } from './DynamicTable';
|
|
20
|
+
import { type TableFeatures } from '../../model';
|
|
21
|
+
import translations from '../../translations';
|
|
22
|
+
|
|
23
|
+
faker.seed(0);
|
|
24
|
+
|
|
25
|
+
const useTestPropertiesAndObjects = () => {
|
|
26
|
+
const properties = useMemo<SchemaPropertyDefinition[]>(
|
|
27
|
+
() => [
|
|
28
|
+
{ name: 'name', format: FormatEnum.String },
|
|
29
|
+
{ name: 'age', format: FormatEnum.Number },
|
|
30
|
+
],
|
|
31
|
+
[],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const [rows] = useState<any[]>(
|
|
35
|
+
Array.from({ length: 10 }, () => ({
|
|
36
|
+
id: faker.string.uuid(),
|
|
37
|
+
name: faker.person.fullName(),
|
|
38
|
+
age: faker.number.int({ min: 18, max: 80 }),
|
|
39
|
+
})),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return { properties, rows };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//
|
|
46
|
+
// Story components.
|
|
47
|
+
//
|
|
48
|
+
|
|
49
|
+
const DynamicTableStory = () => {
|
|
50
|
+
const { properties, rows } = useTestPropertiesAndObjects();
|
|
51
|
+
return <DynamicTable properties={properties} rows={rows} />;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//
|
|
55
|
+
// Story definitions.
|
|
56
|
+
//
|
|
57
|
+
|
|
58
|
+
const meta: Meta = {
|
|
59
|
+
title: 'ui/react-ui-table/DynamicTable',
|
|
60
|
+
component: DynamicTable,
|
|
61
|
+
parameters: { translations },
|
|
62
|
+
decorators: [withTheme, withLayout({ fullscreen: true, tooltips: true })],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default meta;
|
|
66
|
+
|
|
67
|
+
export const Default: StoryObj = {
|
|
68
|
+
render: DynamicTableStory,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const WithRowClicks: StoryObj = {
|
|
72
|
+
render: () => {
|
|
73
|
+
const { properties, rows } = useTestPropertiesAndObjects();
|
|
74
|
+
|
|
75
|
+
const handleRowClicked = (row: any) => {
|
|
76
|
+
console.log('Row clicked:', row);
|
|
77
|
+
alert(`Row clicked: ${row.name}, age: ${row.age}`);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return <DynamicTable properties={properties} rows={rows} onRowClick={handleRowClicked} />;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const WithClickToSelect: StoryObj = {
|
|
85
|
+
render: () => {
|
|
86
|
+
const { properties, rows } = useTestPropertiesAndObjects();
|
|
87
|
+
|
|
88
|
+
const features = useMemo<Partial<TableFeatures>>(
|
|
89
|
+
() => ({ selection: { enabled: true, mode: 'single' as const }, dataEditable: false }),
|
|
90
|
+
[],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return <DynamicTable properties={properties} rows={rows} features={features} />;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const WithJsonSchema: StoryObj = {
|
|
98
|
+
render: () => {
|
|
99
|
+
const schema = useMemo<JsonSchemaType>(
|
|
100
|
+
() => ({
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
name: { type: 'string', title: 'Full Name' },
|
|
104
|
+
age: { type: 'number', title: 'Age (Years)' },
|
|
105
|
+
email: { type: 'string', format: 'email', title: 'Email Address' },
|
|
106
|
+
active: { type: 'boolean', title: 'Active Status' },
|
|
107
|
+
},
|
|
108
|
+
required: ['name', 'email'],
|
|
109
|
+
}),
|
|
110
|
+
[],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const [rows] = useState<any[]>(
|
|
114
|
+
Array.from({ length: 15 }, () => ({
|
|
115
|
+
name: faker.person.fullName(),
|
|
116
|
+
age: faker.number.int({ min: 18, max: 80 }),
|
|
117
|
+
email: faker.internet.email(),
|
|
118
|
+
active: faker.datatype.boolean(),
|
|
119
|
+
})),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return <DynamicTable jsonSchema={schema} rows={rows} />;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const WithEchoSchema: StoryObj = {
|
|
127
|
+
render: () => {
|
|
128
|
+
const client = useClient();
|
|
129
|
+
const { space } = useClientProvider();
|
|
130
|
+
const schema = useSchema(client, space, Testing.Contact.typename);
|
|
131
|
+
const objects = useQuery(space, schema ? Filter.schema(schema) : Filter.nothing());
|
|
132
|
+
if (!schema) {
|
|
133
|
+
return <div>Loading schema...</div>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return <DynamicTable schema={schema} rows={objects} />;
|
|
137
|
+
},
|
|
138
|
+
decorators: [
|
|
139
|
+
withClientProvider({
|
|
140
|
+
types: [Testing.Contact],
|
|
141
|
+
createIdentity: true,
|
|
142
|
+
createSpace: true,
|
|
143
|
+
onSpaceCreated: async ({ space }) => {
|
|
144
|
+
Array.from({ length: 10 }).forEach(() => {
|
|
145
|
+
space.db.add(
|
|
146
|
+
create(Testing.Contact, {
|
|
147
|
+
name: faker.person.fullName(),
|
|
148
|
+
email: faker.internet.email(),
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
],
|
|
155
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useRef, useMemo, useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type BaseSchema, type JsonSchemaType } from '@dxos/echo-schema';
|
|
8
|
+
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
9
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
10
|
+
|
|
11
|
+
import { Table, type TableController } from './Table';
|
|
12
|
+
import { useTableModel } from '../../hooks';
|
|
13
|
+
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
14
|
+
import { getBaseSchems as getBaseSchema, makeDynamicTable, type TablePropertyDefinition } from '../../util';
|
|
15
|
+
|
|
16
|
+
type DynamicTableProps = ThemedClassName<{
|
|
17
|
+
name?: string; // TODO(burdon): Remove?
|
|
18
|
+
rows: any[];
|
|
19
|
+
properties?: TablePropertyDefinition[];
|
|
20
|
+
jsonSchema?: JsonSchemaType;
|
|
21
|
+
schema?: BaseSchema;
|
|
22
|
+
features?: Partial<TableFeatures>;
|
|
23
|
+
rowActions?: TableRowAction[];
|
|
24
|
+
onRowClick?: (row: any) => void;
|
|
25
|
+
onRowAction?: (actionId: string, datum: any) => void;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Properties define both the schema and display characteristics of the table columns.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Use Table.
|
|
32
|
+
*/
|
|
33
|
+
// TODO(burdon): Instead of creating component variants, create helpers/hooks that normalize the props.
|
|
34
|
+
// TODO(burdon): Warning: Cannot update a component (`DynamicTable`) while rendering a different component (`DynamicTable`).
|
|
35
|
+
export const DynamicTable = ({
|
|
36
|
+
classNames,
|
|
37
|
+
name = 'example.com/dynamic-table', // Rmove default or make random; this will lead to type collisions.
|
|
38
|
+
rows,
|
|
39
|
+
properties,
|
|
40
|
+
jsonSchema,
|
|
41
|
+
schema,
|
|
42
|
+
rowActions,
|
|
43
|
+
onRowClick,
|
|
44
|
+
onRowAction,
|
|
45
|
+
...props
|
|
46
|
+
}: DynamicTableProps) => {
|
|
47
|
+
const { table, projection } = useMemo(() => {
|
|
48
|
+
// TODO(burdon): Remove variance from the props (should be normalized externally; possibly via hooks).
|
|
49
|
+
const props = getBaseSchema({ typename: name, properties, jsonSchema, schema });
|
|
50
|
+
return makeDynamicTable({ ...props, properties });
|
|
51
|
+
}, [name, properties, schema, jsonSchema]);
|
|
52
|
+
|
|
53
|
+
const tableRef = useRef<TableController>(null);
|
|
54
|
+
const handleCellUpdate = useCallback((cell: any) => {
|
|
55
|
+
tableRef.current?.update?.(cell);
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const handleRowOrderChange = useCallback(() => {
|
|
59
|
+
tableRef.current?.update?.();
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
const features = useDefaultValue(
|
|
63
|
+
props.features,
|
|
64
|
+
() =>
|
|
65
|
+
({
|
|
66
|
+
selection: { enabled: false },
|
|
67
|
+
dataEditable: false,
|
|
68
|
+
}) as const,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const model = useTableModel({
|
|
72
|
+
table,
|
|
73
|
+
rows,
|
|
74
|
+
projection,
|
|
75
|
+
features,
|
|
76
|
+
rowActions,
|
|
77
|
+
onCellUpdate: handleCellUpdate,
|
|
78
|
+
onRowOrderChange: handleRowOrderChange,
|
|
79
|
+
onRowAction,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const presentation = useMemo(() => {
|
|
83
|
+
if (model) {
|
|
84
|
+
return new TablePresentation(model);
|
|
85
|
+
}
|
|
86
|
+
}, [model]);
|
|
87
|
+
|
|
88
|
+
// TODO(burdon): Do we need the outer divs?
|
|
89
|
+
return (
|
|
90
|
+
<div role='none' className={mx('is-full bs-full grow grid', classNames)}>
|
|
91
|
+
<div role='none' className='grid min-bs-0 overflow-hidden'>
|
|
92
|
+
<Table.Root>
|
|
93
|
+
<Table.Main
|
|
94
|
+
ref={tableRef}
|
|
95
|
+
model={model}
|
|
96
|
+
presentation={presentation}
|
|
97
|
+
ignoreAttention
|
|
98
|
+
onRowClick={onRowClick}
|
|
99
|
+
/>
|
|
100
|
+
</Table.Root>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
8
8
|
import { Popover } from '@dxos/react-ui';
|
|
9
9
|
import { Form } from '@dxos/react-ui-form';
|
|
10
10
|
|
|
@@ -22,11 +22,11 @@ const getRefTargetObj = (space?: Space, id?: string) => {
|
|
|
22
22
|
|
|
23
23
|
export const RefPanel = ({ model, modals }: RefPanelProps) => {
|
|
24
24
|
const state = modals.state.value;
|
|
25
|
-
const space =
|
|
25
|
+
const space = model?.space;
|
|
26
26
|
const targetObj = getRefTargetObj(space, state?.type === 'refPanel' ? state.targetId : undefined);
|
|
27
27
|
const schema = space && state?.type === 'refPanel' ? space.db.schemaRegistry.getSchema(state.typename) : undefined;
|
|
28
28
|
|
|
29
|
-
if (!model.
|
|
29
|
+
if (!model.view || !model.projection) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -23,9 +23,24 @@ export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
|
23
23
|
<DropdownMenu.VirtualTrigger virtualRef={modals.trigger} />
|
|
24
24
|
<DropdownMenu.Content>
|
|
25
25
|
<DropdownMenu.Viewport>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
{model.features.dataEditable !== false && (
|
|
27
|
+
<DropdownMenu.Item data-testid='row-menu-delete' onClick={() => model.deleteRow(state.rowIndex)}>
|
|
28
|
+
{t(hasSelection ? 'bulk delete row label' : 'delete row label')}
|
|
29
|
+
</DropdownMenu.Item>
|
|
30
|
+
)}
|
|
31
|
+
{/* Custom actions */}
|
|
32
|
+
{model.rowActions?.map((action) => (
|
|
33
|
+
<DropdownMenu.Item
|
|
34
|
+
key={action.id}
|
|
35
|
+
data-testid={`row-action-${action.id}`}
|
|
36
|
+
onClick={() => {
|
|
37
|
+
modals.close();
|
|
38
|
+
model.handleRowAction(action.id, state.rowIndex);
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
{t(action.translationKey)}
|
|
42
|
+
</DropdownMenu.Item>
|
|
43
|
+
))}
|
|
29
44
|
</DropdownMenu.Viewport>
|
|
30
45
|
<DropdownMenu.Arrow />
|
|
31
46
|
</DropdownMenu.Content>
|