@dxos/react-ui-table 0.8.4-main.fd6878d → 0.9.0
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/LICENSE +102 -5
- package/dist/lib/browser/chunk-4KOQTPFC.mjs +1702 -0
- package/dist/lib/browser/chunk-4KOQTPFC.mjs.map +7 -0
- package/dist/lib/browser/chunk-62PYOJPY.mjs +67 -0
- package/dist/lib/browser/chunk-62PYOJPY.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1151 -1175
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +37 -45
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/translations.mjs +36 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -3
- package/dist/lib/node-esm/chunk-7LMOZUTS.mjs +68 -0
- package/dist/lib/node-esm/chunk-7LMOZUTS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KOSV2J5N.mjs +1704 -0
- package/dist/lib/node-esm/chunk-KOSV2J5N.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1151 -1175
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +37 -45
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/translations.mjs +37 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +6 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +36 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +112 -5
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +21 -19
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +115 -5
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +18 -0
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -9
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +7 -14
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +38 -5
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +23 -16
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +6 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +9 -9
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -8
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +18 -9
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +111 -30
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +4 -2
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +18 -34
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +21 -23
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +32 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +14 -12
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/signals.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/src/util/table-buttons.d.ts +20 -20
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +4 -4
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/tag.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +68 -77
- package/src/components/Table/ColumnActionsMenu.tsx +17 -12
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +41 -38
- package/src/components/Table/DynamicTable.tsx +32 -36
- package/src/components/Table/Relations.stories.tsx +219 -61
- package/src/components/Table/RowActionsMenu.tsx +27 -17
- package/src/components/Table/Table.stories.tsx +217 -141
- package/src/components/Table/Table.tsx +46 -391
- package/src/components/Table/TableContent.tsx +426 -0
- package/src/components/Table/TableToolbar.tsx +111 -0
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -6
- package/src/components/TableCellEditor/FormCellEditor.tsx +136 -41
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +39 -73
- package/src/components/TableCellEditor/TableCellEditor.tsx +81 -223
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/index.ts +0 -1
- package/src/components/testing.ts +42 -21
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +14 -14
- package/src/hooks/useProjectionModel.ts +38 -0
- package/src/hooks/useTableModel.ts +36 -34
- package/src/index.ts +0 -4
- package/src/model/modal-controller.ts +23 -40
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +86 -56
- package/src/model/table-model.ts +464 -182
- package/src/model/table-presentation.test.ts +64 -59
- package/src/model/table-presentation.ts +107 -83
- package/src/playwright/TableManager.ts +13 -6
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +92 -46
- package/src/testing/useTestTableModel.ts +51 -42
- package/src/translations.ts +20 -22
- package/src/types/Table.ts +80 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.test.ts +63 -0
- package/src/util/dynamic-table.ts +53 -39
- package/src/util/index.ts +2 -1
- package/src/util/query-ast.ts +22 -0
- package/src/util/schema.ts +4 -4
- package/src/util/sort.ts +90 -0
- package/src/util/table-buttons.ts +3 -3
- package/src/util/table-controls.ts +2 -2
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs +0 -1814
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs +0 -1815
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
- package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -53
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -8
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -12
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/components/TableToolbar/TableToolbar.tsx +0 -102
- package/src/components/TableToolbar/index.ts +0 -5
- package/src/model/table-sorting.ts +0 -216
- package/src/types/schema.ts +0 -16
- package/src/util/table.ts +0 -53
|
@@ -2,66 +2,62 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
7
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
9
|
+
|
|
10
|
+
import { Obj, Type, View } from '@dxos/echo';
|
|
11
|
+
import { invariant } from '@dxos/invariant';
|
|
12
|
+
import { type DxGrid } from '@dxos/lit-grid';
|
|
13
|
+
import { random } from '@dxos/random';
|
|
14
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
15
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
16
|
+
import { translations as formTranslations } from '@dxos/react-ui-form/translations';
|
|
17
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
18
|
+
import { ViewModel } from '@dxos/schema';
|
|
16
19
|
import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
|
|
17
|
-
import {
|
|
20
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
21
|
+
import { Organization, Person } from '@dxos/types';
|
|
22
|
+
import '@dxos/lit-ui/dx-tag-picker.pcss';
|
|
18
23
|
|
|
19
|
-
import {
|
|
20
|
-
import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
|
|
21
|
-
import { translations } from '../../translations';
|
|
22
|
-
import { TableView } from '../../types';
|
|
23
|
-
import { createTable } from '../../util';
|
|
24
|
+
import { translations } from '#translations';
|
|
24
25
|
|
|
25
|
-
import {
|
|
26
|
+
import { useProjectionModel, useTableModel } from '../../hooks';
|
|
27
|
+
import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
|
|
28
|
+
import { Table } from '../../types';
|
|
29
|
+
import { Table as TableComponent } from './Table';
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
const generator: ValueGenerator =
|
|
31
|
+
random.seed(1);
|
|
32
|
+
const generator: ValueGenerator = random as any;
|
|
29
33
|
|
|
30
34
|
// TODO(burdon): Many-to-many relations.
|
|
31
35
|
// TODO(burdon): Mutable and immutable views.
|
|
32
36
|
// TODO(burdon): Reconcile schemas types and utils (see API PR).
|
|
33
37
|
// TODO(burdon): Base type for T (with id); see ECHO API PR?
|
|
34
|
-
const useTestModel = <S extends Type.
|
|
35
|
-
const
|
|
36
|
-
const { space } =
|
|
37
|
-
const [
|
|
38
|
-
const [jsonSchema, setJsonSchema] = useState<JsonSchemaType>();
|
|
38
|
+
const useTestModel = <S extends Type.AnyObj>(schema: S, count: number) => {
|
|
39
|
+
const registry = useContext(RegistryContext);
|
|
40
|
+
const { space } = useClientStory();
|
|
41
|
+
const [object, setObject] = useState<Table.Table>();
|
|
39
42
|
|
|
40
43
|
const features = useMemo<TableFeatures>(
|
|
41
44
|
() => ({ schemaEditable: false, dataEditable: true, selection: { enabled: false } }),
|
|
42
45
|
[],
|
|
43
46
|
);
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
useAsyncEffect(async () => {
|
|
46
49
|
if (!space) {
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} = await createTable({ client, space, typename: Type.getTypename(schema) });
|
|
56
|
-
setJsonSchema(jsonSchema);
|
|
57
|
-
setView(view);
|
|
58
|
-
space.db.add(view);
|
|
59
|
-
await space.db.schemaRegistry.register([effectSchema]);
|
|
60
|
-
});
|
|
61
|
-
return () => clearTimeout(timeout);
|
|
62
|
-
}, [client, space, schema]);
|
|
53
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({ db: space.db, typename: Type.getTypename(schema) });
|
|
54
|
+
const object = Table.make({ view, jsonSchema });
|
|
55
|
+
setObject(object);
|
|
56
|
+
space.db.add(object);
|
|
57
|
+
}, [space, schema]);
|
|
63
58
|
|
|
64
|
-
const
|
|
59
|
+
const projection = useProjectionModel(schema, object, registry);
|
|
60
|
+
const model = useTableModel<TableRow>({ object, projection, db: space?.db, features });
|
|
65
61
|
|
|
66
62
|
useEffect(() => {
|
|
67
63
|
if (!model || !space) {
|
|
@@ -70,7 +66,9 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
70
66
|
|
|
71
67
|
const objectGenerator = createAsyncGenerator(generator, schema, { db: space?.db, force: true });
|
|
72
68
|
void objectGenerator.createObjects(count).then((objects) => {
|
|
73
|
-
|
|
69
|
+
// TODO(wittjosiah): Remove cast. Type.InstanceType is now strict (no index signature),
|
|
70
|
+
// so it isn't assignable to TableRow (Record<JsonProp, any>); reconcile the row model type.
|
|
71
|
+
model.setRows(objects as unknown as TableRow[]);
|
|
74
72
|
});
|
|
75
73
|
}, [model, space]);
|
|
76
74
|
|
|
@@ -79,46 +77,206 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
79
77
|
return;
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
return new TablePresentation(model);
|
|
83
|
-
}, [model]);
|
|
80
|
+
return new TablePresentation(registry, model);
|
|
81
|
+
}, [registry, model]);
|
|
84
82
|
|
|
85
83
|
return { model, presentation };
|
|
86
84
|
};
|
|
87
85
|
|
|
88
86
|
const DefaultStory = () => {
|
|
89
|
-
const
|
|
90
|
-
const { model:
|
|
91
|
-
const {
|
|
87
|
+
const { model: orgModel, presentation: orgPresentation } = useTestModel(Organization.Organization, 50);
|
|
88
|
+
const { model: contactModel, presentation: contactPresentation } = useTestModel(Person.Person, 50);
|
|
89
|
+
const { space } = useClientStory();
|
|
90
|
+
|
|
91
|
+
const handleCreate = useCallback(
|
|
92
|
+
(schema: Type.AnyEntity, values: any) => {
|
|
93
|
+
invariant(Type.isObject(schema));
|
|
94
|
+
invariant(space);
|
|
95
|
+
return space.db.add(Obj.make(schema, values));
|
|
96
|
+
},
|
|
97
|
+
[space],
|
|
98
|
+
);
|
|
92
99
|
|
|
93
100
|
return (
|
|
94
|
-
<div className='
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
<div className='dx-expander grid grid-cols-2 divide-x divide-separator'>
|
|
102
|
+
<TableComponent.Root>
|
|
103
|
+
<TableComponent.Content
|
|
104
|
+
model={orgModel}
|
|
105
|
+
schema={Organization.Organization}
|
|
106
|
+
presentation={orgPresentation}
|
|
107
|
+
onCreate={handleCreate}
|
|
108
|
+
ignoreAttention
|
|
109
|
+
testId='relations-0'
|
|
110
|
+
/>
|
|
111
|
+
</TableComponent.Root>
|
|
112
|
+
<TableComponent.Root>
|
|
113
|
+
<TableComponent.Content
|
|
114
|
+
model={contactModel}
|
|
115
|
+
schema={Person.Person}
|
|
116
|
+
presentation={contactPresentation}
|
|
117
|
+
onCreate={handleCreate}
|
|
118
|
+
ignoreAttention
|
|
119
|
+
testId='relations-1'
|
|
120
|
+
/>
|
|
121
|
+
</TableComponent.Root>
|
|
101
122
|
</div>
|
|
102
123
|
);
|
|
103
124
|
};
|
|
104
125
|
|
|
105
|
-
const meta
|
|
106
|
-
title: 'ui/react-ui-table/
|
|
126
|
+
const meta = {
|
|
127
|
+
title: 'ui/react-ui-table/Relations',
|
|
107
128
|
render: DefaultStory,
|
|
108
|
-
parameters: { translations, controls: { disable: true } },
|
|
109
129
|
decorators: [
|
|
130
|
+
withTheme(),
|
|
131
|
+
withRegistry,
|
|
132
|
+
// TODO(thure): Shouldn't `layout: 'fullscreen'` below make this unnecessary?
|
|
133
|
+
withLayout({ classNames: 'fixed inset-0' }),
|
|
110
134
|
withClientProvider({
|
|
111
|
-
types: [
|
|
135
|
+
types: [View.View, Organization.Organization, Person.Person, Table.Table],
|
|
112
136
|
createIdentity: true,
|
|
113
137
|
createSpace: true,
|
|
114
138
|
}),
|
|
115
|
-
withTheme,
|
|
116
|
-
withLayout({ fullscreen: true }),
|
|
117
139
|
],
|
|
118
|
-
|
|
140
|
+
parameters: {
|
|
141
|
+
layout: 'fullscreen',
|
|
142
|
+
controls: { disable: true },
|
|
143
|
+
translations: [...translations, ...formTranslations],
|
|
144
|
+
},
|
|
145
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
119
146
|
|
|
120
147
|
export default meta;
|
|
121
148
|
|
|
122
|
-
type Story = StoryObj<typeof
|
|
149
|
+
type Story = StoryObj<typeof meta>;
|
|
150
|
+
|
|
151
|
+
export const Default: Story = {
|
|
152
|
+
// The play function exercises a deep timing race in dx-grid + React render
|
|
153
|
+
// pipeline (cell focus → keydown → `dispatchEditRequest` → `setEditing` →
|
|
154
|
+
// `FormCellEditor` `useEffect` → `Popover` mount). On chromium browser
|
|
155
|
+
// tests the combobox sometimes fails to render in time; local pass rate
|
|
156
|
+
// ~25%, which makes pure CI re-run lottery a poor fit. Excluding from
|
|
157
|
+
// automated test runs (the story still renders in Storybook for visual
|
|
158
|
+
// review and the production code path is covered by
|
|
159
|
+
// `playwright/smoke.spec.ts`). Re-enable once the underlying race is
|
|
160
|
+
// fixed — likely needs `dispatchEditRequest` to be synchronous from
|
|
161
|
+
// keydown and `FormCellEditor` to render the popover off `contextEditing`
|
|
162
|
+
// directly instead of mirroring it through local state.
|
|
163
|
+
tags: ['!test'],
|
|
164
|
+
play: async ({ canvasElement }) => {
|
|
165
|
+
const canvas = within(canvasElement);
|
|
166
|
+
const body = within(document.body);
|
|
167
|
+
|
|
168
|
+
// Get all dx-grid elements (should have 2 - one for each table)
|
|
169
|
+
const firstGrid = await canvas.findByTestId('relations-0', undefined, { timeout: 30_000 });
|
|
170
|
+
const secondGrid = await canvas.findByTestId('relations-1', undefined, { timeout: 30_000 });
|
|
171
|
+
|
|
172
|
+
// Focus on the second table (Person/contacts table)
|
|
173
|
+
await expect(secondGrid).toBeVisible();
|
|
174
|
+
|
|
175
|
+
// Wait for both grids' data generators to finish populating before
|
|
176
|
+
// interacting. `findByTestId` returns as soon as the cell DOM exists,
|
|
177
|
+
// but dx-grid's internal cell registry (used by `cellReadonly` and the
|
|
178
|
+
// edit-request dispatcher) is filled in lazily. If `keydown` lands
|
|
179
|
+
// before the registry has the row, `dispatchEditRequest` short-circuits
|
|
180
|
+
// and the combobox never opens — that's the "Unable to find combobox"
|
|
181
|
+
// flake. Wait for the first row of each grid to render non-empty
|
|
182
|
+
// content (a reliable proxy for "registry populated") BEFORE scrolling
|
|
183
|
+
// — once we scroll the second grid to column 4, dx-grid virtualizes
|
|
184
|
+
// columns 0-3 out of the DOM, so `grid.0.0` becomes unreachable.
|
|
185
|
+
await waitFor(
|
|
186
|
+
async () => {
|
|
187
|
+
const firstOrgCell = within(firstGrid).getByTestId('grid.0.0');
|
|
188
|
+
const orgText = (firstOrgCell.querySelector('.dx-grid__cell__content') as HTMLElement | null)?.textContent;
|
|
189
|
+
await expect(orgText).toBeTruthy();
|
|
190
|
+
const firstContactCell = within(secondGrid).getByTestId('grid.0.0');
|
|
191
|
+
const contactText = (firstContactCell.querySelector('.dx-grid__cell__content') as HTMLElement | null)
|
|
192
|
+
?.textContent;
|
|
193
|
+
await expect(contactText).toBeTruthy();
|
|
194
|
+
},
|
|
195
|
+
{ timeout: 10_000 },
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
// Scroll to the relations column (column 4) - this mimics the scrollToColumn call
|
|
199
|
+
(secondGrid.closest('dx-grid') as DxGrid).scrollToColumn(4);
|
|
200
|
+
|
|
201
|
+
// Find the target cell (first row, relations column).
|
|
202
|
+
const targetCell = await within(secondGrid).findByTestId('grid.4.0', undefined, { timeout: 10_000 });
|
|
203
|
+
await expect(targetCell).toBeVisible();
|
|
204
|
+
|
|
205
|
+
// Click to focus the cell.
|
|
206
|
+
await userEvent.click(targetCell as HTMLElement);
|
|
207
|
+
await expect(targetCell).toHaveFocus();
|
|
208
|
+
await userEvent.keyboard('{Enter}');
|
|
209
|
+
|
|
210
|
+
// Look for the combobox that should appear in edit mode.
|
|
211
|
+
const combobox = await body.findByRole('combobox', undefined, { timeout: 5000 });
|
|
212
|
+
await userEvent.click(combobox);
|
|
123
213
|
|
|
124
|
-
|
|
214
|
+
const searchField = await body.findByPlaceholderText('Search…');
|
|
215
|
+
await userEvent.click(searchField);
|
|
216
|
+
|
|
217
|
+
// Get the first organization name from the first table to search for
|
|
218
|
+
const orgCell = await within(firstGrid).findByTestId('grid.0.0', undefined, { timeout: 10_000 });
|
|
219
|
+
|
|
220
|
+
const orgName = (orgCell.querySelector('.dx-grid__cell__content') as HTMLElement).textContent;
|
|
221
|
+
// Type the first 4 characters to search
|
|
222
|
+
await userEvent.type(searchField, orgName.substring(0, 4));
|
|
223
|
+
|
|
224
|
+
// Look for an option to select
|
|
225
|
+
const option = await body.findAllByRole('option');
|
|
226
|
+
await expect(option[0]).toBeVisible();
|
|
227
|
+
|
|
228
|
+
// Press Enter to select
|
|
229
|
+
await userEvent.keyboard('{Enter}');
|
|
230
|
+
|
|
231
|
+
// Look for and click save button
|
|
232
|
+
const saveButton = await body.findByTestId('save-button');
|
|
233
|
+
await userEvent.click(saveButton);
|
|
234
|
+
|
|
235
|
+
// Verify the relation was set (cell should now contain the org name).
|
|
236
|
+
// Wait for the grid (Lit web component) to repaint after the reactive data update.
|
|
237
|
+
await waitFor(
|
|
238
|
+
async () => {
|
|
239
|
+
const updatedCell = within(secondGrid).getByTestId('grid.4.0');
|
|
240
|
+
await expect(updatedCell).toHaveTextContent(orgName.substring(0, 4));
|
|
241
|
+
},
|
|
242
|
+
{ timeout: 5000 },
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
// Test object creation (new relations) - equivalent to "new relations work as expected" test
|
|
246
|
+
// Find a different cell to test object creation (second row, relations column)
|
|
247
|
+
const newTargetCell = await within(secondGrid).findByTestId('grid.4.1', undefined, { timeout: 10_000 });
|
|
248
|
+
await expect(newTargetCell).toBeTruthy();
|
|
249
|
+
|
|
250
|
+
// Click to focus the cell
|
|
251
|
+
await userEvent.click(newTargetCell as Element);
|
|
252
|
+
|
|
253
|
+
await userEvent.keyboard('{Enter}');
|
|
254
|
+
|
|
255
|
+
// Look for the combobox that should appear in edit mode
|
|
256
|
+
const newCombobox = await body.findByRole('combobox');
|
|
257
|
+
await userEvent.click(newCombobox);
|
|
258
|
+
|
|
259
|
+
const newSearchField = await body.findByPlaceholderText('Search…');
|
|
260
|
+
await userEvent.click(newSearchField);
|
|
261
|
+
|
|
262
|
+
// Type a new object name (this will create a new object).
|
|
263
|
+
const newOrgName = 'Salieri LLC';
|
|
264
|
+
await userEvent.type(newSearchField, newOrgName);
|
|
265
|
+
|
|
266
|
+
// Click the create option directly to open the create form.
|
|
267
|
+
const createOptionLabel = await body.findByText(/Create new object/, undefined, { timeout: 2000 });
|
|
268
|
+
await userEvent.click(createOptionLabel.closest('[role="option"]') as HTMLElement);
|
|
269
|
+
|
|
270
|
+
// Look for and click save button.
|
|
271
|
+
const createReferencedObjectForm = await body.findByTestId('create-referenced-object-form', undefined, {
|
|
272
|
+
timeout: 2000,
|
|
273
|
+
});
|
|
274
|
+
const saveObjectButton = await within(createReferencedObjectForm).findByTestId('save-button');
|
|
275
|
+
await expect(saveObjectButton).not.toBeDisabled();
|
|
276
|
+
await userEvent.click(saveObjectButton);
|
|
277
|
+
|
|
278
|
+
// Verify the relation was set by checking for the accessory link anchor in the cell.
|
|
279
|
+
const updatedNewCell = await within(secondGrid).findByTestId('grid.4.1', undefined, { timeout: 5000 });
|
|
280
|
+
await expect(updatedNewCell.querySelector('dx-anchor')).toBeTruthy();
|
|
281
|
+
},
|
|
282
|
+
};
|
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { DropdownMenu, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
9
|
|
|
10
|
+
import { translationKey } from '#translations';
|
|
11
|
+
|
|
9
12
|
import { type ModalController, type TableModel } from '../../model';
|
|
10
|
-
import { translationKey } from '../../translations';
|
|
11
13
|
|
|
12
14
|
type RowActionsMenuProps = { model: TableModel; modals: ModalController };
|
|
13
15
|
|
|
14
16
|
export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
15
17
|
const { t } = useTranslation(translationKey);
|
|
16
|
-
const hasSelection = model.selection.hasSelection
|
|
17
|
-
const state = modals.state
|
|
18
|
+
const hasSelection = model.selection.hasSelection;
|
|
19
|
+
const state = useAtomValue(modals.state);
|
|
18
20
|
if (state?.type !== 'row') {
|
|
19
21
|
return null;
|
|
20
22
|
}
|
|
@@ -23,24 +25,32 @@ export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
|
|
|
23
25
|
<DropdownMenu.VirtualTrigger virtualRef={modals.trigger} />
|
|
24
26
|
<DropdownMenu.Content>
|
|
25
27
|
<DropdownMenu.Viewport>
|
|
28
|
+
{/* Custom actions */}
|
|
29
|
+
{model.rowActions?.length > 0 && (
|
|
30
|
+
<>
|
|
31
|
+
<DropdownMenu.Group>
|
|
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
|
+
{toLocalizedString(action.label, t)}
|
|
42
|
+
</DropdownMenu.Item>
|
|
43
|
+
))}
|
|
44
|
+
</DropdownMenu.Group>
|
|
45
|
+
<DropdownMenu.Separator />
|
|
46
|
+
</>
|
|
47
|
+
)}
|
|
48
|
+
{/* Default actions */}
|
|
26
49
|
{model.features.dataEditable !== false && (
|
|
27
50
|
<DropdownMenu.Item data-testid='row-menu-delete' onClick={() => model.deleteRow(state.rowIndex)}>
|
|
28
|
-
{t(hasSelection ? 'bulk
|
|
51
|
+
{t(hasSelection ? 'bulk-delete-row.label' : 'delete-row.label')}
|
|
29
52
|
</DropdownMenu.Item>
|
|
30
53
|
)}
|
|
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
|
-
{toLocalizedString(action.label, t)}
|
|
42
|
-
</DropdownMenu.Item>
|
|
43
|
-
))}
|
|
44
54
|
</DropdownMenu.Viewport>
|
|
45
55
|
<DropdownMenu.Arrow />
|
|
46
56
|
</DropdownMenu.Content>
|