@firecms/data_import_export 3.0.0-canary.3 → 3.0.0-canary.5
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/components/ImportSaveInProgress.d.ts +2 -1
- package/dist/index.es.js +114 -111
- 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/ImportSaveInProgress.tsx +8 -3
- package/src/export_import/ImportCollectionAction.tsx +1 -0
- package/src/export_import/export.ts +1 -1
@@ -1,6 +1,7 @@
|
|
1
1
|
import { EntityCollection } from "@firecms/core";
|
2
2
|
import { ImportConfig } from "../types";
|
3
|
-
export declare function ImportSaveInProgress<C extends EntityCollection>({ importConfig, collection, onImportSuccess }: {
|
3
|
+
export declare function ImportSaveInProgress<C extends EntityCollection>({ path, importConfig, collection, onImportSuccess }: {
|
4
|
+
path: string;
|
4
5
|
importConfig: ImportConfig;
|
5
6
|
collection: C;
|
6
7
|
onImportSuccess: (collection: C) => void;
|
package/dist/index.es.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import C, { useState as j, useRef as
|
1
|
+
import C, { useState as j, useRef as Oe, useEffect as ce, useCallback as x, useMemo as Ie } from "react";
|
2
2
|
import { jsxs as p, Fragment as $, jsx as s } from "react/jsx-runtime";
|
3
|
-
import { getPropertyInPath as
|
4
|
-
import { Table as
|
3
|
+
import { getPropertyInPath as R, EntityReference as Ee, useSnackbarController as de, useCustomizationController as V, getFieldConfig as pe, ErrorBoundary as Ae, PropertyConfigBadge as fe, useDataSource as me, resolveCollection as ue, getPropertiesWithPropertiesOrder as Te, useSelectionController as je, EntityCollectionTable as ke, getArrayValuesCount as Fe, getValueInPath as Pe, useFireCMSContext as Me, useNavigationController as $e } from "@firecms/core";
|
4
|
+
import { Table as Re, TableHeader as Le, TableCell as M, TableBody as _e, TableRow as Be, Typography as u, ChevronRightIcon as Je, Select as he, SelectItem as B, FileUpload as He, UploadIcon as Ue, TextField as We, IconButton as ee, EditIcon as ze, CenteredView as Ve, CircularProgress as ge, Tooltip as te, FileUploadIcon as Ge, Dialog as ye, DialogContent as be, DialogActions as xe, Button as k, cn as _, defaultBorderMixin as Xe, GetAppIcon as qe, Alert as Qe, focusedMixin as U, BooleanSwitchWithLabel as Ye } from "@firecms/ui";
|
5
5
|
import { buildEntityPropertiesFromData as Ze } from "@firecms/schema_inference";
|
6
6
|
import * as ie from "xlsx";
|
7
7
|
const Ke = () => {
|
@@ -41,7 +41,7 @@ function et(e) {
|
|
41
41
|
codepage: 65001,
|
42
42
|
cellDates: !0
|
43
43
|
}
|
44
|
-
), l = o.SheetNames[0], d = o.Sheets[l], m = ie.utils.sheet_to_json(d).map(tt).map(
|
44
|
+
), l = o.SheetNames[0], d = o.Sheets[l], m = ie.utils.sheet_to_json(d).map(tt).map(ve);
|
45
45
|
r(m);
|
46
46
|
}, t.readAsArrayBuffer(e);
|
47
47
|
}
|
@@ -57,7 +57,7 @@ function tt(e) {
|
|
57
57
|
return r;
|
58
58
|
}, {});
|
59
59
|
}
|
60
|
-
function
|
60
|
+
function ve(e) {
|
61
61
|
return Object.keys(e).reduce((r, n) => {
|
62
62
|
let t = r;
|
63
63
|
const a = n.split(".");
|
@@ -71,28 +71,28 @@ function Ce(e) {
|
|
71
71
|
}, {});
|
72
72
|
}
|
73
73
|
function rt(e, r, n, t, a, i) {
|
74
|
-
const o =
|
74
|
+
const o = Ce(e);
|
75
75
|
r && delete o[r];
|
76
76
|
const l = Object.entries(o).map(([c, f]) => {
|
77
77
|
const m = n[c] ?? c;
|
78
|
-
if (!
|
78
|
+
if (!R(t, m))
|
79
79
|
return {};
|
80
80
|
const h = a[m];
|
81
81
|
let S = f;
|
82
82
|
return h && (S = Z(f, h)), {
|
83
83
|
[m]: S
|
84
84
|
};
|
85
|
-
}).reduce((c, f) => ({ ...c, ...f }), {}), d =
|
85
|
+
}).reduce((c, f) => ({ ...c, ...f }), {}), d = ve(l);
|
86
86
|
return {
|
87
87
|
id: r ? e[r] : void 0,
|
88
88
|
values: d,
|
89
89
|
path: i
|
90
90
|
};
|
91
91
|
}
|
92
|
-
function
|
92
|
+
function Ce(e, r = "") {
|
93
93
|
return Object.keys(e).reduce((n, t) => {
|
94
94
|
const a = r ? `${r}.${t}` : t;
|
95
|
-
return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(n,
|
95
|
+
return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(n, Ce(e[t], a)) : n[a] = e[t], n;
|
96
96
|
}, {});
|
97
97
|
}
|
98
98
|
function Z(e, r) {
|
@@ -143,7 +143,7 @@ function Z(e, r) {
|
|
143
143
|
}
|
144
144
|
else if (n === "string" && t === "reference" && typeof e == "string") {
|
145
145
|
const a = e.split("/").slice(0, -1).join("/"), i = e.split("/").slice(-1)[0];
|
146
|
-
return new
|
146
|
+
return new Ee(i, a);
|
147
147
|
} else {
|
148
148
|
if (n === t)
|
149
149
|
return e;
|
@@ -160,7 +160,7 @@ function at(e, r) {
|
|
160
160
|
function n(t, a) {
|
161
161
|
const i = {};
|
162
162
|
return Object.keys(t).forEach((o) => {
|
163
|
-
const l = a ? `${a}.${o}` : o, d =
|
163
|
+
const l = a ? `${a}.${o}` : o, d = R(t, o), c = R(e, l);
|
164
164
|
if (d) {
|
165
165
|
if (d.dataType === "map" && d.properties) {
|
166
166
|
const f = n(d.properties, l);
|
@@ -201,18 +201,18 @@ function it({
|
|
201
201
|
onChange: a
|
202
202
|
}
|
203
203
|
),
|
204
|
-
/* @__PURE__ */ p(
|
204
|
+
/* @__PURE__ */ p(Re, { style: {
|
205
205
|
tableLayout: "fixed"
|
206
206
|
}, children: [
|
207
|
-
/* @__PURE__ */ p(
|
207
|
+
/* @__PURE__ */ p(Le, { children: [
|
208
208
|
/* @__PURE__ */ s(M, { header: !0, style: { width: "20%" }, children: "Column in file" }),
|
209
209
|
/* @__PURE__ */ s(M, { header: !0 }),
|
210
210
|
/* @__PURE__ */ s(M, { header: !0, style: { width: "75%" }, children: "Property" })
|
211
211
|
] }),
|
212
|
-
/* @__PURE__ */ s(
|
212
|
+
/* @__PURE__ */ s(_e, { children: t && Object.entries(r).map(
|
213
213
|
([o, l]) => {
|
214
|
-
const d = r[o], c = l ?
|
215
|
-
return /* @__PURE__ */ p(
|
214
|
+
const d = r[o], c = l ? R(t, l) : null, f = R(n, o), m = f ? f.dataType === "array" && typeof f.of == "object" ? `${f.dataType} - ${f.of.dataType}` : f.dataType : void 0;
|
215
|
+
return /* @__PURE__ */ p(Be, { style: { height: "90px" }, children: [
|
216
216
|
/* @__PURE__ */ p(M, { style: { width: "20%" }, children: [
|
217
217
|
/* @__PURE__ */ s(u, { variant: "body2", children: o }),
|
218
218
|
f && /* @__PURE__ */ s(
|
@@ -224,7 +224,7 @@ function it({
|
|
224
224
|
}
|
225
225
|
)
|
226
226
|
] }),
|
227
|
-
/* @__PURE__ */ s(M, { children: /* @__PURE__ */ s(
|
227
|
+
/* @__PURE__ */ s(M, { children: /* @__PURE__ */ s(Je, {}) }),
|
228
228
|
/* @__PURE__ */ s(
|
229
229
|
M,
|
230
230
|
{
|
@@ -250,7 +250,7 @@ function st({
|
|
250
250
|
onChange: n
|
251
251
|
}) {
|
252
252
|
return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ p(
|
253
|
-
|
253
|
+
he,
|
254
254
|
{
|
255
255
|
size: "small",
|
256
256
|
value: e ?? "",
|
@@ -260,14 +260,14 @@ function st({
|
|
260
260
|
renderValue: (t) => /* @__PURE__ */ s(u, { variant: "body2", children: t !== "" ? t : "Autogenerate ID" }),
|
261
261
|
label: "Column that will be used as ID for each document",
|
262
262
|
children: [
|
263
|
-
/* @__PURE__ */ s(
|
264
|
-
Object.entries(r).map(([t, a]) => /* @__PURE__ */ s(
|
263
|
+
/* @__PURE__ */ s(B, { value: "", children: "Autogenerate ID" }),
|
264
|
+
Object.entries(r).map(([t, a]) => /* @__PURE__ */ s(B, { value: t, children: t }, t))
|
265
265
|
]
|
266
266
|
}
|
267
267
|
) });
|
268
268
|
}
|
269
269
|
function ot({ onDataAdded: e }) {
|
270
|
-
const r =
|
270
|
+
const r = de();
|
271
271
|
return /* @__PURE__ */ s(
|
272
272
|
He,
|
273
273
|
{
|
@@ -306,16 +306,16 @@ function Dt({
|
|
306
306
|
onPropertyNameChanged: a,
|
307
307
|
propertyTypeView: i
|
308
308
|
}) {
|
309
|
-
const { propertyConfigs: o } =
|
310
|
-
return /* @__PURE__ */ s(
|
309
|
+
const { propertyConfigs: o } = V(), l = r ? pe(r, o) : null;
|
310
|
+
return /* @__PURE__ */ s(Ae, { children: /* @__PURE__ */ p(
|
311
311
|
"div",
|
312
312
|
{
|
313
313
|
className: "flex flex-row w-full items-center",
|
314
314
|
children: [
|
315
|
-
/* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(
|
315
|
+
/* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(fe, { propertyConfig: l ?? void 0 }) }),
|
316
316
|
/* @__PURE__ */ s("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ p("div", { className: "flex flex-row items-center gap-2", children: [
|
317
317
|
t && /* @__PURE__ */ s(
|
318
|
-
|
318
|
+
We,
|
319
319
|
{
|
320
320
|
size: "small",
|
321
321
|
className: "text-base grow",
|
@@ -325,62 +325,64 @@ function Dt({
|
|
325
325
|
}
|
326
326
|
}
|
327
327
|
),
|
328
|
-
/* @__PURE__ */ s(ee, { onClick: n, size: "small", children: /* @__PURE__ */ s(
|
328
|
+
/* @__PURE__ */ s(ee, { onClick: n, size: "small", children: /* @__PURE__ */ s(ze, { size: "small" }) })
|
329
329
|
] }) })
|
330
330
|
]
|
331
331
|
}
|
332
332
|
) });
|
333
333
|
}
|
334
334
|
function lt({
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
path: e,
|
336
|
+
importConfig: r,
|
337
|
+
collection: n,
|
338
|
+
onImportSuccess: t
|
338
339
|
}) {
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
340
|
+
console.log("ImportSaveInProgress", e);
|
341
|
+
const a = me(), i = Oe(!1), [o, l] = j(0);
|
342
|
+
function d() {
|
343
|
+
i.current || (i.current = !0, we(
|
344
|
+
a,
|
345
|
+
n,
|
346
|
+
e,
|
347
|
+
r.entities,
|
345
348
|
0,
|
346
349
|
25,
|
347
|
-
|
350
|
+
l
|
348
351
|
).then(() => {
|
349
|
-
n
|
352
|
+
t(n), i.current = !1;
|
350
353
|
}));
|
351
354
|
}
|
352
355
|
return ce(() => {
|
353
|
-
|
354
|
-
}, []), /* @__PURE__ */ p(
|
355
|
-
/* @__PURE__ */ s(
|
356
|
+
d();
|
357
|
+
}, []), /* @__PURE__ */ p(Ve, { className: "flex flex-col gap-4 items-center", children: [
|
358
|
+
/* @__PURE__ */ s(ge, {}),
|
356
359
|
/* @__PURE__ */ s(u, { variant: "h6", children: "Saving data" }),
|
357
360
|
/* @__PURE__ */ p(u, { variant: "body2", children: [
|
358
|
-
|
361
|
+
o,
|
359
362
|
"/",
|
360
|
-
|
363
|
+
r.entities.length,
|
361
364
|
" entities saved"
|
362
365
|
] }),
|
363
366
|
/* @__PURE__ */ s(u, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
|
364
367
|
] });
|
365
368
|
}
|
366
|
-
function
|
367
|
-
console.debug("Saving imported data",
|
368
|
-
const
|
369
|
-
return Promise.all(
|
370
|
-
path:
|
371
|
-
|
372
|
-
|
373
|
-
entityId: l.id,
|
369
|
+
function we(e, r, n, t, a = 0, i = 25, o) {
|
370
|
+
console.debug("Saving imported data", a, i);
|
371
|
+
const l = t.slice(a, a + i);
|
372
|
+
return Promise.all(l.map((d) => e.saveEntity({
|
373
|
+
path: n,
|
374
|
+
values: d.values,
|
375
|
+
entityId: d.id,
|
374
376
|
collection: r,
|
375
377
|
status: "new"
|
376
|
-
}))).then(() =>
|
378
|
+
}))).then(() => a + i < t.length ? (o(a + i), we(e, r, n, t, a + i, i, o)) : (o(t.length), Promise.resolve()));
|
377
379
|
}
|
378
380
|
function ct({
|
379
381
|
collection: e,
|
380
382
|
path: r,
|
381
383
|
collectionEntitiesCount: n
|
382
384
|
}) {
|
383
|
-
const t =
|
385
|
+
const t = V(), a = de(), [i, o] = C.useState(!1), [l, d] = C.useState("initial"), c = Ke(), f = x(() => {
|
384
386
|
o(!0), d("initial");
|
385
387
|
}, [o]), m = x(() => {
|
386
388
|
o(!1);
|
@@ -392,33 +394,33 @@ function ct({
|
|
392
394
|
if (c.setImportData(g), g.length > 0) {
|
393
395
|
const I = await Ze(g, nt);
|
394
396
|
c.setOriginProperties(I);
|
395
|
-
const
|
396
|
-
c.setHeadersMapping(
|
397
|
-
const
|
398
|
-
if (
|
399
|
-
const w =
|
397
|
+
const E = Se(g);
|
398
|
+
c.setHeadersMapping(E);
|
399
|
+
const A = Object.keys(E)?.[0];
|
400
|
+
if (A?.includes("id") || A?.includes("key")) {
|
401
|
+
const w = A;
|
400
402
|
c.setIdColumn(w);
|
401
403
|
}
|
402
404
|
}
|
403
405
|
setTimeout(() => {
|
404
406
|
d("mapping");
|
405
407
|
}, 100);
|
406
|
-
}, N =
|
408
|
+
}, N = ue({
|
407
409
|
collection: e,
|
408
410
|
path: r,
|
409
411
|
fields: t.propertyConfigs
|
410
|
-
}),
|
412
|
+
}), L = Te(N.properties, N.propertiesOrder), O = Object.entries(L).flatMap(([g, I]) => De(g, I, 0)), J = N.propertiesOrder ?? Object.keys(N.properties);
|
411
413
|
return e.collectionGroup ? null : /* @__PURE__ */ p($, { children: [
|
412
414
|
/* @__PURE__ */ s(te, { title: "Import", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: f, children: /* @__PURE__ */ s(Ge, {}) }) }),
|
413
415
|
/* @__PURE__ */ p(
|
414
|
-
|
416
|
+
ye,
|
415
417
|
{
|
416
418
|
open: i,
|
417
419
|
fullWidth: l === "preview",
|
418
420
|
fullHeight: l === "preview",
|
419
421
|
maxWidth: l === "initial" ? "lg" : "7xl",
|
420
422
|
children: [
|
421
|
-
/* @__PURE__ */ p(
|
423
|
+
/* @__PURE__ */ p(be, { className: "flex flex-col gap-4 my-4", fullHeight: l === "preview", children: [
|
422
424
|
l === "initial" && /* @__PURE__ */ p($, { children: [
|
423
425
|
/* @__PURE__ */ s(u, { variant: "h6", children: "Import data" }),
|
424
426
|
/* @__PURE__ */ s(u, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
|
@@ -432,25 +434,25 @@ function ct({
|
|
432
434
|
headersMapping: c.headersMapping,
|
433
435
|
idColumn: c.idColumn,
|
434
436
|
originProperties: c.originProperties,
|
435
|
-
destinationProperties:
|
437
|
+
destinationProperties: L,
|
436
438
|
onIdPropertyChanged: (g) => c.setIdColumn(g),
|
437
439
|
buildPropertyView: ({
|
438
440
|
isIdColumn: g,
|
439
441
|
property: I,
|
440
|
-
propertyKey:
|
441
|
-
importKey:
|
442
|
+
propertyKey: E,
|
443
|
+
importKey: A
|
442
444
|
}) => /* @__PURE__ */ s(
|
443
445
|
dt,
|
444
446
|
{
|
445
|
-
selectedPropertyKey:
|
446
|
-
properties:
|
447
|
+
selectedPropertyKey: E ?? "",
|
448
|
+
properties: L,
|
447
449
|
propertiesAndLevel: O,
|
448
450
|
isIdColumn: g,
|
449
451
|
onIdSelected: () => {
|
450
|
-
c.setIdColumn(
|
452
|
+
c.setIdColumn(A);
|
451
453
|
},
|
452
454
|
onPropertySelected: (w) => {
|
453
|
-
const G = Object.entries(c.headersMapping).map(([b, F]) => F === w ? { [b]: null } : b ===
|
455
|
+
const G = Object.entries(c.headersMapping).map(([b, F]) => F === w ? { [b]: null } : b === A ? { [b]: w } : { [b]: F }).reduce((b, F) => ({ ...b, ...F }), {});
|
454
456
|
c.setHeadersMapping(G), w === c.idColumn && c.setIdColumn(void 0);
|
455
457
|
}
|
456
458
|
}
|
@@ -462,8 +464,8 @@ function ct({
|
|
462
464
|
pt,
|
463
465
|
{
|
464
466
|
importConfig: c,
|
465
|
-
properties:
|
466
|
-
propertiesOrder:
|
467
|
+
properties: L,
|
468
|
+
propertiesOrder: J
|
467
469
|
}
|
468
470
|
),
|
469
471
|
l === "import_data_saving" && c && /* @__PURE__ */ s(
|
@@ -471,6 +473,7 @@ function ct({
|
|
471
473
|
{
|
472
474
|
importConfig: c,
|
473
475
|
collection: e,
|
476
|
+
path: r,
|
474
477
|
onImportSuccess: (g) => {
|
475
478
|
m(), a.open({
|
476
479
|
type: "info",
|
@@ -480,7 +483,7 @@ function ct({
|
|
480
483
|
}
|
481
484
|
)
|
482
485
|
] }),
|
483
|
-
/* @__PURE__ */ p(
|
486
|
+
/* @__PURE__ */ p(xe, { children: [
|
484
487
|
l === "mapping" && /* @__PURE__ */ s(
|
485
488
|
k,
|
486
489
|
{
|
@@ -527,7 +530,7 @@ function ct({
|
|
527
530
|
)
|
528
531
|
] });
|
529
532
|
}
|
530
|
-
const
|
533
|
+
const W = "__internal_id__";
|
531
534
|
function dt({
|
532
535
|
selectedPropertyKey: e,
|
533
536
|
properties: r,
|
@@ -536,30 +539,30 @@ function dt({
|
|
536
539
|
propertiesAndLevel: a,
|
537
540
|
isIdColumn: i
|
538
541
|
}) {
|
539
|
-
const o = e ?
|
542
|
+
const o = e ? R(r, e) : null, l = x((c) => c === W ? /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) : !c || !o ? /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) : /* @__PURE__ */ s(
|
540
543
|
se,
|
541
544
|
{
|
542
545
|
propertyKey: c,
|
543
546
|
property: o
|
544
547
|
}
|
545
548
|
), [o]), d = x((c) => {
|
546
|
-
c ===
|
549
|
+
c === W ? (t(), n(null)) : n(c === "" ? null : c);
|
547
550
|
}, []);
|
548
551
|
return /* @__PURE__ */ p(
|
549
|
-
|
552
|
+
he,
|
550
553
|
{
|
551
|
-
value: i ?
|
554
|
+
value: i ? W : e ?? void 0,
|
552
555
|
onValueChange: d,
|
553
556
|
renderValue: l,
|
554
557
|
children: [
|
555
|
-
/* @__PURE__ */ s(
|
556
|
-
/* @__PURE__ */ s(
|
558
|
+
/* @__PURE__ */ s(B, { value: "", children: /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) }),
|
559
|
+
/* @__PURE__ */ s(B, { value: W, children: /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
|
557
560
|
a.map(({
|
558
561
|
property: c,
|
559
562
|
level: f,
|
560
563
|
propertyKey: m
|
561
564
|
}) => /* @__PURE__ */ s(
|
562
|
-
|
565
|
+
B,
|
563
566
|
{
|
564
567
|
value: m,
|
565
568
|
disabled: c.dataType === "map",
|
@@ -578,14 +581,14 @@ function dt({
|
|
578
581
|
}
|
579
582
|
);
|
580
583
|
}
|
581
|
-
function
|
584
|
+
function De(e, r, n) {
|
582
585
|
const t = [];
|
583
586
|
return t.push({
|
584
587
|
property: r,
|
585
588
|
level: n,
|
586
589
|
propertyKey: e
|
587
590
|
}), r.dataType === "map" && r.properties && Object.entries(r.properties).forEach(([a, i]) => {
|
588
|
-
t.push(...
|
591
|
+
t.push(...De(`${e}.${a}`, i, n + 1));
|
589
592
|
}), t;
|
590
593
|
}
|
591
594
|
function se({
|
@@ -593,14 +596,14 @@ function se({
|
|
593
596
|
property: r,
|
594
597
|
level: n = 0
|
595
598
|
}) {
|
596
|
-
const { propertyConfigs: t } =
|
599
|
+
const { propertyConfigs: t } = V(), a = pe(r, t);
|
597
600
|
return /* @__PURE__ */ p(
|
598
601
|
"div",
|
599
602
|
{
|
600
603
|
className: "flex flex-row w-full text-start items-center h-full",
|
601
604
|
children: [
|
602
|
-
new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className:
|
603
|
-
/* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(te, { title: a?.name, children: /* @__PURE__ */ s(
|
605
|
+
new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: _(Xe, "ml-8 border-l h-12") }, o)),
|
606
|
+
/* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(te, { title: a?.name, children: /* @__PURE__ */ s(fe, { propertyConfig: a }) }) }),
|
604
607
|
/* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
|
605
608
|
/* @__PURE__ */ s(
|
606
609
|
u,
|
@@ -660,12 +663,12 @@ function pt({
|
|
660
663
|
}
|
661
664
|
);
|
662
665
|
}
|
663
|
-
function
|
666
|
+
function Se(e) {
|
664
667
|
const r = {};
|
665
668
|
return e.filter(Boolean).forEach((n) => {
|
666
669
|
Object.keys(n).forEach((t) => {
|
667
670
|
const a = n[t];
|
668
|
-
typeof a == "object" && !Array.isArray(a) && Object.entries(
|
671
|
+
typeof a == "object" && !Array.isArray(a) && Object.entries(Se([a])).forEach(([i, o]) => {
|
669
672
|
r[`${t}.${i}`] = `${t}.${o}`;
|
670
673
|
}), r[t] = t;
|
671
674
|
});
|
@@ -714,13 +717,13 @@ function K(e, r, n = "") {
|
|
714
717
|
const t = n ? `${n}.${r}` : r;
|
715
718
|
return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([a, i]) => K(i, a, t)).flat() : [{ label: t, key: t }];
|
716
719
|
}
|
717
|
-
function
|
720
|
+
function z(e, r, n, t) {
|
718
721
|
let a;
|
719
722
|
if (r.dataType === "map" && r.properties)
|
720
723
|
a = re(e, r.properties, n, t);
|
721
724
|
else if (r.dataType === "array")
|
722
|
-
r.of && Array.isArray(e) ? Array.isArray(r.of) ? a = r.of.map((i, o) =>
|
723
|
-
else if (r.dataType === "reference" && e
|
725
|
+
r.of && Array.isArray(e) ? Array.isArray(r.of) ? a = r.of.map((i, o) => z(e[o], i, n, t)) : r.of.dataType === "map" ? a = n === "csv" ? e.map((i) => JSON.stringify(i)) : e.map((i) => z(i, r.of, n, t)) : a = e.map((i) => z(i, r.of, n, t)) : a = e;
|
726
|
+
else if (r.dataType === "reference" && e.isEntityReference && e.isEntityReference()) {
|
724
727
|
const i = e || void 0;
|
725
728
|
a = i ? i.pathWithId : null;
|
726
729
|
} else
|
@@ -729,7 +732,7 @@ function W(e, r, n, t) {
|
|
729
732
|
}
|
730
733
|
function re(e, r, n, t) {
|
731
734
|
const a = Object.entries(r).map(([i, o]) => {
|
732
|
-
const l = e && e[i], d =
|
735
|
+
const l = e && e[i], d = z(l, o, n, t);
|
733
736
|
return d === void 0 ? {} : { [i]: d };
|
734
737
|
}).reduce((i, o) => ({ ...i, ...o }), {});
|
735
738
|
return { ...e, ...a };
|
@@ -750,15 +753,15 @@ function yt({
|
|
750
753
|
exportAllowed: t,
|
751
754
|
notAllowedView: a
|
752
755
|
}) {
|
753
|
-
const i =
|
756
|
+
const i = V(), o = typeof e.exportable == "object" ? e.exportable : void 0, l = C.useRef(/* @__PURE__ */ new Date()), [d, c] = C.useState(!0), [f, m] = C.useState("csv"), [y, h] = C.useState("string"), S = Me(), N = me(), O = $e().resolveAliasesFrom(r), J = !t || t({
|
754
757
|
collectionEntitiesCount: n,
|
755
758
|
path: O,
|
756
759
|
collection: e
|
757
|
-
}), g = C.useMemo(() =>
|
760
|
+
}), g = C.useMemo(() => ue({
|
758
761
|
collection: e,
|
759
762
|
path: O,
|
760
763
|
fields: i.propertyConfigs
|
761
|
-
}), [e, O]), [I,
|
764
|
+
}), [e, O]), [I, E] = C.useState(!1), [A, w] = C.useState(), [G, b] = C.useState(!1), F = x(() => {
|
762
765
|
b(!0);
|
763
766
|
}, [b]), X = x(() => {
|
764
767
|
b(!1);
|
@@ -776,7 +779,7 @@ function yt({
|
|
776
779
|
} : {}))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [];
|
777
780
|
return [...q, ...Q];
|
778
781
|
}, [o?.additionalFields]), ae = x(async (P, H) => {
|
779
|
-
|
782
|
+
E(!0), N.fetchCollection({
|
780
783
|
path: O,
|
781
784
|
collection: P
|
782
785
|
}).then(async (D) => {
|
@@ -788,20 +791,20 @@ function yt({
|
|
788
791
|
ft(D, q, P, d, Q, f, y);
|
789
792
|
}).catch((D) => {
|
790
793
|
console.error("Error loading export data", D), w(D);
|
791
|
-
}).finally(() =>
|
792
|
-
}, [N, O, ne, d, f, y]),
|
794
|
+
}).finally(() => E(!1));
|
795
|
+
}, [N, O, ne, d, f, y]), Ne = x(() => {
|
793
796
|
ae(g, o), X();
|
794
797
|
}, [ae, g, o, X]);
|
795
798
|
return /* @__PURE__ */ p($, { children: [
|
796
799
|
/* @__PURE__ */ s(te, { title: "Export", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: F, children: /* @__PURE__ */ s(qe, {}) }) }),
|
797
800
|
/* @__PURE__ */ p(
|
798
|
-
|
801
|
+
ye,
|
799
802
|
{
|
800
803
|
open: G,
|
801
804
|
onOpenChange: b,
|
802
805
|
maxWidth: "xl",
|
803
806
|
children: [
|
804
|
-
/* @__PURE__ */ p(
|
807
|
+
/* @__PURE__ */ p(be, { className: "flex flex-col gap-4 my-4", children: [
|
805
808
|
/* @__PURE__ */ s(u, { variant: "h6", children: "Export data" }),
|
806
809
|
/* @__PURE__ */ s("div", { children: "Download the the content of this table as a CSV" }),
|
807
810
|
n > gt && /* @__PURE__ */ s(Qe, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
|
@@ -821,7 +824,7 @@ function yt({
|
|
821
824
|
name: "exportType",
|
822
825
|
checked: f === "csv",
|
823
826
|
onChange: () => m("csv"),
|
824
|
-
className:
|
827
|
+
className: _(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
825
828
|
}
|
826
829
|
),
|
827
830
|
/* @__PURE__ */ s(
|
@@ -843,7 +846,7 @@ function yt({
|
|
843
846
|
name: "exportType",
|
844
847
|
checked: f === "json",
|
845
848
|
onChange: () => m("json"),
|
846
|
-
className:
|
849
|
+
className: _(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
847
850
|
}
|
848
851
|
),
|
849
852
|
/* @__PURE__ */ s(
|
@@ -867,7 +870,7 @@ function yt({
|
|
867
870
|
name: "dateExportType",
|
868
871
|
checked: y === "timestamp",
|
869
872
|
onChange: () => h("timestamp"),
|
870
|
-
className:
|
873
|
+
className: _(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
871
874
|
}
|
872
875
|
),
|
873
876
|
/* @__PURE__ */ p(
|
@@ -893,7 +896,7 @@ function yt({
|
|
893
896
|
name: "dateExportType",
|
894
897
|
checked: y === "string",
|
895
898
|
onChange: () => h("string"),
|
896
|
-
className:
|
899
|
+
className: _(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
|
897
900
|
}
|
898
901
|
),
|
899
902
|
/* @__PURE__ */ p(
|
@@ -921,10 +924,10 @@ function yt({
|
|
921
924
|
label: "Flatten arrays"
|
922
925
|
}
|
923
926
|
),
|
924
|
-
!
|
927
|
+
!J && a
|
925
928
|
] }),
|
926
|
-
/* @__PURE__ */ p(
|
927
|
-
I && /* @__PURE__ */ s(
|
929
|
+
/* @__PURE__ */ p(xe, { children: [
|
930
|
+
I && /* @__PURE__ */ s(ge, { size: "small" }),
|
928
931
|
/* @__PURE__ */ s(
|
929
932
|
k,
|
930
933
|
{
|
@@ -937,8 +940,8 @@ function yt({
|
|
937
940
|
k,
|
938
941
|
{
|
939
942
|
variant: "filled",
|
940
|
-
onClick:
|
941
|
-
disabled: I || !
|
943
|
+
onClick: Ne,
|
944
|
+
disabled: I || !J,
|
942
945
|
children: "Download"
|
943
946
|
}
|
944
947
|
)
|
@@ -949,7 +952,7 @@ function yt({
|
|
949
952
|
] });
|
950
953
|
}
|
951
954
|
function St(e) {
|
952
|
-
return
|
955
|
+
return Ie(() => ({
|
953
956
|
name: "Import/Export",
|
954
957
|
collections: {
|
955
958
|
CollectionActions: [ct, yt],
|
@@ -964,11 +967,11 @@ export {
|
|
964
967
|
lt as ImportSaveInProgress,
|
965
968
|
rt as convertDataToEntity,
|
966
969
|
et as convertFileToJson,
|
967
|
-
|
970
|
+
Ce as flattenEntry,
|
968
971
|
nt as getInferenceType,
|
969
972
|
at as getPropertiesMapping,
|
970
973
|
Z as processValueMapping,
|
971
|
-
|
974
|
+
ve as unflattenObject,
|
972
975
|
Ke as useImportConfig,
|
973
976
|
St as useImportExportPlugin
|
974
977
|
};
|