@firecms/collection_editor 3.0.0-canary.8 → 3.0.0-canary.80
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 +1928 -1847
- 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 +4 -2
- package/dist/ui/CollectionViewHeaderAction.d.ts +3 -2
- package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
- package/dist/ui/PropertyAddColumnComponent.d.ts +3 -1
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +4 -3
- 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/useCollectionEditorPlugin.d.ts +6 -9
- package/dist/utils/collections.d.ts +6 -0
- package/package.json +19 -35
- package/src/ConfigControllerProvider.tsx +65 -62
- package/src/index.ts +1 -0
- package/src/types/collection_editor_controller.tsx +6 -4
- package/src/ui/CollectionViewHeaderAction.tsx +6 -3
- package/src/ui/EditorCollectionAction.tsx +9 -63
- package/src/ui/EditorCollectionActionStart.tsx +87 -0
- package/src/ui/HomePageEditorCollectionAction.tsx +16 -11
- package/src/ui/NewCollectionButton.tsx +12 -10
- package/src/ui/NewCollectionCard.tsx +3 -3
- package/src/ui/PropertyAddColumnComponent.tsx +6 -3
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +34 -4
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +56 -31
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +4 -4
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +27 -24
- package/src/ui/collection_editor/GetCodeDialog.tsx +15 -3
- package/src/ui/collection_editor/PropertyEditView.tsx +5 -4
- 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 +2 -2
- 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/EnumPropertyField.tsx +1 -1
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +5 -5
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
- package/src/useCollectionEditorPlugin.tsx +28 -27
- package/src/utils/collections.ts +30 -0
- package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
- package/src/ui/RootCollectionSuggestions.tsx +0 -63
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { EntityCollection, unslugify, } from "@firecms/core";
|
|
3
|
-
import { Button, Card, Chip, CircularProgress,
|
|
3
|
+
import { Button, Card, Chip, CircularProgress, cls, Container, Icon, Tooltip, Typography, } from "@firecms/ui";
|
|
4
4
|
|
|
5
5
|
import { productsCollectionTemplate } from "./templates/products_template";
|
|
6
6
|
import { blogCollectionTemplate } from "./templates/blog_template";
|
|
@@ -19,7 +19,7 @@ export function CollectionEditorWelcomeView({
|
|
|
19
19
|
path: string;
|
|
20
20
|
pathSuggestions?: (path: string) => Promise<string[]>;
|
|
21
21
|
parentCollection?: EntityCollection;
|
|
22
|
-
onContinue: (importData?: object[]) => void;
|
|
22
|
+
onContinue: (importData?: object[], propertiesOrder?: string[]) => void;
|
|
23
23
|
existingCollectionPaths?: string[];
|
|
24
24
|
}) {
|
|
25
25
|
|
|
@@ -154,7 +154,7 @@ export function CollectionEditorWelcomeView({
|
|
|
154
154
|
● Create a collection from a file (csv, json, xls, xslx...)
|
|
155
155
|
</Typography>
|
|
156
156
|
|
|
157
|
-
<ImportFileUpload onDataAdded={(data) => onContinue(data)}/>
|
|
157
|
+
<ImportFileUpload onDataAdded={(data, propertiesOrder) => onContinue(data, propertiesOrder)}/>
|
|
158
158
|
|
|
159
159
|
</div>}
|
|
160
160
|
|
|
@@ -188,7 +188,7 @@ export function TemplateButton({
|
|
|
188
188
|
<Tooltip title={subtitle}>
|
|
189
189
|
<Card
|
|
190
190
|
onClick={onClick}
|
|
191
|
-
className={
|
|
191
|
+
className={cls(
|
|
192
192
|
"my-2 rounded-md border mx-0 p-6 px-4 focus:outline-none transition ease-in-out duration-150 flex flex-row gap-4 items-center",
|
|
193
193
|
"text-gray-700 dark:text-slate-300",
|
|
194
194
|
"hover:border-primary-dark hover:text-primary-dark dark:hover:text-primary focus:ring-primary hover:ring-1 hover:ring-primary",
|
|
@@ -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(() => values.ownerId ? getUser(values.ownerId) : null, [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
|
}
|
|
@@ -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 })}>
|
|
@@ -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,13 +368,13 @@ 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
379
|
const onWidgetSelectChanged = (newSelectedWidgetId: PropertyConfigId) => {
|
|
379
380
|
setSelectedFieldConfigId(newSelectedWidgetId);
|
|
@@ -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"}>
|
|
@@ -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
|
|
|
@@ -135,7 +135,7 @@ export function SubcollectionsEditTab({
|
|
|
135
135
|
{totalEntityViews === 0 &&
|
|
136
136
|
<Alert action={<Button variant="text"
|
|
137
137
|
size={"small"}
|
|
138
|
-
href={"https://firecms.co/docs/
|
|
138
|
+
href={"https://firecms.co/docs/cloud/quickstart"}
|
|
139
139
|
component={"a"}
|
|
140
140
|
rel="noopener noreferrer"
|
|
141
141
|
target="_blank">More info</Button>}>
|
|
@@ -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 ?? undefined)}
|
|
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
|
<>
|
|
@@ -71,7 +71,7 @@ export function EnumPropertyField({
|
|
|
71
71
|
}}
|
|
72
72
|
getData={getData
|
|
73
73
|
? () => getData()
|
|
74
|
-
.then(res => res.map(
|
|
74
|
+
.then(res => res.map(entry => values.id && getIn(entry, values.id)).filter(Boolean))
|
|
75
75
|
: undefined}
|
|
76
76
|
onValuesChanged={onValuesChanged}/>
|
|
77
77
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { FieldCaption, MapProperty, Property, PropertyConfig, } from "@firecms/core";
|
|
3
3
|
import { AddIcon, BooleanSwitchWithLabel, Button, Paper, Typography } from "@firecms/ui";
|
|
4
4
|
import { PropertyFormDialog } from "../PropertyEditView";
|
|
@@ -42,7 +42,7 @@ export function MapPropertyField({ disabled, getData, allowDataInference, proper
|
|
|
42
42
|
setPropertyDialogOpen(false);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const deleteProperty =
|
|
45
|
+
const deleteProperty = (propertyKey?: string, namespace?: string) => {
|
|
46
46
|
const fullId = propertyKey ? getFullId(propertyKey, namespace) : undefined;
|
|
47
47
|
if (!fullId)
|
|
48
48
|
throw Error("collection editor miss config");
|
|
@@ -58,16 +58,16 @@ export function MapPropertyField({ disabled, getData, allowDataInference, proper
|
|
|
58
58
|
setPropertyDialogOpen(false);
|
|
59
59
|
setSelectedPropertyKey(undefined);
|
|
60
60
|
setSelectedPropertyNamespace(undefined);
|
|
61
|
-
}
|
|
61
|
+
};
|
|
62
62
|
|
|
63
63
|
const selectedPropertyFullId = selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : undefined;
|
|
64
64
|
const selectedProperty = selectedPropertyFullId ? getIn(values.properties, selectedPropertyFullId.replaceAll(".", ".properties.")) : undefined;
|
|
65
65
|
|
|
66
66
|
const empty = !propertiesOrder || propertiesOrder.length < 1;
|
|
67
67
|
|
|
68
|
-
const onPropertyMove =
|
|
68
|
+
const onPropertyMove = (propertiesOrder: string[], namespace?: string) => {
|
|
69
69
|
setFieldValue(namespaceToPropertiesOrderPath(namespace), propertiesOrder, false);
|
|
70
|
-
}
|
|
70
|
+
};
|
|
71
71
|
|
|
72
72
|
return (
|
|
73
73
|
<>
|
|
@@ -39,7 +39,6 @@ export function RepeatPropertyField({
|
|
|
39
39
|
|
|
40
40
|
const onPropertyChanged = ({ id, property, namespace }:
|
|
41
41
|
{ id?: string, property: Property, namespace?: string }) => {
|
|
42
|
-
console.log("onPropertyChanged", id, property, namespace);
|
|
43
42
|
setFieldValue("of", property);
|
|
44
43
|
};
|
|
45
44
|
|