@firecms/collection_editor 3.0.0-canary.7 → 3.0.0-canary.70
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 +113 -21
- package/dist/ConfigControllerProvider.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1944 -1890
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +1 -1
- package/dist/types/persisted_collection.d.ts +1 -1
- package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +2 -2
- package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
- package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
- package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
- package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
- package/dist/ui/collection_editor/utils/supported_fields.d.ts +2 -2
- package/dist/useCollectionEditorPlugin.d.ts +6 -9
- package/dist/utils/collections.d.ts +6 -0
- package/package.json +26 -26
- package/src/ConfigControllerProvider.tsx +53 -59
- package/src/index.ts +1 -0
- package/src/types/collection_editor_controller.tsx +1 -1
- package/src/types/persisted_collection.ts +1 -1
- package/src/ui/EditorCollectionAction.tsx +0 -51
- package/src/ui/EditorCollectionActionStart.tsx +87 -0
- package/src/ui/HomePageEditorCollectionAction.tsx +16 -11
- package/src/ui/MissingReferenceWidget.tsx +2 -1
- package/src/ui/NewCollectionButton.tsx +12 -10
- package/src/ui/NewCollectionCard.tsx +3 -3
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +51 -22
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +49 -32
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +5 -5
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +27 -24
- package/src/ui/collection_editor/EnumForm.tsx +3 -4
- package/src/ui/collection_editor/GetCodeDialog.tsx +15 -3
- package/src/ui/collection_editor/PropertyEditView.tsx +9 -8
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +3 -6
- package/src/ui/collection_editor/PropertySelectItem.tsx +2 -2
- package/src/ui/collection_editor/PropertyTree.tsx +3 -3
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +1 -1
- package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +25 -9
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +9 -7
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +14 -8
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +7 -8
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +7 -8
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +8 -9
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +3 -4
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +3 -4
- package/src/ui/collection_editor/utils/supported_fields.tsx +3 -3
- package/src/useCollectionEditorPlugin.tsx +29 -30
- package/src/utils/collections.ts +30 -0
- package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
- package/dist/ui/collection_editor/properties/FieldHelperView.d.ts +0 -4
- package/src/ui/RootCollectionSuggestions.tsx +0 -63
- package/src/ui/collection_editor/properties/FieldHelperView.tsx +0 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { Field, getIn, useFormex } from "@firecms/formex";
|
|
4
4
|
import {
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
AutoAwesomeIcon,
|
|
20
20
|
Button,
|
|
21
21
|
CircularProgress,
|
|
22
|
-
|
|
22
|
+
cls,
|
|
23
23
|
CodeIcon,
|
|
24
24
|
DebouncedTextField,
|
|
25
25
|
defaultBorderMixin,
|
|
@@ -43,7 +43,7 @@ type CollectionEditorFormProps = {
|
|
|
43
43
|
setDirty?: (dirty: boolean) => void;
|
|
44
44
|
reservedGroups?: string[];
|
|
45
45
|
extraIcon: React.ReactNode;
|
|
46
|
-
getUser
|
|
46
|
+
getUser?: (uid: string) => User | null;
|
|
47
47
|
getData?: () => Promise<object[]>;
|
|
48
48
|
doCollectionInference: (collection: PersistedCollection) => Promise<Partial<EntityCollection> | null> | undefined;
|
|
49
49
|
propertyConfigs: Record<string, PropertyConfig>;
|
|
@@ -158,20 +158,20 @@ export function CollectionPropertiesEditorForm({
|
|
|
158
158
|
}
|
|
159
159
|
: undefined;
|
|
160
160
|
|
|
161
|
-
const getCurrentPropertiesOrder =
|
|
162
|
-
if (!namespace) return currentPropertiesOrderRef.current[""];
|
|
161
|
+
const getCurrentPropertiesOrder = (namespace?: string) => {
|
|
162
|
+
if (!namespace) return currentPropertiesOrderRef.current[""] ?? getIn(values, namespaceToPropertiesOrderPath());
|
|
163
163
|
return currentPropertiesOrderRef.current[namespace] ?? getIn(values, namespaceToPropertiesOrderPath(namespace));
|
|
164
|
-
}
|
|
164
|
+
};
|
|
165
165
|
|
|
166
|
-
const updatePropertiesOrder =
|
|
166
|
+
const updatePropertiesOrder = (newPropertiesOrder: string[], namespace?: string) => {
|
|
167
167
|
const propertiesOrderPath = namespaceToPropertiesOrderPath(namespace);
|
|
168
168
|
|
|
169
169
|
setFieldValue(propertiesOrderPath, newPropertiesOrder, false);
|
|
170
170
|
currentPropertiesOrderRef.current[namespace ?? ""] = newPropertiesOrder;
|
|
171
171
|
|
|
172
|
-
}
|
|
172
|
+
};
|
|
173
173
|
|
|
174
|
-
const deleteProperty =
|
|
174
|
+
const deleteProperty = (propertyKey?: string, namespace?: string) => {
|
|
175
175
|
const fullId = propertyKey ? getFullId(propertyKey, namespace) : undefined;
|
|
176
176
|
if (!fullId)
|
|
177
177
|
throw Error("collection editor miss config");
|
|
@@ -179,15 +179,17 @@ export function CollectionPropertiesEditorForm({
|
|
|
179
179
|
setFieldValue(idToPropertiesPath(fullId), undefined, false);
|
|
180
180
|
|
|
181
181
|
const currentPropertiesOrder = getCurrentPropertiesOrder(namespace);
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
if (currentPropertiesOrder) {
|
|
183
|
+
const newPropertiesOrder = currentPropertiesOrder.filter((p) => p !== propertyKey);
|
|
184
|
+
updatePropertiesOrder(newPropertiesOrder, namespace);
|
|
185
|
+
}
|
|
184
186
|
|
|
185
187
|
setNewPropertyDialogOpen(false);
|
|
186
188
|
|
|
187
189
|
setSelectedPropertyIndex(undefined);
|
|
188
190
|
setSelectedPropertyKey(undefined);
|
|
189
191
|
setSelectedPropertyNamespace(undefined);
|
|
190
|
-
}
|
|
192
|
+
};
|
|
191
193
|
|
|
192
194
|
const onPropertyMove = (propertiesOrder: string[], namespace?: string) => {
|
|
193
195
|
setFieldValue(namespaceToPropertiesOrderPath(namespace), propertiesOrder, false);
|
|
@@ -207,8 +209,8 @@ export function CollectionPropertiesEditorForm({
|
|
|
207
209
|
...(values.properties ?? {}),
|
|
208
210
|
[id]: property
|
|
209
211
|
}, false);
|
|
210
|
-
const newPropertiesOrder = [...(values.propertiesOrder ?? Object.keys(values.properties)), id];
|
|
211
212
|
|
|
213
|
+
const newPropertiesOrder = [...(values.propertiesOrder ?? Object.keys(values.properties)), id];
|
|
212
214
|
updatePropertiesOrder(newPropertiesOrder);
|
|
213
215
|
|
|
214
216
|
setNewPropertyDialogOpen(false);
|
|
@@ -273,7 +275,7 @@ export function CollectionPropertiesEditorForm({
|
|
|
273
275
|
|
|
274
276
|
};
|
|
275
277
|
|
|
276
|
-
const onPropertyErrorInternal =
|
|
278
|
+
const onPropertyErrorInternal = (id: string, namespace?: string, error?: Record<string, any>) => {
|
|
277
279
|
const propertyPath = id ? getFullId(id, namespace) : undefined;
|
|
278
280
|
console.debug("onPropertyErrorInternal", {
|
|
279
281
|
id,
|
|
@@ -286,7 +288,7 @@ export function CollectionPropertiesEditorForm({
|
|
|
286
288
|
onPropertyError(id, namespace, hasError ? error : undefined);
|
|
287
289
|
setFieldError(idToPropertiesPath(propertyPath), hasError ? "Property error" : undefined);
|
|
288
290
|
}
|
|
289
|
-
}
|
|
291
|
+
}
|
|
290
292
|
|
|
291
293
|
const closePropertyDialog = () => {
|
|
292
294
|
setSelectedPropertyIndex(undefined);
|
|
@@ -301,9 +303,9 @@ export function CollectionPropertiesEditorForm({
|
|
|
301
303
|
? values.propertiesOrder
|
|
302
304
|
: Object.keys(values.properties)) as string[];
|
|
303
305
|
|
|
304
|
-
const owner = useMemo(() => getUser(values.ownerId), [getUser, values.ownerId]);
|
|
306
|
+
const owner = useMemo(() => values.ownerId && getUser ? getUser(values.ownerId) : null, [getUser, values.ownerId]);
|
|
305
307
|
|
|
306
|
-
const onPropertyClick =
|
|
308
|
+
const onPropertyClick = (propertyKey: string, namespace?: string) => {
|
|
307
309
|
console.debug("CollectionEditor: onPropertyClick", {
|
|
308
310
|
propertyKey,
|
|
309
311
|
namespace
|
|
@@ -311,11 +313,11 @@ export function CollectionPropertiesEditorForm({
|
|
|
311
313
|
setSelectedPropertyIndex(usedPropertiesOrder.indexOf(propertyKey));
|
|
312
314
|
setSelectedPropertyKey(propertyKey);
|
|
313
315
|
setSelectedPropertyNamespace(namespace);
|
|
314
|
-
}
|
|
316
|
+
};
|
|
315
317
|
|
|
316
318
|
const body = (
|
|
317
319
|
<div className={"grid grid-cols-12 gap-2 h-full bg-gray-50 dark:bg-gray-900"}>
|
|
318
|
-
<div className={
|
|
320
|
+
<div className={cls(
|
|
319
321
|
"p-4 md:p-8 pb-20 md:pb-20",
|
|
320
322
|
"col-span-12 lg:col-span-5 h-full overflow-auto",
|
|
321
323
|
!asDialog && "border-r " + defaultBorderMixin
|
|
@@ -496,11 +498,12 @@ export function CollectionPropertiesEditorForm({
|
|
|
496
498
|
collectionEditable={collectionEditable}
|
|
497
499
|
existingPropertyKeys={values.propertiesOrder as string[]}/>
|
|
498
500
|
|
|
499
|
-
<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
501
|
+
<ErrorBoundary>
|
|
502
|
+
<GetCodeDialog
|
|
503
|
+
collection={values}
|
|
504
|
+
open={codeDialogOpen}
|
|
505
|
+
onOpenChange={setCodeDialogOpen}/>
|
|
506
|
+
</ErrorBoundary>
|
|
504
507
|
</>
|
|
505
508
|
);
|
|
506
509
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
2
|
import equal from "react-fast-compare"
|
|
3
3
|
|
|
4
|
-
import { ArrayContainer, EnumValueConfig, EnumValues, } from "@firecms/core";
|
|
4
|
+
import { ArrayContainer, EnumValueConfig, EnumValues, FieldCaption, } from "@firecms/core";
|
|
5
5
|
import {
|
|
6
6
|
AutoAwesomeIcon,
|
|
7
7
|
Badge,
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
SettingsIcon,
|
|
18
18
|
Typography
|
|
19
19
|
} from "@firecms/ui";
|
|
20
|
-
import { FieldHelperView } from "./properties/FieldHelperView";
|
|
21
20
|
import { extractEnumFromValues } from "@firecms/schema_inference";
|
|
22
21
|
import { Field, Formex, getIn, useCreateFormex, useFormex } from "@firecms/formex";
|
|
23
22
|
|
|
@@ -337,9 +336,9 @@ function EnumEntryDialog({
|
|
|
337
336
|
autoComplete="off"
|
|
338
337
|
error={Boolean(idError)}/>
|
|
339
338
|
|
|
340
|
-
<
|
|
339
|
+
<FieldCaption error={Boolean(idError)}>
|
|
341
340
|
{idError ?? "Value saved in the data source"}
|
|
342
|
-
</
|
|
341
|
+
</FieldCaption>
|
|
343
342
|
</div>}
|
|
344
343
|
</DialogContent>
|
|
345
344
|
|
|
@@ -5,11 +5,17 @@ import JSON5 from "json5";
|
|
|
5
5
|
import { Highlight, themes } from "prism-react-renderer"
|
|
6
6
|
import { camelCase } from "./utils/strings";
|
|
7
7
|
|
|
8
|
-
export function GetCodeDialog({
|
|
8
|
+
export function GetCodeDialog({
|
|
9
|
+
collection,
|
|
10
|
+
onOpenChange,
|
|
11
|
+
open
|
|
12
|
+
}: { onOpenChange: (open: boolean) => void, collection: any, open: any }) {
|
|
9
13
|
|
|
10
14
|
const snackbarController = useSnackbarController();
|
|
11
15
|
|
|
12
|
-
const code =
|
|
16
|
+
const code = collection
|
|
17
|
+
? "import { EntityCollection } from \"firecms\";\n\nconst " + (collection?.name ? camelCase(collection.name) : "my") + "Collection:EntityCollection = " + JSON5.stringify(collectionToCode(collection), null, "\t")
|
|
18
|
+
: "No collection selected";
|
|
13
19
|
return <Dialog open={open}
|
|
14
20
|
onOpenChange={onOpenChange}
|
|
15
21
|
maxWidth={"4xl"}>
|
|
@@ -29,7 +35,13 @@ export function GetCodeDialog({ collection, onOpenChange, open }: { onOpenChange
|
|
|
29
35
|
code={code}
|
|
30
36
|
language="typescript"
|
|
31
37
|
>
|
|
32
|
-
{({
|
|
38
|
+
{({
|
|
39
|
+
className,
|
|
40
|
+
style,
|
|
41
|
+
tokens,
|
|
42
|
+
getLineProps,
|
|
43
|
+
getTokenProps
|
|
44
|
+
}) => (
|
|
33
45
|
<pre style={style} className={"p-4 rounded text-sm"}>
|
|
34
46
|
{tokens.map((line, i) => (
|
|
35
47
|
<div key={i} {...getLineProps({ line })}>
|
|
@@ -5,7 +5,7 @@ import { Formex, FormexController, getIn, useCreateFormex } from "@firecms/forme
|
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_FIELD_CONFIGS,
|
|
7
7
|
DeleteConfirmationDialog,
|
|
8
|
-
|
|
8
|
+
PropertyConfigId,
|
|
9
9
|
getFieldConfig,
|
|
10
10
|
getFieldId,
|
|
11
11
|
isPropertyBuilder,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "@firecms/core";
|
|
18
18
|
import {
|
|
19
19
|
Button,
|
|
20
|
-
|
|
20
|
+
cls,
|
|
21
21
|
DeleteIcon,
|
|
22
22
|
Dialog,
|
|
23
23
|
DialogActions,
|
|
@@ -228,6 +228,7 @@ export const PropertyForm = React.memo(
|
|
|
228
228
|
a.includeIdAndName === b.includeIdAndName &&
|
|
229
229
|
a.autoOpenTypeSelect === b.autoOpenTypeSelect &&
|
|
230
230
|
a.autoUpdateId === b.autoUpdateId &&
|
|
231
|
+
a.existingPropertyKeys === b.existingPropertyKeys &&
|
|
231
232
|
a.existingProperty === b.existingProperty
|
|
232
233
|
);
|
|
233
234
|
|
|
@@ -367,15 +368,15 @@ function PropertyEditFormFields({
|
|
|
367
368
|
}
|
|
368
369
|
}
|
|
369
370
|
}
|
|
370
|
-
}, [deferredValues, includeIdAndTitle,
|
|
371
|
+
}, [deferredValues, includeIdAndTitle, propertyNamespace]);
|
|
371
372
|
|
|
372
373
|
useEffect(() => {
|
|
373
374
|
if (values?.id && onError) {
|
|
374
375
|
onError(values?.id, propertyNamespace, errors);
|
|
375
376
|
}
|
|
376
|
-
}, [errors,
|
|
377
|
+
}, [errors, propertyNamespace, values?.id]);
|
|
377
378
|
|
|
378
|
-
const onWidgetSelectChanged = (newSelectedWidgetId:
|
|
379
|
+
const onWidgetSelectChanged = (newSelectedWidgetId: PropertyConfigId) => {
|
|
379
380
|
setSelectedFieldConfigId(newSelectedWidgetId);
|
|
380
381
|
setValues(updatePropertyFromWidget(values, newSelectedWidgetId, propertyConfigs));
|
|
381
382
|
// Ugly hack to autofocus the name field
|
|
@@ -495,7 +496,7 @@ function PropertyEditFormFields({
|
|
|
495
496
|
return <em>Select a property
|
|
496
497
|
widget</em>;
|
|
497
498
|
}
|
|
498
|
-
const key = value as
|
|
499
|
+
const key = value as PropertyConfigId;
|
|
499
500
|
const propertyConfig = DEFAULT_FIELD_CONFIGS[key] ?? propertyConfigs[key];
|
|
500
501
|
const baseProperty = propertyConfig.property;
|
|
501
502
|
const baseFieldConfig = baseProperty && !isPropertyBuilder(baseProperty) ? getFieldConfig(baseProperty, propertyConfigs) : undefined;
|
|
@@ -508,7 +509,7 @@ function PropertyEditFormFields({
|
|
|
508
509
|
e.preventDefault();
|
|
509
510
|
}
|
|
510
511
|
}}
|
|
511
|
-
className={
|
|
512
|
+
className={cls(
|
|
512
513
|
"flex items-center",
|
|
513
514
|
optionDisabled ? "w-full pointer-events-none opacity-50" : "")}>
|
|
514
515
|
<div className={"mr-8"}>
|
|
@@ -524,7 +525,7 @@ function PropertyEditFormFields({
|
|
|
524
525
|
</div>
|
|
525
526
|
}}
|
|
526
527
|
onValueChange={(value) => {
|
|
527
|
-
onWidgetSelectChanged(value as
|
|
528
|
+
onWidgetSelectChanged(value as PropertyConfigId);
|
|
528
529
|
}}>
|
|
529
530
|
{displayedWidgets.map(([key, propertyConfig]) => {
|
|
530
531
|
const baseProperty = propertyConfig.property;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
cardClickableMixin,
|
|
12
12
|
cardMixin,
|
|
13
13
|
cardSelectedMixin,
|
|
14
|
-
|
|
14
|
+
cls,
|
|
15
15
|
FunctionsIcon,
|
|
16
16
|
Paper,
|
|
17
17
|
RemoveCircleIcon,
|
|
@@ -45,9 +45,6 @@ export function PropertyFieldPreview({
|
|
|
45
45
|
? "border-red-500 dark:border-red-500 border-opacity-100 dark:border-opacity-100 ring-0 dark:ring-0"
|
|
46
46
|
: (selected ? "border-primary" : "border-transparent");
|
|
47
47
|
|
|
48
|
-
if(hasError)
|
|
49
|
-
console.log("PropertyFieldPreview", property)
|
|
50
|
-
|
|
51
48
|
return <ErrorBoundary>
|
|
52
49
|
<div
|
|
53
50
|
onClick={onClick}
|
|
@@ -56,7 +53,7 @@ export function PropertyFieldPreview({
|
|
|
56
53
|
<PropertyConfigBadge propertyConfig={propertyConfig}/>
|
|
57
54
|
</div>
|
|
58
55
|
<Paper
|
|
59
|
-
className={
|
|
56
|
+
className={cls(
|
|
60
57
|
"border",
|
|
61
58
|
"pl-2 w-full flex flex-row gap-4 items-center",
|
|
62
59
|
cardMixin,
|
|
@@ -139,7 +136,7 @@ export function NonEditablePropertyPreview({
|
|
|
139
136
|
<RemoveCircleIcon color={"disabled"} size={"small"} className={"absolute -right-2 -top-2"}/>
|
|
140
137
|
</div>
|
|
141
138
|
<Paper
|
|
142
|
-
className={
|
|
139
|
+
className={cls(
|
|
143
140
|
"pl-2 w-full flex flex-row gap-4 items-center",
|
|
144
141
|
cardMixin,
|
|
145
142
|
onClick ? cardClickableMixin : "",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropertyConfigBadge, PropertyConfig } from "@firecms/core";
|
|
2
|
-
import {
|
|
2
|
+
import { cls, SelectItem, Typography } from "@firecms/ui";
|
|
3
3
|
|
|
4
4
|
export interface PropertySelectItemProps {
|
|
5
5
|
value: string;
|
|
@@ -13,7 +13,7 @@ export function PropertySelectItem({ value, optionDisabled, propertyConfig, exis
|
|
|
13
13
|
disabled={optionDisabled}
|
|
14
14
|
className={"flex flex-row items-center"}>
|
|
15
15
|
<div
|
|
16
|
-
className={
|
|
16
|
+
className={cls(
|
|
17
17
|
"flex flex-row items-center text-base min-h-[52px]",
|
|
18
18
|
optionDisabled ? "w-full" : "")}>
|
|
19
19
|
<div className={"mr-8"}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import equal from "react-fast-compare"
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -48,7 +48,7 @@ export const PropertyTree = React.memo(
|
|
|
48
48
|
|
|
49
49
|
const propertiesOrder = propertiesOrderProp ?? Object.keys(properties);
|
|
50
50
|
|
|
51
|
-
const onDragEnd =
|
|
51
|
+
const onDragEnd = (result: any) => {
|
|
52
52
|
// dropped outside the list
|
|
53
53
|
if (!result.destination) {
|
|
54
54
|
return;
|
|
@@ -61,7 +61,7 @@ export const PropertyTree = React.memo(
|
|
|
61
61
|
newPropertiesOrder.splice(endIndex, 0, removed);
|
|
62
62
|
if (onPropertyMove)
|
|
63
63
|
onPropertyMove(newPropertiesOrder, namespace);
|
|
64
|
-
}
|
|
64
|
+
}
|
|
65
65
|
|
|
66
66
|
return (
|
|
67
67
|
<>
|
|
@@ -41,7 +41,7 @@ export function SubcollectionsEditTab({
|
|
|
41
41
|
parentCollection?: EntityCollection,
|
|
42
42
|
configController: CollectionsConfigController;
|
|
43
43
|
collectionInference?: CollectionInference;
|
|
44
|
-
getUser
|
|
44
|
+
getUser?: (uid: string) => User | null;
|
|
45
45
|
parentCollectionIds?: string[];
|
|
46
46
|
}) {
|
|
47
47
|
|
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
import { convertDataToEntity,
|
|
2
|
-
import { EntityCollectionTable, Properties, useSelectionController } from "@firecms/core";
|
|
3
|
-
import { useEffect } from "react";
|
|
1
|
+
import { convertDataToEntity, ImportConfig } from "@firecms/data_import_export";
|
|
2
|
+
import { CircularProgressCenter, EntityCollectionTable, Properties, useSelectionController } from "@firecms/core";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
4
|
import { Typography } from "@firecms/ui";
|
|
5
5
|
|
|
6
|
-
export function CollectionEditorImportDataPreview({
|
|
6
|
+
export function CollectionEditorImportDataPreview({
|
|
7
|
+
importConfig,
|
|
8
|
+
properties,
|
|
9
|
+
propertiesOrder
|
|
10
|
+
}: {
|
|
7
11
|
importConfig: ImportConfig,
|
|
8
12
|
properties: Properties,
|
|
9
13
|
propertiesOrder: string[]
|
|
10
14
|
}) {
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
17
|
+
|
|
18
|
+
async function loadEntities() {
|
|
19
|
+
// const propertiesMapping = getPropertiesMapping(importConfig.originProperties, properties, importConfig.headersMapping);
|
|
20
|
+
const mappedData = importConfig.importData.map(d => convertDataToEntity(d, importConfig.idColumn, importConfig.headersMapping, properties, "TEMP_PATH", importConfig.defaultValues));
|
|
15
21
|
importConfig.setEntities(mappedData);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
loadEntities().finally(() => setLoading(false));
|
|
16
26
|
}, []);
|
|
17
27
|
|
|
18
28
|
const selectionController = useSelectionController();
|
|
29
|
+
if (loading)
|
|
30
|
+
return <CircularProgressCenter/>
|
|
19
31
|
|
|
20
32
|
return <EntityCollectionTable
|
|
21
33
|
title={<div>
|
|
@@ -31,7 +43,11 @@ export function CollectionEditorImportDataPreview({ importConfig, properties, pr
|
|
|
31
43
|
filterable={false}
|
|
32
44
|
sortable={false}
|
|
33
45
|
selectionController={selectionController}
|
|
34
|
-
displayedColumnIds={propertiesOrder.map(p => ({
|
|
35
|
-
|
|
46
|
+
displayedColumnIds={propertiesOrder.map(p => ({
|
|
47
|
+
key: p,
|
|
48
|
+
disabled: false
|
|
49
|
+
}))}
|
|
50
|
+
properties={properties}
|
|
51
|
+
enablePopupIcon={false}/>
|
|
36
52
|
|
|
37
53
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "@firecms/data_import_export";
|
|
7
7
|
import { getIn, useFormex } from "@firecms/formex";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { getFieldConfig, getFieldId, Properties, Property, PropertyConfig, PropertyConfigBadge, } from "@firecms/core";
|
|
10
10
|
import { Container, Select, Tooltip, Typography } from "@firecms/ui";
|
|
11
11
|
import React, { useState } from "react";
|
|
12
12
|
import { OnPropertyChangedParams, PropertyFormDialog, PropertyWithId } from "../PropertyEditView";
|
|
@@ -143,18 +143,20 @@ export function CollectionEditorImportMapping({
|
|
|
143
143
|
<div className={"overflow-auto my-auto"}>
|
|
144
144
|
<Container maxWidth={"6xl"} className={"flex flex-col gap-4 p-8 m-auto"}>
|
|
145
145
|
|
|
146
|
-
<Typography variant="h6" className={"
|
|
146
|
+
<Typography variant="h6" className={"my-4 ml-3.5"}>Data property mapping</Typography>
|
|
147
147
|
|
|
148
|
-
<DataNewPropertiesMapping
|
|
149
|
-
idColumn={importConfig.idColumn}
|
|
150
|
-
originProperties={importConfig.originProperties}
|
|
148
|
+
<DataNewPropertiesMapping importConfig={importConfig}
|
|
151
149
|
destinationProperties={values.properties as Properties}
|
|
152
|
-
onIdPropertyChanged={(value) => importConfig.setIdColumn(value)}
|
|
153
150
|
buildPropertyView={({
|
|
154
151
|
property,
|
|
155
152
|
propertyKey,
|
|
156
|
-
importKey
|
|
153
|
+
importKey,
|
|
154
|
+
isIdColumn
|
|
157
155
|
}) => {
|
|
156
|
+
if (isIdColumn) {
|
|
157
|
+
return <Typography> This column will be used as ID</Typography>
|
|
158
|
+
}
|
|
159
|
+
|
|
158
160
|
return <ImportNewPropertyFieldPreview
|
|
159
161
|
property={property}
|
|
160
162
|
propertyKey={propertyKey}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { AddIcon, Button, Paper, Typography } from "@firecms/ui";
|
|
3
3
|
import { getIn, useFormex } from "@firecms/formex";
|
|
4
4
|
import { PropertyFormDialog } from "../PropertyEditView";
|
|
5
|
-
import { getFullId, idToPropertiesPath, namespaceToPropertiesOrderPath } from "../util";
|
|
5
|
+
import { getFullId, idToPropertiesPath, namespaceToPropertiesOrderPath, namespaceToPropertiesPath } from "../util";
|
|
6
6
|
import { PropertyTree } from "../PropertyTree";
|
|
7
7
|
import { ArrayProperty, Property, PropertyConfig } from "@firecms/core";
|
|
8
8
|
|
|
9
|
-
export function BlockPropertyField({
|
|
9
|
+
export function BlockPropertyField({
|
|
10
|
+
disabled,
|
|
11
|
+
getData,
|
|
12
|
+
allowDataInference,
|
|
13
|
+
propertyConfigs,
|
|
14
|
+
collectionEditable
|
|
15
|
+
}: {
|
|
10
16
|
disabled: boolean;
|
|
11
17
|
getData?: () => Promise<object[]>;
|
|
12
18
|
allowDataInference: boolean;
|
|
@@ -43,20 +49,20 @@ export function BlockPropertyField({ disabled, getData, allowDataInference, prop
|
|
|
43
49
|
const selectedPropertyFullId = selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : undefined;
|
|
44
50
|
const selectedProperty = selectedPropertyFullId ? getIn(values.oneOf?.properties, selectedPropertyFullId.replaceAll(".", ".properties.")) : undefined;
|
|
45
51
|
|
|
46
|
-
const deleteProperty =
|
|
52
|
+
const deleteProperty = (propertyKey?: string, namespace?: string) => {
|
|
47
53
|
const fullId = propertyKey ? getFullId(propertyKey, namespace) : undefined;
|
|
48
54
|
if (!fullId)
|
|
49
55
|
throw Error("collection editor miss config");
|
|
50
56
|
|
|
51
57
|
setFieldValue(`oneOf.${idToPropertiesPath(fullId)}`, undefined, false);
|
|
52
58
|
const propertiesOrderPath = `oneOf.${namespaceToPropertiesOrderPath(namespace)}`;
|
|
53
|
-
const currentPropertiesOrder: string[] = getIn(values, propertiesOrderPath);
|
|
59
|
+
const currentPropertiesOrder: string[] = getIn(values, propertiesOrderPath) ?? Object.keys(getIn(values, namespaceToPropertiesPath(namespace)));
|
|
54
60
|
setFieldValue(propertiesOrderPath, currentPropertiesOrder.filter((p) => p !== propertyKey), false);
|
|
55
61
|
|
|
56
62
|
setPropertyDialogOpen(false);
|
|
57
63
|
setSelectedPropertyKey(undefined);
|
|
58
64
|
setSelectedPropertyNamespace(undefined);
|
|
59
|
-
}
|
|
65
|
+
};
|
|
60
66
|
|
|
61
67
|
const addChildButton = <Button
|
|
62
68
|
autoFocus
|
|
@@ -68,9 +74,9 @@ export function BlockPropertyField({ disabled, getData, allowDataInference, prop
|
|
|
68
74
|
Add property to {values.name ?? "this block"}
|
|
69
75
|
</Button>;
|
|
70
76
|
|
|
71
|
-
const onPropertyMove =
|
|
77
|
+
const onPropertyMove = (propertiesOrder: string[], namespace?: string) => {
|
|
72
78
|
setFieldValue(`oneOf.${namespaceToPropertiesOrderPath(namespace)}`, propertiesOrder, false);
|
|
73
|
-
}
|
|
79
|
+
};
|
|
74
80
|
|
|
75
81
|
return (
|
|
76
82
|
<>
|
|
@@ -2,8 +2,7 @@ import { Field, getIn, useFormex } from "@firecms/formex";
|
|
|
2
2
|
import { DebouncedTextField } from "@firecms/ui";
|
|
3
3
|
import { PropertyWithId } from "../PropertyEditView";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import {
|
|
6
|
-
import { toSnakeCase, unslugify } from "@firecms/core";
|
|
5
|
+
import { FieldCaption, toSnakeCase, unslugify } from "@firecms/core";
|
|
7
6
|
|
|
8
7
|
type CommonPropertyFieldsProps = {
|
|
9
8
|
showErrors: boolean,
|
|
@@ -64,9 +63,9 @@ export const CommonPropertyFields = React.forwardRef<HTMLDivElement, CommonPrope
|
|
|
64
63
|
disabled={disabled}
|
|
65
64
|
error={Boolean(nameError)}/>
|
|
66
65
|
|
|
67
|
-
<
|
|
66
|
+
<FieldCaption error={Boolean(nameError)}>
|
|
68
67
|
{nameError}
|
|
69
|
-
</
|
|
68
|
+
</FieldCaption>
|
|
70
69
|
</div>
|
|
71
70
|
|
|
72
71
|
<div>
|
|
@@ -88,9 +87,9 @@ export const CommonPropertyFields = React.forwardRef<HTMLDivElement, CommonPrope
|
|
|
88
87
|
required
|
|
89
88
|
size="small"
|
|
90
89
|
error={Boolean(idError)}/>
|
|
91
|
-
<
|
|
90
|
+
<FieldCaption error={Boolean(idError)}>
|
|
92
91
|
{idError}
|
|
93
|
-
</
|
|
92
|
+
</FieldCaption>
|
|
94
93
|
</div>
|
|
95
94
|
|
|
96
95
|
<div>
|
|
@@ -99,9 +98,9 @@ export const CommonPropertyFields = React.forwardRef<HTMLDivElement, CommonPrope
|
|
|
99
98
|
label={"Description"}
|
|
100
99
|
disabled={disabled}
|
|
101
100
|
error={Boolean(descriptionError)}/>
|
|
102
|
-
<
|
|
101
|
+
<FieldCaption error={Boolean(descriptionError)}>
|
|
103
102
|
{descriptionError}
|
|
104
|
-
</
|
|
103
|
+
</FieldCaption>
|
|
105
104
|
</div>
|
|
106
105
|
|
|
107
106
|
</div>
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { getIn, useFormex } from "@firecms/formex";
|
|
3
|
-
import { NumberProperty, StringProperty } from "@firecms/core";
|
|
3
|
+
import { FieldCaption, NumberProperty, StringProperty } from "@firecms/core";
|
|
4
4
|
import { Select, SelectItem } from "@firecms/ui";
|
|
5
5
|
import { GeneralPropertyValidation } from "./validation/GeneralPropertyValidation";
|
|
6
6
|
import { ValidationPanel } from "./validation/ValidationPanel";
|
|
7
|
-
import { FieldHelperView } from "./FieldHelperView";
|
|
8
7
|
|
|
9
8
|
export function DateTimePropertyField({ disabled }: {
|
|
10
9
|
disabled: boolean;
|
|
@@ -47,14 +46,14 @@ export function DateTimePropertyField({ disabled }: {
|
|
|
47
46
|
<SelectItem value={"date_time"}> Date/Time </SelectItem>
|
|
48
47
|
<SelectItem value={"date"}> Date </SelectItem>
|
|
49
48
|
</Select>
|
|
50
|
-
<
|
|
49
|
+
<FieldCaption error={Boolean(modeError)}>
|
|
51
50
|
{modeError}
|
|
52
|
-
</
|
|
51
|
+
</FieldCaption>
|
|
53
52
|
|
|
54
53
|
<Select name={autoValuePath}
|
|
55
54
|
disabled={disabled}
|
|
56
55
|
value={autoValueValue ?? ""}
|
|
57
|
-
onValueChange={(v) => setFieldValue(autoValuePath, v)}
|
|
56
|
+
onValueChange={(v) => setFieldValue(autoValuePath, v === "none" ? null : v)}
|
|
58
57
|
renderValue={(v) => {
|
|
59
58
|
switch (v) {
|
|
60
59
|
case "on_create":
|
|
@@ -67,13 +66,13 @@ export function DateTimePropertyField({ disabled }: {
|
|
|
67
66
|
}}
|
|
68
67
|
error={Boolean(autoValueError)}
|
|
69
68
|
label={"Automatic value"}>
|
|
70
|
-
<SelectItem value={""}> None </SelectItem>
|
|
69
|
+
<SelectItem value={"none"}> None </SelectItem>
|
|
71
70
|
<SelectItem value={"on_create"}> On create </SelectItem>
|
|
72
71
|
<SelectItem value={"on_update"}> On any update </SelectItem>
|
|
73
72
|
</Select>
|
|
74
|
-
<
|
|
73
|
+
<FieldCaption error={Boolean(autoValueError)}>
|
|
75
74
|
{autoValueError ?? "Update this field automatically when creating or updating the entity"}
|
|
76
|
-
</
|
|
75
|
+
</FieldCaption>
|
|
77
76
|
|
|
78
77
|
</div>
|
|
79
78
|
|