@dxos/react-ui-form 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203
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 +1610 -1825
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1610 -1825
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +3 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form-old.stories.d.ts +1 -42
- package/dist/types/src/components/Form/Form-old.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +9 -6
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +32 -32
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +2 -2
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +3 -3
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +8 -12
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +14 -9
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.d.ts +56 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/{ControlSection/ControlSection.stories.d.ts → Settings/Settings.stories.d.ts} +3 -9
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -2
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/echo.d.ts +6 -0
- package/dist/types/src/util/echo.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -45
- package/src/components/FieldEditor/FieldEditor.stories.tsx +39 -18
- package/src/components/FieldEditor/FieldEditor.tsx +13 -6
- package/src/components/Form/Form-old.stories.tsx +42 -42
- package/src/components/Form/Form.stories.tsx +12 -17
- package/src/components/Form/Form.tsx +52 -27
- package/src/components/Form/FormField.tsx +23 -17
- package/src/components/Form/FormFieldComponent.stories.tsx +1 -1
- package/src/components/Form/FormFieldComponent.tsx +17 -16
- package/src/components/Form/FormFieldSet.tsx +8 -5
- package/src/components/Form/fields/ArrayField.tsx +11 -11
- package/src/components/Form/fields/RefField.tsx +82 -99
- package/src/components/Form/fields/SelectOptionField.stories.tsx +1 -1
- package/src/components/Form/fields/SelectOptionField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +12 -5
- package/src/components/ObjectPicker/ObjectPicker.tsx +66 -57
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +234 -0
- package/src/components/{ControlSection → Settings}/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +18 -12
- package/src/components/ViewEditor/ViewEditor.test.tsx +1 -5
- package/src/components/ViewEditor/ViewEditor.tsx +77 -44
- package/src/components/index.ts +1 -1
- package/src/components/testing.tsx +3 -5
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useFormHandler.ts +20 -6
- package/src/translations.ts +1 -1
- package/src/util/echo.ts +25 -0
- package/src/util/index.ts +1 -0
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -30
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryOptions.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryOptions.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
- package/src/components/ControlSection/ControlSection.tsx +0 -153
- package/src/hooks/useQueryRefOptions.ts +0 -70
- package/src/hooks/useRefQueryOptions.ts +0 -37
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Button,
|
|
9
|
+
type ButtonProps,
|
|
10
|
+
Input,
|
|
11
|
+
type Label,
|
|
12
|
+
ScrollArea,
|
|
13
|
+
type ThemedClassName,
|
|
14
|
+
toLocalizedString,
|
|
15
|
+
useTranslation,
|
|
16
|
+
} from '@dxos/react-ui';
|
|
17
|
+
import { mx } from '@dxos/ui-theme';
|
|
18
|
+
|
|
19
|
+
import { translationKey } from '../../translations';
|
|
20
|
+
|
|
21
|
+
const SETTINGS_ROOT_NAME = 'Settings.Root';
|
|
22
|
+
const SETTINGS_SECTION_NAME = 'Settings.Section';
|
|
23
|
+
const SETTINGS_SECTION_HEADING_NAME = 'Settings.SectionHeading';
|
|
24
|
+
const SETTINGS_GROUP_NAME = 'Settings.Group';
|
|
25
|
+
const SETTINGS_GROUP_BUTTON_NAME = 'Settings.GroupButton';
|
|
26
|
+
const SETTINGS_CONTAINER_NAME = 'Settings.Container';
|
|
27
|
+
const SETTINGS_FRAME_NAME = 'Settings.Frame';
|
|
28
|
+
const SETTINGS_FRAME_ITEM_NAME = 'Settings.FrameItem';
|
|
29
|
+
const SETTINGS_ITEM_NAME = 'Settings.Item';
|
|
30
|
+
const SETTINGS_ITEM_INPUT_NAME = 'Settings.ItemInput';
|
|
31
|
+
|
|
32
|
+
const styles = {
|
|
33
|
+
title: 'pbe-trimMd text-baseText text-lg',
|
|
34
|
+
description: 'text-base text-description',
|
|
35
|
+
grid: 'grid grid-cols-1 md:grid-cols-[3fr_2fr] gap-x-trimLg',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//
|
|
39
|
+
// Root
|
|
40
|
+
//
|
|
41
|
+
|
|
42
|
+
type SettingsRootProps = PropsWithChildren;
|
|
43
|
+
|
|
44
|
+
const SettingsRoot = ({ children }: SettingsRootProps) => {
|
|
45
|
+
return (
|
|
46
|
+
<ScrollArea.Root orientation='vertical'>
|
|
47
|
+
<ScrollArea.Viewport classNames='p-trimMd'>{children}</ScrollArea.Viewport>
|
|
48
|
+
</ScrollArea.Root>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
53
|
+
|
|
54
|
+
//
|
|
55
|
+
// Section
|
|
56
|
+
//
|
|
57
|
+
|
|
58
|
+
type SettingsSectionProps = PropsWithChildren<{
|
|
59
|
+
title: Label;
|
|
60
|
+
description?: Label;
|
|
61
|
+
}>;
|
|
62
|
+
|
|
63
|
+
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
<SettingsSectionHeading title={title} description={description} />
|
|
67
|
+
<div className='is-full pbs-trimMd space-y-trimMd'>{children}</div>
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
73
|
+
|
|
74
|
+
//
|
|
75
|
+
// Section Heading
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
const SettingsSectionHeading = ({ title, description }: Omit<SettingsSectionProps, 'children'>) => {
|
|
79
|
+
const { t } = useTranslation(translationKey);
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<h2 className='pli-trimMd container-max-width text-xl mbs-trimMd mbe-trimMd'>{toLocalizedString(title, t)}</h2>
|
|
83
|
+
{description && (
|
|
84
|
+
<p className='pli-trimMd mlb-trimMd container-max-width text-description'>
|
|
85
|
+
{toLocalizedString(description, t)}
|
|
86
|
+
</p>
|
|
87
|
+
)}
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
SettingsSectionHeading.displayName = SETTINGS_SECTION_HEADING_NAME;
|
|
93
|
+
|
|
94
|
+
//
|
|
95
|
+
// Group Button
|
|
96
|
+
//
|
|
97
|
+
|
|
98
|
+
const SettingsGroupButton = ({ classNames, ...props }: ButtonProps) => {
|
|
99
|
+
return <Button {...props} classNames={['md:col-span-2', classNames]} />;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
SettingsGroupButton.displayName = SETTINGS_GROUP_BUTTON_NAME;
|
|
103
|
+
|
|
104
|
+
//
|
|
105
|
+
// Group
|
|
106
|
+
//
|
|
107
|
+
|
|
108
|
+
type SettingsGroupProps = ThemedClassName<PropsWithChildren>;
|
|
109
|
+
|
|
110
|
+
const SettingsGroup = ({ children, classNames }: SettingsGroupProps) => (
|
|
111
|
+
<div role='none' className={mx('group container-max-width space-y-trimMd', classNames)}>
|
|
112
|
+
{children}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
SettingsGroup.displayName = SETTINGS_GROUP_NAME;
|
|
117
|
+
|
|
118
|
+
//
|
|
119
|
+
// Frame
|
|
120
|
+
//
|
|
121
|
+
|
|
122
|
+
const SettingsFrame = ({ children }: SettingsGroupProps) => (
|
|
123
|
+
<div role='none' className={mx('container-max-width p-trimMd', 'border border-separator rounded-md')}>
|
|
124
|
+
{children}
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
SettingsFrame.displayName = SETTINGS_FRAME_NAME;
|
|
129
|
+
|
|
130
|
+
//
|
|
131
|
+
// Frame Item
|
|
132
|
+
//
|
|
133
|
+
|
|
134
|
+
const SettingsFrameItem = ({ title, description, children }: SettingsItemProps) => {
|
|
135
|
+
const { t } = useTranslation(translationKey);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div role='group' className='min-is-0'>
|
|
139
|
+
<h3 className='text-lg mbe-2'>{toLocalizedString(title, t)}</h3>
|
|
140
|
+
{description && <p className='mlb-trimSm md:mbe-0 text-description'>{toLocalizedString(description, t)}</p>}
|
|
141
|
+
{children}
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
SettingsFrameItem.displayName = SETTINGS_FRAME_ITEM_NAME;
|
|
147
|
+
|
|
148
|
+
//
|
|
149
|
+
// Container
|
|
150
|
+
//
|
|
151
|
+
|
|
152
|
+
const SettingsContainer = ({ classNames, children }: ThemedClassName<PropsWithChildren>) => {
|
|
153
|
+
return (
|
|
154
|
+
<div
|
|
155
|
+
role='none'
|
|
156
|
+
className={mx([
|
|
157
|
+
'container-max-width',
|
|
158
|
+
'*:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd',
|
|
159
|
+
'border border-separator rounded-md',
|
|
160
|
+
classNames,
|
|
161
|
+
])}
|
|
162
|
+
>
|
|
163
|
+
{children}
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
SettingsContainer.displayName = SETTINGS_CONTAINER_NAME;
|
|
169
|
+
|
|
170
|
+
//
|
|
171
|
+
// Item
|
|
172
|
+
//
|
|
173
|
+
|
|
174
|
+
type SettingsItemProps = PropsWithChildren<{
|
|
175
|
+
title: Label;
|
|
176
|
+
description?: Label;
|
|
177
|
+
}>;
|
|
178
|
+
|
|
179
|
+
const SettingsItem = ({ title, description = '', children }: SettingsItemProps) => {
|
|
180
|
+
const { t } = useTranslation(translationKey);
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<SettingsContainer classNames={styles.grid}>
|
|
184
|
+
<h3 className={mx(styles.title, 'md:col-span-2')}>{toLocalizedString(title, t)}</h3>
|
|
185
|
+
<p className={styles.description}>{toLocalizedString(description, t)}</p>
|
|
186
|
+
<div role='none' className='text-end plb-1'>
|
|
187
|
+
{children}
|
|
188
|
+
</div>
|
|
189
|
+
</SettingsContainer>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
194
|
+
|
|
195
|
+
//
|
|
196
|
+
// Item Input
|
|
197
|
+
//
|
|
198
|
+
|
|
199
|
+
const SettingsItemInput = ({ title, description = '', children }: SettingsItemProps) => {
|
|
200
|
+
const { t } = useTranslation(translationKey);
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Input.Root>
|
|
204
|
+
<SettingsContainer classNames={styles.grid}>
|
|
205
|
+
<Input.Label classNames={mx(styles.title, 'md:col-span-2')}>{toLocalizedString(title, t)}</Input.Label>
|
|
206
|
+
<Input.DescriptionAndValidation>
|
|
207
|
+
<Input.Description classNames={styles.description}>{toLocalizedString(description, t)}</Input.Description>
|
|
208
|
+
</Input.DescriptionAndValidation>
|
|
209
|
+
<div role='none' className='text-end plb-1'>
|
|
210
|
+
{children}
|
|
211
|
+
</div>
|
|
212
|
+
</SettingsContainer>
|
|
213
|
+
</Input.Root>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
SettingsItemInput.displayName = SETTINGS_ITEM_INPUT_NAME;
|
|
218
|
+
|
|
219
|
+
//
|
|
220
|
+
// Settings
|
|
221
|
+
//
|
|
222
|
+
|
|
223
|
+
export const Settings = {
|
|
224
|
+
Root: SettingsRoot,
|
|
225
|
+
Section: SettingsSection,
|
|
226
|
+
SectionHeading: SettingsSectionHeading,
|
|
227
|
+
Group: SettingsGroup,
|
|
228
|
+
GroupButton: SettingsGroupButton,
|
|
229
|
+
Container: SettingsContainer,
|
|
230
|
+
Frame: SettingsFrame,
|
|
231
|
+
FrameItem: SettingsFrameItem,
|
|
232
|
+
Item: SettingsItem,
|
|
233
|
+
ItemInput: SettingsItemInput,
|
|
234
|
+
};
|
|
@@ -7,13 +7,13 @@ import * as Schema from 'effect/Schema';
|
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
8
|
|
|
9
9
|
import { DXN, Filter, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
|
|
10
|
-
import { type EchoSchema, Format } from '@dxos/echo/internal';
|
|
10
|
+
import { type EchoSchema, Format, type Mutable } from '@dxos/echo/internal';
|
|
11
11
|
import { useQuery } from '@dxos/react-client/echo';
|
|
12
|
-
import {
|
|
12
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
13
13
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
14
14
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
15
|
import { type ProjectionModel, View, getTypenameFromQuery } from '@dxos/schema';
|
|
16
|
-
import { Employer, Organization, Person,
|
|
16
|
+
import { Employer, Organization, Person, Pipeline } from '@dxos/types';
|
|
17
17
|
|
|
18
18
|
import { translations } from '../../translations';
|
|
19
19
|
import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
@@ -24,7 +24,7 @@ const types = [
|
|
|
24
24
|
// TODO(burdon): Get label from annotation.
|
|
25
25
|
{ value: Organization.Organization.typename, label: 'Organization' },
|
|
26
26
|
{ value: Person.Person.typename, label: 'Person' },
|
|
27
|
-
{ value:
|
|
27
|
+
{ value: Pipeline.Pipeline.typename, label: 'Project' },
|
|
28
28
|
{ value: Employer.Employer.typename, label: 'Employer' },
|
|
29
29
|
];
|
|
30
30
|
|
|
@@ -38,12 +38,12 @@ export type ViewEditorDebugObjects = {
|
|
|
38
38
|
type StoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
|
|
39
39
|
|
|
40
40
|
const DefaultStory = (props: StoryProps) => {
|
|
41
|
-
const { space } =
|
|
41
|
+
const { space } = useClientStory();
|
|
42
42
|
const [schema, setSchema] = useState<EchoSchema>();
|
|
43
43
|
const [view, setView] = useState<View.View>();
|
|
44
44
|
const projectionRef = useRef<ProjectionModel>(null);
|
|
45
45
|
|
|
46
|
-
const tags = useQuery(space, Filter.type(Tag.Tag));
|
|
46
|
+
const tags = useQuery(space?.db, Filter.type(Tag.Tag));
|
|
47
47
|
|
|
48
48
|
useAsyncEffect(async () => {
|
|
49
49
|
if (space) {
|
|
@@ -52,7 +52,7 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
52
52
|
email: Format.Email,
|
|
53
53
|
salary: Format.Currency(),
|
|
54
54
|
}).pipe(
|
|
55
|
-
Type.
|
|
55
|
+
Type.object({
|
|
56
56
|
typename: 'example.com/type/Test',
|
|
57
57
|
version: '0.1.0',
|
|
58
58
|
}),
|
|
@@ -63,7 +63,7 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
63
63
|
description: Schema.String,
|
|
64
64
|
completed: Schema.Boolean,
|
|
65
65
|
}).pipe(
|
|
66
|
-
Type.
|
|
66
|
+
Type.object({
|
|
67
67
|
typename: 'example.com/type/Alternate',
|
|
68
68
|
version: '0.1.0',
|
|
69
69
|
}),
|
|
@@ -90,7 +90,9 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
90
90
|
if (props.mode === 'tag') {
|
|
91
91
|
const queue = target && DXN.tryParse(target) ? target : undefined;
|
|
92
92
|
const query = queue ? Query.fromAst(newQuery).options({ queues: [queue] }) : Query.fromAst(newQuery);
|
|
93
|
-
view
|
|
93
|
+
Obj.change(view, (v) => {
|
|
94
|
+
v.query.ast = query.ast as Mutable<typeof query.ast>;
|
|
95
|
+
});
|
|
94
96
|
|
|
95
97
|
const typename = getTypenameFromQuery(query.ast);
|
|
96
98
|
const [newSchema] = await space.db.schemaRegistry.query({ typename }).run();
|
|
@@ -102,10 +104,14 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
102
104
|
query,
|
|
103
105
|
jsonSchema: newSchema.jsonSchema,
|
|
104
106
|
});
|
|
105
|
-
|
|
107
|
+
Obj.change(view, (v) => {
|
|
108
|
+
v.projection = Obj.getSnapshot(newView).projection as Mutable<typeof v.projection>;
|
|
109
|
+
});
|
|
106
110
|
setSchema(() => newSchema);
|
|
107
111
|
} else {
|
|
108
|
-
view
|
|
112
|
+
Obj.change(view, (v) => {
|
|
113
|
+
v.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
114
|
+
});
|
|
109
115
|
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
110
116
|
}
|
|
111
117
|
},
|
|
@@ -169,7 +175,7 @@ const meta = {
|
|
|
169
175
|
space.db.add(Tag.make({ label: 'New' }));
|
|
170
176
|
},
|
|
171
177
|
}),
|
|
172
|
-
withTheme,
|
|
178
|
+
withTheme(),
|
|
173
179
|
],
|
|
174
180
|
parameters: {
|
|
175
181
|
layout: 'fullscreen',
|
|
@@ -89,14 +89,10 @@ describe('ViewEditor', () => {
|
|
|
89
89
|
await Default.run();
|
|
90
90
|
await waitForViewEditor();
|
|
91
91
|
|
|
92
|
-
// Click the add property button.
|
|
92
|
+
// Click the add property button. The new field is auto-expanded by handleAdd.
|
|
93
93
|
const addButton = screen.getByText('Add property');
|
|
94
94
|
fireEvent.click(addButton);
|
|
95
95
|
|
|
96
|
-
// Open the last field.
|
|
97
|
-
const buttons = screen.getAllByTestId('field.toggle');
|
|
98
|
-
fireEvent.click(buttons.at(-1)!);
|
|
99
|
-
|
|
100
96
|
// Fill out the property field.
|
|
101
97
|
const fieldInput = screen.getByPlaceholderText('Property name');
|
|
102
98
|
fireEvent.change(fieldInput, { target: { value: 'added_property' } });
|
|
@@ -2,28 +2,30 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
5
6
|
import * as Array from 'effect/Array';
|
|
6
7
|
import * as Match from 'effect/Match';
|
|
7
8
|
import * as Option from 'effect/Option';
|
|
8
9
|
import * as Schema from 'effect/Schema';
|
|
9
|
-
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from 'react';
|
|
10
|
+
import React, { forwardRef, useCallback, useContext, useImperativeHandle, useMemo, useState } from 'react';
|
|
10
11
|
|
|
11
|
-
import { Filter, Format, Query, QueryAST, type SchemaRegistry } from '@dxos/echo';
|
|
12
|
+
import { Filter, Format, Obj, Query, QueryAST, type SchemaRegistry } from '@dxos/echo';
|
|
12
13
|
import { EchoSchema, type JsonProp, isMutable, toJsonSchema } from '@dxos/echo/internal';
|
|
13
|
-
import {} from '@dxos/echo-db';
|
|
14
14
|
import { invariant } from '@dxos/invariant';
|
|
15
|
+
import { useObject } from '@dxos/react-client/echo';
|
|
15
16
|
import { Callout, IconButton, Input, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
16
17
|
import { QueryForm, type QueryFormProps } from '@dxos/react-ui-components';
|
|
17
18
|
import { List } from '@dxos/react-ui-list';
|
|
18
|
-
import { mx, subtleHover } from '@dxos/react-ui-theme';
|
|
19
19
|
import {
|
|
20
20
|
FieldSchema,
|
|
21
21
|
type FieldType,
|
|
22
22
|
ProjectionModel,
|
|
23
23
|
VIEW_FIELD_LIMIT,
|
|
24
24
|
type View,
|
|
25
|
+
createEchoChangeCallback,
|
|
25
26
|
getTypenameFromQuery,
|
|
26
27
|
} from '@dxos/schema';
|
|
28
|
+
import { mx, osTranslations, subtleHover } from '@dxos/ui-theme';
|
|
27
29
|
|
|
28
30
|
import { translationKey } from '../../translations';
|
|
29
31
|
import { FieldEditor } from '../FieldEditor';
|
|
@@ -71,15 +73,29 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
71
73
|
},
|
|
72
74
|
forwardedRef,
|
|
73
75
|
) => {
|
|
76
|
+
const atomRegistry = useContext(RegistryContext);
|
|
74
77
|
const schemaReadonly = !isMutable(schema);
|
|
75
78
|
const { t } = useTranslation(translationKey);
|
|
79
|
+
|
|
76
80
|
const projectionModel = useMemo(() => {
|
|
77
81
|
// Use reactive and mutable version of json schema when schema is mutable.
|
|
78
82
|
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
85
|
+
// Pass schema only when mutable to allow schema mutations.
|
|
86
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : undefined);
|
|
87
|
+
|
|
88
|
+
const model = new ProjectionModel({
|
|
89
|
+
registry: atomRegistry,
|
|
90
|
+
view,
|
|
91
|
+
baseSchema: jsonSchema,
|
|
92
|
+
change,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return model;
|
|
96
|
+
}, [atomRegistry, schema, view]);
|
|
97
|
+
|
|
81
98
|
useImperativeHandle(forwardedRef, () => projectionModel, [projectionModel]);
|
|
82
|
-
const [expandedField, setExpandedField] = useState<FieldType['id']>();
|
|
83
99
|
|
|
84
100
|
const queueTarget = Match.value(view.query.ast).pipe(
|
|
85
101
|
Match.when({ type: 'options' }, ({ options }) => {
|
|
@@ -124,13 +140,6 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
124
140
|
[mode, types, tags],
|
|
125
141
|
);
|
|
126
142
|
|
|
127
|
-
// TODO(burdon): Check if mutable.
|
|
128
|
-
const handleAdd = useCallback(() => {
|
|
129
|
-
invariant(!readonly);
|
|
130
|
-
const field = projectionModel.createFieldProjection();
|
|
131
|
-
setExpandedField(field.id);
|
|
132
|
-
}, [schema, projectionModel, readonly]);
|
|
133
|
-
|
|
134
143
|
const handleUpdate = useCallback(
|
|
135
144
|
(values: any) => {
|
|
136
145
|
requestAnimationFrame(() => {
|
|
@@ -144,13 +153,9 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
144
153
|
const handleDelete = useCallback(
|
|
145
154
|
(fieldId: string) => {
|
|
146
155
|
invariant(!readonly);
|
|
147
|
-
if (fieldId === expandedField) {
|
|
148
|
-
setExpandedField(undefined);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
156
|
onDelete?.(fieldId);
|
|
152
157
|
},
|
|
153
|
-
[
|
|
158
|
+
[onDelete, readonly],
|
|
154
159
|
);
|
|
155
160
|
|
|
156
161
|
return (
|
|
@@ -176,19 +181,6 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
176
181
|
onDelete={handleDelete}
|
|
177
182
|
/>
|
|
178
183
|
</Form.Root>
|
|
179
|
-
|
|
180
|
-
{!readonly && !expandedField && (
|
|
181
|
-
<div role='none' className='mlb-cardSpacingBlock'>
|
|
182
|
-
<IconButton
|
|
183
|
-
icon='ph--plus--regular'
|
|
184
|
-
label={t('add property button label')}
|
|
185
|
-
onClick={readonly ? undefined : handleAdd}
|
|
186
|
-
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
187
|
-
disabled={view.projection.fields.length >= VIEW_FIELD_LIMIT}
|
|
188
|
-
classNames='is-full'
|
|
189
|
-
/>
|
|
190
|
-
</div>
|
|
191
|
-
)}
|
|
192
184
|
</div>
|
|
193
185
|
);
|
|
194
186
|
},
|
|
@@ -197,15 +189,39 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
197
189
|
type FieldListProps = Pick<ViewEditorProps, 'schema' | 'view' | 'registry' | 'readonly' | 'showHeading' | 'onDelete'>;
|
|
198
190
|
|
|
199
191
|
const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDelete }: FieldListProps) => {
|
|
192
|
+
const atomRegistry = useContext(RegistryContext);
|
|
200
193
|
const schemaReadonly = !isMutable(schema);
|
|
201
194
|
const { t } = useTranslation(translationKey);
|
|
195
|
+
|
|
196
|
+
// Subscribe to view changes for reactivity.
|
|
197
|
+
const [viewSnapshot] = useObject(view);
|
|
198
|
+
|
|
202
199
|
const projectionModel = useMemo(() => {
|
|
203
200
|
// Use reactive and mutable version of json schema when schema is mutable.
|
|
204
201
|
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
|
|
203
|
+
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
204
|
+
// Pass schema only when mutable to allow schema mutations.
|
|
205
|
+
const change = createEchoChangeCallback(view, schema instanceof EchoSchema ? schema : undefined);
|
|
206
|
+
|
|
207
|
+
const model = new ProjectionModel({
|
|
208
|
+
registry: atomRegistry,
|
|
209
|
+
view,
|
|
210
|
+
baseSchema: jsonSchema,
|
|
211
|
+
change,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return model;
|
|
215
|
+
}, [atomRegistry, schema, view]);
|
|
216
|
+
|
|
207
217
|
const [expandedField, setExpandedField] = useState<FieldType['id']>();
|
|
208
218
|
|
|
219
|
+
const handleAdd = useCallback(() => {
|
|
220
|
+
invariant(!readonly);
|
|
221
|
+
const field = projectionModel.createFieldProjection();
|
|
222
|
+
setExpandedField(field.id);
|
|
223
|
+
}, [projectionModel, readonly]);
|
|
224
|
+
|
|
209
225
|
const handleToggleField = useCallback(
|
|
210
226
|
(field: FieldType) => {
|
|
211
227
|
setExpandedField((prevExpandedFieldId) => (prevExpandedFieldId === field.id ? undefined : field.id));
|
|
@@ -228,13 +244,15 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
228
244
|
const handleMove = useCallback(
|
|
229
245
|
(fromIndex: number, toIndex: number) => {
|
|
230
246
|
invariant(!readonly);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
Obj.change(view, (v) => {
|
|
248
|
+
// NOTE(ZaymonFC): Using arrayMove here causes a race condition with the kanban model.
|
|
249
|
+
const fields = [...v.projection.fields];
|
|
250
|
+
const [moved] = fields.splice(fromIndex, 1);
|
|
251
|
+
fields.splice(toIndex, 0, moved);
|
|
252
|
+
v.projection.fields = fields;
|
|
253
|
+
});
|
|
236
254
|
},
|
|
237
|
-
[view
|
|
255
|
+
[view, readonly],
|
|
238
256
|
);
|
|
239
257
|
|
|
240
258
|
const handleClose = useCallback(() => setExpandedField(undefined), []);
|
|
@@ -255,9 +273,13 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
255
273
|
[projectionModel],
|
|
256
274
|
);
|
|
257
275
|
|
|
276
|
+
if (!viewSnapshot) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
258
280
|
return (
|
|
259
281
|
<List.Root<FieldType>
|
|
260
|
-
items={
|
|
282
|
+
items={viewSnapshot.projection.fields as FieldType[]}
|
|
261
283
|
isItem={Schema.is(FieldSchema)}
|
|
262
284
|
getId={(field) => field.id}
|
|
263
285
|
onMove={readonly ? undefined : handleMove}
|
|
@@ -286,7 +308,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
286
308
|
data-testid={hidden ? 'show-field-button' : 'hide-field-button'}
|
|
287
309
|
icon={hidden ? 'ph--eye-closed--regular' : 'ph--eye--regular'}
|
|
288
310
|
autoHide={false}
|
|
289
|
-
disabled={readonly || (!hidden && projectionModel.
|
|
311
|
+
disabled={readonly || (!hidden && projectionModel.getFields().length <= 1)}
|
|
290
312
|
onClick={() => (hidden ? handleShow(field.path) : handleHide(field.id))}
|
|
291
313
|
/>
|
|
292
314
|
{!readonly && (
|
|
@@ -294,14 +316,14 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
294
316
|
<List.ItemDeleteButton
|
|
295
317
|
label={t('delete field label')}
|
|
296
318
|
autoHide={false}
|
|
297
|
-
disabled={readonly || schemaReadonly ||
|
|
319
|
+
disabled={readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1}
|
|
298
320
|
onClick={() => handleDelete(field.id)}
|
|
299
321
|
data-testid='field.delete'
|
|
300
322
|
/>
|
|
301
323
|
<IconButton
|
|
302
324
|
iconOnly
|
|
303
325
|
variant='ghost'
|
|
304
|
-
label={t('toggle expand label', { ns:
|
|
326
|
+
label={t('toggle expand label', { ns: osTranslations })}
|
|
305
327
|
icon={expandedField === field.id ? 'ph--caret-down--regular' : 'ph--caret-right--regular'}
|
|
306
328
|
onClick={() => handleToggleField(field)}
|
|
307
329
|
data-testid='field.toggle'
|
|
@@ -324,6 +346,17 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
324
346
|
);
|
|
325
347
|
})}
|
|
326
348
|
</div>
|
|
349
|
+
{!readonly && !expandedField && (
|
|
350
|
+
<div role='none' className='mlb-cardSpacingBlock'>
|
|
351
|
+
<IconButton
|
|
352
|
+
icon='ph--plus--regular'
|
|
353
|
+
label={t('add property button label')}
|
|
354
|
+
onClick={handleAdd}
|
|
355
|
+
disabled={viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT}
|
|
356
|
+
classNames='is-full'
|
|
357
|
+
/>
|
|
358
|
+
</div>
|
|
359
|
+
)}
|
|
327
360
|
</>
|
|
328
361
|
)}
|
|
329
362
|
</List.Root>
|
package/src/components/index.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import React, { type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
-
import { Card } from '@dxos/react-ui-
|
|
8
|
+
import { Card } from '@dxos/react-ui-mosaic';
|
|
9
9
|
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
|
10
|
-
import { textBlockWidth } from '@dxos/
|
|
10
|
+
import { textBlockWidth } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
12
|
type TestLayoutProps = ThemedClassName<PropsWithChildren<{ json?: any }>>;
|
|
13
13
|
|
|
@@ -25,9 +25,7 @@ export const TestLayout = ({ classNames, children, json }: TestLayoutProps) => {
|
|
|
25
25
|
type TestPanelProps = ThemedClassName<PropsWithChildren>;
|
|
26
26
|
|
|
27
27
|
const TestPanel = ({ classNames, children }: TestPanelProps) => {
|
|
28
|
-
return
|
|
29
|
-
<Card.StaticRoot classNames={['bs-full overflow-y-auto', textBlockWidth, classNames]}>{children}</Card.StaticRoot>
|
|
30
|
-
);
|
|
28
|
+
return <Card.Root classNames={['bs-full overflow-y-auto', textBlockWidth, classNames]}>{children}</Card.Root>;
|
|
31
29
|
};
|
|
32
30
|
|
|
33
31
|
// Symbol for accessing debug objects in tests.
|