@dxos/react-ui-form 0.8.4-main.9735255 → 0.8.4-main.9be5663bfe
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +989 -674
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +989 -674
- 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 -3
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +62 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +23 -18
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +68 -67
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +7 -1
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +0 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +2 -2
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +9 -10
- 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 -6
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +62 -61
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +9 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
- package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +10 -2
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +62 -61
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +83 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +35 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +82 -0
- 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 +5 -5
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +66 -64
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -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/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +62 -61
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/refs.d.ts +1 -0
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -38
- package/src/components/FieldEditor/FieldEditor.stories.tsx +7 -8
- package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
- package/src/components/FieldEditor/FieldEditor.tsx +3 -4
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +25 -26
- package/src/components/Form/Form.tsx +100 -66
- package/src/components/Form/FormField.tsx +32 -14
- package/src/components/Form/FormFieldComponent.stories.tsx +5 -5
- package/src/components/Form/FormFieldComponent.tsx +17 -20
- package/src/components/Form/FormFieldSet.tsx +126 -105
- package/src/components/Form/fields/ArrayField.tsx +11 -8
- package/src/components/Form/fields/GeoPointField.tsx +6 -6
- package/src/components/Form/fields/MarkdownField.tsx +1 -1
- package/src/components/Form/fields/RefField.tsx +37 -20
- package/src/components/Form/fields/SelectField.tsx +1 -1
- package/src/components/Form/fields/SelectOptionField.stories.tsx +2 -3
- package/src/components/Form/fields/SelectOptionField.tsx +9 -10
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectForm/ObjectForm.tsx +113 -0
- package/src/components/{ControlSection → ObjectForm}/index.ts +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +13 -18
- package/src/components/ObjectPicker/ObjectPicker.tsx +71 -60
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +63 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +129 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/Settings/Settings.stories.tsx +55 -0
- package/src/components/Settings/Settings.tsx +129 -0
- package/src/components/Settings/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +36 -33
- package/src/components/ViewEditor/ViewEditor.test.tsx +3 -7
- package/src/components/ViewEditor/ViewEditor.tsx +99 -70
- package/src/components/index.ts +3 -1
- package/src/components/testing.tsx +20 -8
- package/src/hooks/useFormHandler.ts +42 -24
- package/src/hooks/useKeyHandler.tsx +7 -7
- package/src/translations.ts +63 -63
- package/src/util/index.ts +0 -1
- package/src/util/refs.ts +7 -3
- 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 +0 -87
- 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/components/Form/Form-old.stories.d.ts +0 -131
- package/dist/types/src/components/Form/Form-old.stories.d.ts.map +0 -1
- package/dist/types/src/util/echo.d.ts +0 -6
- package/dist/types/src/util/echo.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
- package/src/components/ControlSection/ControlSection.tsx +0 -153
- package/src/components/Form/Form-old.stories.tsx +0 -314
- package/src/util/echo.ts +0 -25
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Input, type Label, ScrollArea, type ThemedClassName, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { composable, composableProps, mx } from '@dxos/ui-theme';
|
|
9
|
+
|
|
10
|
+
import { translationKey } from '../../translations';
|
|
11
|
+
|
|
12
|
+
const SETTINGS_ROOT_NAME = 'Settings.Root';
|
|
13
|
+
const SETTINGS_VIEWPORT_NAME = 'Settings.Viewport';
|
|
14
|
+
const SETTINGS_SECTION_NAME = 'Settings.Section';
|
|
15
|
+
const SETTINGS_PANEL_NAME = 'Settings.Panel';
|
|
16
|
+
const SETTINGS_ITEM_NAME = 'Settings.Item';
|
|
17
|
+
|
|
18
|
+
//
|
|
19
|
+
// Root (headless — no styling, no scroll).
|
|
20
|
+
//
|
|
21
|
+
|
|
22
|
+
type SettingsRootProps = ThemedClassName<PropsWithChildren>;
|
|
23
|
+
|
|
24
|
+
const SettingsRoot = ({ children, classNames }: SettingsRootProps) => {
|
|
25
|
+
return <div className={mx('flex flex-col gap-2', classNames)}>{children}</div>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
29
|
+
|
|
30
|
+
//
|
|
31
|
+
// Viewport (scroll area + padding + document layout).
|
|
32
|
+
//
|
|
33
|
+
|
|
34
|
+
const SettingsViewport = composable<HTMLDivElement>(({ children, ...props }, forwardedRef) => {
|
|
35
|
+
return (
|
|
36
|
+
<ScrollArea.Root {...composableProps(props)} orientation='vertical' centered thin ref={forwardedRef}>
|
|
37
|
+
<ScrollArea.Viewport classNames='px-4 pointer-coarse:px-2'>
|
|
38
|
+
<div role='none' className='dx-document flex flex-col gap-2 py-4'>
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
</ScrollArea.Viewport>
|
|
42
|
+
</ScrollArea.Root>
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
47
|
+
|
|
48
|
+
//
|
|
49
|
+
// Section (title + optional description + children with spacing).
|
|
50
|
+
//
|
|
51
|
+
|
|
52
|
+
type SettingsSectionProps = PropsWithChildren<{
|
|
53
|
+
title: Label;
|
|
54
|
+
description?: Label;
|
|
55
|
+
}>;
|
|
56
|
+
|
|
57
|
+
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
58
|
+
const { t } = useTranslation(translationKey);
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<h2 className='px-trim-md mt-trim-md text-xl'>{toLocalizedString(title, t)}</h2>
|
|
62
|
+
{description && <p className='px-trim-md text-description'>{toLocalizedString(description, t)}</p>}
|
|
63
|
+
<div className='w-full pt-trim-md space-y-trim-md'>{children}</div>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
69
|
+
|
|
70
|
+
//
|
|
71
|
+
// Panel (bordered card container).
|
|
72
|
+
//
|
|
73
|
+
|
|
74
|
+
type SettingsPanelProps = ThemedClassName<PropsWithChildren>;
|
|
75
|
+
|
|
76
|
+
const SettingsPanel = ({ classNames, children }: SettingsPanelProps) => {
|
|
77
|
+
return (
|
|
78
|
+
<div role='none' className={mx('flex flex-col gap-3 p-trim-md border border-separator rounded-sm', classNames)}>
|
|
79
|
+
{children}
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
SettingsPanel.displayName = SETTINGS_PANEL_NAME;
|
|
85
|
+
|
|
86
|
+
//
|
|
87
|
+
// Item (label + optional description + control, proper label semantics).
|
|
88
|
+
//
|
|
89
|
+
|
|
90
|
+
type SettingsItemProps = PropsWithChildren<{
|
|
91
|
+
title: Label;
|
|
92
|
+
description?: Label;
|
|
93
|
+
}>;
|
|
94
|
+
|
|
95
|
+
const SettingsItem = ({ title, description = '', children }: SettingsItemProps) => {
|
|
96
|
+
const { t } = useTranslation(translationKey);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Input.Root>
|
|
100
|
+
<SettingsPanel classNames='grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0'>
|
|
101
|
+
<Input.Label classNames='pb-trim-md text-base-surface-text text-lg md:col-span-2'>
|
|
102
|
+
{toLocalizedString(title, t)}
|
|
103
|
+
</Input.Label>
|
|
104
|
+
<Input.DescriptionAndValidation>
|
|
105
|
+
<Input.Description classNames='text-base text-description'>
|
|
106
|
+
{toLocalizedString(description, t)}
|
|
107
|
+
</Input.Description>
|
|
108
|
+
</Input.DescriptionAndValidation>
|
|
109
|
+
<div role='none' className='text-end py-1'>
|
|
110
|
+
{children}
|
|
111
|
+
</div>
|
|
112
|
+
</SettingsPanel>
|
|
113
|
+
</Input.Root>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
118
|
+
|
|
119
|
+
//
|
|
120
|
+
// Settings
|
|
121
|
+
//
|
|
122
|
+
|
|
123
|
+
export const Settings = {
|
|
124
|
+
Root: SettingsRoot,
|
|
125
|
+
Viewport: SettingsViewport,
|
|
126
|
+
Section: SettingsSection,
|
|
127
|
+
Panel: SettingsPanel,
|
|
128
|
+
Item: SettingsItem,
|
|
129
|
+
};
|
|
@@ -6,25 +6,25 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import { DXN, Filter, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN, Filter, JsonSchema, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
|
|
10
|
+
import { type View } from '@dxos/echo';
|
|
10
11
|
import { type EchoSchema, Format, type Mutable } from '@dxos/echo/internal';
|
|
11
12
|
import { useQuery } from '@dxos/react-client/echo';
|
|
12
13
|
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
13
14
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
14
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
|
-
import { type ProjectionModel,
|
|
16
|
-
import { Employer, Organization, Person,
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { type ProjectionModel, ViewModel, getTypenameFromQuery } from '@dxos/schema';
|
|
17
|
+
import { Employer, Organization, Person, Pipeline } from '@dxos/types';
|
|
17
18
|
|
|
18
19
|
import { translations } from '../../translations';
|
|
19
20
|
import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
20
|
-
|
|
21
21
|
import { ViewEditor, type ViewEditorProps } from './ViewEditor';
|
|
22
22
|
|
|
23
23
|
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
|
|
|
@@ -35,9 +35,9 @@ export type ViewEditorDebugObjects = {
|
|
|
35
35
|
projection: ProjectionModel;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
type
|
|
38
|
+
type DefaultStoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
|
|
39
39
|
|
|
40
|
-
const DefaultStory = (props:
|
|
40
|
+
const DefaultStory = (props: DefaultStoryProps) => {
|
|
41
41
|
const { space } = useClientStory();
|
|
42
42
|
const [schema, setSchema] = useState<EchoSchema>();
|
|
43
43
|
const [view, setView] = useState<View.View>();
|
|
@@ -53,7 +53,7 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
53
53
|
salary: Format.Currency(),
|
|
54
54
|
}).pipe(
|
|
55
55
|
Type.object({
|
|
56
|
-
typename: 'example.
|
|
56
|
+
typename: 'com.example.type.test',
|
|
57
57
|
version: '0.1.0',
|
|
58
58
|
}),
|
|
59
59
|
);
|
|
@@ -64,16 +64,16 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
64
64
|
completed: Schema.Boolean,
|
|
65
65
|
}).pipe(
|
|
66
66
|
Type.object({
|
|
67
|
-
typename: 'example.
|
|
67
|
+
typename: 'com.example.type.alternate',
|
|
68
68
|
version: '0.1.0',
|
|
69
69
|
}),
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
const [testSchema] = await space.db.schemaRegistry.register([TestSchema, AlternateSchema]);
|
|
73
|
-
const view =
|
|
73
|
+
const view = ViewModel.make({
|
|
74
74
|
name: 'Test',
|
|
75
75
|
query: Query.select(Filter.type(TestSchema)),
|
|
76
|
-
jsonSchema:
|
|
76
|
+
jsonSchema: JsonSchema.toJsonSchema(TestSchema),
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
setSchema(testSchema);
|
|
@@ -89,9 +89,9 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
89
89
|
|
|
90
90
|
if (props.mode === 'tag') {
|
|
91
91
|
const queue = target && DXN.tryParse(target) ? target : undefined;
|
|
92
|
-
const query = queue ? Query.fromAst(newQuery).
|
|
93
|
-
Obj.change(view, (
|
|
94
|
-
|
|
92
|
+
const query = queue ? Query.fromAst(newQuery).from({ queues: [queue] }) : Query.fromAst(newQuery);
|
|
93
|
+
Obj.change(view, (view) => {
|
|
94
|
+
view.query.ast = query.ast as Mutable<typeof query.ast>;
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
const typename = getTypenameFromQuery(query.ast);
|
|
@@ -100,17 +100,17 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const newView =
|
|
103
|
+
const newView = ViewModel.make({
|
|
104
104
|
query,
|
|
105
105
|
jsonSchema: newSchema.jsonSchema,
|
|
106
106
|
});
|
|
107
|
-
Obj.change(view, (
|
|
108
|
-
|
|
107
|
+
Obj.change(view, (view) => {
|
|
108
|
+
view.projection = Obj.getSnapshot(newView).projection as Mutable<typeof view.projection>;
|
|
109
109
|
});
|
|
110
110
|
setSchema(() => newSchema);
|
|
111
111
|
} else {
|
|
112
|
-
Obj.change(view, (
|
|
113
|
-
|
|
112
|
+
Obj.change(view, (view) => {
|
|
113
|
+
view.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
114
114
|
});
|
|
115
115
|
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
116
116
|
}
|
|
@@ -146,18 +146,20 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
146
146
|
|
|
147
147
|
return (
|
|
148
148
|
<TestLayout json={json}>
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
<div role='none' className='col-span-full'>
|
|
150
|
+
<ViewEditor
|
|
151
|
+
ref={projectionRef}
|
|
152
|
+
schema={schema}
|
|
153
|
+
view={view}
|
|
154
|
+
registry={space?.db.schemaRegistry}
|
|
155
|
+
mode={props.mode}
|
|
156
|
+
readonly={props.readonly}
|
|
157
|
+
types={types}
|
|
158
|
+
tags={tags}
|
|
159
|
+
onQueryChanged={updateViewQuery}
|
|
160
|
+
onDelete={handleDelete}
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
161
163
|
</TestLayout>
|
|
162
164
|
);
|
|
163
165
|
};
|
|
@@ -175,7 +177,8 @@ const meta = {
|
|
|
175
177
|
space.db.add(Tag.make({ label: 'New' }));
|
|
176
178
|
},
|
|
177
179
|
}),
|
|
178
|
-
withTheme,
|
|
180
|
+
withTheme(),
|
|
181
|
+
withLayout({ layout: 'fullscreen' }),
|
|
179
182
|
],
|
|
180
183
|
parameters: {
|
|
181
184
|
layout: 'fullscreen',
|
|
@@ -6,11 +6,11 @@ import { composeStories } from '@storybook/react';
|
|
|
6
6
|
import { cleanup, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
7
7
|
import { afterEach, describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
|
+
import { View } from '@dxos/echo';
|
|
9
10
|
import { EchoSchema, isInstanceOf } from '@dxos/echo/internal';
|
|
10
|
-
import { ProjectionModel
|
|
11
|
+
import { ProjectionModel } from '@dxos/schema';
|
|
11
12
|
|
|
12
13
|
import { VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
13
|
-
|
|
14
14
|
import * as stories from './ViewEditor.stories';
|
|
15
15
|
import { type ViewEditorDebugObjects } from './ViewEditor.stories';
|
|
16
16
|
|
|
@@ -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' } });
|
|
@@ -9,19 +9,18 @@ import * as Option from 'effect/Option';
|
|
|
9
9
|
import * as Schema from 'effect/Schema';
|
|
10
10
|
import React, { forwardRef, useCallback, useContext, useImperativeHandle, useMemo, useState } from 'react';
|
|
11
11
|
|
|
12
|
-
import { Filter, Format, Obj, Query, QueryAST, type SchemaRegistry } from '@dxos/echo';
|
|
12
|
+
import { Entity, Feed, Filter, Format, Obj, Query, QueryAST, Ref, type SchemaRegistry } from '@dxos/echo';
|
|
13
|
+
import { View } from '@dxos/echo';
|
|
13
14
|
import { EchoSchema, type JsonProp, isMutable, toJsonSchema } from '@dxos/echo/internal';
|
|
14
15
|
import { invariant } from '@dxos/invariant';
|
|
15
|
-
import { useObject } from '@dxos/react-client/echo';
|
|
16
|
-
import {
|
|
16
|
+
import { useObject, useQuery } from '@dxos/react-client/echo';
|
|
17
|
+
import { IconButton, Input, Message, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
17
18
|
import { QueryForm, type QueryFormProps } from '@dxos/react-ui-components';
|
|
18
19
|
import { List } from '@dxos/react-ui-list';
|
|
19
20
|
import {
|
|
20
|
-
|
|
21
|
-
type FieldType,
|
|
21
|
+
ParentLabelAnnotation,
|
|
22
22
|
ProjectionModel,
|
|
23
23
|
VIEW_FIELD_LIMIT,
|
|
24
|
-
type View,
|
|
25
24
|
createEchoChangeCallback,
|
|
26
25
|
getTypenameFromQuery,
|
|
27
26
|
} from '@dxos/schema';
|
|
@@ -35,22 +34,20 @@ import {
|
|
|
35
34
|
type FormFieldComponentProps,
|
|
36
35
|
FormFieldLabel,
|
|
37
36
|
type FormFieldMap,
|
|
37
|
+
type FormRootProps,
|
|
38
38
|
} from '../Form';
|
|
39
39
|
|
|
40
|
-
const listGrid = 'grid grid-cols-[min-content_1fr_min-content_min-content_min-content]';
|
|
41
|
-
const listItemGrid = 'grid grid-cols-subgrid col-span-5';
|
|
42
|
-
|
|
43
40
|
export type ViewEditorProps = ThemedClassName<
|
|
44
41
|
{
|
|
45
42
|
schema: Schema.Schema.AnyNoContext;
|
|
46
43
|
view: View.View;
|
|
47
44
|
mode?: 'schema' | 'tag';
|
|
48
45
|
registry?: SchemaRegistry.SchemaRegistry;
|
|
49
|
-
readonly?: boolean;
|
|
50
46
|
showHeading?: boolean;
|
|
51
47
|
onQueryChanged?: (query: QueryAST.Query, target?: string) => void;
|
|
52
48
|
onDelete?: (fieldId: string) => void;
|
|
53
|
-
} & Pick<QueryFormProps, 'types' | 'tags'>
|
|
49
|
+
} & Pick<QueryFormProps, 'types' | 'tags'> &
|
|
50
|
+
Pick<FormRootProps<any>, 'readonly' | 'db'>
|
|
54
51
|
>;
|
|
55
52
|
|
|
56
53
|
/**
|
|
@@ -64,6 +61,7 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
64
61
|
view,
|
|
65
62
|
mode = 'schema',
|
|
66
63
|
registry,
|
|
64
|
+
db,
|
|
67
65
|
readonly,
|
|
68
66
|
showHeading = false,
|
|
69
67
|
types,
|
|
@@ -96,18 +94,31 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
96
94
|
}, [atomRegistry, schema, view]);
|
|
97
95
|
|
|
98
96
|
useImperativeHandle(forwardedRef, () => projectionModel, [projectionModel]);
|
|
99
|
-
const [expandedField, setExpandedField] = useState<FieldType['id']>();
|
|
100
97
|
|
|
101
98
|
const queueTarget = Match.value(view.query.ast).pipe(
|
|
102
|
-
Match.when({ type: '
|
|
103
|
-
|
|
99
|
+
Match.when({ type: 'from' }, ({ from }) => {
|
|
100
|
+
if (from._tag !== 'scope') {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return Option.fromNullable(from.scope.queues).pipe(
|
|
104
104
|
Option.flatMap((queues) => Array.head(queues)),
|
|
105
|
+
Option.map(String),
|
|
105
106
|
Option.getOrUndefined,
|
|
106
107
|
);
|
|
107
108
|
}),
|
|
108
109
|
Match.orElse(() => undefined),
|
|
109
110
|
);
|
|
110
111
|
|
|
112
|
+
const feeds = useQuery(db, Filter.type(Feed.Feed));
|
|
113
|
+
|
|
114
|
+
const targetRef = useMemo(() => {
|
|
115
|
+
if (!queueTarget) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const feed = feeds.find((feed) => Feed.getQueueDxn(feed)?.toString() === queueTarget);
|
|
119
|
+
return feed ? Ref.fromDXN(Entity.getDXN(feed)) : undefined;
|
|
120
|
+
}, [queueTarget, feeds]);
|
|
121
|
+
|
|
111
122
|
const viewSchema = useMemo(() => {
|
|
112
123
|
const base = Schema.Struct({
|
|
113
124
|
query:
|
|
@@ -119,7 +130,12 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
119
130
|
if (mode === 'tag') {
|
|
120
131
|
return Schema.Struct({
|
|
121
132
|
...base.fields,
|
|
122
|
-
|
|
133
|
+
// TODO(wittjosiah): Replace Type.Feed with Dataset.Dataset when Ref.Ref supports unions.
|
|
134
|
+
target: Ref.Ref(Feed.Feed).pipe(
|
|
135
|
+
Schema.annotations({ title: 'Target Feed' }),
|
|
136
|
+
ParentLabelAnnotation.set(true),
|
|
137
|
+
Schema.optional,
|
|
138
|
+
),
|
|
123
139
|
}).pipe(Schema.mutable);
|
|
124
140
|
}
|
|
125
141
|
|
|
@@ -131,9 +147,9 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
131
147
|
const viewValues = useMemo(
|
|
132
148
|
() => ({
|
|
133
149
|
query: mode === 'schema' ? getTypenameFromQuery(view.query.ast) : view.query.ast,
|
|
134
|
-
target:
|
|
150
|
+
target: targetRef,
|
|
135
151
|
}),
|
|
136
|
-
[mode, view.query.ast,
|
|
152
|
+
[mode, view.query.ast, targetRef],
|
|
137
153
|
);
|
|
138
154
|
|
|
139
155
|
const fieldMap = useMemo<FormFieldMap | undefined>(
|
|
@@ -141,49 +157,51 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
141
157
|
[mode, types, tags],
|
|
142
158
|
);
|
|
143
159
|
|
|
144
|
-
// TODO(burdon): Check if mutable.
|
|
145
|
-
const handleAdd = useCallback(() => {
|
|
146
|
-
invariant(!readonly);
|
|
147
|
-
const field = projectionModel.createFieldProjection();
|
|
148
|
-
setExpandedField(field.id);
|
|
149
|
-
}, [projectionModel, readonly]);
|
|
150
|
-
|
|
151
160
|
const handleUpdate = useCallback(
|
|
152
161
|
(values: any) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
const targetValue = values.target;
|
|
163
|
+
let queueDxn: string | undefined;
|
|
164
|
+
|
|
165
|
+
if (Ref.isRef(targetValue)) {
|
|
166
|
+
const feedDxn = targetValue.dxn.toString();
|
|
167
|
+
const feed = feeds.find((feed) => Obj.getDXN(feed).toString() === feedDxn);
|
|
168
|
+
if (feed) {
|
|
169
|
+
queueDxn = Feed.getQueueDxn(feed)?.toString();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// TODO(wittjosiah): Deep-clone the AST to plain JS or ECHO proxy arrays become objects with numeric keys.
|
|
174
|
+
const query =
|
|
175
|
+
mode === 'schema'
|
|
176
|
+
? Query.select(Filter.typename(values.query)).ast
|
|
177
|
+
: JSON.parse(JSON.stringify(values.query));
|
|
178
|
+
onQueryChanged?.(query, queueDxn);
|
|
157
179
|
},
|
|
158
|
-
[onQueryChanged,
|
|
180
|
+
[onQueryChanged, mode, feeds],
|
|
159
181
|
);
|
|
160
182
|
|
|
161
183
|
const handleDelete = useCallback(
|
|
162
184
|
(fieldId: string) => {
|
|
163
185
|
invariant(!readonly);
|
|
164
|
-
if (fieldId === expandedField) {
|
|
165
|
-
setExpandedField(undefined);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
186
|
onDelete?.(fieldId);
|
|
169
187
|
},
|
|
170
|
-
[
|
|
188
|
+
[onDelete, readonly],
|
|
171
189
|
);
|
|
172
190
|
|
|
173
191
|
return (
|
|
174
192
|
<div role='none' className={mx(classNames)}>
|
|
175
193
|
{/* If readonly is set, then the callout is not needed. */}
|
|
176
194
|
{schemaReadonly && !readonly && (
|
|
177
|
-
<
|
|
178
|
-
<
|
|
179
|
-
</
|
|
195
|
+
<Message.Root valence='info' classNames='my-form-padding'>
|
|
196
|
+
<Message.Title>{t('system-schema.description')}</Message.Title>
|
|
197
|
+
</Message.Root>
|
|
180
198
|
)}
|
|
181
199
|
|
|
182
200
|
{/* TODO(burdon): Is the form read-only or just the schema? */}
|
|
183
|
-
<Form.Root schema={viewSchema} values={viewValues} fieldMap={fieldMap}
|
|
201
|
+
<Form.Root schema={viewSchema} values={viewValues} fieldMap={fieldMap} db={db} onValuesChanged={handleUpdate}>
|
|
184
202
|
<Form.FieldSet />
|
|
185
203
|
|
|
186
|
-
<FormFieldLabel label={t('fields
|
|
204
|
+
<FormFieldLabel label={t('fields.label')} asChild />
|
|
187
205
|
<FieldList
|
|
188
206
|
schema={schema}
|
|
189
207
|
view={view}
|
|
@@ -193,19 +211,6 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
193
211
|
onDelete={handleDelete}
|
|
194
212
|
/>
|
|
195
213
|
</Form.Root>
|
|
196
|
-
|
|
197
|
-
{!readonly && !expandedField && (
|
|
198
|
-
<div role='none' className='mlb-cardSpacingBlock'>
|
|
199
|
-
<IconButton
|
|
200
|
-
icon='ph--plus--regular'
|
|
201
|
-
label={t('add property button label')}
|
|
202
|
-
onClick={readonly ? undefined : handleAdd}
|
|
203
|
-
// TODO(burdon): Show field limit in ux (not tooltip).
|
|
204
|
-
disabled={view.projection.fields.length >= VIEW_FIELD_LIMIT}
|
|
205
|
-
classNames='is-full'
|
|
206
|
-
/>
|
|
207
|
-
</div>
|
|
208
|
-
)}
|
|
209
214
|
</div>
|
|
210
215
|
);
|
|
211
216
|
},
|
|
@@ -239,10 +244,16 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
239
244
|
return model;
|
|
240
245
|
}, [atomRegistry, schema, view]);
|
|
241
246
|
|
|
242
|
-
const [expandedField, setExpandedField] = useState<FieldType['id']>();
|
|
247
|
+
const [expandedField, setExpandedField] = useState<View.FieldType['id']>();
|
|
248
|
+
|
|
249
|
+
const handleAdd = useCallback(() => {
|
|
250
|
+
invariant(!readonly);
|
|
251
|
+
const field = projectionModel.createFieldProjection();
|
|
252
|
+
setExpandedField(field.id);
|
|
253
|
+
}, [projectionModel, readonly]);
|
|
243
254
|
|
|
244
255
|
const handleToggleField = useCallback(
|
|
245
|
-
(field: FieldType) => {
|
|
256
|
+
(field: View.FieldType) => {
|
|
246
257
|
setExpandedField((prevExpandedFieldId) => (prevExpandedFieldId === field.id ? undefined : field.id));
|
|
247
258
|
},
|
|
248
259
|
[readonly],
|
|
@@ -263,12 +274,12 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
263
274
|
const handleMove = useCallback(
|
|
264
275
|
(fromIndex: number, toIndex: number) => {
|
|
265
276
|
invariant(!readonly);
|
|
266
|
-
Obj.change(view, (
|
|
277
|
+
Obj.change(view, (view) => {
|
|
267
278
|
// NOTE(ZaymonFC): Using arrayMove here causes a race condition with the kanban model.
|
|
268
|
-
const fields = [...
|
|
279
|
+
const fields = [...view.projection.fields];
|
|
269
280
|
const [moved] = fields.splice(fromIndex, 1);
|
|
270
281
|
fields.splice(toIndex, 0, moved);
|
|
271
|
-
|
|
282
|
+
view.projection.fields = fields;
|
|
272
283
|
});
|
|
273
284
|
},
|
|
274
285
|
[view, readonly],
|
|
@@ -297,32 +308,39 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
297
308
|
}
|
|
298
309
|
|
|
299
310
|
return (
|
|
300
|
-
<List.Root<FieldType>
|
|
301
|
-
items={viewSnapshot.projection.fields as FieldType[]}
|
|
302
|
-
isItem={Schema.is(FieldSchema)}
|
|
311
|
+
<List.Root<View.FieldType>
|
|
312
|
+
items={viewSnapshot.projection.fields as View.FieldType[]}
|
|
313
|
+
isItem={Schema.is(View.FieldSchema)}
|
|
303
314
|
getId={(field) => field.id}
|
|
304
315
|
onMove={readonly ? undefined : handleMove}
|
|
305
316
|
readonly={readonly}
|
|
306
317
|
>
|
|
307
318
|
{({ items: fields }) => (
|
|
308
319
|
<>
|
|
309
|
-
{showHeading && <h3 className='text-sm'>{t('field
|
|
310
|
-
<div role='list' className=
|
|
320
|
+
{showHeading && <h3 className='text-sm'>{t('field-path.label')}</h3>}
|
|
321
|
+
<div role='list' className='grid grid-cols-[min-content_1fr_min-content_min-content_min-content]'>
|
|
311
322
|
{fields?.map((field) => {
|
|
312
323
|
const hidden = field.visible === false;
|
|
313
324
|
return (
|
|
314
|
-
<List.Item<FieldType>
|
|
325
|
+
<List.Item<View.FieldType>
|
|
315
326
|
key={field.id}
|
|
316
327
|
item={field}
|
|
317
|
-
classNames={
|
|
328
|
+
classNames={'grid grid-cols-subgrid col-span-5'}
|
|
318
329
|
aria-expanded={expandedField === field.id}
|
|
319
330
|
>
|
|
320
|
-
<div
|
|
331
|
+
<div
|
|
332
|
+
role='none'
|
|
333
|
+
className={mx(
|
|
334
|
+
subtleHover,
|
|
335
|
+
'grid grid-cols-subgrid col-span-5',
|
|
336
|
+
'rounded-xs cursor-pointer min-h-10',
|
|
337
|
+
)}
|
|
338
|
+
>
|
|
321
339
|
<List.ItemDragHandle disabled={readonly || schemaReadonly} />
|
|
322
340
|
<List.ItemTitle classNames={hidden && 'text-subdued'} onClick={() => handleToggleField(field)}>
|
|
323
341
|
{field.path}
|
|
324
342
|
</List.ItemTitle>
|
|
325
|
-
<List.
|
|
343
|
+
<List.ItemIconButton
|
|
326
344
|
label={t(hidden ? 'show field label' : 'hide field label')}
|
|
327
345
|
data-testid={hidden ? 'show-field-button' : 'hide-field-button'}
|
|
328
346
|
icon={hidden ? 'ph--eye-closed--regular' : 'ph--eye--regular'}
|
|
@@ -333,16 +351,16 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
333
351
|
{!readonly && (
|
|
334
352
|
<>
|
|
335
353
|
<List.ItemDeleteButton
|
|
336
|
-
label={t('delete
|
|
354
|
+
label={t('delete-field.label')}
|
|
337
355
|
autoHide={false}
|
|
338
356
|
disabled={readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1}
|
|
339
357
|
onClick={() => handleDelete(field.id)}
|
|
340
358
|
data-testid='field.delete'
|
|
341
359
|
/>
|
|
342
|
-
<
|
|
360
|
+
<List.ItemIconButton
|
|
343
361
|
iconOnly
|
|
344
362
|
variant='ghost'
|
|
345
|
-
label={t('toggle
|
|
363
|
+
label={t('toggle-expand.label', { ns: osTranslations })}
|
|
346
364
|
icon={expandedField === field.id ? 'ph--caret-down--regular' : 'ph--caret-right--regular'}
|
|
347
365
|
onClick={() => handleToggleField(field)}
|
|
348
366
|
data-testid='field.toggle'
|
|
@@ -351,7 +369,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
351
369
|
)}
|
|
352
370
|
</div>
|
|
353
371
|
{expandedField === field.id && !readonly && (
|
|
354
|
-
<div role='none' className='col-span-
|
|
372
|
+
<div role='none' className='col-span-full mt-1 mb-1 border border-separator rounded-md'>
|
|
355
373
|
<FieldEditor
|
|
356
374
|
readonly={readonly || schemaReadonly}
|
|
357
375
|
registry={registry}
|
|
@@ -365,6 +383,17 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
365
383
|
);
|
|
366
384
|
})}
|
|
367
385
|
</div>
|
|
386
|
+
{!readonly && !expandedField && (
|
|
387
|
+
<div role='none' className='my-form-padding'>
|
|
388
|
+
<IconButton
|
|
389
|
+
icon='ph--plus--regular'
|
|
390
|
+
label={t('add-property-button.label')}
|
|
391
|
+
onClick={handleAdd}
|
|
392
|
+
disabled={viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT}
|
|
393
|
+
classNames='w-full'
|
|
394
|
+
/>
|
|
395
|
+
</div>
|
|
396
|
+
)}
|
|
368
397
|
</>
|
|
369
398
|
)}
|
|
370
399
|
</List.Root>
|
package/src/components/index.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './ControlSection';
|
|
6
5
|
export * from './FieldEditor';
|
|
7
6
|
export * from './Form';
|
|
7
|
+
export * from './ObjectForm';
|
|
8
8
|
export * from './ObjectPicker';
|
|
9
|
+
export * from './ObjectProperties';
|
|
10
|
+
export * from './Settings';
|
|
9
11
|
export * from './ViewEditor';
|