@firecms/data_import_export 3.0.0-canary.3 → 3.0.0-canary.30

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,221 +1,222 @@
1
- import C, { useState as j, useRef as Ie, useEffect as ce, useCallback as x, useMemo as Ae } from "react";
2
- import { jsxs as p, Fragment as $, jsx as s } from "react/jsx-runtime";
3
- import { getPropertyInPath as L, EntityReference as de, useSnackbarController as pe, useCustomizationController as z, getFieldConfig as fe, ErrorBoundary as Ee, PropertyConfigBadge as me, useDataSource as ue, resolveCollection as he, 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 Le, TableHeader as _e, TableCell as M, TableBody as Be, TableRow as Je, Typography as u, ChevronRightIcon as Re, Select as ge, SelectItem as J, FileUpload as He, UploadIcon as Ue, TextField as Ve, IconButton as ee, EditIcon as We, CenteredView as ze, CircularProgress as ye, Tooltip as te, FileUploadIcon as Ge, Dialog as be, DialogContent as xe, DialogActions as ve, Button as k, cn as B, defaultBorderMixin as Xe, GetAppIcon as qe, Alert as Qe, focusedMixin as U, BooleanSwitchWithLabel as Ye } from "@firecms/ui";
5
- import { buildEntityPropertiesFromData as Ze } from "@firecms/schema_inference";
6
- import * as ie from "xlsx";
7
- const Ke = () => {
8
- const [e, r] = j(!1), [n, t] = j(), [a, i] = j([]), [o, l] = j([]), [d, c] = j({}), [f, m] = j({});
1
+ import C, { useState as O, useRef as Ee, useEffect as de, useCallback as b, useMemo as Ie } from "react";
2
+ import { jsxs as f, Fragment as M, jsx as o } from "react/jsx-runtime";
3
+ import { getPropertyInPath as _, EntityReference as Ae, useSnackbarController as pe, useCustomizationController as X, getFieldConfig as fe, ErrorBoundary as Te, PropertyConfigBadge as me, useDataSource as ue, resolveCollection as he, getPropertiesWithPropertiesOrder as je, useSelectionController as Fe, EntityCollectionTable as Pe, slugify as ke, getArrayValuesCount as Me, getValueInPath as _e, useFireCMSContext as $e, useNavigationController as Re } from "@firecms/core";
4
+ import { Table as Le, TableHeader as Be, TableCell as k, TableBody as Je, TableRow as He, Typography as u, ChevronRightIcon as Ue, Select as ge, SelectItem as H, FileUpload as We, UploadIcon as ze, TextField as Ve, IconButton as ee, EditIcon as Ge, CenteredView as ie, Button as E, CircularProgress as ye, Tooltip as te, FileUploadIcon as Xe, Dialog as be, DialogContent as xe, DialogActions as ve, cn as J, defaultBorderMixin as qe, GetAppIcon as Qe, Alert as Ye, focusedMixin as z, BooleanSwitchWithLabel as Ze } from "@firecms/ui";
5
+ import { buildEntityPropertiesFromData as Ke } from "@firecms/schema_inference";
6
+ import * as oe from "xlsx";
7
+ const et = () => {
8
+ const [e, r] = O(!1), [a, t] = O(), [n, i] = O([]), [s, d] = O([]), [c, l] = O({}), [p, m] = O({});
9
9
  return {
10
10
  inUse: e,
11
11
  setInUse: r,
12
- idColumn: n,
12
+ idColumn: a,
13
13
  setIdColumn: t,
14
- entities: o,
15
- setEntities: l,
16
- importData: a,
14
+ entities: s,
15
+ setEntities: d,
16
+ importData: n,
17
17
  setImportData: i,
18
- headersMapping: d,
19
- setHeadersMapping: c,
20
- originProperties: f,
18
+ headersMapping: c,
19
+ setHeadersMapping: l,
20
+ originProperties: p,
21
21
  setOriginProperties: m
22
22
  };
23
23
  };
24
- function et(e) {
25
- return new Promise((r, n) => {
24
+ function tt(e) {
25
+ return new Promise((r, a) => {
26
26
  if (e.type === "application/json") {
27
27
  console.debug("Converting JSON file to JSON", e.name);
28
28
  const t = new FileReader();
29
- t.onload = function(a) {
30
- const i = a.target?.result, o = JSON.parse(i);
31
- Array.isArray(o) || n(new Error("JSON file should contain an array of objects")), r(o);
29
+ t.onload = function(n) {
30
+ const i = n.target?.result, s = JSON.parse(i);
31
+ Array.isArray(s) || a(new Error("JSON file should contain an array of objects")), r(s);
32
32
  }, t.readAsText(e);
33
33
  } else {
34
34
  console.debug("Converting Excel file to JSON", e.name);
35
35
  const t = new FileReader();
36
- t.onload = function(a) {
37
- const i = new Uint8Array(a.target?.result), o = ie.read(
36
+ t.onload = function(n) {
37
+ const i = new Uint8Array(n.target?.result), s = oe.read(
38
38
  i,
39
39
  {
40
40
  type: "array",
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(Ce);
44
+ ), d = s.SheetNames[0], c = s.Sheets[d], m = oe.utils.sheet_to_json(c).map(rt).map(Ce);
45
45
  r(m);
46
46
  }, t.readAsArrayBuffer(e);
47
47
  }
48
48
  });
49
49
  }
50
- function tt(e) {
51
- return Object.keys(e).reduce((r, n) => {
50
+ function rt(e) {
51
+ return Object.keys(e).reduce((r, a) => {
52
52
  try {
53
- r[n] = JSON.parse(e[n]);
53
+ r[a] = JSON.parse(e[a]);
54
54
  } catch {
55
- r[n] = e[n];
55
+ r[a] = e[a];
56
56
  }
57
57
  return r;
58
58
  }, {});
59
59
  }
60
60
  function Ce(e) {
61
- return Object.keys(e).reduce((r, n) => {
61
+ return Object.keys(e).reduce((r, a) => {
62
62
  let t = r;
63
- const a = n.split(".");
64
- return a.forEach((i, o) => {
63
+ const n = a.split(".");
64
+ return n.forEach((i, s) => {
65
65
  if (/^[\w]+\[\d+\]$/.test(i)) {
66
- const l = i.slice(0, i.indexOf("[")), d = parseInt(i.slice(i.indexOf("[") + 1, i.indexOf("]")));
67
- t[l] || (t[l] = []), o !== a.length - 1 ? (t[l][d] = t[l][d] || {}, t = t[l][d]) : t[l][d] = e[n];
66
+ const d = i.slice(0, i.indexOf("[")), c = parseInt(i.slice(i.indexOf("[") + 1, i.indexOf("]")));
67
+ t[d] || (t[d] = []), s !== n.length - 1 ? (t[d][c] = t[d][c] || {}, t = t[d][c]) : t[d][c] = e[a];
68
68
  } else
69
- o !== a.length - 1 ? (t[i] = t[i] || {}, t = t[i]) : t[i] = e[n];
69
+ s !== n.length - 1 ? (t[i] = t[i] || {}, t = t[i]) : t[i] = e[a];
70
70
  }), r;
71
71
  }, {});
72
72
  }
73
- function rt(e, r, n, t, a, i) {
74
- const o = we(e);
75
- r && delete o[r];
76
- const l = Object.entries(o).map(([c, f]) => {
77
- const m = n[c] ?? c;
78
- if (!L(t, m))
73
+ function nt(e, r, a, t, n, i) {
74
+ const s = we(e);
75
+ r && delete s[r];
76
+ const d = Object.entries(s).map(([p, m]) => {
77
+ const h = a[p] ?? p;
78
+ if (!_(t, h))
79
79
  return {};
80
- const h = a[m];
81
- let S = f;
82
- return h && (S = Z(f, h)), {
83
- [m]: S
80
+ const I = n[h];
81
+ let A = m;
82
+ return I && (A = Z(m, I)), {
83
+ [h]: A
84
84
  };
85
- }).reduce((c, f) => ({ ...c, ...f }), {}), d = Ce(l);
86
- return {
87
- id: r ? e[r] : void 0,
88
- values: d,
85
+ }).reduce((p, m) => ({ ...p, ...m }), {}), c = Ce(d);
86
+ let l = r ? e[r] : void 0;
87
+ return typeof l == "string" ? l = l.trim() : typeof l == "number" || typeof l == "boolean" ? l = l.toString() : l instanceof Date ? l = l.toISOString() : l && "toString" in l && (l = l.toString()), {
88
+ id: l,
89
+ values: c,
89
90
  path: i
90
91
  };
91
92
  }
92
93
  function we(e, r = "") {
93
- return Object.keys(e).reduce((n, t) => {
94
- const a = r ? `${r}.${t}` : t;
95
- return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(n, we(e[t], a)) : n[a] = e[t], n;
94
+ return Object.keys(e).reduce((a, t) => {
95
+ const n = r ? `${r}.${t}` : t;
96
+ return typeof e[t] == "object" && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(a, we(e[t], n)) : a[n] = e[t], a;
96
97
  }, {});
97
98
  }
98
99
  function Z(e, r) {
99
100
  if (r === void 0)
100
101
  return e;
101
102
  const {
102
- from: n,
103
+ from: a,
103
104
  to: t
104
105
  } = r;
105
- if (n === "array" && t === "array" && r.fromSubtype && r.toSubtype && Array.isArray(e))
106
- return e.map((a) => Z(a, {
106
+ if (a === "array" && t === "array" && r.fromSubtype && r.toSubtype && Array.isArray(e))
107
+ return e.map((n) => Z(n, {
107
108
  from: r.fromSubtype,
108
109
  to: r.toSubtype
109
110
  }));
110
- if (n === "string" && t === "number" && typeof e == "string")
111
+ if (a === "string" && t === "number" && typeof e == "string")
111
112
  return Number(e);
112
- if (n === "string" && t === "array" && r.toSubtype && typeof e == "string")
113
- return e.split(",").map((a) => Z(a, {
113
+ if (a === "string" && t === "array" && r.toSubtype && typeof e == "string")
114
+ return e.split(",").map((n) => Z(n, {
114
115
  from: "string",
115
116
  to: r.toSubtype
116
117
  }));
117
- if (n === "string" && t === "boolean")
118
+ if (a === "string" && t === "boolean")
118
119
  return e === "true";
119
- if (n === "number" && t === "boolean")
120
+ if (a === "number" && t === "boolean")
120
121
  return e === 1;
121
- if (n === "boolean" && t === "number")
122
+ if (a === "boolean" && t === "number")
122
123
  return e ? 1 : 0;
123
- if (n === "boolean" && t === "string")
124
+ if (a === "boolean" && t === "string")
124
125
  return e ? "true" : "false";
125
- if (n === "number" && t === "string" && typeof e == "number")
126
+ if (a === "number" && t === "string" && typeof e == "number")
126
127
  return e.toString();
127
- if (n === "string" && t === "array" && typeof e == "string")
128
- return e.split(",").map((a) => a.trim());
129
- if (n === "string" && t === "date" && typeof e == "string")
128
+ if (a === "string" && t === "array" && typeof e == "string")
129
+ return e.split(",").map((n) => n.trim());
130
+ if (a === "string" && t === "date" && typeof e == "string")
130
131
  try {
131
132
  return new Date(e);
132
133
  } catch {
133
134
  return e;
134
135
  }
135
136
  else {
136
- if (n === "date" && t === "string")
137
+ if (a === "date" && t === "string")
137
138
  return e instanceof Date && e.toISOString();
138
- if (n === "number" && t === "date" && typeof e == "number")
139
+ if (a === "number" && t === "date" && typeof e == "number")
139
140
  try {
140
141
  return new Date(e);
141
142
  } catch {
142
143
  return e;
143
144
  }
144
- else if (n === "string" && t === "reference" && typeof e == "string") {
145
- const a = e.split("/").slice(0, -1).join("/"), i = e.split("/").slice(-1)[0];
146
- return new de(i, a);
145
+ else if (a === "string" && t === "reference" && typeof e == "string") {
146
+ const n = e.split("/").slice(0, -1).join("/"), i = e.split("/").slice(-1)[0];
147
+ return new Ae(i, n);
147
148
  } else {
148
- if (n === t)
149
+ if (a === t)
149
150
  return e;
150
- if (n === "array" && t === "string" && Array.isArray(e))
151
+ if (a === "array" && t === "string" && Array.isArray(e))
151
152
  return e.join(",");
152
153
  }
153
154
  }
154
155
  return e;
155
156
  }
156
- function nt(e) {
157
+ function at(e) {
157
158
  return typeof e == "number" ? "number" : typeof e == "string" ? "string" : typeof e == "boolean" ? "boolean" : e instanceof Date ? "date" : Array.isArray(e) ? "array" : "map";
158
159
  }
159
- function at(e, r) {
160
- function n(t, a) {
160
+ function it(e, r) {
161
+ function a(t, n) {
161
162
  const i = {};
162
- return Object.keys(t).forEach((o) => {
163
- const l = a ? `${a}.${o}` : o, d = L(t, o), c = L(e, l);
164
- if (d) {
165
- if (d.dataType === "map" && d.properties) {
166
- const f = n(d.properties, l);
167
- Object.keys(f).forEach((m) => {
168
- i[`${l}.${m}`] = f[m];
163
+ return Object.keys(t).forEach((s) => {
164
+ const d = n ? `${n}.${s}` : s, c = _(t, s), l = _(e, d);
165
+ if (c) {
166
+ if (c.dataType === "map" && c.properties) {
167
+ const p = a(c.properties, d);
168
+ Object.keys(p).forEach((m) => {
169
+ i[`${d}.${m}`] = p[m];
169
170
  });
170
171
  return;
171
172
  }
172
- if (c) {
173
- const f = c.dataType, m = d.dataType;
174
- let y, h;
175
- d.dataType === "array" && d.of && (h = d.of.dataType), c?.dataType === "array" && c?.of && (y = c.of.dataType), (f !== m || y !== h) && (i[o] = {
176
- from: f,
173
+ if (l) {
174
+ const p = l.dataType, m = c.dataType;
175
+ let h, g;
176
+ c.dataType === "array" && c.of && (g = c.of.dataType), l?.dataType === "array" && l?.of && (h = l.of.dataType), (p !== m || h !== g) && (i[s] = {
177
+ from: p,
177
178
  to: m,
178
- fromSubtype: y,
179
- toSubtype: h
179
+ fromSubtype: h,
180
+ toSubtype: g
180
181
  });
181
182
  }
182
183
  }
183
184
  }), i;
184
185
  }
185
- return n(r);
186
+ return a(r);
186
187
  }
187
- function it({
188
+ function ot({
188
189
  idColumn: e,
189
190
  headersMapping: r,
190
- originProperties: n,
191
+ originProperties: a,
191
192
  destinationProperties: t,
192
- onIdPropertyChanged: a,
193
+ onIdPropertyChanged: n,
193
194
  buildPropertyView: i
194
195
  }) {
195
- return /* @__PURE__ */ p($, { children: [
196
- /* @__PURE__ */ s(
196
+ return /* @__PURE__ */ f(M, { children: [
197
+ /* @__PURE__ */ o(
197
198
  st,
198
199
  {
199
200
  idColumn: e,
200
201
  headersMapping: r,
201
- onChange: a
202
+ onChange: n
202
203
  }
203
204
  ),
204
- /* @__PURE__ */ p(Le, { style: {
205
+ /* @__PURE__ */ f(Le, { style: {
205
206
  tableLayout: "fixed"
206
207
  }, children: [
207
- /* @__PURE__ */ p(_e, { children: [
208
- /* @__PURE__ */ s(M, { header: !0, style: { width: "20%" }, children: "Column in file" }),
209
- /* @__PURE__ */ s(M, { header: !0 }),
210
- /* @__PURE__ */ s(M, { header: !0, style: { width: "75%" }, children: "Property" })
208
+ /* @__PURE__ */ f(Be, { children: [
209
+ /* @__PURE__ */ o(k, { header: !0, style: { width: "20%" }, children: "Column in file" }),
210
+ /* @__PURE__ */ o(k, { header: !0 }),
211
+ /* @__PURE__ */ o(k, { header: !0, style: { width: "75%" }, children: "Property" })
211
212
  ] }),
212
- /* @__PURE__ */ s(Be, { children: t && Object.entries(r).map(
213
- ([o, l]) => {
214
- 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;
215
- return /* @__PURE__ */ p(Je, { style: { height: "90px" }, children: [
216
- /* @__PURE__ */ p(M, { style: { width: "20%" }, children: [
217
- /* @__PURE__ */ s(u, { variant: "body2", children: o }),
218
- f && /* @__PURE__ */ s(
213
+ /* @__PURE__ */ o(Je, { children: t && Object.entries(r).map(
214
+ ([s, d]) => {
215
+ const c = r[s], l = d ? _(t, d) : null, p = _(a, s), m = p ? p.dataType === "array" && typeof p.of == "object" ? `${p.dataType} - ${p.of.dataType}` : p.dataType : void 0;
216
+ return /* @__PURE__ */ f(He, { style: { height: "90px" }, children: [
217
+ /* @__PURE__ */ f(k, { style: { width: "20%" }, children: [
218
+ /* @__PURE__ */ o(u, { variant: "body2", children: s }),
219
+ p && /* @__PURE__ */ o(
219
220
  u,
220
221
  {
221
222
  variant: "caption",
@@ -224,21 +225,21 @@ function it({
224
225
  }
225
226
  )
226
227
  ] }),
227
- /* @__PURE__ */ s(M, { children: /* @__PURE__ */ s(Re, {}) }),
228
- /* @__PURE__ */ s(
229
- M,
228
+ /* @__PURE__ */ o(k, { children: /* @__PURE__ */ o(Ue, {}) }),
229
+ /* @__PURE__ */ o(
230
+ k,
230
231
  {
231
- className: o === e ? "text-center" : void 0,
232
+ className: s === e ? "text-center" : void 0,
232
233
  style: { width: "75%" },
233
234
  children: i?.({
234
- isIdColumn: o === e,
235
- property: c,
236
- propertyKey: d,
237
- importKey: o
235
+ isIdColumn: s === e,
236
+ property: l,
237
+ propertyKey: c,
238
+ importKey: s
238
239
  })
239
240
  }
240
241
  )
241
- ] }, o);
242
+ ] }, s);
242
243
  }
243
244
  ) })
244
245
  ] })
@@ -247,29 +248,30 @@ function it({
247
248
  function st({
248
249
  idColumn: e,
249
250
  headersMapping: r,
250
- onChange: n
251
+ onChange: a
251
252
  }) {
252
- return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ p(
253
+ return /* @__PURE__ */ o("div", { children: /* @__PURE__ */ f(
253
254
  ge,
254
255
  {
255
256
  size: "small",
256
257
  value: e ?? "",
257
258
  onChange: (t) => {
258
- n(t.target.value);
259
+ const n = t.target.value;
260
+ a(n === "none" ? null : n);
259
261
  },
260
- renderValue: (t) => /* @__PURE__ */ s(u, { variant: "body2", children: t !== "" ? t : "Autogenerate ID" }),
262
+ renderValue: (t) => /* @__PURE__ */ o(u, { variant: "body2", children: t !== "" ? t : "Autogenerate ID" }),
261
263
  label: "Column that will be used as ID for each document",
262
264
  children: [
263
- /* @__PURE__ */ s(J, { value: "", children: "Autogenerate ID" }),
264
- Object.entries(r).map(([t, a]) => /* @__PURE__ */ s(J, { value: t, children: t }, t))
265
+ /* @__PURE__ */ o(H, { value: "none", children: "Autogenerate ID" }),
266
+ Object.entries(r).map(([t, n]) => /* @__PURE__ */ o(H, { value: t, children: t }, t))
265
267
  ]
266
268
  }
267
269
  ) });
268
270
  }
269
- function ot({ onDataAdded: e }) {
271
+ function lt({ onDataAdded: e }) {
270
272
  const r = pe();
271
- return /* @__PURE__ */ s(
272
- He,
273
+ return /* @__PURE__ */ o(
274
+ We,
273
275
  {
274
276
  accept: {
275
277
  "text/*": [".csv", ".xls", ".xlsx"],
@@ -284,12 +286,12 @@ function ot({ onDataAdded: e }) {
284
286
  preventDropOnDocument: !0,
285
287
  size: "small",
286
288
  maxFiles: 1,
287
- uploadDescription: /* @__PURE__ */ p($, { children: [
288
- /* @__PURE__ */ s(Ue, {}),
289
+ uploadDescription: /* @__PURE__ */ f(M, { children: [
290
+ /* @__PURE__ */ o(ze, {}),
289
291
  "Drag and drop a file here or click to upload"
290
292
  ] }),
291
- onFilesAdded: (n) => {
292
- n.length > 0 && et(n[0]).then((t) => {
293
+ onFilesAdded: (a) => {
294
+ a.length > 0 && tt(a[0]).then((t) => {
293
295
  e(t);
294
296
  }).catch((t) => {
295
297
  console.error("Error parsing file", t), r.open({ type: "error", message: t.message });
@@ -301,178 +303,191 @@ function ot({ onDataAdded: e }) {
301
303
  function Dt({
302
304
  propertyKey: e,
303
305
  property: r,
304
- onEditClick: n,
306
+ onEditClick: a,
305
307
  includeName: t = !0,
306
- onPropertyNameChanged: a,
308
+ onPropertyNameChanged: n,
307
309
  propertyTypeView: i
308
310
  }) {
309
- const { propertyConfigs: o } = z(), l = r ? fe(r, o) : null;
310
- return /* @__PURE__ */ s(Ee, { children: /* @__PURE__ */ p(
311
+ const { propertyConfigs: s } = X(), d = r ? fe(r, s) : null;
312
+ return /* @__PURE__ */ o(Te, { children: /* @__PURE__ */ f(
311
313
  "div",
312
314
  {
313
315
  className: "flex flex-row w-full items-center",
314
316
  children: [
315
- /* @__PURE__ */ s("div", { className: "mx-4", children: i ?? /* @__PURE__ */ s(me, { propertyConfig: l ?? void 0 }) }),
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
- t && /* @__PURE__ */ s(
317
+ /* @__PURE__ */ o("div", { className: "mx-4", children: i ?? /* @__PURE__ */ o(me, { propertyConfig: d ?? void 0 }) }),
318
+ /* @__PURE__ */ o("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ f("div", { className: "flex flex-row items-center gap-2", children: [
319
+ t && /* @__PURE__ */ o(
318
320
  Ve,
319
321
  {
320
322
  size: "small",
321
323
  className: "text-base grow",
322
324
  value: r?.name ?? "",
323
- onChange: (d) => {
324
- a && e && a(e, d.target.value);
325
+ onChange: (c) => {
326
+ n && e && n(e, c.target.value);
325
327
  }
326
328
  }
327
329
  ),
328
- /* @__PURE__ */ s(ee, { onClick: n, size: "small", children: /* @__PURE__ */ s(We, { size: "small" }) })
330
+ /* @__PURE__ */ o(ee, { onClick: a, size: "small", children: /* @__PURE__ */ o(Ge, { size: "small" }) })
329
331
  ] }) })
330
332
  ]
331
333
  }
332
334
  ) });
333
335
  }
334
- function lt({
335
- importConfig: e,
336
- collection: r,
337
- onImportSuccess: n
336
+ function ct({
337
+ path: e,
338
+ importConfig: r,
339
+ collection: a,
340
+ onImportSuccess: t
338
341
  }) {
339
- const t = ue(), a = Ie(!1), [i, o] = j(0);
340
- function l() {
341
- a.current || (a.current = !0, De(
342
- t,
343
- r,
344
- e.entities,
342
+ const [n, i] = O(void 0), s = ue(), d = Ee(!1), [c, l] = O(0);
343
+ function p() {
344
+ d.current || (d.current = !0, Se(
345
+ s,
346
+ a,
347
+ e,
348
+ r.entities,
345
349
  0,
346
350
  25,
347
- o
351
+ l
348
352
  ).then(() => {
349
- n(r), a.current = !1;
353
+ t(a), d.current = !1;
354
+ }).catch((m) => {
355
+ i(m), d.current = !1;
350
356
  }));
351
357
  }
352
- return ce(() => {
353
- l();
354
- }, []), /* @__PURE__ */ p(ze, { className: "flex flex-col gap-4 items-center", children: [
355
- /* @__PURE__ */ s(ye, {}),
356
- /* @__PURE__ */ s(u, { variant: "h6", children: "Saving data" }),
357
- /* @__PURE__ */ p(u, { variant: "body2", children: [
358
- i,
358
+ return de(() => {
359
+ p();
360
+ }, []), n ? /* @__PURE__ */ f(ie, { className: "flex flex-col gap-4 items-center", children: [
361
+ /* @__PURE__ */ o(u, { variant: "h6", children: "Error saving data" }),
362
+ /* @__PURE__ */ o(u, { variant: "body2", color: "error", children: n.message }),
363
+ /* @__PURE__ */ o(
364
+ E,
365
+ {
366
+ onClick: p,
367
+ variant: "outlined",
368
+ children: "Retry"
369
+ }
370
+ )
371
+ ] }) : /* @__PURE__ */ f(ie, { className: "flex flex-col gap-4 items-center", children: [
372
+ /* @__PURE__ */ o(ye, {}),
373
+ /* @__PURE__ */ o(u, { variant: "h6", children: "Saving data" }),
374
+ /* @__PURE__ */ f(u, { variant: "body2", children: [
375
+ c,
359
376
  "/",
360
- e.entities.length,
377
+ r.entities.length,
361
378
  " entities saved"
362
379
  ] }),
363
- /* @__PURE__ */ s(u, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
380
+ /* @__PURE__ */ o(u, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
364
381
  ] });
365
382
  }
366
- function De(e, r, n, t = 0, a = 25, i) {
367
- console.debug("Saving imported data", t, a);
368
- const o = n.slice(t, t + a);
369
- return Promise.all(o.map((l) => e.saveEntity({
370
- path: r.path,
371
- // TODO: should check if this is correct, specially for subcollections
372
- values: l.values,
373
- entityId: l.id,
383
+ function Se(e, r, a, t, n = 0, i = 25, s) {
384
+ console.debug("Saving imported data", n, i);
385
+ const d = t.slice(n, n + i);
386
+ return Promise.all(d.map((c) => e.saveEntity({
387
+ path: a,
388
+ values: c.values,
389
+ entityId: c.id,
374
390
  collection: r,
375
391
  status: "new"
376
- }))).then(() => t + a < n.length ? (i(t + a), De(e, r, n, t + a, a, i)) : (i(n.length), Promise.resolve()));
392
+ }))).then(() => n + i < t.length ? (s(n + i), Se(e, r, a, t, n + i, i, s)) : (s(t.length), Promise.resolve()));
377
393
  }
378
- function ct({
394
+ function dt({
379
395
  collection: e,
380
396
  path: r,
381
- collectionEntitiesCount: n
397
+ collectionEntitiesCount: a,
398
+ onAnalyticsEvent: t
382
399
  }) {
383
- const t = z(), a = pe(), [i, o] = C.useState(!1), [l, d] = C.useState("initial"), c = Ke(), f = x(() => {
384
- o(!0), d("initial");
385
- }, [o]), m = x(() => {
386
- o(!1);
387
- }, [o]), y = x(() => {
388
- d("preview");
389
- }, []), h = x(() => {
390
- d("import_data_saving");
391
- }, []), S = async (g) => {
392
- if (c.setImportData(g), g.length > 0) {
393
- const I = await Ze(g, nt);
394
- c.setOriginProperties(I);
395
- const A = Ne(g);
396
- c.setHeadersMapping(A);
397
- const E = Object.keys(A)?.[0];
398
- if (E?.includes("id") || E?.includes("key")) {
399
- const w = E;
400
- c.setIdColumn(w);
401
- }
400
+ const n = X(), i = pe(), [s, d] = C.useState(!1), [c, l] = C.useState("initial"), p = et(), m = b(() => {
401
+ d(!0), l("initial");
402
+ }, [d]), h = b(() => {
403
+ d(!1);
404
+ }, [d]), g = b(() => {
405
+ l("preview");
406
+ }, []), I = b(() => {
407
+ l("import_data_saving");
408
+ }, []), A = async (y) => {
409
+ if (p.setImportData(y), y.length > 0) {
410
+ const T = await Ke(y, at);
411
+ p.setOriginProperties(T);
412
+ const L = Ne(y, e?.properties);
413
+ p.setHeadersMapping(L);
414
+ const w = Object.keys(L)?.[0];
415
+ (w?.includes("id") || w?.includes("key")) && p.setIdColumn(w);
402
416
  }
403
417
  setTimeout(() => {
404
- d("mapping");
418
+ l("mapping");
405
419
  }, 100);
406
- }, N = he({
420
+ }, $ = he({
407
421
  collection: e,
408
422
  path: r,
409
- fields: t.propertyConfigs
410
- }), _ = Te(N.properties, N.propertiesOrder), O = Object.entries(_).flatMap(([g, I]) => Se(g, I, 0)), R = N.propertiesOrder ?? Object.keys(N.properties);
411
- return e.collectionGroup ? null : /* @__PURE__ */ p($, { children: [
412
- /* @__PURE__ */ s(te, { title: "Import", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: f, children: /* @__PURE__ */ s(Ge, {}) }) }),
413
- /* @__PURE__ */ p(
423
+ fields: n.propertyConfigs
424
+ }), x = je($.properties, $.propertiesOrder), U = Object.entries(x).flatMap(([y, T]) => De(y, T, 0)), R = $.propertiesOrder ?? Object.keys($.properties);
425
+ return e.collectionGroup ? null : /* @__PURE__ */ f(M, { children: [
426
+ /* @__PURE__ */ o(te, { title: "Import", children: /* @__PURE__ */ o(ee, { color: "primary", onClick: m, children: /* @__PURE__ */ o(Xe, {}) }) }),
427
+ /* @__PURE__ */ f(
414
428
  be,
415
429
  {
416
- open: i,
417
- fullWidth: l === "preview",
418
- fullHeight: l === "preview",
419
- maxWidth: l === "initial" ? "lg" : "7xl",
430
+ open: s,
431
+ fullWidth: c === "preview",
432
+ fullHeight: c === "preview",
433
+ maxWidth: c === "initial" ? "lg" : "7xl",
420
434
  children: [
421
- /* @__PURE__ */ p(xe, { className: "flex flex-col gap-4 my-4", fullHeight: l === "preview", children: [
422
- l === "initial" && /* @__PURE__ */ p($, { children: [
423
- /* @__PURE__ */ s(u, { variant: "h6", children: "Import data" }),
424
- /* @__PURE__ */ s(u, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
425
- /* @__PURE__ */ s(ot, { onDataAdded: S })
435
+ /* @__PURE__ */ f(xe, { className: "flex flex-col gap-4 my-4", fullHeight: c === "preview", children: [
436
+ c === "initial" && /* @__PURE__ */ f(M, { children: [
437
+ /* @__PURE__ */ o(u, { variant: "h6", children: "Import data" }),
438
+ /* @__PURE__ */ o(u, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
439
+ /* @__PURE__ */ o(lt, { onDataAdded: A })
426
440
  ] }),
427
- l === "mapping" && /* @__PURE__ */ p($, { children: [
428
- /* @__PURE__ */ s(u, { variant: "h6", children: "Map fields" }),
429
- /* @__PURE__ */ s(
430
- it,
441
+ c === "mapping" && /* @__PURE__ */ f(M, { children: [
442
+ /* @__PURE__ */ o(u, { variant: "h6", children: "Map fields" }),
443
+ /* @__PURE__ */ o(
444
+ ot,
431
445
  {
432
- headersMapping: c.headersMapping,
433
- idColumn: c.idColumn,
434
- originProperties: c.originProperties,
435
- destinationProperties: _,
436
- onIdPropertyChanged: (g) => c.setIdColumn(g),
446
+ headersMapping: p.headersMapping,
447
+ idColumn: p.idColumn,
448
+ originProperties: p.originProperties,
449
+ destinationProperties: x,
450
+ onIdPropertyChanged: (y) => p.setIdColumn(y ?? void 0),
437
451
  buildPropertyView: ({
438
- isIdColumn: g,
439
- property: I,
440
- propertyKey: A,
441
- importKey: E
442
- }) => /* @__PURE__ */ s(
443
- dt,
452
+ isIdColumn: y,
453
+ property: T,
454
+ propertyKey: L,
455
+ importKey: w
456
+ }) => /* @__PURE__ */ o(
457
+ pt,
444
458
  {
445
- selectedPropertyKey: A ?? "",
446
- properties: _,
447
- propertiesAndLevel: O,
448
- isIdColumn: g,
459
+ selectedPropertyKey: L ?? "",
460
+ properties: x,
461
+ propertiesAndLevel: U,
462
+ isIdColumn: y,
449
463
  onIdSelected: () => {
450
- c.setIdColumn(E);
464
+ p.setIdColumn(w);
451
465
  },
452
- onPropertySelected: (w) => {
453
- const G = Object.entries(c.headersMapping).map(([b, F]) => F === w ? { [b]: null } : b === E ? { [b]: w } : { [b]: F }).reduce((b, F) => ({ ...b, ...F }), {});
454
- c.setHeadersMapping(G), w === c.idColumn && c.setIdColumn(void 0);
466
+ onPropertySelected: (B) => {
467
+ const j = Object.entries(p.headersMapping).map(([S, D]) => D === B ? { [S]: null } : S === w ? { [S]: B } : { [S]: D }).reduce((S, D) => ({ ...S, ...D }), {});
468
+ p.setHeadersMapping(j), B === p.idColumn && p.setIdColumn(void 0);
455
469
  }
456
470
  }
457
471
  )
458
472
  }
459
473
  )
460
474
  ] }),
461
- l === "preview" && /* @__PURE__ */ s(
462
- pt,
475
+ c === "preview" && /* @__PURE__ */ o(
476
+ ft,
463
477
  {
464
- importConfig: c,
465
- properties: _,
478
+ importConfig: p,
479
+ properties: x,
466
480
  propertiesOrder: R
467
481
  }
468
482
  ),
469
- l === "import_data_saving" && c && /* @__PURE__ */ s(
470
- lt,
483
+ c === "import_data_saving" && p && /* @__PURE__ */ o(
484
+ ct,
471
485
  {
472
- importConfig: c,
486
+ importConfig: p,
473
487
  collection: e,
474
- onImportSuccess: (g) => {
475
- m(), a.open({
488
+ path: r,
489
+ onImportSuccess: (y) => {
490
+ h(), i.open({
476
491
  type: "info",
477
492
  message: "Data imported successfully"
478
493
  });
@@ -480,44 +495,44 @@ function ct({
480
495
  }
481
496
  )
482
497
  ] }),
483
- /* @__PURE__ */ p(ve, { children: [
484
- l === "mapping" && /* @__PURE__ */ s(
485
- k,
498
+ /* @__PURE__ */ f(ve, { children: [
499
+ c === "mapping" && /* @__PURE__ */ o(
500
+ E,
486
501
  {
487
- onClick: () => d("initial"),
502
+ onClick: () => l("initial"),
488
503
  variant: "text",
489
504
  children: "Back"
490
505
  }
491
506
  ),
492
- l === "preview" && /* @__PURE__ */ s(
493
- k,
507
+ c === "preview" && /* @__PURE__ */ o(
508
+ E,
494
509
  {
495
- onClick: () => d("mapping"),
510
+ onClick: () => l("mapping"),
496
511
  variant: "text",
497
512
  children: "Back"
498
513
  }
499
514
  ),
500
- /* @__PURE__ */ s(
501
- k,
515
+ /* @__PURE__ */ o(
516
+ E,
502
517
  {
503
- onClick: m,
518
+ onClick: h,
504
519
  variant: "text",
505
520
  children: "Cancel"
506
521
  }
507
522
  ),
508
- l === "mapping" && /* @__PURE__ */ s(
509
- k,
523
+ c === "mapping" && /* @__PURE__ */ o(
524
+ E,
510
525
  {
511
526
  variant: "filled",
512
- onClick: y,
527
+ onClick: g,
513
528
  children: "Next"
514
529
  }
515
530
  ),
516
- l === "preview" && /* @__PURE__ */ s(
517
- k,
531
+ c === "preview" && /* @__PURE__ */ o(
532
+ E,
518
533
  {
519
534
  variant: "filled",
520
- onClick: h,
535
+ onClick: I,
521
536
  children: "Save data"
522
537
  }
523
538
  )
@@ -528,47 +543,47 @@ function ct({
528
543
  ] });
529
544
  }
530
545
  const V = "__internal_id__";
531
- function dt({
546
+ function pt({
532
547
  selectedPropertyKey: e,
533
548
  properties: r,
534
- onPropertySelected: n,
549
+ onPropertySelected: a,
535
550
  onIdSelected: t,
536
- propertiesAndLevel: a,
551
+ propertiesAndLevel: n,
537
552
  isIdColumn: i
538
553
  }) {
539
- const o = e ? L(r, e) : null, l = x((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(
554
+ const s = e ? _(r, e) : null, d = b((l) => l === V ? /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) : !l || !s ? /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) : /* @__PURE__ */ o(
540
555
  se,
541
556
  {
542
- propertyKey: c,
543
- property: o
557
+ propertyKey: l,
558
+ property: s
544
559
  }
545
- ), [o]), d = x((c) => {
546
- c === V ? (t(), n(null)) : n(c === "" ? null : c);
560
+ ), [s]), c = b((l) => {
561
+ l === V ? (t(), a(null)) : a(l === "__do_not_import" ? null : l);
547
562
  }, []);
548
- return /* @__PURE__ */ p(
563
+ return /* @__PURE__ */ f(
549
564
  ge,
550
565
  {
551
566
  value: i ? V : e ?? void 0,
552
- onValueChange: d,
553
- renderValue: l,
567
+ onValueChange: c,
568
+ renderValue: d,
554
569
  children: [
555
- /* @__PURE__ */ s(J, { value: "", children: /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) }),
556
- /* @__PURE__ */ s(J, { value: V, children: /* @__PURE__ */ s(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
557
- a.map(({
558
- property: c,
559
- level: f,
570
+ /* @__PURE__ */ o(H, { value: "__do_not_import", children: /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Do not import this property" }) }),
571
+ /* @__PURE__ */ o(H, { value: V, children: /* @__PURE__ */ o(u, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
572
+ n.map(({
573
+ property: l,
574
+ level: p,
560
575
  propertyKey: m
561
- }) => /* @__PURE__ */ s(
562
- J,
576
+ }) => /* @__PURE__ */ o(
577
+ H,
563
578
  {
564
579
  value: m,
565
- disabled: c.dataType === "map",
566
- children: /* @__PURE__ */ s(
580
+ disabled: l.dataType === "map",
581
+ children: /* @__PURE__ */ o(
567
582
  se,
568
583
  {
569
584
  propertyKey: m,
570
- property: c,
571
- level: f
585
+ property: l,
586
+ level: p
572
587
  }
573
588
  )
574
589
  },
@@ -578,31 +593,31 @@ function dt({
578
593
  }
579
594
  );
580
595
  }
581
- function Se(e, r, n) {
596
+ function De(e, r, a) {
582
597
  const t = [];
583
598
  return t.push({
584
599
  property: r,
585
- level: n,
600
+ level: a,
586
601
  propertyKey: e
587
- }), r.dataType === "map" && r.properties && Object.entries(r.properties).forEach(([a, i]) => {
588
- t.push(...Se(`${e}.${a}`, i, n + 1));
602
+ }), r.dataType === "map" && r.properties && Object.entries(r.properties).forEach(([n, i]) => {
603
+ t.push(...De(`${e}.${n}`, i, a + 1));
589
604
  }), t;
590
605
  }
591
606
  function se({
592
607
  propertyKey: e,
593
608
  property: r,
594
- level: n = 0
609
+ level: a = 0
595
610
  }) {
596
- const { propertyConfigs: t } = z(), a = fe(r, t);
597
- return /* @__PURE__ */ p(
611
+ const { propertyConfigs: t } = X(), n = fe(r, t);
612
+ return /* @__PURE__ */ f(
598
613
  "div",
599
614
  {
600
615
  className: "flex flex-row w-full text-start items-center h-full",
601
616
  children: [
602
- new Array(n).fill(0).map((i, o) => /* @__PURE__ */ s("div", { className: B(Xe, "ml-8 border-l h-12") }, o)),
603
- /* @__PURE__ */ s("div", { className: "m-4", children: /* @__PURE__ */ s(te, { title: a?.name, children: /* @__PURE__ */ s(me, { propertyConfig: a }) }) }),
604
- /* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
605
- /* @__PURE__ */ s(
617
+ new Array(a).fill(0).map((i, s) => /* @__PURE__ */ o("div", { className: J(qe, "ml-8 border-l h-12") }, s)),
618
+ /* @__PURE__ */ o("div", { className: "m-4", children: /* @__PURE__ */ o(te, { title: n?.name, children: /* @__PURE__ */ o(me, { propertyConfig: n }) }) }),
619
+ /* @__PURE__ */ f("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
620
+ /* @__PURE__ */ o(
606
621
  u,
607
622
  {
608
623
  variant: "body1",
@@ -611,7 +626,7 @@ function se({
611
626
  children: r.name ? r.name : " "
612
627
  }
613
628
  ),
614
- /* @__PURE__ */ s(
629
+ /* @__PURE__ */ o(
615
630
  u,
616
631
  {
617
632
  className: " pr-2",
@@ -626,284 +641,295 @@ function se({
626
641
  }
627
642
  );
628
643
  }
629
- function pt({
644
+ function ft({
630
645
  importConfig: e,
631
646
  properties: r,
632
- propertiesOrder: n
647
+ propertiesOrder: a
633
648
  }) {
634
- ce(() => {
635
- const a = at(e.originProperties, r), i = e.importData.map((o) => rt(o, e.idColumn, e.headersMapping, r, a, "TEMP_PATH"));
649
+ de(() => {
650
+ const n = it(e.originProperties, r), i = e.importData.map((s) => nt(s, e.idColumn, e.headersMapping, r, n, "TEMP_PATH"));
636
651
  e.setEntities(i);
637
652
  }, []);
638
- const t = je();
639
- return /* @__PURE__ */ s(
640
- ke,
653
+ const t = Fe();
654
+ return /* @__PURE__ */ o(
655
+ Pe,
641
656
  {
642
- title: /* @__PURE__ */ p("div", { children: [
643
- /* @__PURE__ */ s(u, { variant: "subtitle2", children: "Imported data preview" }),
644
- /* @__PURE__ */ s(u, { variant: "caption", children: "Entities with the same id will be overwritten" })
657
+ title: /* @__PURE__ */ f("div", { children: [
658
+ /* @__PURE__ */ o(u, { variant: "subtitle2", children: "Imported data preview" }),
659
+ /* @__PURE__ */ o(u, { variant: "caption", children: "Entities with the same id will be overwritten" })
645
660
  ] }),
646
661
  tableController: {
647
662
  data: e.entities,
648
663
  dataLoading: !1,
649
664
  noMoreToLoad: !1
650
665
  },
651
- endAdornment: /* @__PURE__ */ s("div", { className: "h-12" }),
666
+ endAdornment: /* @__PURE__ */ o("div", { className: "h-12" }),
652
667
  filterable: !1,
653
668
  sortable: !1,
654
669
  selectionController: t,
655
- displayedColumnIds: n.map((a) => ({
656
- key: a,
670
+ displayedColumnIds: a.map((n) => ({
671
+ key: n,
657
672
  disabled: !1
658
673
  })),
659
674
  properties: r
660
675
  }
661
676
  );
662
677
  }
663
- function Ne(e) {
664
- const r = {};
665
- return e.filter(Boolean).forEach((n) => {
666
- Object.keys(n).forEach((t) => {
667
- const a = n[t];
668
- typeof a == "object" && !Array.isArray(a) && Object.entries(Ne([a])).forEach(([i, o]) => {
669
- r[`${t}.${i}`] = `${t}.${o}`;
670
- }), r[t] = t;
678
+ function Ne(e, r) {
679
+ const a = {};
680
+ return e.filter(Boolean).forEach((t) => {
681
+ Object.keys(t).forEach((n) => {
682
+ const i = t[n];
683
+ if (typeof i == "object" && !Array.isArray(i)) {
684
+ const s = r?.[n], d = s && "properties" in s ? s.properties : void 0, c = Ne([i], d);
685
+ Object.entries(c).forEach(([l, p]) => {
686
+ a[`${n}.${l}`] = `${n}.${p}`;
687
+ });
688
+ }
689
+ if (!r)
690
+ a[n] = n;
691
+ else if (n in r)
692
+ a[n] = n;
693
+ else {
694
+ const s = ke(n);
695
+ s in r ? a[n] = s : a[n] = n;
696
+ }
671
697
  });
672
- }), r;
698
+ }), a;
673
699
  }
674
- function ft(e, r, n, t, a, i, o) {
675
- console.debug("Downloading export", { dataLength: e.length, collection: n, exportType: i, dateExportType: o });
676
- const l = n.properties;
700
+ function mt(e, r, a, t, n, i, s) {
701
+ console.debug("Downloading export", { dataLength: e.length, collection: a, exportType: i, dateExportType: s });
702
+ const d = a.properties;
677
703
  if (i === "csv") {
678
- const d = t ? Fe(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));
679
- le([m, ...y], `${n.name}.csv`, "text/csv");
704
+ const c = t ? Me(e.map((g) => g.values)) : {}, l = gt(d, n, c), p = ut(e, r, d, l, s), m = le(l.map((g) => g.label)), h = p.map((g) => le(g));
705
+ ce([m, ...h], `${a.name}.csv`, "text/csv");
680
706
  } else {
681
- const d = ut(e, r, l, o), c = JSON.stringify(d, null, 2);
682
- le([c], `${n.name}.json`, "application/json");
707
+ const c = ht(e, r, d, s), l = JSON.stringify(c, null, 2);
708
+ ce([l], `${a.name}.json`, "application/json");
683
709
  }
684
710
  }
685
- function mt(e, r, n, t, a) {
686
- const i = e.map((o) => ({
687
- id: o.id,
688
- ...re(o.values, n, "csv", a)
711
+ function ut(e, r, a, t, n) {
712
+ const i = e.map((s) => ({
713
+ id: s.id,
714
+ ...re(s.values, a, "csv", n)
689
715
  }));
690
- return r && r.forEach((o, l) => {
691
- i[l] = { ...i[l], ...o };
692
- }), i && i.map((o) => t.map((l) => Pe(o, l.key)));
716
+ return r && r.forEach((s, d) => {
717
+ i[d] = { ...i[d], ...s };
718
+ }), i && i.map((s) => t.map((d) => _e(s, d.key)));
693
719
  }
694
- function ut(e, r, n, t) {
695
- const a = e.map((i) => ({
720
+ function ht(e, r, a, t) {
721
+ const n = e.map((i) => ({
696
722
  id: i.id,
697
- ...re(i.values, n, "json", t)
723
+ ...re(i.values, a, "json", t)
698
724
  }));
699
- return r && r.forEach((i, o) => {
700
- a[o] = { ...a[o], ...i };
701
- }), a;
725
+ return r && r.forEach((i, s) => {
726
+ n[s] = { ...n[s], ...i };
727
+ }), n;
702
728
  }
703
- function ht(e, r, n) {
729
+ function gt(e, r, a) {
704
730
  const t = [
705
731
  { label: "id", key: "id" },
706
- ...Object.entries(e).flatMap(([a, i]) => n && n[a] > 1 ? Array.from(
707
- { length: n[a] },
708
- (o, l) => K(i, `${a}[${l}]`, "")
709
- ).flat() : K(i, a, ""))
732
+ ...Object.entries(e).flatMap(([n, i]) => a && a[n] > 1 ? Array.from(
733
+ { length: a[n] },
734
+ (s, d) => K(i, `${n}[${d}]`, "")
735
+ ).flat() : K(i, n, ""))
710
736
  ];
711
- return r && t.push(...r.map((a) => ({ label: a, key: a }))), t;
737
+ return r && t.push(...r.map((n) => ({ label: n, key: n }))), t;
712
738
  }
713
- function K(e, r, n = "") {
714
- const t = n ? `${n}.${r}` : r;
715
- return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([a, i]) => K(i, a, t)).flat() : [{ label: t, key: t }];
739
+ function K(e, r, a = "") {
740
+ const t = a ? `${a}.${r}` : r;
741
+ return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([n, i]) => K(i, n, t)).flat() : [{ label: t, key: t }];
716
742
  }
717
- function W(e, r, n, t) {
718
- let a;
743
+ function G(e, r, a, t) {
744
+ let n;
719
745
  if (r.dataType === "map" && r.properties)
720
- a = re(e, r.properties, n, t);
746
+ n = re(e, r.properties, a, t);
721
747
  else if (r.dataType === "array")
722
- r.of && Array.isArray(e) ? Array.isArray(r.of) ? a = r.of.map((i, o) => W(e[o], i, n, t)) : r.of.dataType === "map" ? a = n === "csv" ? e.map((i) => JSON.stringify(i)) : e.map((i) => W(i, r.of, n, t)) : a = e.map((i) => W(i, r.of, n, t)) : a = e;
723
- else if (r.dataType === "reference" && e instanceof de) {
748
+ r.of && Array.isArray(e) ? Array.isArray(r.of) ? n = r.of.map((i, s) => G(e[s], i, a, t)) : r.of.dataType === "map" ? n = a === "csv" ? e.map((i) => JSON.stringify(i)) : e.map((i) => G(i, r.of, a, t)) : n = e.map((i) => G(i, r.of, a, t)) : n = e;
749
+ else if (r.dataType === "reference" && e && e.isEntityReference && e.isEntityReference()) {
724
750
  const i = e || void 0;
725
- a = i ? i.pathWithId : null;
751
+ n = i ? i.pathWithId : null;
726
752
  } else
727
- r.dataType === "date" && e instanceof Date ? a = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : a = e;
728
- return a;
753
+ r.dataType === "date" && e instanceof Date ? n = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : n = e;
754
+ return n;
729
755
  }
730
- function re(e, r, n, t) {
731
- const a = Object.entries(r).map(([i, o]) => {
732
- const l = e && e[i], d = W(l, o, n, t);
733
- return d === void 0 ? {} : { [i]: d };
734
- }).reduce((i, o) => ({ ...i, ...o }), {});
735
- return { ...e, ...a };
756
+ function re(e, r, a, t) {
757
+ const n = Object.entries(r).map(([i, s]) => {
758
+ const d = e && e[i], c = G(d, s, a, t);
759
+ return c === void 0 ? {} : { [i]: c };
760
+ }).reduce((i, s) => ({ ...i, ...s }), {});
761
+ return { ...e, ...n };
736
762
  }
737
- function oe(e) {
763
+ function le(e) {
738
764
  return e.map((r) => r == null ? "" : Array.isArray(r) ? '"' + JSON.stringify(r).replaceAll('"', '\\"') + '"' : '"' + String(r).replaceAll('"', '""') + '"').join(",") + `\r
739
765
  `;
740
766
  }
741
- function le(e, r, n) {
742
- const t = new Blob(e, { type: n }), a = URL.createObjectURL(t), i = document.createElement("a");
743
- i.href = a, i.setAttribute("download", r), i.click();
767
+ function ce(e, r, a) {
768
+ const t = new Blob(e, { type: a }), n = URL.createObjectURL(t), i = document.createElement("a");
769
+ i.href = n, i.setAttribute("download", r), i.click();
744
770
  }
745
- const gt = 500;
746
- function yt({
771
+ const yt = 500;
772
+ function bt({
747
773
  collection: e,
748
774
  path: r,
749
- collectionEntitiesCount: n,
775
+ collectionEntitiesCount: a,
750
776
  exportAllowed: t,
751
- notAllowedView: a
777
+ notAllowedView: n
752
778
  }) {
753
- 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 = ue(), O = $e().resolveAliasesFrom(r), R = !t || t({
754
- collectionEntitiesCount: n,
755
- path: O,
779
+ const i = X(), s = typeof e.exportable == "object" ? e.exportable : void 0, d = C.useRef(/* @__PURE__ */ new Date()), [c, l] = C.useState(!0), [p, m] = C.useState("csv"), [h, g] = C.useState("string"), I = $e(), A = ue(), x = Re().resolveAliasesFrom(r), U = !t || t({
780
+ collectionEntitiesCount: a,
781
+ path: x,
756
782
  collection: e
757
- }), g = C.useMemo(() => he({
783
+ }), R = C.useMemo(() => he({
758
784
  collection: e,
759
- path: O,
785
+ path: x,
760
786
  fields: i.propertyConfigs
761
- }), [e, O]), [I, A] = C.useState(!1), [E, w] = C.useState(), [G, b] = C.useState(!1), F = x(() => {
762
- b(!0);
763
- }, [b]), X = x(() => {
764
- b(!1);
765
- }, [b]), ne = x(async (P) => {
766
- const H = o?.additionalFields, D = g.additionalFields, q = H ? await Promise.all(P.map(async (T) => (await Promise.all(H.map(async (v) => ({
787
+ }), [e, x]), [y, T] = C.useState(!1), [L, w] = C.useState(), [B, j] = C.useState(!1), S = b(() => {
788
+ j(!0);
789
+ }, [j]), D = b(() => {
790
+ j(!1);
791
+ }, [j]), ne = b(async (P) => {
792
+ const W = s?.additionalFields, N = R.additionalFields, q = W ? await Promise.all(P.map(async (F) => (await Promise.all(W.map(async (v) => ({
767
793
  [v.key]: await v.builder({
768
- entity: T,
769
- context: S
794
+ entity: F,
795
+ context: I
770
796
  })
771
- })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = D ? await Promise.all(P.map(async (T) => (await Promise.all(D.map(async (v) => v.value ? {
797
+ })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = N ? await Promise.all(P.map(async (F) => (await Promise.all(N.map(async (v) => v.value ? {
772
798
  [v.key]: await v.value({
773
- entity: T,
774
- context: S
799
+ entity: F,
800
+ context: I
775
801
  })
776
802
  } : {}))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [];
777
803
  return [...q, ...Q];
778
- }, [o?.additionalFields]), ae = x(async (P, H) => {
779
- A(!0), N.fetchCollection({
780
- path: O,
804
+ }, [s?.additionalFields]), ae = b(async (P, W) => {
805
+ T(!0), A.fetchCollection({
806
+ path: x,
781
807
  collection: P
782
- }).then(async (D) => {
808
+ }).then(async (N) => {
783
809
  w(void 0);
784
- const q = await ne(D), Q = [
785
- ...H?.additionalFields?.map((T) => T.key) ?? [],
786
- ...P.additionalFields?.map((T) => T.key) ?? []
810
+ const q = await ne(N), Q = [
811
+ ...W?.additionalFields?.map((F) => F.key) ?? [],
812
+ ...P.additionalFields?.map((F) => F.key) ?? []
787
813
  ];
788
- ft(D, q, P, d, Q, f, y);
789
- }).catch((D) => {
790
- console.error("Error loading export data", D), w(D);
791
- }).finally(() => A(!1));
792
- }, [N, O, ne, d, f, y]), Oe = x(() => {
793
- ae(g, o), X();
794
- }, [ae, g, o, X]);
795
- return /* @__PURE__ */ p($, { children: [
796
- /* @__PURE__ */ s(te, { title: "Export", children: /* @__PURE__ */ s(ee, { color: "primary", onClick: F, children: /* @__PURE__ */ s(qe, {}) }) }),
797
- /* @__PURE__ */ p(
814
+ mt(N, q, P, c, Q, p, h);
815
+ }).catch((N) => {
816
+ console.error("Error loading export data", N), w(N);
817
+ }).finally(() => T(!1));
818
+ }, [A, x, ne, c, p, h]), Oe = b(() => {
819
+ ae(R, s), D();
820
+ }, [ae, R, s, D]);
821
+ return /* @__PURE__ */ f(M, { children: [
822
+ /* @__PURE__ */ o(te, { title: "Export", children: /* @__PURE__ */ o(ee, { color: "primary", onClick: S, children: /* @__PURE__ */ o(Qe, {}) }) }),
823
+ /* @__PURE__ */ f(
798
824
  be,
799
825
  {
800
- open: G,
801
- onOpenChange: b,
826
+ open: B,
827
+ onOpenChange: j,
802
828
  maxWidth: "xl",
803
829
  children: [
804
- /* @__PURE__ */ p(xe, { className: "flex flex-col gap-4 my-4", children: [
805
- /* @__PURE__ */ s(u, { variant: "h6", children: "Export data" }),
806
- /* @__PURE__ */ s("div", { children: "Download the the content of this table as a CSV" }),
807
- n > gt && /* @__PURE__ */ s(Qe, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
830
+ /* @__PURE__ */ f(xe, { className: "flex flex-col gap-4 my-4", children: [
831
+ /* @__PURE__ */ o(u, { variant: "h6", children: "Export data" }),
832
+ /* @__PURE__ */ o("div", { children: "Download the the content of this table as a CSV" }),
833
+ a > yt && /* @__PURE__ */ o(Ye, { color: "warning", children: /* @__PURE__ */ f("div", { children: [
808
834
  "This collections has a large number of documents (",
809
- n,
835
+ a,
810
836
  ")."
811
837
  ] }) }),
812
- /* @__PURE__ */ p("div", { className: "flex flex-row gap-4", children: [
813
- /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
814
- /* @__PURE__ */ p("div", { className: "flex items-center", children: [
815
- /* @__PURE__ */ s(
838
+ /* @__PURE__ */ f("div", { className: "flex flex-row gap-4", children: [
839
+ /* @__PURE__ */ f("div", { className: "p-4 flex flex-col", children: [
840
+ /* @__PURE__ */ f("div", { className: "flex items-center", children: [
841
+ /* @__PURE__ */ o(
816
842
  "input",
817
843
  {
818
844
  id: "radio-csv",
819
845
  type: "radio",
820
846
  value: "csv",
821
847
  name: "exportType",
822
- checked: f === "csv",
848
+ checked: p === "csv",
823
849
  onChange: () => m("csv"),
824
- className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
850
+ className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
825
851
  }
826
852
  ),
827
- /* @__PURE__ */ s(
853
+ /* @__PURE__ */ o(
828
854
  "label",
829
855
  {
830
856
  htmlFor: "radio-csv",
831
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
857
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
832
858
  children: "CSV"
833
859
  }
834
860
  )
835
861
  ] }),
836
- /* @__PURE__ */ p("div", { className: "flex items-center", children: [
837
- /* @__PURE__ */ s(
862
+ /* @__PURE__ */ f("div", { className: "flex items-center", children: [
863
+ /* @__PURE__ */ o(
838
864
  "input",
839
865
  {
840
866
  id: "radio-json",
841
867
  type: "radio",
842
868
  value: "json",
843
869
  name: "exportType",
844
- checked: f === "json",
870
+ checked: p === "json",
845
871
  onChange: () => m("json"),
846
- className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
872
+ className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
847
873
  }
848
874
  ),
849
- /* @__PURE__ */ s(
875
+ /* @__PURE__ */ o(
850
876
  "label",
851
877
  {
852
878
  htmlFor: "radio-json",
853
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
879
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
854
880
  children: "JSON"
855
881
  }
856
882
  )
857
883
  ] })
858
884
  ] }),
859
- /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
860
- /* @__PURE__ */ p("div", { className: "flex items-center", children: [
861
- /* @__PURE__ */ s(
885
+ /* @__PURE__ */ f("div", { className: "p-4 flex flex-col", children: [
886
+ /* @__PURE__ */ f("div", { className: "flex items-center", children: [
887
+ /* @__PURE__ */ o(
862
888
  "input",
863
889
  {
864
890
  id: "radio-timestamp",
865
891
  type: "radio",
866
892
  value: "timestamp",
867
893
  name: "dateExportType",
868
- checked: y === "timestamp",
869
- onChange: () => h("timestamp"),
870
- className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
894
+ checked: h === "timestamp",
895
+ onChange: () => g("timestamp"),
896
+ className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
871
897
  }
872
898
  ),
873
- /* @__PURE__ */ p(
899
+ /* @__PURE__ */ f(
874
900
  "label",
875
901
  {
876
902
  htmlFor: "radio-timestamp",
877
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
903
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
878
904
  children: [
879
905
  "Dates as timestamps (",
880
- l.current.getTime(),
906
+ d.current.getTime(),
881
907
  ")"
882
908
  ]
883
909
  }
884
910
  )
885
911
  ] }),
886
- /* @__PURE__ */ p("div", { className: "flex items-center", children: [
887
- /* @__PURE__ */ s(
912
+ /* @__PURE__ */ f("div", { className: "flex items-center", children: [
913
+ /* @__PURE__ */ o(
888
914
  "input",
889
915
  {
890
916
  id: "radio-string",
891
917
  type: "radio",
892
918
  value: "string",
893
919
  name: "dateExportType",
894
- checked: y === "string",
895
- onChange: () => h("string"),
896
- className: B(U, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
920
+ checked: h === "string",
921
+ onChange: () => g("string"),
922
+ className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
897
923
  }
898
924
  ),
899
- /* @__PURE__ */ p(
925
+ /* @__PURE__ */ f(
900
926
  "label",
901
927
  {
902
928
  htmlFor: "radio-string",
903
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
929
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
904
930
  children: [
905
931
  "Dates as strings (",
906
- l.current.toISOString(),
932
+ d.current.toISOString(),
907
933
  ")"
908
934
  ]
909
935
  }
@@ -911,34 +937,34 @@ function yt({
911
937
  ] })
912
938
  ] })
913
939
  ] }),
914
- /* @__PURE__ */ s(
915
- Ye,
940
+ /* @__PURE__ */ o(
941
+ Ze,
916
942
  {
917
943
  size: "small",
918
- disabled: f !== "csv",
919
- value: d,
920
- onValueChange: c,
944
+ disabled: p !== "csv",
945
+ value: c,
946
+ onValueChange: l,
921
947
  label: "Flatten arrays"
922
948
  }
923
949
  ),
924
- !R && a
950
+ !U && n
925
951
  ] }),
926
- /* @__PURE__ */ p(ve, { children: [
927
- I && /* @__PURE__ */ s(ye, { size: "small" }),
928
- /* @__PURE__ */ s(
929
- k,
952
+ /* @__PURE__ */ f(ve, { children: [
953
+ y && /* @__PURE__ */ o(ye, { size: "small" }),
954
+ /* @__PURE__ */ o(
955
+ E,
930
956
  {
931
- onClick: X,
957
+ onClick: D,
932
958
  variant: "text",
933
959
  children: "Cancel"
934
960
  }
935
961
  ),
936
- /* @__PURE__ */ s(
937
- k,
962
+ /* @__PURE__ */ o(
963
+ E,
938
964
  {
939
965
  variant: "filled",
940
966
  onClick: Oe,
941
- disabled: I || !R,
967
+ disabled: y || !U,
942
968
  children: "Download"
943
969
  }
944
970
  )
@@ -948,28 +974,28 @@ function yt({
948
974
  )
949
975
  ] });
950
976
  }
951
- function St(e) {
952
- return Ae(() => ({
953
- name: "Import/Export",
954
- collections: {
955
- CollectionActions: [ct, yt],
977
+ function Nt(e) {
978
+ return Ie(() => ({
979
+ key: "import_export",
980
+ collectionView: {
981
+ CollectionActions: [dt, bt],
956
982
  collectionActionsProps: e
957
983
  }
958
984
  }), [e]);
959
985
  }
960
986
  export {
961
- it as DataNewPropertiesMapping,
962
- ot as ImportFileUpload,
987
+ ot as DataNewPropertiesMapping,
988
+ lt as ImportFileUpload,
963
989
  Dt as ImportNewPropertyFieldPreview,
964
- lt as ImportSaveInProgress,
965
- rt as convertDataToEntity,
966
- et as convertFileToJson,
990
+ ct as ImportSaveInProgress,
991
+ nt as convertDataToEntity,
992
+ tt as convertFileToJson,
967
993
  we as flattenEntry,
968
- nt as getInferenceType,
969
- at as getPropertiesMapping,
994
+ at as getInferenceType,
995
+ it as getPropertiesMapping,
970
996
  Z as processValueMapping,
971
997
  Ce as unflattenObject,
972
- Ke as useImportConfig,
973
- St as useImportExportPlugin
998
+ et as useImportConfig,
999
+ Nt as useImportExportPlugin
974
1000
  };
975
1001
  //# sourceMappingURL=index.es.js.map