@firecms/data_import_export 3.0.0-beta.1 → 3.0.0-beta.2-pre.2

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 CHANGED
@@ -1,11 +1,11 @@
1
- import C, { useState as T, useRef as Ie, useEffect as ce, useCallback as b, useMemo as Oe } from "react";
2
- import { jsxs as p, Fragment as M, jsx as s } from "react/jsx-runtime";
3
- import { getPropertyInPath as $, EntityReference as de, useCustomizationController as z, getFieldConfig as pe, ErrorBoundary as Ae, FieldConfigBadge as fe, useDataSource as me, useSnackbarController as Ee, resolveCollection as ue, getPropertiesWithPropertiesOrder as Te, useSelectionController as je, EntityCollectionTable as Fe, getArrayValuesCount as ke, getValueInPath as Pe, useFireCMSContext as Me, useNavigationController as $e } from "@firecms/core";
4
- import { Table as _e, TableHeader as Be, TableCell as P, TableBody as Le, TableRow as Re, Typography as u, ChevronRightIcon as He, Select as he, SelectItem as R, FileUpload as Je, UploadIcon as Ue, TextField as Ve, IconButton as ee, EditIcon as We, CenteredView as ze, CircularProgress as ge, Tooltip as te, FileUploadIcon as Ge, Dialog as ye, DialogContent as xe, DialogActions as be, Button as j, cn as L, defaultBorderMixin as Xe, GetAppIcon as qe, Alert as Qe, focusedMixin as U, BooleanSwitchWithLabel as Ye } from "@firecms/ui";
1
+ import C, { useState as j, useRef as Ie, useEffect as ce, useCallback as b, useMemo as Oe } from "react";
2
+ import { jsxs as p, Fragment as $, jsx as s } from "react/jsx-runtime";
3
+ import { getPropertyInPath as L, EntityReference as de, useCustomizationController as z, getFieldConfig as pe, ErrorBoundary as Ae, PropertyConfigBadge as fe, useDataSource as me, useSnackbarController as Ee, resolveCollection as ue, getPropertiesWithPropertiesOrder as Te, useSelectionController as je, EntityCollectionTable as Fe, getArrayValuesCount as ke, getValueInPath as Pe, useFireCMSContext as Me, useNavigationController as $e } from "@firecms/core";
4
+ import { Table as Le, TableHeader as _e, TableCell as M, TableBody as Be, TableRow as Re, Typography as u, ChevronRightIcon as He, Select as he, SelectItem as R, FileUpload as Je, UploadIcon as Ue, TextField as Ve, IconButton as ee, EditIcon as We, CenteredView as ze, CircularProgress as ge, Tooltip as te, FileUploadIcon as Ge, Dialog as ye, DialogContent as xe, DialogActions as be, Button as F, cn as B, 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 = () => {
8
- const [e, r] = T(!1), [n, t] = T(), [a, i] = T([]), [o, l] = T([]), [d, c] = T({}), [f, m] = T({});
8
+ const [e, r] = j(!1), [n, t] = j(), [a, i] = j([]), [o, l] = j([]), [d, c] = j({}), [f, m] = j({});
9
9
  return {
10
10
  inUse: e,
11
11
  setInUse: r,
@@ -73,12 +73,12 @@ function rt(e, r, n, t, a, i) {
73
73
  r && delete o[r];
74
74
  const l = Object.entries(o).map(([c, f]) => {
75
75
  const m = n[c] ?? c;
76
- if (!$(t, m))
76
+ if (!L(t, m))
77
77
  return {};
78
78
  const h = a[m];
79
- let D = f;
80
- return h && (D = Z(f, h)), {
81
- [m]: D
79
+ let S = f;
80
+ return h && (S = Z(f, h)), {
81
+ [m]: S
82
82
  };
83
83
  }).reduce((c, f) => ({ ...c, ...f }), {}), d = ve(l);
84
84
  return {
@@ -158,7 +158,7 @@ function at(e, r) {
158
158
  function n(t, a) {
159
159
  const i = {};
160
160
  return Object.keys(t).forEach((o) => {
161
- const l = a ? `${a}.${o}` : o, d = $(t, o), c = $(e, l);
161
+ const l = a ? `${a}.${o}` : o, d = L(t, o), c = L(e, l);
162
162
  if (d) {
163
163
  if (d.dataType === "map" && d.properties) {
164
164
  const f = n(d.properties, l);
@@ -190,7 +190,7 @@ function it({
190
190
  onIdPropertyChanged: a,
191
191
  buildPropertyView: i
192
192
  }) {
193
- return /* @__PURE__ */ p(M, { children: [
193
+ return /* @__PURE__ */ p($, { children: [
194
194
  /* @__PURE__ */ s(
195
195
  st,
196
196
  {
@@ -199,19 +199,19 @@ function it({
199
199
  onChange: a
200
200
  }
201
201
  ),
202
- /* @__PURE__ */ p(_e, { style: {
202
+ /* @__PURE__ */ p(Le, { style: {
203
203
  tableLayout: "fixed"
204
204
  }, children: [
205
- /* @__PURE__ */ p(Be, { children: [
206
- /* @__PURE__ */ s(P, { header: !0, style: { width: "20%" }, children: "Column in file" }),
207
- /* @__PURE__ */ s(P, { header: !0 }),
208
- /* @__PURE__ */ s(P, { header: !0, style: { width: "75%" }, children: "Property" })
205
+ /* @__PURE__ */ p(_e, { children: [
206
+ /* @__PURE__ */ s(M, { header: !0, style: { width: "20%" }, children: "Column in file" }),
207
+ /* @__PURE__ */ s(M, { header: !0 }),
208
+ /* @__PURE__ */ s(M, { header: !0, style: { width: "75%" }, children: "Property" })
209
209
  ] }),
210
- /* @__PURE__ */ s(Le, { children: t && Object.entries(r).map(
210
+ /* @__PURE__ */ s(Be, { children: t && Object.entries(r).map(
211
211
  ([o, l]) => {
212
- const d = r[o], c = l ? $(t, l) : null, f = $(n, o), m = f ? f.dataType === "array" && typeof f.of == "object" ? `${f.dataType} - ${f.of.dataType}` : f.dataType : void 0;
212
+ const d = r[o], c = l ? L(t, l) : null, f = L(n, o), m = f ? f.dataType === "array" && typeof f.of == "object" ? `${f.dataType} - ${f.of.dataType}` : f.dataType : void 0;
213
213
  return /* @__PURE__ */ p(Re, { style: { height: "90px" }, children: [
214
- /* @__PURE__ */ p(P, { style: { width: "20%" }, children: [
214
+ /* @__PURE__ */ p(M, { style: { width: "20%" }, children: [
215
215
  /* @__PURE__ */ s(u, { variant: "body2", children: o }),
216
216
  f && /* @__PURE__ */ s(
217
217
  u,
@@ -222,9 +222,9 @@ function it({
222
222
  }
223
223
  )
224
224
  ] }),
225
- /* @__PURE__ */ s(P, { children: /* @__PURE__ */ s(He, {}) }),
225
+ /* @__PURE__ */ s(M, { children: /* @__PURE__ */ s(He, {}) }),
226
226
  /* @__PURE__ */ s(
227
- P,
227
+ M,
228
228
  {
229
229
  className: o === e ? "text-center" : void 0,
230
230
  style: { width: "75%" },
@@ -281,7 +281,7 @@ function ot({ onDataAdded: e }) {
281
281
  preventDropOnDocument: !0,
282
282
  size: "small",
283
283
  maxFiles: 1,
284
- uploadDescription: /* @__PURE__ */ p(M, { children: [
284
+ uploadDescription: /* @__PURE__ */ p($, { children: [
285
285
  /* @__PURE__ */ s(Ue, {}),
286
286
  "Drag and drop a file here or click to upload"
287
287
  ] }),
@@ -331,7 +331,7 @@ function lt({
331
331
  collection: r,
332
332
  onImportSuccess: n
333
333
  }) {
334
- const t = me(), a = Ie(!1), [i, o] = T(0);
334
+ const t = me(), a = Ie(!1), [i, o] = j(0);
335
335
  function l() {
336
336
  a.current || (a.current = !0, we(
337
337
  t,
@@ -383,27 +383,27 @@ function ct({
383
383
  d("preview");
384
384
  }, []), h = b(() => {
385
385
  d("import_data_saving");
386
- }, []), D = async (g) => {
386
+ }, []), S = async (g) => {
387
387
  if (c.setImportData(g), g.length > 0) {
388
- const I = await Ze(g, nt);
389
- c.setOriginProperties(I);
390
- const O = Se(g);
391
- c.setHeadersMapping(O);
392
- const A = Object.keys(O)?.[0];
393
- if (A?.includes("id") || A?.includes("key")) {
394
- const w = A;
388
+ const O = await Ze(g, nt);
389
+ c.setOriginProperties(O);
390
+ const A = Se(g);
391
+ c.setHeadersMapping(A);
392
+ const E = Object.keys(A)?.[0];
393
+ if (E?.includes("id") || E?.includes("key")) {
394
+ const w = E;
395
395
  c.setIdColumn(w);
396
396
  }
397
397
  }
398
398
  setTimeout(() => {
399
399
  d("mapping");
400
400
  }, 100);
401
- }, S = ue({
401
+ }, N = ue({
402
402
  collection: e,
403
403
  path: r,
404
404
  fields: t.propertyConfigs
405
- }), _ = Te(S.properties, S.propertiesOrder), N = Object.entries(_).flatMap(([g, I]) => De(g, I, 0)), H = S.propertiesOrder ?? Object.keys(S.properties);
406
- return e.collectionGroup ? null : /* @__PURE__ */ p(M, { children: [
405
+ }), _ = Te(N.properties, N.propertiesOrder), I = Object.entries(_).flatMap(([g, O]) => De(g, O, 0)), H = N.propertiesOrder ?? Object.keys(N.properties);
406
+ return e.collectionGroup ? null : /* @__PURE__ */ p($, { children: [
407
407
  /* @__PURE__ */ s(te, { title: "Import", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: f, children: /* @__PURE__ */ s(Ge, {}) }) }),
408
408
  /* @__PURE__ */ p(
409
409
  ye,
@@ -414,12 +414,12 @@ function ct({
414
414
  maxWidth: l === "initial" ? "lg" : "7xl",
415
415
  children: [
416
416
  /* @__PURE__ */ p(xe, { className: "flex flex-col gap-4 my-4", fullHeight: l === "preview", children: [
417
- l === "initial" && /* @__PURE__ */ p(M, { children: [
417
+ l === "initial" && /* @__PURE__ */ p($, { children: [
418
418
  /* @__PURE__ */ s(u, { variant: "h6", children: "Import data" }),
419
419
  /* @__PURE__ */ s(u, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
420
- /* @__PURE__ */ s(ot, { onDataAdded: D })
420
+ /* @__PURE__ */ s(ot, { onDataAdded: S })
421
421
  ] }),
422
- l === "mapping" && /* @__PURE__ */ p(M, { children: [
422
+ l === "mapping" && /* @__PURE__ */ p($, { children: [
423
423
  /* @__PURE__ */ s(u, { variant: "h6", children: "Map fields" }),
424
424
  /* @__PURE__ */ s(
425
425
  it,
@@ -431,21 +431,21 @@ function ct({
431
431
  onIdPropertyChanged: (g) => c.setIdColumn(g),
432
432
  buildPropertyView: ({
433
433
  isIdColumn: g,
434
- property: I,
435
- propertyKey: O,
436
- importKey: A
434
+ property: O,
435
+ propertyKey: A,
436
+ importKey: E
437
437
  }) => /* @__PURE__ */ s(
438
438
  dt,
439
439
  {
440
- selectedPropertyKey: O ?? "",
440
+ selectedPropertyKey: A ?? "",
441
441
  properties: _,
442
- propertiesAndLevel: N,
442
+ propertiesAndLevel: I,
443
443
  isIdColumn: g,
444
444
  onIdSelected: () => {
445
- c.setIdColumn(A);
445
+ c.setIdColumn(E);
446
446
  },
447
447
  onPropertySelected: (w) => {
448
- const G = Object.entries(c.headersMapping).map(([x, F]) => F === w ? { [x]: null } : x === A ? { [x]: w } : { [x]: F }).reduce((x, F) => ({ ...x, ...F }), {});
448
+ const G = Object.entries(c.headersMapping).map(([x, k]) => k === w ? { [x]: null } : x === E ? { [x]: w } : { [x]: k }).reduce((x, k) => ({ ...x, ...k }), {});
449
449
  c.setHeadersMapping(G), w === c.idColumn && c.setIdColumn(void 0);
450
450
  }
451
451
  }
@@ -477,7 +477,7 @@ function ct({
477
477
  ] }),
478
478
  /* @__PURE__ */ p(be, { children: [
479
479
  l === "mapping" && /* @__PURE__ */ s(
480
- j,
480
+ F,
481
481
  {
482
482
  onClick: () => d("initial"),
483
483
  variant: "text",
@@ -485,7 +485,7 @@ function ct({
485
485
  }
486
486
  ),
487
487
  l === "preview" && /* @__PURE__ */ s(
488
- j,
488
+ F,
489
489
  {
490
490
  onClick: () => d("mapping"),
491
491
  variant: "text",
@@ -493,7 +493,7 @@ function ct({
493
493
  }
494
494
  ),
495
495
  /* @__PURE__ */ s(
496
- j,
496
+ F,
497
497
  {
498
498
  onClick: m,
499
499
  variant: "text",
@@ -501,7 +501,7 @@ function ct({
501
501
  }
502
502
  ),
503
503
  l === "mapping" && /* @__PURE__ */ s(
504
- j,
504
+ F,
505
505
  {
506
506
  variant: "filled",
507
507
  onClick: y,
@@ -509,7 +509,7 @@ function ct({
509
509
  }
510
510
  ),
511
511
  l === "preview" && /* @__PURE__ */ s(
512
- j,
512
+ F,
513
513
  {
514
514
  variant: "filled",
515
515
  onClick: h,
@@ -531,7 +531,7 @@ function dt({
531
531
  propertiesAndLevel: a,
532
532
  isIdColumn: i
533
533
  }) {
534
- const o = e ? $(r, e) : null, l = b((c) => c === V ? /* @__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(
534
+ const o = e ? L(r, e) : null, l = b((c) => c === V ? /* @__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(
535
535
  se,
536
536
  {
537
537
  propertyKey: c,
@@ -594,7 +594,7 @@ function se({
594
594
  {
595
595
  className: "flex flex-row w-full text-start items-center h-full",
596
596
  children: [
597
- new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: L(Xe, "ml-8 border-l h-12") }, o)),
597
+ new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: B(Xe, "ml-8 border-l h-12") }, o)),
598
598
  /* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(te, { title: a?.name, children: /* @__PURE__ */ s(fe, { propertyConfig: a }) }) }),
599
599
  /* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
600
600
  /* @__PURE__ */ s(
@@ -667,6 +667,7 @@ function Se(e) {
667
667
  }), r;
668
668
  }
669
669
  function ft(e, r, n, t, a, i, o) {
670
+ console.debug("Downloading export", { dataLength: e.length, collection: n, exportType: i, dateExportType: o });
670
671
  const l = n.properties;
671
672
  if (i === "csv") {
672
673
  const d = t ? ke(e.map((h) => h.values)) : {}, c = ht(l, a, d), f = mt(e, r, l, c, o), m = oe(c.map((h) => h.label)), y = f.map((h) => oe(h));
@@ -744,48 +745,50 @@ function yt({
744
745
  exportAllowed: t,
745
746
  notAllowedView: a
746
747
  }) {
747
- const i = z(), 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"), D = Me(), S = me(), N = $e().resolveAliasesFrom(r), H = !t || t({
748
+ const i = z(), 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(), I = $e().resolveAliasesFrom(r), H = !t || t({
748
749
  collectionEntitiesCount: n,
749
- path: N,
750
+ path: I,
750
751
  collection: e
751
752
  }), g = C.useMemo(() => ue({
752
753
  collection: e,
753
- path: N,
754
+ path: I,
754
755
  fields: i.propertyConfigs
755
- }), [e, N]), [I, O] = C.useState(!1), [A, w] = C.useState(), [G, x] = C.useState(!1), F = b(() => {
756
+ }), [e, I]), [O, A] = C.useState(!1), [E, w] = C.useState(), [G, x] = C.useState(!1), k = b(() => {
756
757
  x(!0);
757
758
  }, [x]), X = b(() => {
758
759
  x(!1);
759
- }, [x]), ne = b(async (k) => {
760
- const J = o?.additionalFields, B = g.additionalFields, q = J ? await Promise.all(k.map(async (E) => (await Promise.all(J.map(async (v) => ({
760
+ }, [x]), ne = b(async (P) => {
761
+ const J = o?.additionalFields, D = g.additionalFields, q = J ? await Promise.all(P.map(async (T) => (await Promise.all(J.map(async (v) => ({
761
762
  [v.key]: await v.builder({
762
- entity: E,
763
- context: D
763
+ entity: T,
764
+ context: S
764
765
  })
765
- })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = B ? await Promise.all(k.map(async (E) => (await Promise.all(B.map(async (v) => v.value ? {
766
+ })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = D ? await Promise.all(P.map(async (T) => (await Promise.all(D.map(async (v) => v.value ? {
766
767
  [v.key]: await v.value({
767
- entity: E,
768
- context: D
768
+ entity: T,
769
+ context: S
769
770
  })
770
771
  } : {}))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [];
771
772
  return [...q, ...Q];
772
- }, [o?.additionalFields]), ae = b(async (k, J) => {
773
- O(!0), S.fetchCollection({
774
- path: N,
775
- collection: k
776
- }).then(async (B) => {
773
+ }, [o?.additionalFields]), ae = b(async (P, J) => {
774
+ A(!0), N.fetchCollection({
775
+ path: I,
776
+ collection: P
777
+ }).then(async (D) => {
777
778
  w(void 0);
778
- const q = await ne(B), Q = [
779
- ...J?.additionalFields?.map((E) => E.key) ?? [],
780
- ...k.additionalFields?.map((E) => E.key) ?? []
779
+ const q = await ne(D), Q = [
780
+ ...J?.additionalFields?.map((T) => T.key) ?? [],
781
+ ...P.additionalFields?.map((T) => T.key) ?? []
781
782
  ];
782
- ft(B, q, k, d, Q, f, y);
783
- }).catch(w).finally(() => O(!1));
784
- }, [S, N, ne, d, f, y]), Ne = b(() => {
783
+ ft(D, q, P, d, Q, f, y);
784
+ }).catch((D) => {
785
+ console.error("Error loading export data", D), w(D);
786
+ }).finally(() => A(!1));
787
+ }, [N, I, ne, d, f, y]), Ne = b(() => {
785
788
  ae(g, o), X();
786
789
  }, [ae, g, o, X]);
787
- return /* @__PURE__ */ p(M, { children: [
788
- /* @__PURE__ */ s(te, { title: "Export", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: F, children: /* @__PURE__ */ s(qe, {}) }) }),
790
+ return /* @__PURE__ */ p($, { children: [
791
+ /* @__PURE__ */ s(te, { title: "Export", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: k, children: /* @__PURE__ */ s(qe, {}) }) }),
789
792
  /* @__PURE__ */ p(
790
793
  ye,
791
794
  {
@@ -813,7 +816,7 @@ function yt({
813
816
  name: "exportType",
814
817
  checked: f === "csv",
815
818
  onChange: () => m("csv"),
816
- className: L(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
819
+ className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
817
820
  }
818
821
  ),
819
822
  /* @__PURE__ */ s(
@@ -835,7 +838,7 @@ function yt({
835
838
  name: "exportType",
836
839
  checked: f === "json",
837
840
  onChange: () => m("json"),
838
- className: L(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
841
+ className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
839
842
  }
840
843
  ),
841
844
  /* @__PURE__ */ s(
@@ -859,7 +862,7 @@ function yt({
859
862
  name: "dateExportType",
860
863
  checked: y === "timestamp",
861
864
  onChange: () => h("timestamp"),
862
- className: L(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
865
+ className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
863
866
  }
864
867
  ),
865
868
  /* @__PURE__ */ p(
@@ -885,7 +888,7 @@ function yt({
885
888
  name: "dateExportType",
886
889
  checked: y === "string",
887
890
  onChange: () => h("string"),
888
- className: L(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
891
+ className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
889
892
  }
890
893
  ),
891
894
  /* @__PURE__ */ p(
@@ -916,9 +919,9 @@ function yt({
916
919
  !H && a
917
920
  ] }),
918
921
  /* @__PURE__ */ p(be, { children: [
919
- I && /* @__PURE__ */ s(ge, { size: "small" }),
922
+ O && /* @__PURE__ */ s(ge, { size: "small" }),
920
923
  /* @__PURE__ */ s(
921
- j,
924
+ F,
922
925
  {
923
926
  onClick: X,
924
927
  variant: "text",
@@ -926,11 +929,11 @@ function yt({
926
929
  }
927
930
  ),
928
931
  /* @__PURE__ */ s(
929
- j,
932
+ F,
930
933
  {
931
934
  variant: "filled",
932
935
  onClick: Ne,
933
- disabled: I || !H,
936
+ disabled: O || !H,
934
937
  children: "Download"
935
938
  }
936
939
  )