@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.
Files changed (149) hide show
  1. package/LICENSE +114 -21
  2. package/dist/ConfigControllerProvider.d.ts +13 -3
  3. package/dist/index.d.ts +4 -2
  4. package/dist/index.es.js +5587 -4976
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +6829 -1
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +36 -8
  9. package/dist/types/collection_inference.d.ts +1 -1
  10. package/dist/types/config_controller.d.ts +33 -6
  11. package/dist/types/persisted_collection.d.ts +4 -2
  12. package/dist/ui/CollectionViewHeaderAction.d.ts +11 -0
  13. package/dist/{components → ui}/EditorCollectionAction.d.ts +1 -1
  14. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  15. package/dist/ui/MissingReferenceWidget.d.ts +3 -0
  16. package/dist/ui/NewCollectionButton.d.ts +1 -0
  17. package/dist/ui/PropertyAddColumnComponent.d.ts +8 -0
  18. package/dist/{components → ui}/collection_editor/CollectionDetailsForm.d.ts +3 -2
  19. package/dist/{components → ui}/collection_editor/CollectionEditorDialog.d.ts +15 -11
  20. package/dist/{components → ui}/collection_editor/CollectionEditorWelcomeView.d.ts +3 -3
  21. package/dist/{components → ui}/collection_editor/CollectionPropertiesEditorForm.d.ts +8 -6
  22. package/dist/{components → ui}/collection_editor/CollectionYupValidation.d.ts +3 -0
  23. package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  24. package/dist/{components → ui}/collection_editor/EnumForm.d.ts +1 -2
  25. package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
  26. package/dist/{components → ui}/collection_editor/PropertyEditView.d.ts +21 -11
  27. package/dist/{components → ui}/collection_editor/PropertyFieldPreview.d.ts +4 -3
  28. package/dist/{components → ui}/collection_editor/PropertyTree.d.ts +11 -7
  29. package/dist/{components → ui}/collection_editor/SubcollectionsEditTab.d.ts +3 -3
  30. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  31. package/dist/{components → ui}/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
  32. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +14 -0
  33. package/dist/{components → ui}/collection_editor/import/clean_import_data.d.ts +1 -1
  34. package/dist/{components → ui}/collection_editor/properties/BlockPropertyField.d.ts +4 -1
  35. package/dist/{components → ui}/collection_editor/properties/CommonPropertyFields.d.ts +1 -1
  36. package/dist/{components → ui}/collection_editor/properties/MapPropertyField.d.ts +4 -1
  37. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  38. package/dist/{components → ui}/collection_editor/properties/RepeatPropertyField.d.ts +4 -1
  39. package/dist/{components → ui}/collection_editor/properties/StringPropertyField.d.ts +1 -1
  40. package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
  41. package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
  42. package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
  43. package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
  44. package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
  45. package/dist/{components → ui}/collection_editor/util.d.ts +1 -0
  46. package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
  47. package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
  48. package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  49. package/dist/useCollectionEditorPlugin.d.ts +17 -6
  50. package/dist/utils/collections.d.ts +6 -0
  51. package/dist/utils/entities.d.ts +3 -4
  52. package/package.json +35 -37
  53. package/src/ConfigControllerProvider.tsx +350 -0
  54. package/src/index.ts +36 -0
  55. package/src/types/collection_editor_controller.tsx +53 -0
  56. package/src/types/collection_inference.ts +3 -0
  57. package/src/types/config_controller.tsx +60 -0
  58. package/src/types/config_permissions.ts +20 -0
  59. package/src/types/persisted_collection.ts +9 -0
  60. package/src/ui/CollectionViewHeaderAction.tsx +48 -0
  61. package/src/ui/EditorCollectionAction.tsx +56 -0
  62. package/src/ui/EditorCollectionActionStart.tsx +88 -0
  63. package/src/ui/HomePageEditorCollectionAction.tsx +89 -0
  64. package/src/ui/MissingReferenceWidget.tsx +37 -0
  65. package/src/ui/NewCollectionButton.tsx +18 -0
  66. package/src/ui/NewCollectionCard.tsx +48 -0
  67. package/src/ui/PropertyAddColumnComponent.tsx +47 -0
  68. package/src/ui/collection_editor/CollectionDetailsForm.tsx +426 -0
  69. package/src/ui/collection_editor/CollectionEditorDialog.tsx +826 -0
  70. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +214 -0
  71. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +513 -0
  72. package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
  73. package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
  74. package/src/ui/collection_editor/EnumForm.tsx +357 -0
  75. package/src/ui/collection_editor/GetCodeDialog.tsx +122 -0
  76. package/src/ui/collection_editor/PropertyEditView.tsx +789 -0
  77. package/src/ui/collection_editor/PropertyFieldPreview.tsx +204 -0
  78. package/src/ui/collection_editor/PropertyTree.tsx +254 -0
  79. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +269 -0
  80. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  81. package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
  82. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +53 -0
  83. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +299 -0
  84. package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
  85. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +144 -0
  86. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +40 -0
  87. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +110 -0
  88. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +89 -0
  89. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +114 -0
  90. package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  91. package/src/ui/collection_editor/properties/MapPropertyField.tsx +150 -0
  92. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  93. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
  94. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +160 -0
  95. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +108 -0
  96. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +215 -0
  97. package/src/ui/collection_editor/properties/StringPropertyField.tsx +70 -0
  98. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
  99. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +45 -0
  100. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
  101. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +61 -0
  102. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +115 -0
  103. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +150 -0
  104. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
  105. package/src/ui/collection_editor/templates/blog_template.ts +115 -0
  106. package/src/ui/collection_editor/templates/pages_template.ts +183 -0
  107. package/src/ui/collection_editor/templates/products_template.ts +88 -0
  108. package/src/ui/collection_editor/templates/users_template.ts +42 -0
  109. package/src/ui/collection_editor/util.ts +28 -0
  110. package/src/ui/collection_editor/utils/strings.ts +9 -0
  111. package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
  112. package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
  113. package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
  114. package/src/useCollectionEditorController.tsx +9 -0
  115. package/src/useCollectionEditorPlugin.tsx +164 -0
  116. package/src/useCollectionsConfigController.tsx +9 -0
  117. package/src/utils/arrays.ts +3 -0
  118. package/src/utils/collections.ts +30 -0
  119. package/src/utils/entities.ts +38 -0
  120. package/src/vite-env.d.ts +1 -0
  121. package/dist/components/collection_editor/PropertySelectItem.d.ts +0 -8
  122. package/dist/components/collection_editor/SelectIcons.d.ts +0 -6
  123. package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +0 -4
  124. package/dist/components/collection_editor/properties/FieldHelperView.d.ts +0 -4
  125. package/dist/components/collection_editor/templates/blog_template.d.ts +0 -10
  126. package/dist/components/collection_editor/templates/products_template.d.ts +0 -12
  127. package/dist/components/collection_editor/templates/users_template.d.ts +0 -7
  128. package/dist/components/collection_editor/utils/supported_fields.d.ts +0 -3
  129. package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +0 -3
  130. package/dist/types/editable_properties.d.ts +0 -10
  131. package/dist/utils/icons.d.ts +0 -2
  132. package/dist/utils/synonyms.d.ts +0 -1951
  133. /package/dist/{components → ui}/HomePageEditorCollectionAction.d.ts +0 -0
  134. /package/dist/{components → ui}/NewCollectionCard.d.ts +0 -0
  135. /package/dist/{components → ui}/collection_editor/UnsavedChangesDialog.d.ts +0 -0
  136. /package/dist/{components → ui}/collection_editor/properties/BooleanPropertyField.d.ts +0 -0
  137. /package/dist/{components → ui}/collection_editor/properties/DateTimePropertyField.d.ts +0 -0
  138. /package/dist/{components → ui}/collection_editor/properties/EnumPropertyField.d.ts +0 -0
  139. /package/dist/{components → ui}/collection_editor/properties/KeyValuePropertyField.d.ts +0 -0
  140. /package/dist/{components → ui}/collection_editor/properties/NumberPropertyField.d.ts +0 -0
  141. /package/dist/{components → ui}/collection_editor/properties/ReferencePropertyField.d.ts +0 -0
  142. /package/dist/{components → ui}/collection_editor/properties/StoragePropertyField.d.ts +0 -0
  143. /package/dist/{components → ui}/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +0 -0
  144. /package/dist/{components → ui}/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +0 -0
  145. /package/dist/{components → ui}/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +0 -0
  146. /package/dist/{components → ui}/collection_editor/properties/validation/NumberPropertyValidation.d.ts +0 -0
  147. /package/dist/{components → ui}/collection_editor/properties/validation/StringPropertyValidation.d.ts +0 -0
  148. /package/dist/{components → ui}/collection_editor/properties/validation/ValidationPanel.d.ts +0 -0
  149. /package/dist/{components → ui}/collection_editor/utils/useTraceUpdate.d.ts +0 -0
@@ -0,0 +1,269 @@
1
+ import React from "react";
2
+ import {
3
+ ConfirmationDialog,
4
+ EntityCollection,
5
+ EntityCustomView,
6
+ resolveEntityView,
7
+ useCustomizationController,
8
+ User
9
+ } from "@firecms/core";
10
+ import {
11
+ AddIcon,
12
+ Alert,
13
+ Button,
14
+ Container,
15
+ DeleteIcon,
16
+ IconButton,
17
+ Paper,
18
+ Table,
19
+ TableBody,
20
+ TableCell,
21
+ TableRow,
22
+ Tooltip,
23
+ Typography,
24
+ } from "@firecms/ui";
25
+ import { CollectionEditorDialog } from "./CollectionEditorDialog";
26
+ import { CollectionsConfigController } from "../../types/config_controller";
27
+ import { PersistedCollection } from "../../types/persisted_collection";
28
+ import { CollectionInference } from "../../types/collection_inference";
29
+ import { EntityCustomViewsSelectDialog } from "./EntityCustomViewsSelectDialog";
30
+ import { useFormex } from "@firecms/formex";
31
+
32
+ export function SubcollectionsEditTab({
33
+ collection,
34
+ parentCollection,
35
+ configController,
36
+ collectionInference,
37
+ getUser,
38
+ parentCollectionIds
39
+ }: {
40
+ collection: PersistedCollection,
41
+ parentCollection?: EntityCollection,
42
+ configController: CollectionsConfigController;
43
+ collectionInference?: CollectionInference;
44
+ getUser?: (uid: string) => User | null;
45
+ parentCollectionIds?: string[];
46
+ }) {
47
+
48
+ const { entityViews: contextEntityViews } = useCustomizationController();
49
+
50
+ const [subcollectionToDelete, setSubcollectionToDelete] = React.useState<string | undefined>();
51
+ const [addEntityViewDialogOpen, setAddEntityViewDialogOpen] = React.useState<boolean>(false);
52
+ const [viewToDelete, setViewToDelete] = React.useState<string | undefined>();
53
+
54
+ const [currentDialog, setCurrentDialog] = React.useState<{
55
+ isNewCollection: boolean,
56
+ editedCollectionId?: string,
57
+ }>();
58
+
59
+ const {
60
+ values,
61
+ setFieldValue,
62
+ } = useFormex<EntityCollection>();
63
+
64
+ const [subcollections, setSubcollections] = React.useState<EntityCollection[]>(collection.subcollections ?? []);
65
+ const resolvedEntityViews = values.entityViews?.filter(e => typeof e === "string")
66
+ .map(e => resolveEntityView(e, contextEntityViews))
67
+ .filter(Boolean) as EntityCustomView[] ?? [];
68
+ const hardCodedEntityViews = collection.entityViews?.filter(e => typeof e !== "string") as EntityCustomView[] ?? [];
69
+ const totalEntityViews = resolvedEntityViews.length + hardCodedEntityViews.length;
70
+
71
+ return (
72
+ <div className={"overflow-auto my-auto"}>
73
+ <Container maxWidth={"2xl"} className={"flex flex-col gap-4 p-8 m-auto"}>
74
+ <div className={"flex flex-col gap-16"}>
75
+
76
+ <div className={"flex-grow flex flex-col gap-4 items-start"}>
77
+ <Typography variant={"h5"}>
78
+ Subcollections of {values.name}
79
+ </Typography>
80
+
81
+ <Paper className={"flex flex-col gap-4 p-2 w-full"}>
82
+ {subcollections && subcollections.length > 0 && <Table>
83
+ <TableBody>
84
+ {subcollections.map((subcollection) => (
85
+ <TableRow key={subcollection.path}
86
+ onClick={() => setCurrentDialog({
87
+ isNewCollection: false,
88
+ editedCollectionId: subcollection.id
89
+ })}>
90
+ <TableCell
91
+ align="left">
92
+ <Typography variant={"subtitle2"} className={"flex-grow"}>
93
+ {subcollection.name}
94
+ </Typography>
95
+ </TableCell>
96
+ <TableCell
97
+ align="right">
98
+ <Tooltip title={"Remove"}
99
+ asChild={true}>
100
+ <IconButton size="small"
101
+ onClick={(e) => {
102
+ e.preventDefault();
103
+ e.stopPropagation();
104
+ setSubcollectionToDelete(subcollection.id);
105
+ }}
106
+ color="inherit">
107
+ <DeleteIcon size={"small"}/>
108
+ </IconButton>
109
+ </Tooltip>
110
+ </TableCell>
111
+ </TableRow>
112
+ ))}
113
+ </TableBody>
114
+ </Table>}
115
+
116
+ <Button
117
+ onClick={() => {
118
+ setCurrentDialog({
119
+ isNewCollection: true
120
+ });
121
+ }}
122
+ variant={"text"}
123
+ startIcon={<AddIcon/>}>
124
+ Add subcollection
125
+ </Button>
126
+
127
+ </Paper>
128
+
129
+ </div>
130
+
131
+ <div className={"flex-grow flex flex-col gap-4 items-start"}>
132
+ <Typography variant={"h5"}>
133
+ Custom views
134
+ </Typography>
135
+
136
+ {totalEntityViews === 0 &&
137
+ <Alert action={<Button variant="text"
138
+ size={"small"}
139
+ href={"https://firecms.co/docs/cloud/quickstart"}
140
+ component={"a"}
141
+ rel="noopener noreferrer"
142
+ target="_blank">More info</Button>}>
143
+ Define your own custom views by uploading them with the CLI.
144
+ </Alert>
145
+ }
146
+
147
+ {<>
148
+ <Paper className={"flex flex-col gap-4 p-2 w-full"}>
149
+ <Table>
150
+ <TableBody>
151
+ {resolvedEntityViews.map((view) => (
152
+ <TableRow key={view.key}>
153
+ <TableCell
154
+ align="left">
155
+ <Typography variant={"subtitle2"} className={"flex-grow"}>
156
+ {view.name}
157
+ </Typography>
158
+ </TableCell>
159
+ <TableCell
160
+ align="right">
161
+ <Tooltip title={"Remove"}
162
+ asChild={true}>
163
+ <IconButton size="small"
164
+ onClick={(e) => {
165
+ e.preventDefault();
166
+ e.stopPropagation();
167
+ setViewToDelete(view.key);
168
+ }}
169
+ color="inherit">
170
+ <DeleteIcon size={"small"}/>
171
+ </IconButton>
172
+ </Tooltip>
173
+ </TableCell>
174
+ </TableRow>
175
+ ))}
176
+ {hardCodedEntityViews.map((view) => (
177
+ <TableRow key={view.key}>
178
+ <TableCell
179
+ align="left">
180
+ <Typography variant={"subtitle2"} className={"flex-grow"}>
181
+ {view.name}
182
+ </Typography>
183
+ <Typography variant={"caption"} className={"flex-grow"}>
184
+ This view is defined in code with
185
+ key <code>{view.key}</code>
186
+ </Typography>
187
+ </TableCell>
188
+ </TableRow>
189
+ ))}
190
+ </TableBody>
191
+ </Table>
192
+
193
+ <Button
194
+ onClick={() => {
195
+ setAddEntityViewDialogOpen(true);
196
+ }}
197
+ variant={"text"}
198
+ startIcon={<AddIcon/>}>
199
+ Add custom entity view
200
+ </Button>
201
+ </Paper>
202
+
203
+ </>}
204
+
205
+
206
+ </div>
207
+
208
+ </div>
209
+ </Container>
210
+
211
+ <div style={{ height: "52px" }}/>
212
+
213
+ {subcollectionToDelete &&
214
+ <ConfirmationDialog open={Boolean(subcollectionToDelete)}
215
+ onAccept={() => {
216
+ const props = {
217
+ id: subcollectionToDelete,
218
+ parentCollectionIds: [...(parentCollectionIds ?? []), collection.id]
219
+ };
220
+ console.debug("Deleting subcollection", props)
221
+ configController.deleteCollection(props).then(() => {
222
+ setSubcollectionToDelete(undefined);
223
+ setSubcollections(subcollections?.filter(e => e.id !== subcollectionToDelete))
224
+ });
225
+ }}
226
+ onCancel={() => setSubcollectionToDelete(undefined)}
227
+ title={<>Delete this subcollection?</>}
228
+ body={<> This will <b>not
229
+ delete any data</b>, only
230
+ the collection in the CMS</>}/>}
231
+ {viewToDelete &&
232
+ <ConfirmationDialog open={Boolean(viewToDelete)}
233
+ onAccept={() => {
234
+ setFieldValue("entityViews", values.entityViews?.filter(e => e !== viewToDelete));
235
+ setViewToDelete(undefined);
236
+ }}
237
+ onCancel={() => setViewToDelete(undefined)}
238
+ title={<>Remove this view?</>}
239
+ body={<>This will <b>not
240
+ delete any data</b>, only
241
+ the view in the CMS</>}/>}
242
+
243
+ <CollectionEditorDialog
244
+ open={Boolean(currentDialog)}
245
+ configController={configController}
246
+ parentCollection={collection}
247
+ collectionInference={collectionInference}
248
+ parentCollectionIds={[...parentCollectionIds ?? [], values.id]}
249
+ isNewCollection={false}
250
+ {...currentDialog}
251
+ getUser={getUser}
252
+ handleClose={(updatedCollection) => {
253
+ if (updatedCollection && !subcollections.map(e => e.id).includes(updatedCollection.id)) {
254
+ setSubcollections([...subcollections, updatedCollection]);
255
+ }
256
+ setCurrentDialog(undefined);
257
+ }}/>
258
+
259
+ <EntityCustomViewsSelectDialog
260
+ open={addEntityViewDialogOpen}
261
+ onClose={(selectedViewKey) => {
262
+ if (selectedViewKey) {
263
+ setFieldValue("entityViews", [...(values.entityViews ?? []), selectedViewKey]);
264
+ }
265
+ setAddEntityViewDialogOpen(false);
266
+ }}/>
267
+ </div>
268
+ );
269
+ }
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+
3
+ import { BooleanSwitchWithLabel, Tooltip } from "@firecms/ui";
4
+ import { FormexFieldProps } from "@firecms/formex";
5
+
6
+ export function SwitchControl({
7
+ field,
8
+ form,
9
+ label,
10
+ tooltip,
11
+ disabled,
12
+ size = "small",
13
+ allowIndeterminate
14
+ }: FormexFieldProps & {
15
+ label: string,
16
+ tooltip?: string,
17
+ disabled?: boolean,
18
+ size?: "small" | "medium",
19
+ allowIndeterminate?: boolean
20
+ }) {
21
+
22
+ const formControlLabel = <BooleanSwitchWithLabel
23
+ label={label}
24
+ size={size}
25
+ position={"start"}
26
+ value={field.value}
27
+ disabled={disabled}
28
+ allowIndeterminate={allowIndeterminate}
29
+ onValueChange={(checked:boolean | null) => form.setFieldValue(field.name, checked)}/>;
30
+
31
+ if (tooltip)
32
+ return (
33
+ <Tooltip
34
+ title={tooltip}>
35
+ {formControlLabel}
36
+ </Tooltip>
37
+ );
38
+ return formControlLabel;
39
+ }
@@ -0,0 +1,47 @@
1
+ import React from "react";
2
+ import { Button, Dialog, DialogActions, DialogContent, Typography } from "@firecms/ui";
3
+
4
+ export interface UnsavedChangesDialogProps {
5
+ open: boolean;
6
+ body?: React.ReactNode;
7
+ title?: string;
8
+ handleOk: () => void;
9
+ handleCancel: () => void;
10
+ }
11
+
12
+ export function UnsavedChangesDialog({
13
+ open,
14
+ handleOk,
15
+ handleCancel,
16
+ body,
17
+ title
18
+ }: UnsavedChangesDialogProps) {
19
+
20
+ return (
21
+ <Dialog
22
+ open={open}
23
+ onOpenChange={(open) => open ? handleCancel() : handleOk()}
24
+ aria-labelledby="alert-dialog-title"
25
+ aria-describedby="alert-dialog-description"
26
+ >
27
+ <DialogContent>
28
+ <Typography variant={"h6"}>
29
+ {title ?? "Unsaved changes"}
30
+ </Typography>
31
+
32
+ {body && <Typography>
33
+ {body}
34
+ </Typography>}
35
+ <Typography>
36
+ Are you sure?
37
+ </Typography>
38
+
39
+ </DialogContent>
40
+
41
+ <DialogActions>
42
+ <Button variant="text" onClick={handleCancel} autoFocus> Cancel </Button>
43
+ <Button onClick={handleOk}> Ok </Button>
44
+ </DialogActions>
45
+ </Dialog>
46
+ );
47
+ }
@@ -0,0 +1,53 @@
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
+ import { Typography } from "@firecms/ui";
5
+
6
+ export function CollectionEditorImportDataPreview({
7
+ importConfig,
8
+ properties,
9
+ propertiesOrder
10
+ }: {
11
+ importConfig: ImportConfig,
12
+ properties: Properties,
13
+ propertiesOrder: string[]
14
+ }) {
15
+
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));
21
+ importConfig.setEntities(mappedData);
22
+ }
23
+
24
+ useEffect(() => {
25
+ loadEntities().finally(() => setLoading(false));
26
+ }, []);
27
+
28
+ const selectionController = useSelectionController();
29
+ if (loading)
30
+ return <CircularProgressCenter/>
31
+
32
+ return <EntityCollectionTable
33
+ title={<div>
34
+ <Typography variant={"subtitle2"}>Imported data preview</Typography>
35
+ <Typography variant={"caption"}>Entities with the same id will be overwritten</Typography>
36
+ </div>}
37
+ tableController={{
38
+ data: importConfig.entities,
39
+ dataLoading: false,
40
+ noMoreToLoad: false
41
+ }}
42
+ endAdornment={<div className={"h-12"}/>}
43
+ filterable={false}
44
+ sortable={false}
45
+ selectionController={selectionController}
46
+ displayedColumnIds={propertiesOrder.map(p => ({
47
+ key: p,
48
+ disabled: false
49
+ }))}
50
+ properties={properties}
51
+ enablePopupIcon={false}/>
52
+
53
+ }