@dxos/react-ui-table 0.6.11 → 0.6.12-main.568932b
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/index.mjs +49 -60
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts +12 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts +83 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts +1 -1
- package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +42 -0
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableContext.d.ts +2 -4
- package/dist/types/src/components/Table/TableContext.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableHead.d.ts.map +1 -1
- package/dist/types/src/components/Table/index.d.ts +2 -1
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/hooks/useRowSelection.d.ts.map +1 -1
- package/dist/types/src/schema/{SchemaToTable.stories.d.ts → Schema.stories.d.ts} +2 -3
- package/dist/types/src/schema/Schema.stories.d.ts.map +1 -0
- package/dist/types/src/schema/{schemaToColumns.d.ts → column-utils.d.ts} +2 -2
- package/dist/types/src/schema/column-utils.d.ts.map +1 -0
- package/dist/types/src/schema/index.d.ts +3 -1
- package/dist/types/src/schema/index.d.ts.map +1 -1
- package/dist/types/src/schema/schema.d.ts +2 -3
- package/dist/types/src/schema/schema.d.ts.map +1 -1
- package/dist/types/src/schema/types.d.ts +1 -1
- package/dist/types/src/schema/types.d.ts.map +1 -1
- package/package.json +22 -20
- package/src/components/ColumnMenu/ColumnMenu.stories.tsx +9 -9
- package/src/components/ColumnMenu/ColumnMenu.tsx +2 -2
- package/src/components/ColumnMenu/{ColumnSettingsForm.stories.tsx → ColumnSettings.stories.tsx} +18 -15
- package/src/components/ColumnMenu/{ColumnSettingsForm.tsx → ColumnSettings.tsx} +34 -36
- package/src/components/ColumnMenu/index.ts +1 -1
- package/src/components/Form/Form.stories.tsx +69 -0
- package/src/components/Table/Table.stories.tsx +2 -2
- package/src/components/Table/Table.tsx +3 -3
- package/src/components/Table/TableContext.tsx +13 -7
- package/src/components/Table/TableHead.tsx +0 -1
- package/src/components/Table/index.ts +2 -1
- package/src/helpers.tsx +4 -6
- package/src/hooks/useRowSelection.ts +1 -0
- package/src/schema/{SchemaToTable.stories.tsx → Schema.stories.tsx} +6 -15
- package/src/schema/{schemaToColumns.ts → column-utils.ts} +5 -5
- package/src/schema/index.ts +3 -1
- package/src/schema/schema.test.ts +21 -93
- package/src/schema/schema.ts +23 -30
- package/src/schema/types.ts +4 -2
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts +0 -12
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts +0 -63
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts.map +0 -1
- package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +0 -1
- package/dist/types/src/schema/schemaToColumns.d.ts.map +0 -1
|
@@ -9,7 +9,7 @@ import React, { useRef, useState, useCallback } from 'react';
|
|
|
9
9
|
import { Button, Popover, DropdownMenu } from '@dxos/react-ui';
|
|
10
10
|
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { ColumnSettings } from './ColumnSettings';
|
|
13
13
|
import { useSortColumn } from '../../hooks';
|
|
14
14
|
import { type TableDef, type ColumnProps } from '../../schema';
|
|
15
15
|
|
|
@@ -138,7 +138,7 @@ export const ColumnMenu = <TData extends RowData, TValue>({
|
|
|
138
138
|
<Popover.Portal>
|
|
139
139
|
<Popover.Content>
|
|
140
140
|
<Popover.Viewport>
|
|
141
|
-
<
|
|
141
|
+
<ColumnSettings {...props} column={column} onClose={() => setIsColumnSettingsOpen(false)} />
|
|
142
142
|
</Popover.Viewport>
|
|
143
143
|
<Popover.Arrow />
|
|
144
144
|
</Popover.Content>
|
package/src/components/ColumnMenu/{ColumnSettingsForm.stories.tsx → ColumnSettings.stories.tsx}
RENAMED
|
@@ -3,17 +3,29 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
|
+
|
|
6
7
|
import React from 'react';
|
|
7
8
|
|
|
8
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
9
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
+
import { ColumnSettings, type ColumnSettingsProps } from './ColumnSettings';
|
|
11
12
|
import { type TableDef } from '../../schema';
|
|
13
|
+
import translations from '../../translations';
|
|
14
|
+
|
|
15
|
+
const Story = (props: ColumnSettingsProps) => (
|
|
16
|
+
<div className='flex w-[240px] m-2 p-2 border border-separator rounded'>
|
|
17
|
+
<ColumnSettings {...props} />
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
12
20
|
|
|
13
21
|
export default {
|
|
14
|
-
title: 'react-ui-table/
|
|
15
|
-
component:
|
|
16
|
-
decorators: [withTheme],
|
|
22
|
+
title: 'react-ui-table/ColumnSettings',
|
|
23
|
+
component: ColumnSettings,
|
|
24
|
+
decorators: [withTheme, withLayout()],
|
|
25
|
+
parameters: {
|
|
26
|
+
translations,
|
|
27
|
+
},
|
|
28
|
+
render: Story,
|
|
17
29
|
};
|
|
18
30
|
|
|
19
31
|
const sampleTableDef: TableDef = {
|
|
@@ -37,7 +49,7 @@ const sampleTablesToReference: TableDef[] = [
|
|
|
37
49
|
},
|
|
38
50
|
];
|
|
39
51
|
|
|
40
|
-
const defaultArgs:
|
|
52
|
+
const defaultArgs: ColumnSettingsProps = {
|
|
41
53
|
column: {
|
|
42
54
|
id: 'col-1',
|
|
43
55
|
prop: 'name',
|
|
@@ -93,12 +105,3 @@ export const NewColumn = {
|
|
|
93
105
|
},
|
|
94
106
|
},
|
|
95
107
|
};
|
|
96
|
-
|
|
97
|
-
const Template = (args: ColumnSettingsFormProps) => (
|
|
98
|
-
<div className='p-4 max-is-64'>
|
|
99
|
-
<ColumnSettingsForm {...args} />
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
export const Interactive = Template.bind({});
|
|
104
|
-
(Interactive as any).args = defaultArgs;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
|
+
|
|
4
5
|
import React, { useRef, useState } from 'react';
|
|
5
6
|
|
|
6
7
|
import { Button, Input, Select, useTranslation } from '@dxos/react-ui';
|
|
@@ -9,23 +10,24 @@ import { safeParseInt } from '@dxos/util';
|
|
|
9
10
|
import { type TableDef, type ColumnProps, type ColumnType } from '../../schema';
|
|
10
11
|
import { translationKey } from '../../translations';
|
|
11
12
|
|
|
12
|
-
export type
|
|
13
|
+
export type ColumnSettingsProps = {
|
|
13
14
|
column: ColumnProps;
|
|
14
15
|
tableDef: TableDef;
|
|
16
|
+
// TODO(burdon): Rename.
|
|
15
17
|
tablesToReference: TableDef[];
|
|
16
|
-
onUpdate?: (
|
|
17
|
-
onDelete?: (
|
|
18
|
+
onUpdate?: (id: string, column: ColumnProps) => void;
|
|
19
|
+
onDelete?: (id: string) => void;
|
|
18
20
|
onClose?: () => void;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export const
|
|
23
|
+
export const ColumnSettings = ({
|
|
22
24
|
column,
|
|
23
25
|
tableDef,
|
|
24
26
|
tablesToReference,
|
|
25
27
|
onUpdate,
|
|
26
28
|
onDelete,
|
|
27
29
|
onClose,
|
|
28
|
-
}:
|
|
30
|
+
}: ColumnSettingsProps) => {
|
|
29
31
|
const [formState, setFormState] = useState({
|
|
30
32
|
prop: column.id,
|
|
31
33
|
refTable: column.refTable,
|
|
@@ -75,9 +77,10 @@ export const ColumnSettingsForm = ({
|
|
|
75
77
|
onClose?.();
|
|
76
78
|
};
|
|
77
79
|
|
|
80
|
+
// TODO(burdon): Standardize dialog/popup.
|
|
78
81
|
return (
|
|
79
|
-
<div className='
|
|
80
|
-
<div className='
|
|
82
|
+
<div className='flex flex-col w-full gap-4'>
|
|
83
|
+
<div className='flex flex-col gap-2'>
|
|
81
84
|
<Input.Root>
|
|
82
85
|
<Input.Label>{t('column label label')}</Input.Label>
|
|
83
86
|
<Input.TextInput
|
|
@@ -88,8 +91,7 @@ export const ColumnSettingsForm = ({
|
|
|
88
91
|
data-testid='table.column-settings.label'
|
|
89
92
|
/>
|
|
90
93
|
</Input.Root>
|
|
91
|
-
|
|
92
|
-
<div className='space-y-1'>
|
|
94
|
+
|
|
93
95
|
<Input.Root>
|
|
94
96
|
<Input.Label>{t('property key label')}</Input.Label>
|
|
95
97
|
<Input.TextInput
|
|
@@ -101,8 +103,7 @@ export const ColumnSettingsForm = ({
|
|
|
101
103
|
}
|
|
102
104
|
/>
|
|
103
105
|
</Input.Root>
|
|
104
|
-
|
|
105
|
-
<div className='space-y-1'>
|
|
106
|
+
|
|
106
107
|
<Input.Root>
|
|
107
108
|
<Input.Label>{t('column type label')}</Input.Label>
|
|
108
109
|
<Select.Root
|
|
@@ -123,9 +124,8 @@ export const ColumnSettingsForm = ({
|
|
|
123
124
|
</Select.Portal>
|
|
124
125
|
</Select.Root>
|
|
125
126
|
</Input.Root>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<div className='space-y-1'>
|
|
127
|
+
|
|
128
|
+
{formState.type === 'number' && (
|
|
129
129
|
<Input.Root>
|
|
130
130
|
<Input.Label>{t('digits label')}</Input.Label>
|
|
131
131
|
<Input.TextInput
|
|
@@ -133,12 +133,10 @@ export const ColumnSettingsForm = ({
|
|
|
133
133
|
onChange={(event) => setFormState((prevState) => ({ ...prevState, digits: event.target.value }))}
|
|
134
134
|
/>
|
|
135
135
|
</Input.Root>
|
|
136
|
-
|
|
137
|
-
)}
|
|
136
|
+
)}
|
|
138
137
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
<div className='space-y-1'>
|
|
138
|
+
{formState.type === 'ref' && (
|
|
139
|
+
<>
|
|
142
140
|
<Input.Root>
|
|
143
141
|
<Input.Label>Table</Input.Label>
|
|
144
142
|
<Select.Root
|
|
@@ -161,9 +159,8 @@ export const ColumnSettingsForm = ({
|
|
|
161
159
|
</Select.Portal>
|
|
162
160
|
</Select.Root>
|
|
163
161
|
</Input.Root>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
<div className='space-y-1'>
|
|
162
|
+
|
|
163
|
+
{formState.refTable && (
|
|
167
164
|
<Input.Root>
|
|
168
165
|
<Input.Label>Table property</Input.Label>
|
|
169
166
|
<Select.Root
|
|
@@ -186,20 +183,21 @@ export const ColumnSettingsForm = ({
|
|
|
186
183
|
</Select.Portal>
|
|
187
184
|
</Select.Root>
|
|
188
185
|
</Input.Root>
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
<div
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
186
|
+
)}
|
|
187
|
+
</>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
<div>
|
|
192
|
+
{/* TODO(burdon): Change delete to cancel. Delete should be menu item. */}
|
|
193
|
+
<div className='flex flex-row justify-end gap-1'>
|
|
194
|
+
<Button onClick={handleDelete} data-testid='table.column-settings.delete'>
|
|
195
|
+
{t('delete label')}
|
|
196
|
+
</Button>
|
|
197
|
+
<Button variant='primary' onClick={handleSave} data-testid='table.column-settings.save'>
|
|
198
|
+
{t('save label')}
|
|
199
|
+
</Button>
|
|
200
|
+
</div>
|
|
203
201
|
</div>
|
|
204
202
|
</div>
|
|
205
203
|
);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { AST, S } from '@dxos/echo-schema';
|
|
10
|
+
import { Input } from '@dxos/react-ui';
|
|
11
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import translations from '../../translations';
|
|
14
|
+
|
|
15
|
+
const Story = (props: FormProps) => (
|
|
16
|
+
<div className='flex w-[240px] m-2 p-2 border border-separator rounded'>
|
|
17
|
+
<Form {...props} />
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
type FormProps = {
|
|
22
|
+
schema: S.Schema<any>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const Form = ({ schema }: FormProps) => {
|
|
26
|
+
// const types = getColumnTypes(schema);
|
|
27
|
+
const props = AST.getPropertySignatures(schema.ast);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className='flex flex-col w-full gap-2'>
|
|
31
|
+
{props.map((prop, i) => {
|
|
32
|
+
const { name, annotations } = prop;
|
|
33
|
+
const a = AST.getDescriptionAnnotation(prop);
|
|
34
|
+
console.log(a, annotations);
|
|
35
|
+
return (
|
|
36
|
+
<Input.Root key={i}>
|
|
37
|
+
<Input.Label>{name.toString()}</Input.Label>
|
|
38
|
+
<Input.TextInput
|
|
39
|
+
placeholder={name.toString()}
|
|
40
|
+
// value={formState.label ?? ''}
|
|
41
|
+
// onChange={(event) => setFormState((prevState) => ({ ...prevState, label: event.target.value }))}
|
|
42
|
+
/>
|
|
43
|
+
</Input.Root>
|
|
44
|
+
);
|
|
45
|
+
})}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const schema = S.Struct({
|
|
51
|
+
name: S.String.annotations({ [AST.DescriptionAnnotationId]: 'Name' }),
|
|
52
|
+
email: S.String,
|
|
53
|
+
age: S.Number,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export default {
|
|
57
|
+
title: 'react-ui-table/Form',
|
|
58
|
+
decorators: [withTheme, withLayout()],
|
|
59
|
+
parameters: {
|
|
60
|
+
translations,
|
|
61
|
+
},
|
|
62
|
+
render: Story,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const Default = {
|
|
66
|
+
args: {
|
|
67
|
+
schema,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -8,7 +8,7 @@ import { Plugs, PlugsConnected } from '@phosphor-icons/react';
|
|
|
8
8
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { create } from '@dxos/echo-schema';
|
|
11
|
-
import {
|
|
11
|
+
import { registerSignalsRuntime } from '@dxos/echo-signals/react';
|
|
12
12
|
import { PublicKey } from '@dxos/keys';
|
|
13
13
|
import { faker } from '@dxos/random';
|
|
14
14
|
import { Button, DensityProvider } from '@dxos/react-ui';
|
|
@@ -406,7 +406,7 @@ export const TenThousandRows = {
|
|
|
406
406
|
},
|
|
407
407
|
};
|
|
408
408
|
|
|
409
|
-
|
|
409
|
+
registerSignalsRuntime();
|
|
410
410
|
const state = create({ items: createItems(10) });
|
|
411
411
|
|
|
412
412
|
export const RealTimeUpdates = {
|
|
@@ -79,8 +79,8 @@ export const TablePrimitive = <TData extends RowData>(props: TableProps<TData>)
|
|
|
79
79
|
pinLastRow,
|
|
80
80
|
} = props;
|
|
81
81
|
|
|
82
|
-
const columns = useDefaultValue(props.columns, []);
|
|
83
|
-
const incomingData = useDefaultValue(props.data, []);
|
|
82
|
+
const columns = useDefaultValue(props.columns, () => []);
|
|
83
|
+
const incomingData = useDefaultValue(props.data, () => []);
|
|
84
84
|
|
|
85
85
|
const [data, setData] = useState([...incomingData]);
|
|
86
86
|
|
|
@@ -110,7 +110,7 @@ export const TablePrimitive = <TData extends RowData>(props: TableProps<TData>)
|
|
|
110
110
|
// Columns
|
|
111
111
|
columns,
|
|
112
112
|
defaultColumn: {
|
|
113
|
-
size:
|
|
113
|
+
size: 400, // Required in order remove default width.
|
|
114
114
|
maxSize: 1024,
|
|
115
115
|
},
|
|
116
116
|
|
|
@@ -3,26 +3,32 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type RowData } from '@tanstack/react-table';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
useContext,
|
|
8
|
+
createContext,
|
|
9
|
+
type Context,
|
|
10
|
+
type JSX,
|
|
11
|
+
type PropsWithChildren,
|
|
12
|
+
type ReactNode,
|
|
13
|
+
} from 'react';
|
|
14
|
+
|
|
15
|
+
import { raise } from '@dxos/debug';
|
|
7
16
|
|
|
8
17
|
import { type TableContextValue } from './props';
|
|
9
18
|
|
|
10
19
|
export const TABLE_NAME = 'Table';
|
|
11
20
|
|
|
12
|
-
|
|
13
|
-
// The expectation is that the provider will always supply a value, so no need to define a default here.
|
|
14
|
-
const TableContext = createContext<TableContextValue<RowData>>({} as TableContextValue<RowData>);
|
|
21
|
+
const TableContext = createContext<TableContextValue<RowData> | undefined>(undefined);
|
|
15
22
|
|
|
16
23
|
export type TypedTableProvider<TData extends RowData> = {
|
|
17
24
|
(props: TableContextValue<TData> & { children: ReactNode }): JSX.Element;
|
|
18
25
|
displayName: string;
|
|
19
26
|
};
|
|
20
27
|
|
|
21
|
-
export const TableProvider
|
|
28
|
+
export const TableProvider = ({ children, ...value }: PropsWithChildren<TableContextValue<RowData>>) => {
|
|
22
29
|
return <TableContext.Provider value={value}>{children}</TableContext.Provider>;
|
|
23
30
|
};
|
|
24
31
|
|
|
25
|
-
// Create a custom hook to consume the context.
|
|
26
32
|
export const useTableContext = <TData extends RowData>(): TableContextValue<TData> => {
|
|
27
|
-
return useContext(TableContext as Context<TableContextValue<TData>>);
|
|
33
|
+
return useContext(TableContext as Context<TableContextValue<TData>>) ?? raise(new Error('Missing TableContext'));
|
|
28
34
|
};
|
package/src/helpers.tsx
CHANGED
|
@@ -21,8 +21,7 @@ import { log } from '@dxos/log';
|
|
|
21
21
|
import { type ClassNameValue, Input, Tooltip } from '@dxos/react-ui';
|
|
22
22
|
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
23
23
|
|
|
24
|
-
import { CellCombobox } from './components';
|
|
25
|
-
import { useTableContext } from './components/Table/TableContext';
|
|
24
|
+
import { CellCombobox, useTableContext } from './components';
|
|
26
25
|
import { textPadding } from './theme';
|
|
27
26
|
|
|
28
27
|
export type ValueUpdater<TData extends RowData, TValue> = (row: TData, id: string, value: TValue) => void;
|
|
@@ -470,7 +469,7 @@ export class ColumnBuilder<TData extends RowData> {
|
|
|
470
469
|
size: 50,
|
|
471
470
|
minSize: 50,
|
|
472
471
|
header: (column) => label ?? column.header.id,
|
|
473
|
-
// TODO(zan): Implement sort algorithm
|
|
472
|
+
// TODO(zan): Implement sort algorithm.
|
|
474
473
|
enableSorting: true,
|
|
475
474
|
cell: SwitchBuilderCell,
|
|
476
475
|
...props,
|
|
@@ -486,7 +485,7 @@ export class ColumnBuilder<TData extends RowData> {
|
|
|
486
485
|
const IconOff = off?.Icon ?? X;
|
|
487
486
|
return {
|
|
488
487
|
size: size ?? 32,
|
|
489
|
-
// TODO(zan): Implement sort algorithm
|
|
488
|
+
// TODO(zan): Implement sort algorithm.
|
|
490
489
|
enableSorting: false,
|
|
491
490
|
header: (column) => <div className={'justify-center'}>{label ?? column.header.id}</div>,
|
|
492
491
|
cell: (cell) => {
|
|
@@ -506,14 +505,13 @@ export class ColumnBuilder<TData extends RowData> {
|
|
|
506
505
|
/**
|
|
507
506
|
* This display column type is for nested/unhandled data to appear as JSON.
|
|
508
507
|
*/
|
|
509
|
-
|
|
508
|
+
json({ label, classNames, ...props }: KeyColumnOptions<TData> = {}): Partial<ColumnDef<TData, PublicKey>> {
|
|
510
509
|
return {
|
|
511
510
|
size: 120,
|
|
512
511
|
minSize: 120,
|
|
513
512
|
header: (cell) => label ?? cell.header.id,
|
|
514
513
|
cell: (cell) => {
|
|
515
514
|
const value = cell.getValue();
|
|
516
|
-
|
|
517
515
|
return (
|
|
518
516
|
<div className='overflow-scroll'>
|
|
519
517
|
<code className='text-xs'>{JSON.stringify(value)}</code>
|
|
@@ -4,28 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { Arbitrary } from '@effect/schema';
|
|
8
8
|
import * as fc from 'fast-check';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
|
|
11
11
|
import { S } from '@dxos/echo-schema';
|
|
12
|
-
import {
|
|
13
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
14
13
|
|
|
15
|
-
import { schemaToColumnDefs } from './
|
|
14
|
+
import { schemaToColumnDefs } from './column-utils';
|
|
16
15
|
import { Table } from '../components';
|
|
17
16
|
|
|
18
17
|
export default {
|
|
19
|
-
title: 'react-ui-table/
|
|
20
|
-
|
|
21
|
-
decorators: [
|
|
22
|
-
withTheme,
|
|
23
|
-
(Story: any) => (
|
|
24
|
-
<DensityProvider density='fine'>
|
|
25
|
-
<Story />
|
|
26
|
-
</DensityProvider>
|
|
27
|
-
),
|
|
28
|
-
],
|
|
18
|
+
title: 'react-ui-table/Schema',
|
|
19
|
+
decorators: [withTheme, withLayout()],
|
|
29
20
|
};
|
|
30
21
|
|
|
31
22
|
const exampleSchema = S.Struct({
|
|
@@ -49,7 +40,7 @@ const exampleSchemaArbitrary = Arbitrary.make(exampleSchema);
|
|
|
49
40
|
|
|
50
41
|
const items = fc.sample(exampleSchemaArbitrary, 10);
|
|
51
42
|
|
|
52
|
-
export const
|
|
43
|
+
export const Default = {
|
|
53
44
|
render: () => {
|
|
54
45
|
return (
|
|
55
46
|
<Table.Root>
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import { type ColumnDef } from '@tanstack/react-table';
|
|
6
6
|
|
|
7
|
-
import type
|
|
7
|
+
import { type S } from '@dxos/echo-schema';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { getColumnTypes } from './schema';
|
|
10
10
|
import { createColumnBuilder } from '../helpers';
|
|
11
11
|
|
|
12
12
|
export const schemaToColumnDefs = <T>(schema: S.Schema<T, any>): ColumnDef<T, any>[] => {
|
|
13
13
|
const { helper, builder } = createColumnBuilder<T>();
|
|
14
14
|
|
|
15
|
-
const classified =
|
|
15
|
+
const classified = getColumnTypes(schema);
|
|
16
16
|
return classified.map(([name, type]) => {
|
|
17
17
|
const propertyKey = name.toString();
|
|
18
18
|
|
|
@@ -34,8 +34,8 @@ export const schemaToColumnDefs = <T>(schema: S.Schema<T, any>): ColumnDef<T, an
|
|
|
34
34
|
column = builder.date({ label: propertyKey });
|
|
35
35
|
break;
|
|
36
36
|
}
|
|
37
|
-
case '
|
|
38
|
-
column = builder.
|
|
37
|
+
case 'json': {
|
|
38
|
+
column = builder.json({ label: propertyKey, id: propertyKey });
|
|
39
39
|
break;
|
|
40
40
|
}
|
|
41
41
|
default: {
|