@firecms/collection_editor 3.0.0-alpha.9 → 3.0.0-beta.2-pre.1
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/ConfigControllerProvider.d.ts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.es.js +3128 -4094
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +22 -7
- package/dist/types/collection_inference.d.ts +1 -1
- package/dist/types/config_controller.d.ts +32 -5
- package/dist/types/persisted_collection.d.ts +3 -1
- package/dist/ui/CollectionViewHeaderAction.d.ts +10 -0
- package/dist/{components → ui}/EditorCollectionAction.d.ts +1 -1
- package/dist/ui/MissingReferenceWidget.d.ts +3 -0
- package/dist/ui/NewCollectionButton.d.ts +1 -0
- package/dist/ui/PropertyAddColumnComponent.d.ts +6 -0
- package/dist/ui/RootCollectionSuggestions.d.ts +1 -0
- package/dist/{components → ui}/collection_editor/CollectionDetailsForm.d.ts +3 -2
- package/dist/{components → ui}/collection_editor/CollectionEditorDialog.d.ts +11 -6
- package/dist/{components → ui}/collection_editor/CollectionPropertiesEditorForm.d.ts +6 -3
- package/dist/{components → ui}/collection_editor/CollectionYupValidation.d.ts +3 -0
- package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
- package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
- package/dist/{components → ui}/collection_editor/PropertyEditView.d.ts +8 -6
- package/dist/{components → ui}/collection_editor/PropertyFieldPreview.d.ts +4 -3
- package/dist/ui/collection_editor/PropertySelectItem.d.ts +8 -0
- package/dist/{components → ui}/collection_editor/PropertyTree.d.ts +8 -5
- package/dist/{components → ui}/collection_editor/SubcollectionsEditTab.d.ts +2 -2
- package/dist/{components → ui}/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
- package/dist/{components → ui}/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/{components → ui}/collection_editor/properties/BlockPropertyField.d.ts +4 -1
- package/dist/{components → ui}/collection_editor/properties/CommonPropertyFields.d.ts +1 -0
- package/dist/{components → ui}/collection_editor/properties/MapPropertyField.d.ts +4 -1
- package/dist/{components → ui}/collection_editor/properties/RepeatPropertyField.d.ts +4 -1
- package/dist/{components → ui}/collection_editor/properties/StringPropertyField.d.ts +1 -1
- package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
- package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
- package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
- package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
- package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
- package/dist/useCollectionEditorPlugin.d.ts +5 -3
- package/dist/utils/entities.d.ts +3 -4
- package/package.json +22 -19
- package/src/ConfigControllerProvider.tsx +336 -0
- package/src/index.ts +35 -0
- package/src/types/collection_editor_controller.tsx +42 -0
- package/src/types/collection_inference.ts +3 -0
- package/src/types/config_controller.tsx +60 -0
- package/src/types/config_permissions.ts +20 -0
- package/src/types/persisted_collection.ts +9 -0
- package/src/ui/CollectionViewHeaderAction.tsx +43 -0
- package/src/ui/EditorCollectionAction.tsx +109 -0
- package/src/ui/HomePageEditorCollectionAction.tsx +84 -0
- package/src/ui/MissingReferenceWidget.tsx +35 -0
- package/src/ui/NewCollectionButton.tsx +16 -0
- package/src/ui/NewCollectionCard.tsx +47 -0
- package/src/ui/PropertyAddColumnComponent.tsx +42 -0
- package/src/ui/RootCollectionSuggestions.tsx +55 -0
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +366 -0
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +754 -0
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +206 -0
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +481 -0
- package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
- package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
- package/src/ui/collection_editor/EnumForm.tsx +354 -0
- package/src/ui/collection_editor/GetCodeDialog.tsx +110 -0
- package/src/ui/collection_editor/PropertyEditView.tsx +558 -0
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +203 -0
- package/src/ui/collection_editor/PropertySelectItem.tsx +32 -0
- package/src/ui/collection_editor/PropertyTree.tsx +233 -0
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +253 -0
- package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
- package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +37 -0
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +260 -0
- package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +135 -0
- package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +36 -0
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +137 -0
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +87 -0
- package/src/ui/collection_editor/properties/EnumPropertyField.tsx +117 -0
- package/src/ui/collection_editor/properties/FieldHelperView.tsx +13 -0
- package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +149 -0
- package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +165 -0
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +108 -0
- package/src/ui/collection_editor/properties/StoragePropertyField.tsx +194 -0
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +79 -0
- package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
- package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +36 -0
- package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
- package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +50 -0
- package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +100 -0
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +132 -0
- package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
- package/src/ui/collection_editor/templates/blog_template.ts +115 -0
- package/src/ui/collection_editor/templates/pages_template.ts +188 -0
- package/src/ui/collection_editor/templates/products_template.ts +88 -0
- package/src/ui/collection_editor/templates/users_template.ts +42 -0
- package/src/ui/collection_editor/util.ts +21 -0
- package/src/ui/collection_editor/utils/strings.ts +8 -0
- package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
- package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
- package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
- package/src/useCollectionEditorController.tsx +9 -0
- package/src/useCollectionEditorPlugin.tsx +137 -0
- package/src/useCollectionsConfigController.tsx +9 -0
- package/src/utils/arrays.ts +3 -0
- package/src/utils/entities.ts +38 -0
- package/src/vite-env.d.ts +1 -0
- package/dist/components/collection_editor/PropertySelectItem.d.ts +0 -8
- package/dist/components/collection_editor/SelectIcons.d.ts +0 -6
- package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +0 -4
- package/dist/components/collection_editor/templates/blog_template.d.ts +0 -10
- package/dist/components/collection_editor/templates/products_template.d.ts +0 -12
- package/dist/components/collection_editor/templates/users_template.d.ts +0 -7
- package/dist/components/collection_editor/utils/supported_fields.d.ts +0 -3
- package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +0 -3
- package/dist/types/editable_properties.d.ts +0 -10
- package/dist/utils/icons.d.ts +0 -2
- package/dist/utils/synonyms.d.ts +0 -1951
- /package/dist/{components → ui}/HomePageEditorCollectionAction.d.ts +0 -0
- /package/dist/{components → ui}/NewCollectionCard.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/CollectionEditorWelcomeView.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/EnumForm.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/UnsavedChangesDialog.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/BooleanPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/DateTimePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/EnumPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/FieldHelperView.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/KeyValuePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/NumberPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/ReferencePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/StoragePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/NumberPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/StringPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/ValidationPanel.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/util.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/utils/useTraceUpdate.d.ts +0 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorBoundary,
|
|
3
|
+
PropertyConfigBadge,
|
|
4
|
+
getFieldConfig,
|
|
5
|
+
isPropertyBuilder,
|
|
6
|
+
Property,
|
|
7
|
+
PropertyOrBuilder,
|
|
8
|
+
useCustomizationController,
|
|
9
|
+
} from "@firecms/core";
|
|
10
|
+
import {
|
|
11
|
+
cardClickableMixin,
|
|
12
|
+
cardMixin,
|
|
13
|
+
cardSelectedMixin,
|
|
14
|
+
cn,
|
|
15
|
+
FunctionsIcon,
|
|
16
|
+
Paper,
|
|
17
|
+
RemoveCircleIcon,
|
|
18
|
+
Typography,
|
|
19
|
+
} from "@firecms/ui";
|
|
20
|
+
|
|
21
|
+
import { editableProperty } from "../../utils/entities";
|
|
22
|
+
|
|
23
|
+
export function PropertyFieldPreview({
|
|
24
|
+
property,
|
|
25
|
+
onClick,
|
|
26
|
+
hasError,
|
|
27
|
+
includeName,
|
|
28
|
+
includeEditButton,
|
|
29
|
+
selected
|
|
30
|
+
}: {
|
|
31
|
+
property: Property,
|
|
32
|
+
hasError?: boolean,
|
|
33
|
+
selected?: boolean,
|
|
34
|
+
includeName?: boolean,
|
|
35
|
+
includeEditButton?: boolean;
|
|
36
|
+
onClick?: () => void
|
|
37
|
+
}) {
|
|
38
|
+
|
|
39
|
+
const { propertyConfigs } = useCustomizationController();
|
|
40
|
+
|
|
41
|
+
const propertyConfig = getFieldConfig(property, propertyConfigs);
|
|
42
|
+
const disabled = !editableProperty(property);
|
|
43
|
+
|
|
44
|
+
const borderColorClass = hasError
|
|
45
|
+
? "border-red-500"
|
|
46
|
+
: (selected ? "border-primary" : "border-transparent");
|
|
47
|
+
|
|
48
|
+
return <ErrorBoundary>
|
|
49
|
+
<div
|
|
50
|
+
onClick={onClick}
|
|
51
|
+
className="flex flex-row w-full cursor-pointer">
|
|
52
|
+
<div className={"m-4"}>
|
|
53
|
+
<PropertyConfigBadge propertyConfig={propertyConfig}/>
|
|
54
|
+
</div>
|
|
55
|
+
<Paper
|
|
56
|
+
className={cn(
|
|
57
|
+
"pl-2 w-full flex flex-row gap-4 items-center",
|
|
58
|
+
cardMixin,
|
|
59
|
+
onClick ? cardClickableMixin : "",
|
|
60
|
+
selected ? cardSelectedMixin : "",
|
|
61
|
+
"flex-grow p-4 border transition-colors duration-200",
|
|
62
|
+
borderColorClass
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
|
|
66
|
+
<div className="w-full flex flex-col">
|
|
67
|
+
|
|
68
|
+
{includeName &&
|
|
69
|
+
<ErrorBoundary>
|
|
70
|
+
<Typography variant="body1"
|
|
71
|
+
component="span"
|
|
72
|
+
className="flex-grow pr-2">
|
|
73
|
+
{property.name
|
|
74
|
+
? property.name
|
|
75
|
+
: "\u00a0"
|
|
76
|
+
}
|
|
77
|
+
</Typography>
|
|
78
|
+
</ErrorBoundary>}
|
|
79
|
+
|
|
80
|
+
<div className="flex flex-row items-center">
|
|
81
|
+
<ErrorBoundary>
|
|
82
|
+
<Typography className="flex-grow pr-2"
|
|
83
|
+
variant={includeName ? "body2" : "subtitle1"}
|
|
84
|
+
component="span"
|
|
85
|
+
color="secondary">
|
|
86
|
+
{propertyConfig?.name}
|
|
87
|
+
</Typography>
|
|
88
|
+
</ErrorBoundary>
|
|
89
|
+
<ErrorBoundary>
|
|
90
|
+
<Typography variant="body2"
|
|
91
|
+
component="span"
|
|
92
|
+
color="disabled">
|
|
93
|
+
{property.dataType}
|
|
94
|
+
</Typography>
|
|
95
|
+
</ErrorBoundary>
|
|
96
|
+
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{includeEditButton && <Typography variant={"button"}>
|
|
101
|
+
EDIT
|
|
102
|
+
</Typography>}
|
|
103
|
+
|
|
104
|
+
</Paper>
|
|
105
|
+
</div>
|
|
106
|
+
</ErrorBoundary>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function NonEditablePropertyPreview({
|
|
110
|
+
name,
|
|
111
|
+
selected,
|
|
112
|
+
onClick,
|
|
113
|
+
property
|
|
114
|
+
}: {
|
|
115
|
+
name: string,
|
|
116
|
+
selected: boolean,
|
|
117
|
+
onClick?: () => void,
|
|
118
|
+
property?: PropertyOrBuilder
|
|
119
|
+
}) {
|
|
120
|
+
|
|
121
|
+
const { propertyConfigs } = useCustomizationController();
|
|
122
|
+
|
|
123
|
+
const propertyConfig = !isPropertyBuilder(property) && property ? getFieldConfig(property, propertyConfigs) : undefined;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
onClick={onClick}
|
|
128
|
+
className="flex flex-row w-full cursor-pointer">
|
|
129
|
+
<div className={"relative m-4"}>
|
|
130
|
+
{propertyConfig && <PropertyConfigBadge propertyConfig={propertyConfig}/>}
|
|
131
|
+
{!propertyConfig && <div
|
|
132
|
+
className={"h-8 w-8 p-1 rounded-full shadow text-white bg-gray-500"}>
|
|
133
|
+
<FunctionsIcon color={"inherit"} size={"medium"}/>
|
|
134
|
+
</div>}
|
|
135
|
+
<RemoveCircleIcon color={"disabled"} size={"small"} className={"absolute -right-2 -top-2"}/>
|
|
136
|
+
</div>
|
|
137
|
+
<Paper
|
|
138
|
+
className={cn(
|
|
139
|
+
"pl-2 w-full flex flex-row gap-4 items-center",
|
|
140
|
+
cardMixin,
|
|
141
|
+
onClick ? cardClickableMixin : "",
|
|
142
|
+
selected ? cardSelectedMixin : "",
|
|
143
|
+
"flex-grow p-4 border transition-colors duration-200",
|
|
144
|
+
selected ? "border-primary" : "border-transparent")}
|
|
145
|
+
>
|
|
146
|
+
|
|
147
|
+
<div className="w-full flex flex-col">
|
|
148
|
+
<Typography variant="body1"
|
|
149
|
+
component="span"
|
|
150
|
+
className="flex-grow pr-2">
|
|
151
|
+
{property?.name
|
|
152
|
+
? property.name
|
|
153
|
+
: name
|
|
154
|
+
}
|
|
155
|
+
</Typography>
|
|
156
|
+
|
|
157
|
+
<div className="flex flex-row items-center">
|
|
158
|
+
{propertyConfig && <Typography className="flex-grow pr-2"
|
|
159
|
+
variant={"body2"}
|
|
160
|
+
component="span"
|
|
161
|
+
color="secondary">
|
|
162
|
+
{propertyConfig?.name}
|
|
163
|
+
</Typography>}
|
|
164
|
+
|
|
165
|
+
{property && !isPropertyBuilder(property) && <ErrorBoundary>
|
|
166
|
+
<Typography variant="body2"
|
|
167
|
+
component="span"
|
|
168
|
+
color="disabled">
|
|
169
|
+
{property.dataType}
|
|
170
|
+
</Typography>
|
|
171
|
+
</ErrorBoundary>}
|
|
172
|
+
|
|
173
|
+
{property && isPropertyBuilder(property) && <ErrorBoundary>
|
|
174
|
+
<Typography variant="body2"
|
|
175
|
+
component="span"
|
|
176
|
+
color="disabled">
|
|
177
|
+
This property is defined as a property builder in code
|
|
178
|
+
</Typography>
|
|
179
|
+
</ErrorBoundary>}
|
|
180
|
+
|
|
181
|
+
{!property && <ErrorBoundary>
|
|
182
|
+
<Typography variant="body2"
|
|
183
|
+
component="span"
|
|
184
|
+
color="disabled">
|
|
185
|
+
This field is defined as an additional field in code
|
|
186
|
+
</Typography>
|
|
187
|
+
</ErrorBoundary>}
|
|
188
|
+
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
{/*<div className="flex flex-row text-xs">*/}
|
|
192
|
+
{/* <Typography className="flex-grow pr-2"*/}
|
|
193
|
+
{/* variant="body2"*/}
|
|
194
|
+
{/* component="span"*/}
|
|
195
|
+
{/* color="secondary">*/}
|
|
196
|
+
{/* This field can only be edited in code*/}
|
|
197
|
+
{/* </Typography>*/}
|
|
198
|
+
{/*</div>*/}
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
</Paper>
|
|
202
|
+
</div>)
|
|
203
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropertyConfigBadge, PropertyConfig } from "@firecms/core";
|
|
2
|
+
import { cn, SelectItem, Typography } from "@firecms/ui";
|
|
3
|
+
|
|
4
|
+
export interface PropertySelectItemProps {
|
|
5
|
+
value: string;
|
|
6
|
+
optionDisabled: boolean;
|
|
7
|
+
propertyConfig: PropertyConfig;
|
|
8
|
+
existing: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps) {
|
|
12
|
+
return <SelectItem value={value}
|
|
13
|
+
disabled={optionDisabled}
|
|
14
|
+
className={"flex flex-row items-center"}>
|
|
15
|
+
<div
|
|
16
|
+
className={cn(
|
|
17
|
+
"flex flex-row items-center text-base min-h-[52px]",
|
|
18
|
+
optionDisabled ? "w-full" : "")}>
|
|
19
|
+
<div className={"mr-8"}>
|
|
20
|
+
<PropertyConfigBadge propertyConfig={propertyConfig}/>
|
|
21
|
+
</div>
|
|
22
|
+
<div>
|
|
23
|
+
<div>{propertyConfig.name}</div>
|
|
24
|
+
<Typography variant={"caption"}
|
|
25
|
+
color={"disabled"}
|
|
26
|
+
className={"max-w-sm"}>
|
|
27
|
+
{existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description}
|
|
28
|
+
</Typography>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</SelectItem>
|
|
32
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AdditionalFieldDelegate,
|
|
3
|
+
CMSType,
|
|
4
|
+
ErrorBoundary,
|
|
5
|
+
isPropertyBuilder,
|
|
6
|
+
PropertiesOrBuilders,
|
|
7
|
+
PropertyOrBuilder,
|
|
8
|
+
} from "@firecms/core";
|
|
9
|
+
import { AutoAwesomeIcon, defaultBorderMixin, DragHandleIcon, IconButton, RemoveIcon, Tooltip } from "@firecms/ui";
|
|
10
|
+
import { NonEditablePropertyPreview, PropertyFieldPreview } from "./PropertyFieldPreview";
|
|
11
|
+
import { DragDropContext, Draggable, DraggableProvided, Droppable } from "@hello-pangea/dnd";
|
|
12
|
+
import { getFullId, idToPropertiesPath } from "./util";
|
|
13
|
+
import { getIn } from "formik";
|
|
14
|
+
import { editableProperty } from "../../utils/entities";
|
|
15
|
+
import { useCallback } from "react";
|
|
16
|
+
|
|
17
|
+
export function PropertyTree<M extends {
|
|
18
|
+
[Key: string]: CMSType
|
|
19
|
+
}>({
|
|
20
|
+
namespace,
|
|
21
|
+
selectedPropertyKey,
|
|
22
|
+
onPropertyClick,
|
|
23
|
+
properties,
|
|
24
|
+
propertiesOrder: propertiesOrderProp,
|
|
25
|
+
additionalFields,
|
|
26
|
+
errors,
|
|
27
|
+
onPropertyMove,
|
|
28
|
+
onPropertyRemove,
|
|
29
|
+
className,
|
|
30
|
+
inferredPropertyKeys,
|
|
31
|
+
collectionEditable,
|
|
32
|
+
}: {
|
|
33
|
+
namespace?: string;
|
|
34
|
+
selectedPropertyKey?: string;
|
|
35
|
+
onPropertyClick?: (propertyKey: string, namespace?: string) => void;
|
|
36
|
+
properties: PropertiesOrBuilders<M>;
|
|
37
|
+
propertiesOrder?: string[];
|
|
38
|
+
additionalFields?: AdditionalFieldDelegate<M>[];
|
|
39
|
+
errors: Record<string, any>;
|
|
40
|
+
onPropertyMove?: (propertiesOrder: string[], namespace?: string) => void;
|
|
41
|
+
onPropertyRemove?: (propertyKey: string, namespace?: string) => void;
|
|
42
|
+
className?: string;
|
|
43
|
+
inferredPropertyKeys?: string[];
|
|
44
|
+
collectionEditable: boolean;
|
|
45
|
+
}) {
|
|
46
|
+
|
|
47
|
+
const propertiesOrder = propertiesOrderProp ?? Object.keys(properties);
|
|
48
|
+
|
|
49
|
+
const onDragEnd = useCallback((result: any) => {
|
|
50
|
+
// dropped outside the list
|
|
51
|
+
if (!result.destination) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const startIndex = result.source.index;
|
|
55
|
+
const endIndex = result.destination.index;
|
|
56
|
+
|
|
57
|
+
const newPropertiesOrder = Array.from(propertiesOrder);
|
|
58
|
+
const [removed] = newPropertiesOrder.splice(startIndex, 1);
|
|
59
|
+
newPropertiesOrder.splice(endIndex, 0, removed);
|
|
60
|
+
if (onPropertyMove)
|
|
61
|
+
onPropertyMove(newPropertiesOrder, namespace);
|
|
62
|
+
}, [namespace, onPropertyMove, propertiesOrder])
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
|
|
67
|
+
<DragDropContext onDragEnd={onDragEnd}>
|
|
68
|
+
<Droppable droppableId={`droppable_${namespace}`}>
|
|
69
|
+
{(droppableProvided, droppableSnapshot) => (
|
|
70
|
+
<div
|
|
71
|
+
{...droppableProvided.droppableProps}
|
|
72
|
+
ref={droppableProvided.innerRef}
|
|
73
|
+
className={className}>
|
|
74
|
+
{propertiesOrder && propertiesOrder
|
|
75
|
+
// .filter((propertyKey) => Boolean(properties[propertyKey]))
|
|
76
|
+
.map((propertyKey: string, index: number) => {
|
|
77
|
+
const property = properties[propertyKey] as PropertyOrBuilder;
|
|
78
|
+
const additionalField = additionalFields?.find(field => field.key === propertyKey);
|
|
79
|
+
|
|
80
|
+
if (!property && !additionalField) {
|
|
81
|
+
console.warn(`Property ${propertyKey} not found in properties or additionalFields`);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return (
|
|
85
|
+
<Draggable
|
|
86
|
+
key={`array_field_${namespace}_${propertyKey}}`}
|
|
87
|
+
draggableId={`array_field_${namespace}_${propertyKey}}`}
|
|
88
|
+
index={index}>
|
|
89
|
+
{(provided, snapshot) => {
|
|
90
|
+
return (
|
|
91
|
+
<ErrorBoundary>
|
|
92
|
+
<PropertyTreeEntry
|
|
93
|
+
propertyKey={propertyKey as string}
|
|
94
|
+
propertyOrBuilder={property}
|
|
95
|
+
additionalField={additionalField}
|
|
96
|
+
provided={provided}
|
|
97
|
+
errors={errors}
|
|
98
|
+
namespace={namespace}
|
|
99
|
+
inferredPropertyKeys={inferredPropertyKeys}
|
|
100
|
+
onPropertyMove={onPropertyMove}
|
|
101
|
+
onPropertyRemove={onPropertyRemove}
|
|
102
|
+
onPropertyClick={snapshot.isDragging ? undefined : onPropertyClick}
|
|
103
|
+
selectedPropertyKey={selectedPropertyKey}
|
|
104
|
+
collectionEditable={collectionEditable}
|
|
105
|
+
/>
|
|
106
|
+
</ErrorBoundary>
|
|
107
|
+
);
|
|
108
|
+
}}
|
|
109
|
+
</Draggable>);
|
|
110
|
+
}).filter(Boolean)}
|
|
111
|
+
|
|
112
|
+
{droppableProvided.placeholder}
|
|
113
|
+
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
</Droppable>
|
|
117
|
+
</DragDropContext>
|
|
118
|
+
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function PropertyTreeEntry({
|
|
124
|
+
propertyKey,
|
|
125
|
+
namespace,
|
|
126
|
+
propertyOrBuilder,
|
|
127
|
+
additionalField,
|
|
128
|
+
provided,
|
|
129
|
+
selectedPropertyKey,
|
|
130
|
+
errors,
|
|
131
|
+
onPropertyClick,
|
|
132
|
+
onPropertyMove,
|
|
133
|
+
onPropertyRemove,
|
|
134
|
+
inferredPropertyKeys,
|
|
135
|
+
collectionEditable,
|
|
136
|
+
}: {
|
|
137
|
+
propertyKey: string;
|
|
138
|
+
namespace?: string;
|
|
139
|
+
propertyOrBuilder: PropertyOrBuilder;
|
|
140
|
+
additionalField?: AdditionalFieldDelegate<any>;
|
|
141
|
+
selectedPropertyKey?: string;
|
|
142
|
+
provided: DraggableProvided;
|
|
143
|
+
errors: Record<string, any>;
|
|
144
|
+
onPropertyClick?: (propertyKey: string, namespace?: string) => void;
|
|
145
|
+
onPropertyMove?: (propertiesOrder: string[], namespace?: string) => void;
|
|
146
|
+
onPropertyRemove?: (propertyKey: string, namespace?: string) => void;
|
|
147
|
+
inferredPropertyKeys?: string[];
|
|
148
|
+
collectionEditable: boolean;
|
|
149
|
+
}) {
|
|
150
|
+
|
|
151
|
+
const isPropertyInferred = inferredPropertyKeys?.includes(namespace ? `${namespace}.${propertyKey}` : propertyKey);
|
|
152
|
+
|
|
153
|
+
const fullId = getFullId(propertyKey, namespace);
|
|
154
|
+
|
|
155
|
+
let subtree;
|
|
156
|
+
if (typeof propertyOrBuilder === "object") {
|
|
157
|
+
const property = propertyOrBuilder;
|
|
158
|
+
if (property.dataType === "map" && property.properties) {
|
|
159
|
+
subtree = <PropertyTree
|
|
160
|
+
selectedPropertyKey={selectedPropertyKey}
|
|
161
|
+
namespace={fullId}
|
|
162
|
+
properties={property.properties}
|
|
163
|
+
propertiesOrder={property.propertiesOrder}
|
|
164
|
+
errors={errors}
|
|
165
|
+
onPropertyClick={onPropertyClick}
|
|
166
|
+
onPropertyMove={onPropertyMove}
|
|
167
|
+
onPropertyRemove={onPropertyRemove}
|
|
168
|
+
collectionEditable={collectionEditable}
|
|
169
|
+
/>
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const hasError = fullId ? getIn(errors, idToPropertiesPath(fullId)) : false;
|
|
174
|
+
const selected = selectedPropertyKey === fullId;
|
|
175
|
+
const editable = propertyOrBuilder && ((collectionEditable && !isPropertyBuilder(propertyOrBuilder)) || editableProperty(propertyOrBuilder));
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<div
|
|
179
|
+
ref={provided.innerRef}
|
|
180
|
+
{...provided.draggableProps}
|
|
181
|
+
{...provided.dragHandleProps}
|
|
182
|
+
className="relative -ml-8"
|
|
183
|
+
>
|
|
184
|
+
{subtree && <div
|
|
185
|
+
className={"absolute border-l " + defaultBorderMixin}
|
|
186
|
+
style={{
|
|
187
|
+
left: "32px",
|
|
188
|
+
top: "64px",
|
|
189
|
+
bottom: "16px"
|
|
190
|
+
}}/>}
|
|
191
|
+
|
|
192
|
+
{!isPropertyBuilder(propertyOrBuilder) && !additionalField && editable
|
|
193
|
+
? <PropertyFieldPreview
|
|
194
|
+
property={propertyOrBuilder}
|
|
195
|
+
onClick={onPropertyClick ? () => onPropertyClick(propertyKey, namespace) : undefined}
|
|
196
|
+
includeName={true}
|
|
197
|
+
selected={selected}
|
|
198
|
+
hasError={hasError}/>
|
|
199
|
+
: <NonEditablePropertyPreview name={propertyKey}
|
|
200
|
+
property={propertyOrBuilder}
|
|
201
|
+
onClick={onPropertyClick ? () => onPropertyClick(propertyKey, namespace) : undefined}
|
|
202
|
+
selected={selected}/>}
|
|
203
|
+
|
|
204
|
+
<div className="absolute top-2 right-2 flex flex-row ">
|
|
205
|
+
|
|
206
|
+
{isPropertyInferred && <Tooltip title={"Inferred property"}>
|
|
207
|
+
<AutoAwesomeIcon size="small" className={"p-2"}/>
|
|
208
|
+
</Tooltip>}
|
|
209
|
+
|
|
210
|
+
{onPropertyRemove && <Tooltip title={"Remove"}>
|
|
211
|
+
<IconButton size="small"
|
|
212
|
+
color="inherit"
|
|
213
|
+
onClick={() => onPropertyRemove(propertyKey, namespace)}>
|
|
214
|
+
<RemoveIcon size={"small"}/>
|
|
215
|
+
</IconButton>
|
|
216
|
+
</Tooltip>}
|
|
217
|
+
|
|
218
|
+
{onPropertyMove && <Tooltip title={"Move"}>
|
|
219
|
+
<IconButton
|
|
220
|
+
component={"span"}
|
|
221
|
+
size="small"
|
|
222
|
+
>
|
|
223
|
+
<DragHandleIcon size={"small"}/>
|
|
224
|
+
</IconButton>
|
|
225
|
+
</Tooltip>}
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
{subtree && <div className={"ml-16"}>{subtree}</div>}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
}
|