@dxos/react-ui-table 0.7.4 → 0.7.5-labs.401163d
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-IYCSJDMB.mjs → chunk-3FR6NHPD.mjs} +7 -5
- package/dist/lib/browser/chunk-3FR6NHPD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1488 -1112
- 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-MHBMVCFZ.cjs → chunk-NB3SFHGA.cjs} +9 -7
- package/dist/lib/node/chunk-NB3SFHGA.cjs.map +7 -0
- package/dist/lib/node/index.cjs +1493 -1097
- 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-BMWGPXPL.mjs → chunk-RLVVOZW5.mjs} +7 -5
- package/dist/lib/node-esm/chunk-RLVVOZW5.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1488 -1112
- 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/_deprecated/hooks/useColumnSorting.d.ts +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +4 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +3 -2
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RefPanel.d.ts +4 -3
- package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +3 -2
- 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 +1 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -2
- 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 +18 -0
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -0
- package/dist/types/src/components/TableToolbar/index.d.ts +2 -0
- package/dist/types/src/components/TableToolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +31 -71
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.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/modal-controller.d.ts +6 -2
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +19 -31
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +22 -0
- package/dist/types/src/model/table-presentation.d.ts.map +1 -0
- package/dist/types/src/model/table-presentation.test.d.ts +2 -0
- package/dist/types/src/model/table-presentation.test.d.ts.map +1 -0
- package/dist/types/src/model/table-sorting.d.ts +53 -0
- package/dist/types/src/model/table-sorting.d.ts.map +1 -0
- 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/translations.d.ts +2 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +46 -154
- package/dist/types/src/types/table.d.ts.map +1 -1
- 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-buttons.d.ts +63 -19
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +32 -9
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +3 -2
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +35 -34
- package/src/_deprecated/schema/Schema.stories.tsx +1 -1
- package/src/components/Table/ColumnActionsMenu.tsx +12 -12
- package/src/components/Table/ColumnSettings.tsx +11 -11
- package/src/components/Table/CreateRefPanel.tsx +13 -14
- package/src/components/Table/RefPanel.tsx +9 -9
- package/src/components/Table/RowActionsMenu.tsx +6 -7
- package/src/components/Table/Table.stories.tsx +84 -56
- package/src/components/Table/Table.tsx +239 -148
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +13 -12
- package/src/components/TableCellEditor/TableCellEditor.tsx +6 -4
- package/src/components/TableToolbar/TableToolbar.tsx +72 -0
- package/src/components/{Toolbar → TableToolbar}/index.ts +1 -1
- package/src/components/index.ts +1 -1
- package/src/components/testing.ts +10 -8
- package/src/hooks/useTableModel.ts +19 -0
- package/src/index.ts +2 -0
- package/src/model/index.ts +1 -0
- package/src/model/modal-controller.ts +15 -48
- package/src/model/selection-model.ts +12 -1
- package/src/model/table-model.test.ts +4 -76
- package/src/model/table-model.ts +73 -304
- package/src/model/table-presentation.test.ts +102 -0
- package/src/model/table-presentation.ts +235 -0
- package/src/model/table-sorting.ts +215 -0
- package/src/playwright/TableManager.ts +5 -1
- package/src/playwright/smoke.spec.ts +94 -9
- package/src/translations.ts +2 -1
- package/src/types/table.ts +4 -4
- package/src/util/index.ts +1 -0
- package/src/util/table-buttons.ts +127 -48
- package/src/util/table-controls.ts +71 -7
- package/src/util/table.ts +93 -52
- package/dist/lib/browser/chunk-IYCSJDMB.mjs.map +0 -7
- package/dist/lib/node/chunk-MHBMVCFZ.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-BMWGPXPL.mjs.map +0 -7
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -21
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/common.d.ts +0 -14
- package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/index.d.ts +0 -2
- package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
- package/src/components/Toolbar/Toolbar.tsx +0 -87
- package/src/components/Toolbar/common.tsx +0 -71
|
@@ -9,13 +9,13 @@ import { DropdownMenu } from '@dxos/react-ui';
|
|
|
9
9
|
import { FieldEditor } from '@dxos/react-ui-form';
|
|
10
10
|
import { type FieldType } from '@dxos/schema';
|
|
11
11
|
|
|
12
|
-
import { type TableModel } from '../../model';
|
|
12
|
+
import { type TableModel, type ModalController } from '../../model';
|
|
13
13
|
|
|
14
|
-
type ColumnSettingsProps = { model?: TableModel; onNewColumn: () => void };
|
|
14
|
+
type ColumnSettingsProps = { model?: TableModel; modals: ModalController; onNewColumn: () => void };
|
|
15
15
|
|
|
16
|
-
export const ColumnSettings = ({ model, onNewColumn }: ColumnSettingsProps) => {
|
|
16
|
+
export const ColumnSettings = ({ model, modals, onNewColumn }: ColumnSettingsProps) => {
|
|
17
17
|
const [newField, setNewField] = useState<FieldType>();
|
|
18
|
-
const state =
|
|
18
|
+
const state = modals.state.value;
|
|
19
19
|
|
|
20
20
|
const space = getSpace(model?.table);
|
|
21
21
|
|
|
@@ -34,17 +34,17 @@ export const ColumnSettings = ({ model, onNewColumn }: ColumnSettingsProps) => {
|
|
|
34
34
|
if (state?.type === 'columnSettings') {
|
|
35
35
|
const { mode } = state;
|
|
36
36
|
if (mode.type === 'edit') {
|
|
37
|
-
return model?.table?.view?.fields.find((f) => f.id === mode.fieldId);
|
|
37
|
+
return model?.table?.view?.target?.fields.find((f) => f.id === mode.fieldId);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return undefined;
|
|
41
|
-
}, [model?.table?.view?.fields, state]);
|
|
41
|
+
}, [model?.table?.view?.target?.fields, state]);
|
|
42
42
|
|
|
43
43
|
const field = existingField ?? newField;
|
|
44
44
|
|
|
45
45
|
const handleSave = useCallback(() => {
|
|
46
|
-
|
|
47
|
-
}, [
|
|
46
|
+
modals.close();
|
|
47
|
+
}, [modals]);
|
|
48
48
|
|
|
49
49
|
const handleCancel = useCallback(() => {
|
|
50
50
|
if (state?.type === 'columnSettings' && state.mode.type === 'create' && newField) {
|
|
@@ -52,18 +52,18 @@ export const ColumnSettings = ({ model, onNewColumn }: ColumnSettingsProps) => {
|
|
|
52
52
|
}
|
|
53
53
|
}, [model?.projection, state, newField]);
|
|
54
54
|
|
|
55
|
-
if (!model?.table?.view || !model.projection || !field) {
|
|
55
|
+
if (!model?.table?.view?.target || !model.projection || !field) {
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<DropdownMenu.Root modal={false} open={state?.type === 'columnSettings'}>
|
|
61
|
-
<DropdownMenu.VirtualTrigger virtualRef={
|
|
61
|
+
<DropdownMenu.VirtualTrigger virtualRef={modals.trigger} />
|
|
62
62
|
<DropdownMenu.Portal>
|
|
63
63
|
<DropdownMenu.Content classNames='md:is-64'>
|
|
64
64
|
<DropdownMenu.Viewport>
|
|
65
65
|
<FieldEditor
|
|
66
|
-
view={model.table.view}
|
|
66
|
+
view={model.table.view.target!}
|
|
67
67
|
projection={model.projection}
|
|
68
68
|
field={field}
|
|
69
69
|
registry={space?.db.schemaRegistry}
|
|
@@ -10,22 +10,22 @@ 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';
|
|
12
12
|
|
|
13
|
-
import { type TableModel } from '../../model';
|
|
13
|
+
import { type TableModel, type ModalController } from '../../model';
|
|
14
14
|
|
|
15
|
-
export type CreateRefPanelProps = { model?: TableModel };
|
|
15
|
+
export type CreateRefPanelProps = { model?: TableModel; modals: ModalController };
|
|
16
16
|
|
|
17
17
|
// TODO(burdon): Factor out Space dependency (to plugin?)
|
|
18
|
-
export const CreateRefPanel = ({ model, __gridScope }: GridScopedProps<CreateRefPanelProps>) => {
|
|
18
|
+
export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<CreateRefPanelProps>) => {
|
|
19
19
|
const { id: gridId } = useGridContext('TableCellEditor', __gridScope);
|
|
20
20
|
const space = getSpace(model?.table);
|
|
21
|
-
const state =
|
|
21
|
+
const state = modals.state.value;
|
|
22
|
+
|
|
22
23
|
const schema = useMemo<S.Schema<any> | undefined>(() => {
|
|
23
24
|
if (!space || state?.type !== 'createRefPanel') {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
const schema: S.Schema<any> | undefined = space.db.schemaRegistry.getSchema(state.typename)?.schema;
|
|
28
|
+
const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
|
|
29
29
|
if (schema) {
|
|
30
30
|
const omit = S.omit<any, any, ['id']>('id');
|
|
31
31
|
return omit(schema);
|
|
@@ -38,22 +38,21 @@ export const CreateRefPanel = ({ model, __gridScope }: GridScopedProps<CreateRef
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const schema
|
|
41
|
+
const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
|
|
42
42
|
if (schema) {
|
|
43
43
|
const obj = space.db.add(create(schema, values));
|
|
44
44
|
state.onCreate?.(obj);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
void model.modalController.close();
|
|
46
|
+
void modals.close();
|
|
48
47
|
},
|
|
49
|
-
[
|
|
48
|
+
[modals, space, state],
|
|
50
49
|
);
|
|
51
50
|
|
|
52
51
|
const handleCancel = useCallback(() => {
|
|
53
52
|
if (model) {
|
|
54
|
-
|
|
53
|
+
modals.close();
|
|
55
54
|
}
|
|
56
|
-
}, [
|
|
55
|
+
}, [modals]);
|
|
57
56
|
|
|
58
57
|
if (!model?.table?.view || !model.projection) {
|
|
59
58
|
return null;
|
|
@@ -65,11 +64,11 @@ export const CreateRefPanel = ({ model, __gridScope }: GridScopedProps<CreateRef
|
|
|
65
64
|
open={state?.type === 'createRefPanel' && !!schema}
|
|
66
65
|
onOpenChange={(nextOpen) => {
|
|
67
66
|
if (model && !nextOpen) {
|
|
68
|
-
return
|
|
67
|
+
return modals.close();
|
|
69
68
|
}
|
|
70
69
|
}}
|
|
71
70
|
>
|
|
72
|
-
<Popover.VirtualTrigger virtualRef={
|
|
71
|
+
<Popover.VirtualTrigger virtualRef={modals.trigger} />
|
|
73
72
|
<Popover.Portal>
|
|
74
73
|
<Popover.Content classNames='md:is-64' data-grid={gridId}>
|
|
75
74
|
{state?.type === 'createRefPanel' && schema && (
|
|
@@ -8,9 +8,9 @@ import { getSpace, 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
|
|
|
11
|
-
import { type TableModel } from '../../model';
|
|
11
|
+
import { type TableModel, type ModalController } from '../../model';
|
|
12
12
|
|
|
13
|
-
type RefPanelProps = { model
|
|
13
|
+
type RefPanelProps = { model: TableModel; modals: ModalController };
|
|
14
14
|
|
|
15
15
|
const getRefTargetObj = (space?: Space, id?: string) => {
|
|
16
16
|
if (space && id) {
|
|
@@ -20,13 +20,13 @@ const getRefTargetObj = (space?: Space, id?: string) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export const RefPanel = ({ model }: RefPanelProps) => {
|
|
24
|
-
const state =
|
|
25
|
-
const space = getSpace(model
|
|
23
|
+
export const RefPanel = ({ model, modals }: RefPanelProps) => {
|
|
24
|
+
const state = modals.state.value;
|
|
25
|
+
const space = getSpace(model.table);
|
|
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.table?.view || !model.projection) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -35,12 +35,12 @@ export const RefPanel = ({ model }: RefPanelProps) => {
|
|
|
35
35
|
modal={false}
|
|
36
36
|
open={state?.type === 'refPanel' && !!targetObj && !!schema}
|
|
37
37
|
onOpenChange={(nextOpen) => {
|
|
38
|
-
if (
|
|
39
|
-
return
|
|
38
|
+
if (!nextOpen) {
|
|
39
|
+
return modals.close();
|
|
40
40
|
}
|
|
41
41
|
}}
|
|
42
42
|
>
|
|
43
|
-
<Popover.VirtualTrigger virtualRef={
|
|
43
|
+
<Popover.VirtualTrigger virtualRef={modals.trigger} />
|
|
44
44
|
<Popover.Portal>
|
|
45
45
|
<Popover.Content classNames='md:is-64'>
|
|
46
46
|
{targetObj && schema && <Form readonly values={targetObj} schema={schema} />}
|
|
@@ -6,22 +6,21 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { DropdownMenu, useTranslation } from '@dxos/react-ui';
|
|
8
8
|
|
|
9
|
-
import { type TableModel } from '../../model';
|
|
9
|
+
import { type TableModel, type ModalController } from '../../model';
|
|
10
10
|
import { translationKey } from '../../translations';
|
|
11
11
|
|
|
12
|
-
type RowActionsMenuProps = { model: TableModel };
|
|
12
|
+
type RowActionsMenuProps = { model: TableModel; modals: ModalController };
|
|
13
13
|
|
|
14
|
-
export const RowActionsMenu = ({ model }: RowActionsMenuProps) => {
|
|
14
|
+
export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
15
15
|
const { t } = useTranslation(translationKey);
|
|
16
16
|
const hasSelection = model.selection.hasSelection.value;
|
|
17
|
-
const state =
|
|
17
|
+
const state = modals.state.value;
|
|
18
18
|
if (state?.type !== 'row') {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
return (
|
|
23
|
-
<DropdownMenu.Root modal={false} open={true} onOpenChange={
|
|
24
|
-
<DropdownMenu.VirtualTrigger virtualRef={
|
|
22
|
+
<DropdownMenu.Root modal={false} open={true} onOpenChange={modals.close}>
|
|
23
|
+
<DropdownMenu.VirtualTrigger virtualRef={modals.trigger} />
|
|
25
24
|
<DropdownMenu.Content>
|
|
26
25
|
<DropdownMenu.Viewport>
|
|
27
26
|
<DropdownMenu.Item data-testid='row-menu-delete' onClick={() => model.deleteRow(state.rowIndex)}>
|
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
9
|
|
|
10
|
-
import { type MutableSchema } from '@dxos/echo-schema';
|
|
11
10
|
import { invariant } from '@dxos/invariant';
|
|
12
11
|
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
13
12
|
import { faker } from '@dxos/random';
|
|
14
|
-
import { Filter,
|
|
15
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
|
+
import { Filter, useQuery, useSchema, create } from '@dxos/react-client/echo';
|
|
14
|
+
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
16
15
|
import { useDefaultValue } from '@dxos/react-ui';
|
|
17
16
|
import { ViewEditor } from '@dxos/react-ui-form';
|
|
18
17
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
@@ -21,12 +20,14 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
|
21
20
|
|
|
22
21
|
import { Table, type TableController } from './Table';
|
|
23
22
|
import { useTableModel, type UseTableModelParams } from '../../hooks';
|
|
23
|
+
import { TablePresentation } from '../../model';
|
|
24
24
|
import translations from '../../translations';
|
|
25
25
|
import { TableType } from '../../types';
|
|
26
26
|
import { initializeTable } from '../../util';
|
|
27
|
-
import {
|
|
27
|
+
import { TableToolbar } from '../TableToolbar';
|
|
28
28
|
import { createItems, createTable, type SimulatorProps, useSimulator } from '../testing';
|
|
29
29
|
|
|
30
|
+
// NOTE(ZaymonFC): We rely on this seed being 0 in the smoke tests.
|
|
30
31
|
faker.seed(0);
|
|
31
32
|
|
|
32
33
|
//
|
|
@@ -34,25 +35,26 @@ faker.seed(0);
|
|
|
34
35
|
//
|
|
35
36
|
|
|
36
37
|
const DefaultStory = () => {
|
|
37
|
-
const
|
|
38
|
-
|
|
38
|
+
const { space } = useClientProvider();
|
|
39
|
+
invariant(space);
|
|
40
|
+
|
|
39
41
|
const tables = useQuery(space, Filter.schema(TableType));
|
|
40
42
|
const [table, setTable] = useState<TableType>();
|
|
41
|
-
const
|
|
43
|
+
const schema = useSchema(space, table?.view?.target?.query.type);
|
|
44
|
+
|
|
42
45
|
useEffect(() => {
|
|
43
|
-
if (tables.length && !table) {
|
|
46
|
+
if (space && tables.length && !table) {
|
|
44
47
|
const table = tables[0];
|
|
45
48
|
invariant(table.view);
|
|
46
49
|
setTable(table);
|
|
47
|
-
setSchema(space.db.schemaRegistry.getSchema(table.view.query.type));
|
|
48
50
|
}
|
|
49
|
-
}, [tables]);
|
|
51
|
+
}, [space, tables]);
|
|
50
52
|
|
|
51
53
|
const projection = useMemo(() => {
|
|
52
|
-
if (schema && table?.view) {
|
|
53
|
-
return new ViewProjection(schema, table.view);
|
|
54
|
+
if (schema && table?.view?.target) {
|
|
55
|
+
return new ViewProjection(schema, table.view.target);
|
|
54
56
|
}
|
|
55
|
-
}, [schema, table?.view]);
|
|
57
|
+
}, [schema, table?.view?.target]);
|
|
56
58
|
|
|
57
59
|
const objects = useQuery(space, schema ? Filter.schema(schema) : Filter.nothing());
|
|
58
60
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
@@ -81,6 +83,32 @@ const DefaultStory = () => {
|
|
|
81
83
|
[table, projection],
|
|
82
84
|
);
|
|
83
85
|
|
|
86
|
+
const tableRef = useRef<TableController>(null);
|
|
87
|
+
const handleCellUpdate = useCallback((cell: any) => {
|
|
88
|
+
tableRef.current?.update?.(cell);
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const handleRowOrderChanged = useCallback(() => {
|
|
92
|
+
tableRef.current?.update?.();
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const model = useTableModel({
|
|
96
|
+
table,
|
|
97
|
+
projection,
|
|
98
|
+
objects: filteredObjects,
|
|
99
|
+
onInsertRow: handleInsertRow,
|
|
100
|
+
onDeleteRows: handleDeleteRows,
|
|
101
|
+
onDeleteColumn: handleDeleteColumn,
|
|
102
|
+
onCellUpdate: handleCellUpdate,
|
|
103
|
+
onRowOrderChanged: handleRowOrderChanged,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const presentation = useMemo(() => {
|
|
107
|
+
if (model) {
|
|
108
|
+
return new TablePresentation(model);
|
|
109
|
+
}
|
|
110
|
+
}, [model]);
|
|
111
|
+
|
|
84
112
|
const handleAction = useCallback(
|
|
85
113
|
(action: { type: string }) => {
|
|
86
114
|
switch (action.type) {
|
|
@@ -90,23 +118,26 @@ const DefaultStory = () => {
|
|
|
90
118
|
}
|
|
91
119
|
case 'add-row': {
|
|
92
120
|
handleInsertRow();
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'save-view': {
|
|
124
|
+
model?.saveView();
|
|
125
|
+
break;
|
|
93
126
|
}
|
|
94
127
|
}
|
|
95
128
|
},
|
|
96
|
-
[table,
|
|
129
|
+
[table, model],
|
|
97
130
|
);
|
|
98
131
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
onRowOrderChanged: () => tableRef.current?.update?.(),
|
|
109
|
-
});
|
|
132
|
+
const onTypenameChanged = useCallback(
|
|
133
|
+
(typename: string) => {
|
|
134
|
+
if (table?.view?.target) {
|
|
135
|
+
schema?.updateTypename(typename);
|
|
136
|
+
table.view.target.query.type = typename;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
[table?.view?.target, schema],
|
|
140
|
+
);
|
|
110
141
|
|
|
111
142
|
if (!schema || !table) {
|
|
112
143
|
return <div />;
|
|
@@ -115,27 +146,24 @@ const DefaultStory = () => {
|
|
|
115
146
|
return (
|
|
116
147
|
<div className='grow grid grid-cols-[1fr_350px]'>
|
|
117
148
|
<div className='grid grid-rows-[min-content_1fr] min-bs-0 overflow-hidden'>
|
|
118
|
-
<
|
|
119
|
-
<Toolbar.Editing />
|
|
120
|
-
<Toolbar.Separator />
|
|
121
|
-
<Toolbar.Actions />
|
|
122
|
-
</Toolbar.Root>
|
|
149
|
+
<TableToolbar classNames='border-b border-separator' onAction={handleAction} />
|
|
123
150
|
<Table.Root>
|
|
124
|
-
<Table.Main ref={tableRef} model={model} ignoreAttention />
|
|
151
|
+
<Table.Main ref={tableRef} model={model} presentation={presentation} ignoreAttention />
|
|
125
152
|
</Table.Root>
|
|
126
153
|
</div>
|
|
127
154
|
<div className='flex flex-col h-full border-l border-separator overflow-y-auto'>
|
|
128
|
-
{table.view && (
|
|
155
|
+
{table.view?.target && (
|
|
129
156
|
<ViewEditor
|
|
130
157
|
registry={space?.db.schemaRegistry}
|
|
131
158
|
schema={schema}
|
|
132
|
-
view={table.view}
|
|
159
|
+
view={table.view.target!}
|
|
160
|
+
onTypenameChanged={onTypenameChanged}
|
|
133
161
|
onDelete={handleDeleteColumn}
|
|
134
162
|
/>
|
|
135
163
|
)}
|
|
136
164
|
|
|
137
165
|
<SyntaxHighlighter language='json' className='w-full text-xs'>
|
|
138
|
-
{JSON.stringify({ view: table.view, schema }, null, 2)}
|
|
166
|
+
{JSON.stringify({ view: table.view?.target, schema }, null, 2)}
|
|
139
167
|
</SyntaxHighlighter>
|
|
140
168
|
</div>
|
|
141
169
|
</div>
|
|
@@ -146,7 +174,7 @@ type StoryProps = {
|
|
|
146
174
|
rows?: number;
|
|
147
175
|
} & Pick<SimulatorProps, 'insertInterval' | 'updateInterval'>;
|
|
148
176
|
|
|
149
|
-
const
|
|
177
|
+
const _TablePerformanceStory = (props: StoryProps) => {
|
|
150
178
|
const getDefaultRows = useCallback(() => 10, []);
|
|
151
179
|
const rows = useDefaultValue(props.rows, getDefaultRows);
|
|
152
180
|
const table = useMemo(() => createTable(), []);
|
|
@@ -161,9 +189,9 @@ const TablePerformanceStory = (props: StoryProps) => {
|
|
|
161
189
|
|
|
162
190
|
const handleDeleteColumn = useCallback<NonNullable<UseTableModelParams<any>['onDeleteColumn']>>(
|
|
163
191
|
(fieldId) => {
|
|
164
|
-
if (table && table.view) {
|
|
165
|
-
const fieldPosition = table.view.fields.findIndex((field) => field.id === fieldId);
|
|
166
|
-
table.view.fields.splice(fieldPosition, 1);
|
|
192
|
+
if (table && table.view?.target) {
|
|
193
|
+
const fieldPosition = table.view.target!.fields.findIndex((field) => field.id === fieldId);
|
|
194
|
+
table.view.target!.fields.splice(fieldPosition, 1);
|
|
167
195
|
}
|
|
168
196
|
},
|
|
169
197
|
[table],
|
|
@@ -202,7 +230,7 @@ const meta: Meta<StoryProps> = {
|
|
|
202
230
|
createSpace: true,
|
|
203
231
|
onSpaceCreated: async ({ space }) => {
|
|
204
232
|
const table = space.db.add(create(TableType, {}));
|
|
205
|
-
const schema = initializeTable({ space, table, initialRow: false });
|
|
233
|
+
const schema = await initializeTable({ space, table, initialRow: false });
|
|
206
234
|
Array.from({ length: 10 }).map(() => {
|
|
207
235
|
return space.db.add(
|
|
208
236
|
create(schema, {
|
|
@@ -219,22 +247,22 @@ const meta: Meta<StoryProps> = {
|
|
|
219
247
|
|
|
220
248
|
export default meta;
|
|
221
249
|
|
|
222
|
-
type Story = StoryObj<StoryProps>;
|
|
223
|
-
|
|
224
250
|
export const Default = {};
|
|
225
251
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
252
|
+
// TODO(ZaymonFC): Restore the performance stories.
|
|
253
|
+
// type Story = StoryObj<StoryProps>;
|
|
254
|
+
// export const Mutations: Story = {
|
|
255
|
+
// render: TablePerformanceStory,
|
|
256
|
+
// args: {
|
|
257
|
+
// rows: 1000,
|
|
258
|
+
// updateInterval: 1,
|
|
259
|
+
// },
|
|
260
|
+
// };
|
|
233
261
|
|
|
234
|
-
export const RapidInsertions: Story = {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
};
|
|
262
|
+
// export const RapidInsertions: Story = {
|
|
263
|
+
// render: TablePerformanceStory,
|
|
264
|
+
// args: {
|
|
265
|
+
// rows: 0,
|
|
266
|
+
// insertInterval: 100,
|
|
267
|
+
// },
|
|
268
|
+
// };
|