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