@firecms/data_import_export 3.0.0-alpha.63 → 3.0.0-alpha.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +53 -52
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/components/DataNewPropertiesMapping.tsx +2 -3
- package/src/components/ImportFileUpload.tsx +1 -1
- package/src/components/ImportNewPropertyFieldPreview.tsx +5 -3
- package/src/components/ImportSaveInProgress.tsx +2 -10
- package/src/export_import/ExportCollectionAction.tsx +13 -11
- package/src/export_import/ImportCollectionAction.tsx +15 -13
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import w, { useState as T, useRef as Ne, useEffect as le, useCallback as b, useMemo as Ie } from "react";
|
|
2
2
|
import { jsxs as p, Fragment as P, jsx as s } from "react/jsx-runtime";
|
|
3
|
-
import { getPropertyInPath as M, EntityReference as ce,
|
|
3
|
+
import { getPropertyInPath as M, EntityReference as ce, useFireCMSContext as G, getFieldConfig as de, ErrorBoundary as Oe, FieldConfigBadge as pe, useDataSource as fe, useSnackbarController as Ae, resolveCollection as me, getPropertiesWithPropertiesOrder as Ee, useSelectionController as Te, EntityCollectionTable as je, getArrayValuesCount as Fe, getValueInPath as ke, useNavigationController as Pe } from "@firecms/core";
|
|
4
|
+
import { Table as Me, TableHeader as $e, TableCell as k, TableBody as _e, TableRow as Be, Typography as h, ChevronRightIcon as Le, Select as ue, SelectItem as H, FileUpload as Re, UploadIcon as He, TextField as Je, IconButton as K, EditIcon as Ue, CenteredView as Ve, CircularProgress as he, Tooltip as ee, FileUploadIcon as We, Dialog as ge, DialogContent as ye, DialogActions as be, Button as j, cn as R, defaultBorderMixin as ze, GetAppIcon as Ge, Alert as Xe, focusedMixin as V, BooleanSwitchWithLabel as qe } from "@firecms/ui";
|
|
4
5
|
import { buildEntityPropertiesFromData as Qe } from "@firecms/schema_inference";
|
|
5
6
|
import * as ae from "xlsx";
|
|
6
7
|
const Ye = () => {
|
|
@@ -198,18 +199,18 @@ function nt({
|
|
|
198
199
|
onChange: a
|
|
199
200
|
}
|
|
200
201
|
),
|
|
201
|
-
/* @__PURE__ */ p(
|
|
202
|
+
/* @__PURE__ */ p(Me, { style: {
|
|
202
203
|
tableLayout: "fixed"
|
|
203
204
|
}, children: [
|
|
204
|
-
/* @__PURE__ */ p(
|
|
205
|
+
/* @__PURE__ */ p($e, { children: [
|
|
205
206
|
/* @__PURE__ */ s(k, { header: !0, style: { width: "20%" }, children: "Column in file" }),
|
|
206
207
|
/* @__PURE__ */ s(k, { header: !0 }),
|
|
207
208
|
/* @__PURE__ */ s(k, { header: !0, style: { width: "75%" }, children: "Property" })
|
|
208
209
|
] }),
|
|
209
|
-
/* @__PURE__ */ s(
|
|
210
|
+
/* @__PURE__ */ s(_e, { children: t && Object.entries(r).map(
|
|
210
211
|
([o, l]) => {
|
|
211
212
|
const d = r[o], c = l ? M(t, l) : null, f = M(n, o), m = f ? f.dataType === "array" && typeof f.of == "object" ? `${f.dataType} - ${f.of.dataType}` : f.dataType : void 0;
|
|
212
|
-
return /* @__PURE__ */ p(
|
|
213
|
+
return /* @__PURE__ */ p(Be, { style: { height: "90px" }, children: [
|
|
213
214
|
/* @__PURE__ */ p(k, { style: { width: "20%" }, children: [
|
|
214
215
|
/* @__PURE__ */ s(h, { variant: "body2", children: o }),
|
|
215
216
|
f && /* @__PURE__ */ s(
|
|
@@ -221,7 +222,7 @@ function nt({
|
|
|
221
222
|
}
|
|
222
223
|
)
|
|
223
224
|
] }),
|
|
224
|
-
/* @__PURE__ */ s(k, { children: /* @__PURE__ */ s(
|
|
225
|
+
/* @__PURE__ */ s(k, { children: /* @__PURE__ */ s(Le, {}) }),
|
|
225
226
|
/* @__PURE__ */ s(
|
|
226
227
|
k,
|
|
227
228
|
{
|
|
@@ -247,7 +248,7 @@ function at({
|
|
|
247
248
|
onChange: n
|
|
248
249
|
}) {
|
|
249
250
|
return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ p(
|
|
250
|
-
|
|
251
|
+
ue,
|
|
251
252
|
{
|
|
252
253
|
size: "small",
|
|
253
254
|
value: e ?? "",
|
|
@@ -265,7 +266,7 @@ function at({
|
|
|
265
266
|
}
|
|
266
267
|
function it({ onDataAdded: e }) {
|
|
267
268
|
return /* @__PURE__ */ s(
|
|
268
|
-
|
|
269
|
+
Re,
|
|
269
270
|
{
|
|
270
271
|
accept: {
|
|
271
272
|
"text/*": [".csv", ".xls", ".xlsx"],
|
|
@@ -281,7 +282,7 @@ function it({ onDataAdded: e }) {
|
|
|
281
282
|
size: "small",
|
|
282
283
|
maxFiles: 1,
|
|
283
284
|
uploadDescription: /* @__PURE__ */ p(P, { children: [
|
|
284
|
-
/* @__PURE__ */ s(
|
|
285
|
+
/* @__PURE__ */ s(He, {}),
|
|
285
286
|
"Drag and drop a file here or click to upload"
|
|
286
287
|
] }),
|
|
287
288
|
onFilesAdded: (r) => {
|
|
@@ -292,7 +293,7 @@ function it({ onDataAdded: e }) {
|
|
|
292
293
|
}
|
|
293
294
|
);
|
|
294
295
|
}
|
|
295
|
-
function
|
|
296
|
+
function wt({
|
|
296
297
|
propertyKey: e,
|
|
297
298
|
property: r,
|
|
298
299
|
onEditClick: n,
|
|
@@ -300,16 +301,16 @@ function vt({
|
|
|
300
301
|
onPropertyNameChanged: a,
|
|
301
302
|
propertyTypeView: i
|
|
302
303
|
}) {
|
|
303
|
-
const { propertyConfigs: o } = G(), l = r ?
|
|
304
|
-
return /* @__PURE__ */ s(
|
|
304
|
+
const { propertyConfigs: o } = G(), l = r ? de(r, o) : null;
|
|
305
|
+
return /* @__PURE__ */ s(Oe, { children: /* @__PURE__ */ p(
|
|
305
306
|
"div",
|
|
306
307
|
{
|
|
307
308
|
className: "flex flex-row w-full items-center",
|
|
308
309
|
children: [
|
|
309
|
-
/* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(
|
|
310
|
+
/* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(pe, { propertyConfig: l ?? void 0 }) }),
|
|
310
311
|
/* @__PURE__ */ s("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ p("div", { className: "flex flex-row items-center gap-2", children: [
|
|
311
312
|
t && /* @__PURE__ */ s(
|
|
312
|
-
|
|
313
|
+
Je,
|
|
313
314
|
{
|
|
314
315
|
size: "small",
|
|
315
316
|
className: "text-base grow",
|
|
@@ -319,7 +320,7 @@ function vt({
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
),
|
|
322
|
-
/* @__PURE__ */ s(K, { onClick: n, size: "small", children: /* @__PURE__ */ s(
|
|
323
|
+
/* @__PURE__ */ s(K, { onClick: n, size: "small", children: /* @__PURE__ */ s(Ue, { size: "small" }) })
|
|
323
324
|
] }) })
|
|
324
325
|
]
|
|
325
326
|
}
|
|
@@ -330,7 +331,7 @@ function st({
|
|
|
330
331
|
collection: r,
|
|
331
332
|
onImportSuccess: n
|
|
332
333
|
}) {
|
|
333
|
-
const t =
|
|
334
|
+
const t = fe(), a = Ne(!1), [i, o] = T(0);
|
|
334
335
|
function l() {
|
|
335
336
|
a.current || (a.current = !0, we(
|
|
336
337
|
t,
|
|
@@ -345,8 +346,8 @@ function st({
|
|
|
345
346
|
}
|
|
346
347
|
return le(() => {
|
|
347
348
|
l();
|
|
348
|
-
}, []), /* @__PURE__ */ p(
|
|
349
|
-
/* @__PURE__ */ s(
|
|
349
|
+
}, []), /* @__PURE__ */ p(Ve, { className: "flex flex-col gap-4 items-center", children: [
|
|
350
|
+
/* @__PURE__ */ s(he, {}),
|
|
350
351
|
/* @__PURE__ */ s(h, { variant: "h6", children: "Saving data" }),
|
|
351
352
|
/* @__PURE__ */ p(h, { variant: "body2", children: [
|
|
352
353
|
i,
|
|
@@ -374,7 +375,7 @@ function ot({
|
|
|
374
375
|
path: r,
|
|
375
376
|
collectionEntitiesCount: n
|
|
376
377
|
}) {
|
|
377
|
-
const t = G(), a =
|
|
378
|
+
const t = G(), a = Ae(), [i, o] = w.useState(!1), [l, d] = w.useState("initial"), c = Ye(), f = b(() => {
|
|
378
379
|
o(!0), d("initial");
|
|
379
380
|
}, [o]), m = b(() => {
|
|
380
381
|
o(!1);
|
|
@@ -386,9 +387,9 @@ function ot({
|
|
|
386
387
|
if (c.setImportData(g), g.length > 0) {
|
|
387
388
|
const I = await Qe(g, tt);
|
|
388
389
|
c.setOriginProperties(I);
|
|
389
|
-
const
|
|
390
|
-
c.setHeadersMapping(
|
|
391
|
-
const C = Object.keys(
|
|
390
|
+
const B = De(g);
|
|
391
|
+
c.setHeadersMapping(B);
|
|
392
|
+
const C = Object.keys(B)?.[0];
|
|
392
393
|
if (C?.includes("id") || C?.includes("key")) {
|
|
393
394
|
const O = C;
|
|
394
395
|
c.setIdColumn(O);
|
|
@@ -397,13 +398,13 @@ function ot({
|
|
|
397
398
|
setTimeout(() => {
|
|
398
399
|
d("mapping");
|
|
399
400
|
}, 100);
|
|
400
|
-
}, $ =
|
|
401
|
+
}, $ = me({
|
|
401
402
|
collection: e,
|
|
402
403
|
path: r,
|
|
403
404
|
fields: t.propertyConfigs
|
|
404
|
-
}), x =
|
|
405
|
+
}), x = Ee($.properties, $.propertiesOrder), J = Object.entries(x).flatMap(([g, I]) => Ce(g, I, 0)), _ = $.propertiesOrder ?? Object.keys($.properties);
|
|
405
406
|
return e.collectionGroup ? null : /* @__PURE__ */ p(P, { children: [
|
|
406
|
-
/* @__PURE__ */ s(ee, { title: "Import", children: /* @__PURE__ */ s(K, { color: "primary", onClick: f, children: /* @__PURE__ */ s(
|
|
407
|
+
/* @__PURE__ */ s(ee, { title: "Import", children: /* @__PURE__ */ s(K, { color: "primary", onClick: f, children: /* @__PURE__ */ s(We, {}) }) }),
|
|
407
408
|
/* @__PURE__ */ p(
|
|
408
409
|
ge,
|
|
409
410
|
{
|
|
@@ -431,12 +432,12 @@ function ot({
|
|
|
431
432
|
buildPropertyView: ({
|
|
432
433
|
isIdColumn: g,
|
|
433
434
|
property: I,
|
|
434
|
-
propertyKey:
|
|
435
|
+
propertyKey: B,
|
|
435
436
|
importKey: C
|
|
436
437
|
}) => /* @__PURE__ */ s(
|
|
437
438
|
lt,
|
|
438
439
|
{
|
|
439
|
-
selectedPropertyKey:
|
|
440
|
+
selectedPropertyKey: B ?? "",
|
|
440
441
|
properties: x,
|
|
441
442
|
propertiesAndLevel: J,
|
|
442
443
|
isIdColumn: g,
|
|
@@ -540,7 +541,7 @@ function lt({
|
|
|
540
541
|
c === W ? (t(), n(null)) : n(c === "" ? null : c);
|
|
541
542
|
}, []);
|
|
542
543
|
return /* @__PURE__ */ p(
|
|
543
|
-
|
|
544
|
+
ue,
|
|
544
545
|
{
|
|
545
546
|
value: i ? W : e ?? void 0,
|
|
546
547
|
onValueChange: d,
|
|
@@ -587,14 +588,14 @@ function ie({
|
|
|
587
588
|
property: r,
|
|
588
589
|
level: n = 0
|
|
589
590
|
}) {
|
|
590
|
-
const { propertyConfigs: t } = G(), a =
|
|
591
|
+
const { propertyConfigs: t } = G(), a = de(r, t);
|
|
591
592
|
return /* @__PURE__ */ p(
|
|
592
593
|
"div",
|
|
593
594
|
{
|
|
594
595
|
className: "flex flex-row w-full text-start items-center h-full",
|
|
595
596
|
children: [
|
|
596
|
-
new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className:
|
|
597
|
-
/* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(ee, { title: a?.name, children: /* @__PURE__ */ s(
|
|
597
|
+
new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: R(ze, "ml-8 border-l h-12") }, o)),
|
|
598
|
+
/* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(ee, { title: a?.name, children: /* @__PURE__ */ s(pe, { propertyConfig: a }) }) }),
|
|
598
599
|
/* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
|
|
599
600
|
/* @__PURE__ */ s(
|
|
600
601
|
h,
|
|
@@ -629,9 +630,9 @@ function ct({
|
|
|
629
630
|
const a = rt(e.originProperties, r), i = e.importData.map((o) => et(o, e.idColumn, e.headersMapping, r, a, "TEMP_PATH"));
|
|
630
631
|
e.setEntities(i);
|
|
631
632
|
}, []);
|
|
632
|
-
const t =
|
|
633
|
+
const t = Te();
|
|
633
634
|
return /* @__PURE__ */ s(
|
|
634
|
-
|
|
635
|
+
je,
|
|
635
636
|
{
|
|
636
637
|
title: /* @__PURE__ */ p("div", { children: [
|
|
637
638
|
/* @__PURE__ */ s(h, { variant: "subtitle2", children: "Imported data preview" }),
|
|
@@ -656,7 +657,7 @@ function ct({
|
|
|
656
657
|
}
|
|
657
658
|
function De(e) {
|
|
658
659
|
const r = {};
|
|
659
|
-
return e.forEach((n) => {
|
|
660
|
+
return e.filter(Boolean).forEach((n) => {
|
|
660
661
|
Object.keys(n).forEach((t) => {
|
|
661
662
|
const a = n[t];
|
|
662
663
|
typeof a == "object" && !Array.isArray(a) && Object.entries(De([a])).forEach(([i, o]) => {
|
|
@@ -668,7 +669,7 @@ function De(e) {
|
|
|
668
669
|
function dt(e, r, n, t, a, i, o) {
|
|
669
670
|
const l = n.properties;
|
|
670
671
|
if (i === "csv") {
|
|
671
|
-
const d = t ?
|
|
672
|
+
const d = t ? Fe(e.map((u) => u.values)) : {}, c = mt(l, a, d), f = pt(e, r, l, c, o), m = se(c.map((u) => u.label)), y = f.map((u) => se(u));
|
|
672
673
|
oe([m, ...y], `${n.name}.csv`, "text/csv");
|
|
673
674
|
} else {
|
|
674
675
|
const d = ft(e, r, l, o), c = JSON.stringify(d, null, 2);
|
|
@@ -682,7 +683,7 @@ function pt(e, r, n, t, a) {
|
|
|
682
683
|
}));
|
|
683
684
|
return r && r.forEach((o, l) => {
|
|
684
685
|
i[l] = { ...i[l], ...o };
|
|
685
|
-
}), i && i.map((o) => t.map((l) =>
|
|
686
|
+
}), i && i.map((o) => t.map((l) => ke(o, l.key)));
|
|
686
687
|
}
|
|
687
688
|
function ft(e, r, n, t) {
|
|
688
689
|
const a = e.map((i) => ({
|
|
@@ -743,25 +744,25 @@ function ht({
|
|
|
743
744
|
exportAllowed: t,
|
|
744
745
|
notAllowedView: a
|
|
745
746
|
}) {
|
|
746
|
-
const i = typeof e.exportable == "object" ? e.exportable : void 0, o = w.useRef(/* @__PURE__ */ new Date()), [l, d] = w.useState(!0), [c, f] = w.useState("csv"), [m, y] = w.useState("string"), u = G(), N =
|
|
747
|
+
const i = typeof e.exportable == "object" ? e.exportable : void 0, o = w.useRef(/* @__PURE__ */ new Date()), [l, d] = w.useState(!0), [c, f] = w.useState("csv"), [m, y] = w.useState("string"), u = G(), N = fe(), x = Pe().resolveAliasesFrom(r), J = !t || t({
|
|
747
748
|
collectionEntitiesCount: n,
|
|
748
749
|
path: x,
|
|
749
750
|
collection: e
|
|
750
|
-
}), _ = w.useMemo(() =>
|
|
751
|
+
}), _ = w.useMemo(() => me({
|
|
751
752
|
collection: e,
|
|
752
753
|
path: x,
|
|
753
754
|
fields: u.propertyConfigs
|
|
754
|
-
}), [e, x]), [g, I] = w.useState(!1), [
|
|
755
|
+
}), [e, x]), [g, I] = w.useState(!1), [B, C] = w.useState(), [O, A] = w.useState(!1), D = b(() => {
|
|
755
756
|
A(!0);
|
|
756
757
|
}, [A]), S = b(() => {
|
|
757
758
|
A(!1);
|
|
758
759
|
}, [A]), re = b(async (F) => {
|
|
759
|
-
const U = i?.additionalFields,
|
|
760
|
+
const U = i?.additionalFields, L = _.additionalFields, X = U ? await Promise.all(F.map(async (E) => (await Promise.all(U.map(async (v) => ({
|
|
760
761
|
[v.key]: await v.builder({
|
|
761
762
|
entity: E,
|
|
762
763
|
context: u
|
|
763
764
|
})
|
|
764
|
-
})))).reduce((v, Q) => ({ ...v, ...Q }), {}))) : [], q =
|
|
765
|
+
})))).reduce((v, Q) => ({ ...v, ...Q }), {}))) : [], q = L ? await Promise.all(F.map(async (E) => (await Promise.all(L.map(async (v) => v.value ? {
|
|
765
766
|
[v.key]: await v.value({
|
|
766
767
|
entity: E,
|
|
767
768
|
context: u
|
|
@@ -772,13 +773,13 @@ function ht({
|
|
|
772
773
|
I(!0), N.fetchCollection({
|
|
773
774
|
path: x,
|
|
774
775
|
collection: F
|
|
775
|
-
}).then(async (
|
|
776
|
+
}).then(async (L) => {
|
|
776
777
|
C(void 0);
|
|
777
|
-
const X = await re(
|
|
778
|
+
const X = await re(L), q = [
|
|
778
779
|
...U?.additionalFields?.map((E) => E.key) ?? [],
|
|
779
780
|
...F.additionalFields?.map((E) => E.key) ?? []
|
|
780
781
|
];
|
|
781
|
-
dt(
|
|
782
|
+
dt(L, X, F, l, q, c, m);
|
|
782
783
|
}).catch(C).finally(() => I(!1));
|
|
783
784
|
}, [N, x, re, l, c, m]), Se = b(() => {
|
|
784
785
|
ne(_, i), S();
|
|
@@ -812,7 +813,7 @@ function ht({
|
|
|
812
813
|
name: "exportType",
|
|
813
814
|
checked: c === "csv",
|
|
814
815
|
onChange: () => f("csv"),
|
|
815
|
-
className:
|
|
816
|
+
className: R(V, "w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
|
816
817
|
}
|
|
817
818
|
),
|
|
818
819
|
/* @__PURE__ */ s(
|
|
@@ -834,7 +835,7 @@ function ht({
|
|
|
834
835
|
name: "exportType",
|
|
835
836
|
checked: c === "json",
|
|
836
837
|
onChange: () => f("json"),
|
|
837
|
-
className:
|
|
838
|
+
className: R(V, "w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
|
838
839
|
}
|
|
839
840
|
),
|
|
840
841
|
/* @__PURE__ */ s(
|
|
@@ -858,7 +859,7 @@ function ht({
|
|
|
858
859
|
name: "dateExportType",
|
|
859
860
|
checked: m === "timestamp",
|
|
860
861
|
onChange: () => y("timestamp"),
|
|
861
|
-
className:
|
|
862
|
+
className: R(V, "w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
|
862
863
|
}
|
|
863
864
|
),
|
|
864
865
|
/* @__PURE__ */ p(
|
|
@@ -884,7 +885,7 @@ function ht({
|
|
|
884
885
|
name: "dateExportType",
|
|
885
886
|
checked: m === "string",
|
|
886
887
|
onChange: () => y("string"),
|
|
887
|
-
className:
|
|
888
|
+
className: R(V, "w-4 text-blue-600 bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
|
888
889
|
}
|
|
889
890
|
),
|
|
890
891
|
/* @__PURE__ */ p(
|
|
@@ -915,7 +916,7 @@ function ht({
|
|
|
915
916
|
!J && a
|
|
916
917
|
] }),
|
|
917
918
|
/* @__PURE__ */ p(be, { children: [
|
|
918
|
-
g && /* @__PURE__ */ s(
|
|
919
|
+
g && /* @__PURE__ */ s(he, { size: "small" }),
|
|
919
920
|
/* @__PURE__ */ s(
|
|
920
921
|
j,
|
|
921
922
|
{
|
|
@@ -939,7 +940,7 @@ function ht({
|
|
|
939
940
|
)
|
|
940
941
|
] });
|
|
941
942
|
}
|
|
942
|
-
function
|
|
943
|
+
function Ct(e) {
|
|
943
944
|
return Ie(() => ({
|
|
944
945
|
name: "Import/Export",
|
|
945
946
|
collections: {
|
|
@@ -951,7 +952,7 @@ function wt(e) {
|
|
|
951
952
|
export {
|
|
952
953
|
nt as DataNewPropertiesMapping,
|
|
953
954
|
it as ImportFileUpload,
|
|
954
|
-
|
|
955
|
+
wt as ImportNewPropertyFieldPreview,
|
|
955
956
|
st as ImportSaveInProgress,
|
|
956
957
|
et as convertDataToEntity,
|
|
957
958
|
Ze as convertFileToJson,
|
|
@@ -961,6 +962,6 @@ export {
|
|
|
961
962
|
Y as processValueMapping,
|
|
962
963
|
xe as unflattenObject,
|
|
963
964
|
Ye as useImportConfig,
|
|
964
|
-
|
|
965
|
+
Ct as useImportExportPlugin
|
|
965
966
|
};
|
|
966
967
|
//# sourceMappingURL=index.es.js.map
|