@firecms/data_import_export 3.0.0-canary.8 → 3.0.0-canary.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +113 -21
  2. package/README.md +1 -1
  3. package/dist/components/DataNewPropertiesMapping.d.ts +3 -5
  4. package/dist/components/ImportFileUpload.d.ts +1 -1
  5. package/dist/export_import/BasicExportAction.d.ts +7 -0
  6. package/dist/export_import/ExportCollectionAction.d.ts +1 -1
  7. package/dist/export_import/export.d.ts +15 -4
  8. package/dist/export_import/index.d.ts +4 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.es.js +940 -570
  11. package/dist/index.es.js.map +1 -1
  12. package/dist/index.umd.js +2 -2
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/types/column_mapping.d.ts +5 -7
  15. package/dist/useImportExportPlugin.d.ts +1 -1
  16. package/dist/utils/data.d.ts +3 -10
  17. package/dist/utils/file_headers.d.ts +1 -0
  18. package/dist/utils/file_to_json.d.ts +6 -1
  19. package/dist/utils/get_properties_mapping.d.ts +0 -3
  20. package/dist/utils/index.d.ts +0 -1
  21. package/package.json +20 -34
  22. package/src/components/DataNewPropertiesMapping.tsx +153 -40
  23. package/src/components/ImportFileUpload.tsx +12 -4
  24. package/src/components/ImportNewPropertyFieldPreview.tsx +7 -2
  25. package/src/export_import/BasicExportAction.tsx +147 -0
  26. package/src/export_import/ExportCollectionAction.tsx +45 -9
  27. package/src/export_import/ImportCollectionAction.tsx +22 -22
  28. package/src/export_import/export.ts +63 -29
  29. package/src/export_import/index.ts +4 -0
  30. package/src/hooks/useImportConfig.tsx +6 -0
  31. package/src/index.ts +1 -0
  32. package/src/types/column_mapping.ts +6 -6
  33. package/src/useImportExportPlugin.tsx +2 -2
  34. package/src/utils/data.ts +36 -126
  35. package/src/utils/file_headers.ts +90 -0
  36. package/src/utils/file_to_json.ts +33 -15
  37. package/src/utils/get_properties_mapping.ts +63 -59
  38. package/src/utils/index.ts +0 -1
package/dist/index.es.js CHANGED
@@ -1,277 +1,414 @@
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({});
1
+ import b, { useState as N, useRef as He, useEffect as Ne, useCallback as C, useMemo as Ue } from "react";
2
+ import { jsxs as p, Fragment as M, jsx as i } from "react/jsx-runtime";
3
+ import { getPropertyInPath as J, mergeDeep as ze, resolveProperty as We, isPropertyBuilder as me, EntityReference as Xe, useSnackbarController as Se, useCustomizationController as q, getFieldConfig as Oe, ErrorBoundary as Ge, PropertyConfigBadge as ke, useDataSource as Ie, resolveCollection as _e, getPropertiesWithPropertiesOrder as Ye, useSelectionController as qe, EntityCollectionTable as Qe, slugify as Ze, getArrayValuesCount as Ke, getValueInPath as et, useFireCMSContext as tt, useNavigationController as rt, getDefaultValuesFor as at } from "@firecms/core";
4
+ import { Table as fe, TableHeader as he, TableCell as w, TableBody as ge, TableRow as xe, Typography as f, ChevronRightIcon as ye, ExpandablePanel as nt, Select as Ae, SelectItem as H, TextField as re, BooleanSwitchWithLabel as Y, DateTimeField as st, FileUpload as it, UploadIcon as lt, IconButton as Q, EditIcon as ot, CenteredView as be, Button as S, CircularProgress as Ee, Tooltip as Z, FileUploadIcon as ct, Dialog as se, DialogContent as ie, DialogActions as le, cls as _, defaultBorderMixin as dt, GetAppIcon as Te, Alert as pt, focusedMixin as T } from "@firecms/ui";
5
+ import { inferTypeFromValue as ut, buildEntityPropertiesFromData as mt } from "@firecms/schema_inference";
6
+ import * as U from "xlsx";
7
+ import { getIn as Fe, setIn as ft } from "@firecms/formex";
8
+ const ht = () => {
9
+ const [e, a] = N(!1), [s, t] = N({}), [r, n] = N(), [l, o] = N([]), [c, d] = N([]), [u, m] = N({}), [h, g] = N([]), [y, A] = N({});
9
10
  return {
10
11
  inUse: e,
11
- setInUse: r,
12
- idColumn: a,
13
- setIdColumn: t,
14
- entities: s,
12
+ setInUse: a,
13
+ idColumn: r,
14
+ setIdColumn: n,
15
+ entities: c,
15
16
  setEntities: d,
16
- importData: n,
17
- setImportData: i,
18
- headersMapping: c,
19
- setHeadersMapping: l,
20
- originProperties: p,
21
- setOriginProperties: m
17
+ importData: l,
18
+ setImportData: o,
19
+ headingsOrder: (h ?? []).length > 0 ? h : Object.keys(u),
20
+ setHeadingsOrder: g,
21
+ headersMapping: u,
22
+ setHeadersMapping: m,
23
+ originProperties: y,
24
+ setOriginProperties: A,
25
+ defaultValues: s,
26
+ setDefaultValues: t
22
27
  };
23
28
  };
24
- function tt(e) {
25
- return new Promise((r, a) => {
29
+ function gt(e) {
30
+ let a = 0;
31
+ const s = [], t = {};
32
+ if (e == null || e["!ref"] == null) return [];
33
+ const r = t.range !== void 0 ? t.range : e["!ref"];
34
+ let n;
35
+ switch (t.header === 1 ? a = 1 : t.header === "A" ? a = 2 : Array.isArray(t.header) && (a = 3), typeof r) {
36
+ case "string":
37
+ n = ve(r);
38
+ break;
39
+ case "number":
40
+ n = ve(e["!ref"]), n.s.r = r;
41
+ break;
42
+ default:
43
+ n = r;
44
+ }
45
+ const l = U.utils.encode_row(n.s.r), o = new Array(n.e.c - n.s.c + 1);
46
+ for (let c = n.s.c; c <= n.e.c; ++c) {
47
+ o[c] = U.utils.encode_col(c);
48
+ const d = e[o[c] + l];
49
+ switch (a) {
50
+ case 1:
51
+ s.push(c);
52
+ break;
53
+ case 2:
54
+ s.push(o[c]);
55
+ break;
56
+ case 3:
57
+ s.push(t.header[c - n.s.c]);
58
+ break;
59
+ default:
60
+ if (d === void 0) continue;
61
+ s.push(U.utils.format_cell(d));
62
+ }
63
+ }
64
+ return s;
65
+ }
66
+ function ve(e) {
67
+ const a = {
68
+ s: {
69
+ c: 0,
70
+ r: 0
71
+ },
72
+ e: {
73
+ c: 0,
74
+ r: 0
75
+ }
76
+ };
77
+ let s = 0, t = 0, r = 0;
78
+ const n = e.length;
79
+ for (s = 0; t < n && !((r = e.charCodeAt(t) - 64) < 1 || r > 26); ++t)
80
+ s = 26 * s + r;
81
+ for (a.s.c = --s, s = 0; t < n && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
82
+ s = 10 * s + r;
83
+ if (a.s.r = --s, t === n || e.charCodeAt(++t) === 58)
84
+ return a.e.c = a.s.c, a.e.r = a.s.r, a;
85
+ for (s = 0; t !== n && !((r = e.charCodeAt(t) - 64) < 1 || r > 26); ++t)
86
+ s = 26 * s + r;
87
+ for (a.e.c = --s, s = 0; t !== n && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
88
+ s = 10 * s + r;
89
+ return a.e.r = --s, a;
90
+ }
91
+ function xt(e) {
92
+ return new Promise((a, s) => {
26
93
  if (e.type === "application/json") {
27
94
  console.debug("Converting JSON file to JSON", e.name);
28
95
  const t = new FileReader();
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);
96
+ t.onload = function(r) {
97
+ try {
98
+ const n = r.target?.result, l = JSON.parse(n);
99
+ if (!Array.isArray(l))
100
+ s(new Error("JSON file should contain an array of objects"));
101
+ else {
102
+ const o = l.length > 0 ? Object.keys(l[0]) : [];
103
+ a({
104
+ data: l,
105
+ propertiesOrder: o
106
+ });
107
+ }
108
+ } catch (n) {
109
+ console.error("Error parsing JSON file", n), s(n);
110
+ }
32
111
  }, t.readAsText(e);
33
112
  } else {
34
113
  console.debug("Converting Excel file to JSON", e.name);
35
114
  const t = new FileReader();
36
- t.onload = function(n) {
37
- const i = new Uint8Array(n.target?.result), s = oe.read(
38
- i,
39
- {
40
- type: "array",
41
- codepage: 65001,
42
- cellDates: !0
43
- }
44
- ), d = s.SheetNames[0], c = s.Sheets[d], m = oe.utils.sheet_to_json(c).map(rt).map(Ce);
45
- r(m);
115
+ t.onload = function(r) {
116
+ const n = new Uint8Array(r.target?.result), l = U.read(n, {
117
+ type: "array",
118
+ codepage: 65001,
119
+ cellDates: !0
120
+ }), o = l.SheetNames[0], c = l.Sheets[o], d = U.utils.sheet_to_json(c), u = gt(c), h = d.map(yt).map(je);
121
+ a({
122
+ data: h,
123
+ propertiesOrder: u
124
+ });
46
125
  }, t.readAsArrayBuffer(e);
47
126
  }
48
127
  });
49
128
  }
50
- function rt(e) {
51
- return Object.keys(e).reduce((r, a) => {
129
+ function yt(e) {
130
+ return Object.keys(e).reduce((a, s) => {
52
131
  try {
53
- r[a] = JSON.parse(e[a]);
132
+ a[s] = JSON.parse(e[s]);
54
133
  } catch {
55
- r[a] = e[a];
134
+ a[s] = e[s];
56
135
  }
57
- return r;
136
+ return a;
58
137
  }, {});
59
138
  }
60
- function Ce(e) {
61
- return Object.keys(e).reduce((r, a) => {
62
- let t = r;
63
- const n = a.split(".");
64
- return n.forEach((i, s) => {
65
- if (/^[\w]+\[\d+\]$/.test(i)) {
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
- } else
69
- s !== n.length - 1 ? (t[i] = t[i] || {}, t = t[i]) : t[i] = e[a];
70
- }), r;
139
+ function je(e) {
140
+ return Object.keys(e).reduce((a, s) => {
141
+ let t = a;
142
+ const r = s.split(".");
143
+ return r.forEach((n, l) => {
144
+ if (/^[\w]+\[\d+\]$/.test(n)) {
145
+ const o = n.slice(0, n.indexOf("[")), c = parseInt(n.slice(n.indexOf("[") + 1, n.indexOf("]")));
146
+ t[o] || (t[o] = []), l !== r.length - 1 ? (t[o][c] = t[o][c] || {}, t = t[o][c]) : t[o][c] = e[s];
147
+ } else l !== r.length - 1 ? (t[n] = t[n] || {}, t = t[n]) : t[n] = e[s];
148
+ }), a;
71
149
  }, {});
72
150
  }
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))
151
+ function bt(e, a, s, t, r, n) {
152
+ const l = Pe(e);
153
+ a && delete l[a];
154
+ const o = Object.entries(l).map(([u, m]) => {
155
+ const h = Fe(s, u) ?? u, g = J(t, h);
156
+ if (!g)
79
157
  return {};
80
- const I = n[h];
81
- let A = m;
82
- return I && (A = Z(m, I)), {
83
- [h]: A
158
+ const y = ae(m, g);
159
+ return {
160
+ [h]: y
84
161
  };
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,
162
+ }).reduce((u, m) => ({ ...u, ...m }), {}), c = ze(n ?? {}, je(o));
163
+ let d = a ? e[a] : void 0;
164
+ return typeof d == "string" ? d = d.trim() : typeof d == "number" || typeof d == "boolean" ? d = d.toString() : d instanceof Date ? d = d.toISOString() : d && "toString" in d && (d = d.toString()), {
165
+ id: d,
89
166
  values: c,
90
- path: i
167
+ path: r
91
168
  };
92
169
  }
93
- function we(e, r = "") {
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;
170
+ function Pe(e, a = "") {
171
+ return Object.keys(e).reduce((s, t) => {
172
+ const r = a ? `${a}.${t}` : t;
173
+ return typeof e[t] == "object" && !(e[t] instanceof Date) && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(s, Pe(e[t], r)) : s[r] = e[t], s;
97
174
  }, {});
98
175
  }
99
- function Z(e, r) {
100
- if (r === void 0)
101
- return e;
102
- const {
103
- from: a,
104
- to: t
105
- } = r;
106
- if (a === "array" && t === "array" && r.fromSubtype && r.toSubtype && Array.isArray(e))
107
- return e.map((n) => Z(n, {
108
- from: r.fromSubtype,
109
- to: r.toSubtype
110
- }));
111
- if (a === "string" && t === "number" && typeof e == "string")
176
+ function ae(e, a) {
177
+ if (e === null) return null;
178
+ if (a === void 0) return e;
179
+ const s = We({
180
+ propertyOrBuilder: a
181
+ });
182
+ if (s === null) return e;
183
+ const t = ut(e), r = s.dataType;
184
+ if (t === "array" && r === "array" && Array.isArray(e) && s.of && !me(s.of))
185
+ return e.map((n) => ae(n, s.of));
186
+ if (t === "string" && r === "number" && typeof e == "string")
112
187
  return Number(e);
113
- if (a === "string" && t === "array" && r.toSubtype && typeof e == "string")
114
- return e.split(",").map((n) => Z(n, {
115
- from: "string",
116
- to: r.toSubtype
117
- }));
118
- if (a === "string" && t === "boolean")
188
+ if (t === "string" && r === "array" && typeof e == "string" && s.of && !me(s.of))
189
+ return e.split(",").map((n) => ae(n, s.of));
190
+ if (t === "string" && r === "boolean")
119
191
  return e === "true";
120
- if (a === "number" && t === "boolean")
192
+ if (t === "number" && r === "boolean")
121
193
  return e === 1;
122
- if (a === "boolean" && t === "number")
194
+ if (t === "boolean" && r === "number")
123
195
  return e ? 1 : 0;
124
- if (a === "boolean" && t === "string")
196
+ if (t === "boolean" && r === "string")
125
197
  return e ? "true" : "false";
126
- if (a === "number" && t === "string" && typeof e == "number")
198
+ if (t === "number" && r === "string" && typeof e == "number")
127
199
  return e.toString();
128
- if (a === "string" && t === "array" && typeof e == "string")
200
+ if (t === "string" && r === "array" && typeof e == "string")
129
201
  return e.split(",").map((n) => n.trim());
130
- if (a === "string" && t === "date" && typeof e == "string")
202
+ if (t === "string" && r === "date" && typeof e == "string")
131
203
  try {
132
204
  return new Date(e);
133
205
  } catch {
134
206
  return e;
135
207
  }
136
208
  else {
137
- if (a === "date" && t === "string")
209
+ if (t === "date" && r === "string")
138
210
  return e instanceof Date && e.toISOString();
139
- if (a === "number" && t === "date" && typeof e == "number")
211
+ if (t === "number" && r === "date" && typeof e == "number")
140
212
  try {
141
213
  return new Date(e);
142
214
  } catch {
143
215
  return e;
144
216
  }
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);
217
+ else if (t === "string" && r === "reference" && typeof e == "string") {
218
+ const n = e.split("/").slice(0, -1).join("/"), l = e.split("/").slice(-1)[0];
219
+ return new Xe(l, n);
148
220
  } else {
149
- if (a === t)
221
+ if (t === r)
150
222
  return e;
151
- if (a === "array" && t === "string" && Array.isArray(e))
223
+ if (t === "array" && r === "string" && Array.isArray(e))
152
224
  return e.join(",");
153
225
  }
154
226
  }
155
227
  return e;
156
228
  }
157
- function at(e) {
229
+ function vt(e) {
158
230
  return typeof e == "number" ? "number" : typeof e == "string" ? "string" : typeof e == "boolean" ? "boolean" : e instanceof Date ? "date" : Array.isArray(e) ? "array" : "map";
159
231
  }
160
- function it(e, r) {
161
- function a(t, n) {
162
- const i = {};
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];
170
- });
171
- return;
172
- }
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,
178
- to: m,
179
- fromSubtype: h,
180
- toSubtype: g
181
- });
182
- }
183
- }
184
- }), i;
185
- }
186
- return a(r);
187
- }
188
- function ot({
189
- idColumn: e,
190
- headersMapping: r,
191
- originProperties: a,
192
- destinationProperties: t,
193
- onIdPropertyChanged: n,
194
- buildPropertyView: i
232
+ function Ct({
233
+ importConfig: e,
234
+ destinationProperties: a,
235
+ buildPropertyView: s
195
236
  }) {
196
- return /* @__PURE__ */ f(M, { children: [
197
- /* @__PURE__ */ o(
198
- st,
237
+ const t = e.headersMapping, r = e.headingsOrder, n = e.idColumn, l = e.originProperties;
238
+ return /* @__PURE__ */ p(M, { children: [
239
+ /* @__PURE__ */ i(
240
+ wt,
199
241
  {
200
- idColumn: e,
201
- headersMapping: r,
202
- onChange: n
242
+ idColumn: n,
243
+ headersMapping: t,
244
+ onChange: (o) => e.setIdColumn(o ?? void 0)
203
245
  }
204
246
  ),
205
- /* @__PURE__ */ f(Le, { style: {
247
+ /* @__PURE__ */ i("div", { className: "h-4" }),
248
+ /* @__PURE__ */ p(fe, { style: {
206
249
  tableLayout: "fixed"
207
250
  }, children: [
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" })
251
+ /* @__PURE__ */ p(he, { children: [
252
+ /* @__PURE__ */ i(w, { header: !0, style: { width: "20%" }, children: "Column in file" }),
253
+ /* @__PURE__ */ i(w, { header: !0 }),
254
+ /* @__PURE__ */ i(w, { header: !0, style: { width: "75%" }, children: "Map to Property" })
212
255
  ] }),
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(
220
- u,
256
+ /* @__PURE__ */ i(ge, { children: a && r.map(
257
+ (o) => {
258
+ const c = t[o], d = t[o], u = c ? J(a, c) : null, m = J(l, o), h = m ? m.dataType === "array" && typeof m.of == "object" ? `${m.dataType} - ${m.of.dataType}` : m.dataType : void 0;
259
+ return /* @__PURE__ */ p(xe, { style: { height: "90px" }, children: [
260
+ /* @__PURE__ */ p(w, { style: { width: "20%" }, children: [
261
+ /* @__PURE__ */ i(f, { variant: "body2", children: o }),
262
+ m && /* @__PURE__ */ i(
263
+ f,
221
264
  {
222
265
  variant: "caption",
223
266
  color: "secondary",
224
- children: m
267
+ children: h
225
268
  }
226
269
  )
227
270
  ] }),
228
- /* @__PURE__ */ o(k, { children: /* @__PURE__ */ o(Ue, {}) }),
229
- /* @__PURE__ */ o(
230
- k,
271
+ /* @__PURE__ */ i(w, { children: /* @__PURE__ */ i(ye, {}) }),
272
+ /* @__PURE__ */ i(
273
+ w,
231
274
  {
232
- className: s === e ? "text-center" : void 0,
275
+ className: o === n ? "text-center" : void 0,
233
276
  style: { width: "75%" },
234
- children: i?.({
235
- isIdColumn: s === e,
236
- property: l,
237
- propertyKey: c,
238
- importKey: s
277
+ children: s?.({
278
+ isIdColumn: o === n,
279
+ property: u,
280
+ propertyKey: d,
281
+ importKey: o
239
282
  })
240
283
  }
241
284
  )
242
- ] }, s);
285
+ ] }, o);
243
286
  }
244
287
  ) })
288
+ ] }),
289
+ /* @__PURE__ */ p(nt, { title: "Default values", initiallyExpanded: !1, className: "p-4 mt-4", children: [
290
+ /* @__PURE__ */ i("div", { className: "text-sm text-slate-500 dark:text-slate-300 font-medium ml-3.5 mb-1", children: "You can select a default value for unmapped columns and empty values:" }),
291
+ /* @__PURE__ */ p(fe, { style: {
292
+ tableLayout: "fixed"
293
+ }, children: [
294
+ /* @__PURE__ */ p(he, { children: [
295
+ /* @__PURE__ */ i(w, { header: !0, style: { width: "30%" }, children: "Property" }),
296
+ /* @__PURE__ */ i(w, { header: !0 }),
297
+ /* @__PURE__ */ i(w, { header: !0, style: { width: "65%" }, children: "Default value" })
298
+ ] }),
299
+ /* @__PURE__ */ i(ge, { children: a && Me(a).map(
300
+ (o) => {
301
+ const c = J(a, o);
302
+ return typeof c != "object" || c === null || !["number", "string", "boolean", "map"].includes(c.dataType) ? null : /* @__PURE__ */ p(xe, { style: { height: "70px" }, children: [
303
+ /* @__PURE__ */ i(w, { style: { width: "20%" }, children: /* @__PURE__ */ i(f, { variant: "body2", children: o }) }),
304
+ /* @__PURE__ */ i(w, { children: /* @__PURE__ */ i(ye, {}) }),
305
+ /* @__PURE__ */ i(
306
+ w,
307
+ {
308
+ className: o === n ? "text-center" : void 0,
309
+ style: { width: "75%" },
310
+ children: /* @__PURE__ */ i(
311
+ Dt,
312
+ {
313
+ property: c,
314
+ defaultValue: Fe(e.defaultValues, o),
315
+ onValueChange: (d) => {
316
+ const u = ft(e.defaultValues, o, d);
317
+ e.setDefaultValues(u);
318
+ }
319
+ }
320
+ )
321
+ }
322
+ )
323
+ ] }, o);
324
+ }
325
+ ) })
326
+ ] })
245
327
  ] })
246
328
  ] });
247
329
  }
248
- function st({
330
+ function Me(e, a) {
331
+ return Object.entries(e).reduce((s, [t, r]) => {
332
+ const n = a ? `${a}.${t}` : t;
333
+ if (typeof r != "function" && r.dataType === "map" && r.properties) {
334
+ const l = Me(r.properties, n);
335
+ return [...s, ...l];
336
+ }
337
+ return [...s, n];
338
+ }, []);
339
+ }
340
+ function wt({
249
341
  idColumn: e,
250
- headersMapping: r,
251
- onChange: a
342
+ headersMapping: a,
343
+ onChange: s
252
344
  }) {
253
- return /* @__PURE__ */ o("div", { children: /* @__PURE__ */ f(
254
- ge,
345
+ return /* @__PURE__ */ i("div", { children: /* @__PURE__ */ p(
346
+ Ae,
255
347
  {
256
348
  size: "small",
257
349
  value: e ?? "",
258
350
  onChange: (t) => {
259
- const n = t.target.value;
260
- a(n === "none" ? null : n);
351
+ const r = t.target.value;
352
+ s(r === "__none__" ? null : r);
261
353
  },
262
- renderValue: (t) => /* @__PURE__ */ o(u, { variant: "body2", children: t !== "" ? t : "Autogenerate ID" }),
354
+ placeholder: "Autogenerate ID",
355
+ renderValue: (t) => /* @__PURE__ */ i(f, { variant: "body2", children: t !== "__none__" ? t : "Autogenerate ID" }),
263
356
  label: "Column that will be used as ID for each document",
264
357
  children: [
265
- /* @__PURE__ */ o(H, { value: "none", children: "Autogenerate ID" }),
266
- Object.entries(r).map(([t, n]) => /* @__PURE__ */ o(H, { value: t, children: t }, t))
358
+ /* @__PURE__ */ i(H, { value: "__none__", children: "Autogenerate ID" }),
359
+ Object.entries(a).map(([t, r]) => /* @__PURE__ */ i(H, { value: t, children: t }, t))
267
360
  ]
268
361
  }
269
362
  ) });
270
363
  }
271
- function lt({ onDataAdded: e }) {
272
- const r = pe();
273
- return /* @__PURE__ */ o(
274
- We,
364
+ function Dt({
365
+ property: e,
366
+ onValueChange: a,
367
+ defaultValue: s
368
+ }) {
369
+ return e.dataType === "string" ? /* @__PURE__ */ i(
370
+ re,
371
+ {
372
+ size: "small",
373
+ placeholder: "Default value",
374
+ value: s ?? "",
375
+ onChange: (t) => a(t.target.value)
376
+ }
377
+ ) : e.dataType === "number" ? /* @__PURE__ */ i(
378
+ re,
379
+ {
380
+ size: "small",
381
+ type: "number",
382
+ value: s ?? "",
383
+ placeholder: "Default value",
384
+ onChange: (t) => a(t.target.value)
385
+ }
386
+ ) : e.dataType === "boolean" ? /* @__PURE__ */ i(
387
+ Y,
388
+ {
389
+ value: s ?? null,
390
+ allowIndeterminate: !0,
391
+ size: "small",
392
+ onValueChange: (t) => a(t === null ? void 0 : t),
393
+ label: s === void 0 ? "Do not set value" : s === !0 ? "Set value to true" : "Set value to false"
394
+ }
395
+ ) : e.dataType === "date" ? /* @__PURE__ */ i(
396
+ st,
397
+ {
398
+ mode: e.mode ?? "date",
399
+ size: "small",
400
+ value: s ?? void 0,
401
+ onChange: (t) => {
402
+ a(t);
403
+ },
404
+ clearable: !0
405
+ }
406
+ ) : null;
407
+ }
408
+ function Nt({ onDataAdded: e }) {
409
+ const a = Se();
410
+ return /* @__PURE__ */ i(
411
+ it,
275
412
  {
276
413
  accept: {
277
414
  "text/*": [".csv", ".xls", ".xlsx"],
@@ -286,208 +423,212 @@ function lt({ onDataAdded: e }) {
286
423
  preventDropOnDocument: !0,
287
424
  size: "small",
288
425
  maxFiles: 1,
289
- uploadDescription: /* @__PURE__ */ f(M, { children: [
290
- /* @__PURE__ */ o(ze, {}),
426
+ uploadDescription: /* @__PURE__ */ p(M, { children: [
427
+ /* @__PURE__ */ i(lt, {}),
291
428
  "Drag and drop a file here or click to upload"
292
429
  ] }),
293
- onFilesAdded: (a) => {
294
- a.length > 0 && tt(a[0]).then((t) => {
295
- e(t);
430
+ onFilesAdded: (s) => {
431
+ s.length > 0 && xt(s[0]).then(({
432
+ data: t,
433
+ propertiesOrder: r
434
+ }) => {
435
+ e(t, r);
296
436
  }).catch((t) => {
297
- console.error("Error parsing file", t), r.open({ type: "error", message: t.message });
437
+ console.error("Error parsing file", t), a.open({
438
+ type: "error",
439
+ message: t.message
440
+ });
298
441
  });
299
442
  }
300
443
  }
301
444
  );
302
445
  }
303
- function Dt({
446
+ function Bt({
304
447
  propertyKey: e,
305
- property: r,
306
- onEditClick: a,
448
+ property: a,
449
+ onEditClick: s,
307
450
  includeName: t = !0,
308
- onPropertyNameChanged: n,
309
- propertyTypeView: i
451
+ onPropertyNameChanged: r,
452
+ propertyTypeView: n
310
453
  }) {
311
- const { propertyConfigs: s } = X(), d = r ? fe(r, s) : null;
312
- return /* @__PURE__ */ o(Te, { children: /* @__PURE__ */ f(
454
+ const { propertyConfigs: l } = q(), o = a ? Oe(a, l) : null;
455
+ return /* @__PURE__ */ i(Ge, { children: /* @__PURE__ */ p(
313
456
  "div",
314
457
  {
315
458
  className: "flex flex-row w-full items-center",
316
459
  children: [
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(
320
- Ve,
460
+ /* @__PURE__ */ i("div", { className: "mx-4", children: n ?? /* @__PURE__ */ i(ke, { propertyConfig: o ?? void 0 }) }),
461
+ /* @__PURE__ */ i("div", { className: "w-full flex flex-col grow", children: /* @__PURE__ */ p("div", { className: "flex flex-row items-center gap-2", children: [
462
+ t && /* @__PURE__ */ i(
463
+ re,
321
464
  {
322
465
  size: "small",
323
466
  className: "text-base grow",
324
- value: r?.name ?? "",
467
+ value: a?.name ?? "",
325
468
  onChange: (c) => {
326
- n && e && n(e, c.target.value);
469
+ r && e && r(e, c.target.value);
327
470
  }
328
471
  }
329
472
  ),
330
- /* @__PURE__ */ o(ee, { onClick: a, size: "small", children: /* @__PURE__ */ o(Ge, { size: "small" }) })
473
+ /* @__PURE__ */ i(Q, { onClick: s, size: "small", children: /* @__PURE__ */ i(ot, { size: "small" }) })
331
474
  ] }) })
332
475
  ]
333
476
  }
334
477
  ) });
335
478
  }
336
- function ct({
479
+ function St({
337
480
  path: e,
338
- importConfig: r,
339
- collection: a,
481
+ importConfig: a,
482
+ collection: s,
340
483
  onImportSuccess: t
341
484
  }) {
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(
485
+ const [r, n] = N(void 0), l = Ie(), o = He(!1), [c, d] = N(0);
486
+ function u() {
487
+ o.current || (o.current = !0, Re(
488
+ l,
345
489
  s,
346
- a,
347
490
  e,
348
- r.entities,
491
+ a.entities,
349
492
  0,
350
493
  25,
351
- l
494
+ d
352
495
  ).then(() => {
353
- t(a), d.current = !1;
496
+ t(s), o.current = !1;
354
497
  }).catch((m) => {
355
- i(m), d.current = !1;
498
+ n(m), o.current = !1;
356
499
  }));
357
500
  }
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,
501
+ return Ne(() => {
502
+ u();
503
+ }, []), r ? /* @__PURE__ */ p(be, { className: "flex flex-col gap-4 items-center", children: [
504
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Error saving data" }),
505
+ /* @__PURE__ */ i(f, { variant: "body2", color: "error", children: r.message }),
506
+ /* @__PURE__ */ i(
507
+ S,
365
508
  {
366
- onClick: p,
509
+ onClick: u,
367
510
  variant: "outlined",
368
511
  children: "Retry"
369
512
  }
370
513
  )
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: [
514
+ ] }) : /* @__PURE__ */ p(be, { className: "flex flex-col gap-4 items-center", children: [
515
+ /* @__PURE__ */ i(Ee, {}),
516
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Saving data" }),
517
+ /* @__PURE__ */ p(f, { variant: "body2", children: [
375
518
  c,
376
519
  "/",
377
- r.entities.length,
520
+ a.entities.length,
378
521
  " entities saved"
379
522
  ] }),
380
- /* @__PURE__ */ o(u, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
523
+ /* @__PURE__ */ i(f, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
381
524
  ] });
382
525
  }
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,
526
+ function Re(e, a, s, t, r = 0, n = 25, l) {
527
+ console.debug("Saving imported data", r, n);
528
+ const o = t.slice(r, r + n);
529
+ return Promise.all(o.map((c) => e.saveEntity({
530
+ path: s,
388
531
  values: c.values,
389
532
  entityId: c.id,
390
- collection: r,
533
+ collection: a,
391
534
  status: "new"
392
- }))).then(() => n + i < t.length ? (s(n + i), Se(e, r, a, t, n + i, i, s)) : (s(t.length), Promise.resolve()));
535
+ }))).then(() => r + n < t.length ? (l(r + n), Re(e, a, s, t, r + n, n, l)) : (l(t.length), Promise.resolve()));
393
536
  }
394
- function dt({
537
+ function Ot({
395
538
  collection: e,
396
- path: r,
397
- collectionEntitiesCount: a,
539
+ path: a,
540
+ collectionEntitiesCount: s,
398
541
  onAnalyticsEvent: t
399
542
  }) {
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);
543
+ const r = q(), n = Se(), [l, o] = b.useState(!1), [c, d] = b.useState("initial"), u = ht(), m = C(() => {
544
+ o(!0), t?.("import_open"), d("initial");
545
+ }, [t]), h = C(() => {
546
+ o(!1);
547
+ }, [o]), g = C(() => {
548
+ t?.("import_mapping_complete"), d("preview");
549
+ }, [t]), y = C(() => {
550
+ t?.("import_data_save"), d("import_data_saving");
551
+ }, [t]), A = async (v) => {
552
+ if (u.setImportData(v), v.length > 0) {
553
+ const P = await mt(v, vt);
554
+ u.setOriginProperties(P);
555
+ const E = $e(v, e?.properties);
556
+ u.setHeadersMapping(E);
557
+ const O = Object.keys(E)?.[0];
558
+ (O?.includes("id") || O?.includes("key")) && u.setIdColumn(O);
416
559
  }
417
560
  setTimeout(() => {
418
- l("mapping");
561
+ t?.("import_data_added"), d("mapping");
419
562
  }, 100);
420
- }, $ = he({
563
+ }, F = _e({
421
564
  collection: e,
422
- path: r,
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(
428
- be,
565
+ path: a,
566
+ fields: r.propertyConfigs
567
+ }), j = Ye(F.properties, F.propertiesOrder), z = Object.entries(j).flatMap(([v, P]) => Ve(v, P, 0)), ce = F.propertiesOrder ?? Object.keys(F.properties);
568
+ return e.collectionGroup ? null : /* @__PURE__ */ p(M, { children: [
569
+ /* @__PURE__ */ i(Z, { title: "Import", children: /* @__PURE__ */ i(Q, { color: "primary", onClick: m, children: /* @__PURE__ */ i(ct, {}) }) }),
570
+ /* @__PURE__ */ p(
571
+ se,
429
572
  {
430
- open: s,
573
+ open: l,
431
574
  fullWidth: c === "preview",
432
575
  fullHeight: c === "preview",
433
576
  maxWidth: c === "initial" ? "lg" : "7xl",
434
577
  children: [
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 })
578
+ /* @__PURE__ */ p(ie, { className: "flex flex-col gap-4 my-4", fullHeight: c === "preview", children: [
579
+ c === "initial" && /* @__PURE__ */ p(M, { children: [
580
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Import data" }),
581
+ /* @__PURE__ */ i(f, { variant: "body2", children: "Upload a CSV, Excel or JSON file and map it to your existing schema" }),
582
+ /* @__PURE__ */ i(Nt, { onDataAdded: A })
440
583
  ] }),
441
- c === "mapping" && /* @__PURE__ */ f(M, { children: [
442
- /* @__PURE__ */ o(u, { variant: "h6", children: "Map fields" }),
443
- /* @__PURE__ */ o(
444
- ot,
584
+ c === "mapping" && /* @__PURE__ */ p(M, { children: [
585
+ /* @__PURE__ */ i(f, { variant: "h6", className: "ml-3.5", children: "Map fields" }),
586
+ /* @__PURE__ */ i(
587
+ Ct,
445
588
  {
446
- headersMapping: p.headersMapping,
447
- idColumn: p.idColumn,
448
- originProperties: p.originProperties,
449
- destinationProperties: x,
450
- onIdPropertyChanged: (y) => p.setIdColumn(y ?? void 0),
589
+ importConfig: u,
590
+ destinationProperties: j,
451
591
  buildPropertyView: ({
452
- isIdColumn: y,
453
- property: T,
454
- propertyKey: L,
455
- importKey: w
456
- }) => /* @__PURE__ */ o(
457
- pt,
592
+ isIdColumn: v,
593
+ property: P,
594
+ propertyKey: E,
595
+ importKey: O
596
+ }) => /* @__PURE__ */ i(
597
+ kt,
458
598
  {
459
- selectedPropertyKey: L ?? "",
460
- properties: x,
461
- propertiesAndLevel: U,
462
- isIdColumn: y,
599
+ selectedPropertyKey: E ?? "",
600
+ properties: j,
601
+ propertiesAndLevel: z,
602
+ isIdColumn: v,
463
603
  onIdSelected: () => {
464
- p.setIdColumn(w);
604
+ u.setIdColumn(O);
465
605
  },
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);
606
+ onPropertySelected: (R) => {
607
+ t?.("import_mapping_field_updated");
608
+ const de = Object.entries(u.headersMapping).map(([k, V]) => V === R ? { [k]: null } : k === O ? { [k]: R } : { [k]: V }).reduce((k, V) => ({ ...k, ...V }), {});
609
+ u.setHeadersMapping(de), R === u.idColumn && u.setIdColumn(void 0);
469
610
  }
470
611
  }
471
612
  )
472
613
  }
473
614
  )
474
615
  ] }),
475
- c === "preview" && /* @__PURE__ */ o(
476
- ft,
616
+ c === "preview" && /* @__PURE__ */ i(
617
+ It,
477
618
  {
478
- importConfig: p,
479
- properties: x,
480
- propertiesOrder: R
619
+ importConfig: u,
620
+ properties: j,
621
+ propertiesOrder: ce
481
622
  }
482
623
  ),
483
- c === "import_data_saving" && p && /* @__PURE__ */ o(
484
- ct,
624
+ c === "import_data_saving" && u && /* @__PURE__ */ i(
625
+ St,
485
626
  {
486
- importConfig: p,
627
+ importConfig: u,
487
628
  collection: e,
488
- path: r,
489
- onImportSuccess: (y) => {
490
- h(), i.open({
629
+ path: a,
630
+ onImportSuccess: (v) => {
631
+ h(), n.open({
491
632
  type: "info",
492
633
  message: "Data imported successfully"
493
634
  });
@@ -495,44 +636,44 @@ function dt({
495
636
  }
496
637
  )
497
638
  ] }),
498
- /* @__PURE__ */ f(ve, { children: [
499
- c === "mapping" && /* @__PURE__ */ o(
500
- E,
639
+ /* @__PURE__ */ p(le, { children: [
640
+ c === "mapping" && /* @__PURE__ */ i(
641
+ S,
501
642
  {
502
- onClick: () => l("initial"),
643
+ onClick: () => d("initial"),
503
644
  variant: "text",
504
645
  children: "Back"
505
646
  }
506
647
  ),
507
- c === "preview" && /* @__PURE__ */ o(
508
- E,
648
+ c === "preview" && /* @__PURE__ */ i(
649
+ S,
509
650
  {
510
- onClick: () => l("mapping"),
651
+ onClick: () => d("mapping"),
511
652
  variant: "text",
512
653
  children: "Back"
513
654
  }
514
655
  ),
515
- /* @__PURE__ */ o(
516
- E,
656
+ /* @__PURE__ */ i(
657
+ S,
517
658
  {
518
659
  onClick: h,
519
660
  variant: "text",
520
661
  children: "Cancel"
521
662
  }
522
663
  ),
523
- c === "mapping" && /* @__PURE__ */ o(
524
- E,
664
+ c === "mapping" && /* @__PURE__ */ i(
665
+ S,
525
666
  {
526
667
  variant: "filled",
527
668
  onClick: g,
528
669
  children: "Next"
529
670
  }
530
671
  ),
531
- c === "preview" && /* @__PURE__ */ o(
532
- E,
672
+ c === "preview" && /* @__PURE__ */ i(
673
+ S,
533
674
  {
534
675
  variant: "filled",
535
- onClick: I,
676
+ onClick: y,
536
677
  children: "Save data"
537
678
  }
538
679
  )
@@ -542,48 +683,48 @@ function dt({
542
683
  )
543
684
  ] });
544
685
  }
545
- const V = "__internal_id__";
546
- function pt({
686
+ const X = "__internal_id__";
687
+ function kt({
547
688
  selectedPropertyKey: e,
548
- properties: r,
549
- onPropertySelected: a,
689
+ properties: a,
690
+ onPropertySelected: s,
550
691
  onIdSelected: t,
551
- propertiesAndLevel: n,
552
- isIdColumn: i
692
+ propertiesAndLevel: r,
693
+ isIdColumn: n
553
694
  }) {
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(
555
- se,
695
+ const l = e ? J(a, e) : null, o = C((d) => d === X ? /* @__PURE__ */ i(f, { variant: "body2", className: "p-4", children: "Use this column as ID" }) : !d || !l ? /* @__PURE__ */ i(f, { variant: "body2", color: "disabled", className: "p-4", children: "Do not import this property" }) : /* @__PURE__ */ i(
696
+ Ce,
556
697
  {
557
- propertyKey: l,
558
- property: s
698
+ propertyKey: d,
699
+ property: l
559
700
  }
560
- ), [s]), c = b((l) => {
561
- l === V ? (t(), a(null)) : a(l === "__do_not_import" ? null : l);
562
- }, []);
563
- return /* @__PURE__ */ f(
564
- ge,
701
+ ), [l]);
702
+ return /* @__PURE__ */ p(
703
+ Ae,
565
704
  {
566
- value: i ? V : e ?? void 0,
567
- onValueChange: c,
568
- renderValue: d,
705
+ value: n ? X : e ?? void 0,
706
+ onValueChange: (d) => {
707
+ d === X ? (t(), s(null)) : s(d === "__do_not_import" ? null : d);
708
+ },
709
+ renderValue: o,
569
710
  children: [
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,
711
+ /* @__PURE__ */ i(H, { value: "__do_not_import", children: /* @__PURE__ */ i(f, { variant: "body2", color: "disabled", className: "p-4", children: "Do not import this property" }) }),
712
+ /* @__PURE__ */ i(H, { value: X, children: /* @__PURE__ */ i(f, { variant: "body2", className: "p-4", children: "Use this column as ID" }) }),
713
+ r.map(({
714
+ property: d,
715
+ level: u,
575
716
  propertyKey: m
576
- }) => /* @__PURE__ */ o(
717
+ }) => /* @__PURE__ */ i(
577
718
  H,
578
719
  {
579
720
  value: m,
580
- disabled: l.dataType === "map",
581
- children: /* @__PURE__ */ o(
582
- se,
721
+ disabled: d.dataType === "map",
722
+ children: /* @__PURE__ */ i(
723
+ Ce,
583
724
  {
584
725
  propertyKey: m,
585
- property: l,
586
- level: p
726
+ property: d,
727
+ level: u
587
728
  }
588
729
  )
589
730
  },
@@ -593,41 +734,41 @@ function pt({
593
734
  }
594
735
  );
595
736
  }
596
- function De(e, r, a) {
737
+ function Ve(e, a, s) {
597
738
  const t = [];
598
739
  return t.push({
599
- property: r,
600
- level: a,
740
+ property: a,
741
+ level: s,
601
742
  propertyKey: e
602
- }), r.dataType === "map" && r.properties && Object.entries(r.properties).forEach(([n, i]) => {
603
- t.push(...De(`${e}.${n}`, i, a + 1));
743
+ }), a.dataType === "map" && a.properties && Object.entries(a.properties).forEach(([r, n]) => {
744
+ t.push(...Ve(`${e}.${r}`, n, s + 1));
604
745
  }), t;
605
746
  }
606
- function se({
747
+ function Ce({
607
748
  propertyKey: e,
608
- property: r,
609
- level: a = 0
749
+ property: a,
750
+ level: s = 0
610
751
  }) {
611
- const { propertyConfigs: t } = X(), n = fe(r, t);
612
- return /* @__PURE__ */ f(
752
+ const { propertyConfigs: t } = q(), r = Oe(a, t);
753
+ return /* @__PURE__ */ p(
613
754
  "div",
614
755
  {
615
756
  className: "flex flex-row w-full text-start items-center h-full",
616
757
  children: [
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(
621
- u,
758
+ new Array(s).fill(0).map((n, l) => /* @__PURE__ */ i("div", { className: _(dt, "ml-8 border-l h-12") }, l)),
759
+ /* @__PURE__ */ i("div", { className: "m-4", children: /* @__PURE__ */ i(Z, { title: r?.name, children: /* @__PURE__ */ i(ke, { propertyConfig: r }) }) }),
760
+ /* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
761
+ /* @__PURE__ */ i(
762
+ f,
622
763
  {
623
764
  variant: "body1",
624
765
  component: "span",
625
766
  className: "flex-grow pr-2",
626
- children: r.name ? r.name : " "
767
+ children: a.name ? a.name : " "
627
768
  }
628
769
  ),
629
- /* @__PURE__ */ o(
630
- u,
770
+ /* @__PURE__ */ i(
771
+ f,
631
772
  {
632
773
  className: " pr-2",
633
774
  variant: "body2",
@@ -641,216 +782,258 @@ function se({
641
782
  }
642
783
  );
643
784
  }
644
- function ft({
785
+ function It({
645
786
  importConfig: e,
646
- properties: r,
647
- propertiesOrder: a
787
+ properties: a,
788
+ propertiesOrder: s
648
789
  }) {
649
- de(() => {
650
- const n = it(e.originProperties, r), i = e.importData.map((s) => nt(s, e.idColumn, e.headersMapping, r, n, "TEMP_PATH"));
651
- e.setEntities(i);
790
+ Ne(() => {
791
+ const r = e.importData.map((n) => bt(n, e.idColumn, e.headersMapping, a, "TEMP_PATH", e.defaultValues));
792
+ e.setEntities(r);
652
793
  }, []);
653
- const t = Fe();
654
- return /* @__PURE__ */ o(
655
- Pe,
794
+ const t = qe();
795
+ return /* @__PURE__ */ i(
796
+ Qe,
656
797
  {
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" })
798
+ title: /* @__PURE__ */ p("div", { children: [
799
+ /* @__PURE__ */ i(f, { variant: "subtitle2", children: "Imported data preview" }),
800
+ /* @__PURE__ */ i(f, { variant: "caption", children: "Entities with the same id will be overwritten" })
660
801
  ] }),
661
802
  tableController: {
662
803
  data: e.entities,
663
804
  dataLoading: !1,
664
805
  noMoreToLoad: !1
665
806
  },
666
- endAdornment: /* @__PURE__ */ o("div", { className: "h-12" }),
807
+ enablePopupIcon: !1,
808
+ endAdornment: /* @__PURE__ */ i("div", { className: "h-12" }),
667
809
  filterable: !1,
668
810
  sortable: !1,
669
811
  selectionController: t,
670
- displayedColumnIds: a.map((n) => ({
671
- key: n,
672
- disabled: !1
673
- })),
674
- properties: r
812
+ properties: a
675
813
  }
676
814
  );
677
815
  }
678
- function Ne(e, r) {
679
- const a = {};
816
+ function $e(e, a) {
817
+ const s = {};
680
818
  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}`;
819
+ Object.keys(t).forEach((r) => {
820
+ const n = t[r];
821
+ if (typeof n == "object" && !Array.isArray(n)) {
822
+ const l = a?.[r], o = l && "properties" in l ? l.properties : void 0, c = $e([n], o);
823
+ Object.entries(c).forEach(([d, u]) => {
824
+ s[`${r}.${d}`] = `${r}.${u}`;
687
825
  });
688
826
  }
689
- if (!r)
690
- a[n] = n;
691
- else if (n in r)
692
- a[n] = n;
827
+ if (!a)
828
+ s[r] = r;
829
+ else if (r in a)
830
+ s[r] = r;
693
831
  else {
694
- const s = ke(n);
695
- s in r ? a[n] = s : a[n] = n;
832
+ const l = Ze(r);
833
+ l in a ? s[r] = l : s[r] = r;
696
834
  }
697
835
  });
698
- }), a;
699
- }
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;
703
- if (i === "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");
836
+ }), s;
837
+ }
838
+ function Be({
839
+ data: e,
840
+ additionalData: a,
841
+ properties: s,
842
+ propertiesOrder: t,
843
+ name: r,
844
+ flattenArrays: n,
845
+ additionalHeaders: l,
846
+ exportType: o,
847
+ dateExportType: c
848
+ }) {
849
+ if (console.debug("Downloading export", {
850
+ dataLength: e.length,
851
+ properties: s,
852
+ exportType: o,
853
+ dateExportType: c
854
+ }), o === "csv") {
855
+ const d = n ? Ke(e.map((y) => y.values)) : {}, u = Et(s, t, l, d), m = _t(e, a, s, u, c), h = we(u.map((y) => y.label)), g = m.map((y) => we(y));
856
+ De([h, ...g], `${r}.csv`, "text/csv");
706
857
  } else {
707
- const c = ht(e, r, d, s), l = JSON.stringify(c, null, 2);
708
- ce([l], `${a.name}.json`, "application/json");
858
+ const d = At(e, a, s, c), u = JSON.stringify(d, null, 2);
859
+ De([u], `${r}.json`, "application/json");
709
860
  }
710
861
  }
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)
862
+ function _t(e, a, s, t, r) {
863
+ const n = e.map((l) => ({
864
+ id: l.id,
865
+ ...oe(l.values, s, "csv", r)
715
866
  }));
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)));
719
- }
720
- function ht(e, r, a, t) {
721
- const n = e.map((i) => ({
722
- id: i.id,
723
- ...re(i.values, a, "json", t)
867
+ return a && a.forEach((l, o) => {
868
+ n[o] = { ...n[o], ...l };
869
+ }), n && n.map((l) => t.map((o) => et(l, o.key)));
870
+ }
871
+ function At(e, a, s, t) {
872
+ const r = e.map((n) => ({
873
+ id: n.id,
874
+ ...oe(n.values, s, "json", t)
724
875
  }));
725
- return r && r.forEach((i, s) => {
726
- n[s] = { ...n[s], ...i };
727
- }), n;
728
- }
729
- function gt(e, r, a) {
730
- const t = [
731
- { label: "id", key: "id" },
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, ""))
876
+ return a && a.forEach((n, l) => {
877
+ r[l] = { ...r[l], ...n };
878
+ }), r;
879
+ }
880
+ function Et(e, a, s, t) {
881
+ const r = [
882
+ {
883
+ label: "id",
884
+ key: "id"
885
+ },
886
+ ...(a ?? Object.keys(e)).flatMap((n) => {
887
+ const l = e[n];
888
+ return l ? t && t[n] > 1 ? Array.from(
889
+ { length: t[n] },
890
+ (o, c) => ne(l, `${n}[${c}]`, "")
891
+ ).flat() : ne(l, n, "") : (console.warn("Property not found", n, e), []);
892
+ })
736
893
  ];
737
- return r && t.push(...r.map((n) => ({ label: n, key: n }))), t;
894
+ return s && r.push(...s.map((n) => ({
895
+ label: n,
896
+ key: n
897
+ }))), r;
738
898
  }
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 }];
899
+ function ne(e, a, s = "") {
900
+ const t = s ? `${s}.${a}` : a;
901
+ return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([r, n]) => ne(n, r, t)).flat() : [{
902
+ label: t,
903
+ key: t
904
+ }];
742
905
  }
743
- function G(e, r, a, t) {
744
- let n;
745
- if (r.dataType === "map" && r.properties)
746
- n = re(e, r.properties, a, t);
747
- else if (r.dataType === "array")
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()) {
750
- const i = e || void 0;
751
- n = i ? i.pathWithId : null;
752
- } else
753
- r.dataType === "date" && e instanceof Date ? n = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : n = e;
754
- return n;
755
- }
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 };
762
- }
763
- function le(e) {
764
- return e.map((r) => r == null ? "" : Array.isArray(r) ? '"' + JSON.stringify(r).replaceAll('"', '\\"') + '"' : '"' + String(r).replaceAll('"', '""') + '"').join(",") + `\r
906
+ function G(e, a, s, t) {
907
+ let r;
908
+ if (a.dataType === "map" && a.properties)
909
+ r = oe(e, a.properties, s, t);
910
+ else if (a.dataType === "array")
911
+ a.of && Array.isArray(e) ? Array.isArray(a.of) ? r = a.of.map((n, l) => G(e[l], n, s, t)) : a.of.dataType === "map" ? r = s === "csv" ? e.map((n) => JSON.stringify(n)) : e.map((n) => G(n, a.of, s, t)) : r = e.map((n) => G(n, a.of, s, t)) : r = e;
912
+ else if (a.dataType === "reference" && e && e.isEntityReference && e.isEntityReference()) {
913
+ const n = e || void 0;
914
+ r = n ? n.pathWithId : null;
915
+ } else a.dataType === "date" && e instanceof Date ? r = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : r = e;
916
+ return r;
917
+ }
918
+ function oe(e, a, s, t) {
919
+ const r = Object.entries(a).map(([n, l]) => {
920
+ const o = e && e[n], c = G(o, l, s, t);
921
+ return c === void 0 ? {} : { [n]: c };
922
+ }).reduce((n, l) => ({ ...n, ...l }), {});
923
+ return { ...e, ...r };
924
+ }
925
+ function we(e) {
926
+ return e.map((a) => a == null ? "" : Array.isArray(a) ? '"' + JSON.stringify(a).replaceAll('"', '\\"') + '"' : '"' + String(a).replaceAll('"', '""') + '"').join(",") + `\r
765
927
  `;
766
928
  }
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();
929
+ function De(e, a, s) {
930
+ const t = new Blob(e, { type: s }), r = URL.createObjectURL(t), n = document.createElement("a");
931
+ n.href = r, n.setAttribute("download", a), n.click();
770
932
  }
771
- const yt = 500;
772
- function bt({
933
+ const Tt = 500;
934
+ function Ft({
773
935
  collection: e,
774
- path: r,
775
- collectionEntitiesCount: a,
776
- exportAllowed: t,
936
+ path: a,
937
+ collectionEntitiesCount: s,
938
+ onAnalyticsEvent: t,
939
+ exportAllowed: r,
777
940
  notAllowedView: n
778
941
  }) {
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,
942
+ const l = q(), o = typeof e.exportable == "object" ? e.exportable : void 0, c = b.useRef(/* @__PURE__ */ new Date()), [d, u] = b.useState(!1), [m, h] = b.useState(!0), [g, y] = b.useState("csv"), [A, F] = b.useState("string"), j = tt(), z = Ie(), v = rt().resolveAliasesFrom(a), P = !r || r({
943
+ collectionEntitiesCount: s,
944
+ path: v,
782
945
  collection: e
783
- }), R = C.useMemo(() => he({
946
+ }), E = b.useMemo(() => _e({
784
947
  collection: e,
785
- path: x,
786
- fields: i.propertyConfigs
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) => ({
793
- [v.key]: await v.builder({
794
- entity: F,
795
- context: I
948
+ path: v,
949
+ fields: l.propertyConfigs
950
+ }), [e, v]), [O, R] = b.useState(!1), [de, k] = b.useState(), [V, $] = b.useState(!1), Le = C(() => {
951
+ $(!0);
952
+ }, [$]), K = C(() => {
953
+ $(!1);
954
+ }, [$]), pe = C(async (D) => {
955
+ const W = o?.additionalFields, I = E.additionalFields, ee = W ? await Promise.all(D.map(async (B) => (await Promise.all(W.map(async (x) => ({
956
+ [x.key]: await x.builder({
957
+ entity: B,
958
+ context: j
796
959
  })
797
- })))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [], Q = N ? await Promise.all(P.map(async (F) => (await Promise.all(N.map(async (v) => v.value ? {
798
- [v.key]: await v.value({
799
- entity: F,
800
- context: I
960
+ })))).reduce((x, L) => ({ ...x, ...L }), {}))) : [], te = I ? await Promise.all(D.map(async (B) => (await Promise.all(I.map(async (x) => x.value ? {
961
+ [x.key]: await x.value({
962
+ entity: B,
963
+ context: j
801
964
  })
802
- } : {}))).reduce((v, Y) => ({ ...v, ...Y }), {}))) : [];
803
- return [...q, ...Q];
804
- }, [s?.additionalFields]), ae = b(async (P, W) => {
805
- T(!0), A.fetchCollection({
806
- path: x,
807
- collection: P
808
- }).then(async (N) => {
809
- w(void 0);
810
- const q = await ne(N), Q = [
811
- ...W?.additionalFields?.map((F) => F.key) ?? [],
812
- ...P.additionalFields?.map((F) => F.key) ?? []
813
- ];
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(
824
- be,
965
+ } : {}))).reduce((x, L) => ({ ...x, ...L }), {}))) : [];
966
+ return [...ee, ...te];
967
+ }, [o?.additionalFields]), ue = C(async (D, W) => {
968
+ t?.("export_collection", {
969
+ collection: D.path
970
+ }), R(!0), z.fetchCollection({
971
+ path: v,
972
+ collection: D
973
+ }).then(async (I) => {
974
+ k(void 0);
975
+ const ee = await pe(I), te = [
976
+ ...W?.additionalFields?.map((x) => x.key) ?? [],
977
+ ...D.additionalFields?.map((x) => x.key) ?? []
978
+ ], B = d ? I.map((x) => {
979
+ const L = at(D.properties);
980
+ return {
981
+ ...x,
982
+ values: { ...L, ...x.values }
983
+ };
984
+ }) : I;
985
+ Be({
986
+ data: B,
987
+ additionalData: ee,
988
+ properties: D.properties,
989
+ propertiesOrder: D.propertiesOrder,
990
+ name: D.name,
991
+ flattenArrays: m,
992
+ additionalHeaders: te,
993
+ exportType: g,
994
+ dateExportType: A
995
+ }), t?.("export_collection_success", {
996
+ collection: D.path
997
+ });
998
+ }).catch((I) => {
999
+ console.error("Error loading export data", I), k(I);
1000
+ }).finally(() => R(!1));
1001
+ }, [t, z, v, pe, d, m, g, A]), Je = C(() => {
1002
+ ue(E, o), K();
1003
+ }, [ue, E, o, K]);
1004
+ return /* @__PURE__ */ p(M, { children: [
1005
+ /* @__PURE__ */ i(Z, { title: "Export", children: /* @__PURE__ */ i(Q, { color: "primary", onClick: Le, children: /* @__PURE__ */ i(Te, {}) }) }),
1006
+ /* @__PURE__ */ p(
1007
+ se,
825
1008
  {
826
- open: B,
827
- onOpenChange: j,
1009
+ open: V,
1010
+ onOpenChange: $,
828
1011
  maxWidth: "xl",
829
1012
  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: [
1013
+ /* @__PURE__ */ p(ie, { className: "flex flex-col gap-4 my-4", children: [
1014
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Export data" }),
1015
+ /* @__PURE__ */ i("div", { children: "Download the the content of this table as a CSV" }),
1016
+ s > Tt && /* @__PURE__ */ i(pt, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
834
1017
  "This collections has a large number of documents (",
835
- a,
1018
+ s,
836
1019
  ")."
837
1020
  ] }) }),
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(
1021
+ /* @__PURE__ */ p("div", { className: "flex flex-row gap-4", children: [
1022
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1023
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1024
+ /* @__PURE__ */ i(
842
1025
  "input",
843
1026
  {
844
1027
  id: "radio-csv",
845
1028
  type: "radio",
846
1029
  value: "csv",
847
1030
  name: "exportType",
848
- checked: p === "csv",
849
- onChange: () => m("csv"),
850
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1031
+ checked: g === "csv",
1032
+ onChange: () => y("csv"),
1033
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
851
1034
  }
852
1035
  ),
853
- /* @__PURE__ */ o(
1036
+ /* @__PURE__ */ i(
854
1037
  "label",
855
1038
  {
856
1039
  htmlFor: "radio-csv",
@@ -859,20 +1042,20 @@ function bt({
859
1042
  }
860
1043
  )
861
1044
  ] }),
862
- /* @__PURE__ */ f("div", { className: "flex items-center", children: [
863
- /* @__PURE__ */ o(
1045
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1046
+ /* @__PURE__ */ i(
864
1047
  "input",
865
1048
  {
866
1049
  id: "radio-json",
867
1050
  type: "radio",
868
1051
  value: "json",
869
1052
  name: "exportType",
870
- checked: p === "json",
871
- onChange: () => m("json"),
872
- className: J(z, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1053
+ checked: g === "json",
1054
+ onChange: () => y("json"),
1055
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
873
1056
  }
874
1057
  ),
875
- /* @__PURE__ */ o(
1058
+ /* @__PURE__ */ i(
876
1059
  "label",
877
1060
  {
878
1061
  htmlFor: "radio-json",
@@ -882,54 +1065,54 @@ function bt({
882
1065
  )
883
1066
  ] })
884
1067
  ] }),
885
- /* @__PURE__ */ f("div", { className: "p-4 flex flex-col", children: [
886
- /* @__PURE__ */ f("div", { className: "flex items-center", children: [
887
- /* @__PURE__ */ o(
1068
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1069
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1070
+ /* @__PURE__ */ i(
888
1071
  "input",
889
1072
  {
890
1073
  id: "radio-timestamp",
891
1074
  type: "radio",
892
1075
  value: "timestamp",
893
1076
  name: "dateExportType",
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")
1077
+ checked: A === "timestamp",
1078
+ onChange: () => F("timestamp"),
1079
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
897
1080
  }
898
1081
  ),
899
- /* @__PURE__ */ f(
1082
+ /* @__PURE__ */ p(
900
1083
  "label",
901
1084
  {
902
1085
  htmlFor: "radio-timestamp",
903
1086
  className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
904
1087
  children: [
905
1088
  "Dates as timestamps (",
906
- d.current.getTime(),
1089
+ c.current.getTime(),
907
1090
  ")"
908
1091
  ]
909
1092
  }
910
1093
  )
911
1094
  ] }),
912
- /* @__PURE__ */ f("div", { className: "flex items-center", children: [
913
- /* @__PURE__ */ o(
1095
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1096
+ /* @__PURE__ */ i(
914
1097
  "input",
915
1098
  {
916
1099
  id: "radio-string",
917
1100
  type: "radio",
918
1101
  value: "string",
919
1102
  name: "dateExportType",
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")
1103
+ checked: A === "string",
1104
+ onChange: () => F("string"),
1105
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
923
1106
  }
924
1107
  ),
925
- /* @__PURE__ */ f(
1108
+ /* @__PURE__ */ p(
926
1109
  "label",
927
1110
  {
928
1111
  htmlFor: "radio-string",
929
1112
  className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
930
1113
  children: [
931
1114
  "Dates as strings (",
932
- d.current.toISOString(),
1115
+ c.current.toISOString(),
933
1116
  ")"
934
1117
  ]
935
1118
  }
@@ -937,34 +1120,43 @@ function bt({
937
1120
  ] })
938
1121
  ] })
939
1122
  ] }),
940
- /* @__PURE__ */ o(
941
- Ze,
1123
+ /* @__PURE__ */ i(
1124
+ Y,
942
1125
  {
943
1126
  size: "small",
944
- disabled: p !== "csv",
945
- value: c,
946
- onValueChange: l,
1127
+ disabled: g !== "csv",
1128
+ value: m,
1129
+ onValueChange: h,
947
1130
  label: "Flatten arrays"
948
1131
  }
949
1132
  ),
950
- !U && n
1133
+ /* @__PURE__ */ i(
1134
+ Y,
1135
+ {
1136
+ size: "small",
1137
+ value: d,
1138
+ onValueChange: u,
1139
+ label: "Include undefined values"
1140
+ }
1141
+ ),
1142
+ !P && n
951
1143
  ] }),
952
- /* @__PURE__ */ f(ve, { children: [
953
- y && /* @__PURE__ */ o(ye, { size: "small" }),
954
- /* @__PURE__ */ o(
955
- E,
1144
+ /* @__PURE__ */ p(le, { children: [
1145
+ O && /* @__PURE__ */ i(Ee, { size: "small" }),
1146
+ /* @__PURE__ */ i(
1147
+ S,
956
1148
  {
957
- onClick: D,
1149
+ onClick: K,
958
1150
  variant: "text",
959
1151
  children: "Cancel"
960
1152
  }
961
1153
  ),
962
- /* @__PURE__ */ o(
963
- E,
1154
+ /* @__PURE__ */ i(
1155
+ S,
964
1156
  {
965
1157
  variant: "filled",
966
- onClick: Oe,
967
- disabled: y || !U,
1158
+ onClick: Je,
1159
+ disabled: O || !P,
968
1160
  children: "Download"
969
1161
  }
970
1162
  )
@@ -974,28 +1166,206 @@ function bt({
974
1166
  )
975
1167
  ] });
976
1168
  }
977
- function Nt(e) {
978
- return Ie(() => ({
979
- name: "Import/Export",
1169
+ function Lt(e) {
1170
+ return Ue(() => ({
1171
+ key: "import_export",
980
1172
  collectionView: {
981
- CollectionActions: [dt, bt],
1173
+ CollectionActions: [Ot, Ft],
982
1174
  collectionActionsProps: e
983
1175
  }
984
1176
  }), [e]);
985
1177
  }
1178
+ function Jt({
1179
+ data: e,
1180
+ properties: a,
1181
+ propertiesOrder: s
1182
+ }) {
1183
+ const t = b.useRef(/* @__PURE__ */ new Date()), [r, n] = b.useState(!0), [l, o] = b.useState("csv"), [c, d] = b.useState("string"), [u, m] = b.useState(!1), h = C(() => {
1184
+ m(!0);
1185
+ }, [m]), g = C(() => {
1186
+ m(!1);
1187
+ }, [m]), y = C(() => {
1188
+ Be({
1189
+ data: e,
1190
+ additionalData: [],
1191
+ properties: a,
1192
+ propertiesOrder: s,
1193
+ name: "export.csv",
1194
+ flattenArrays: r,
1195
+ additionalHeaders: [],
1196
+ exportType: l,
1197
+ dateExportType: c
1198
+ }), g();
1199
+ }, []);
1200
+ return /* @__PURE__ */ p(M, { children: [
1201
+ /* @__PURE__ */ i(Z, { title: "Export", children: /* @__PURE__ */ i(Q, { color: "primary", onClick: h, children: /* @__PURE__ */ i(Te, {}) }) }),
1202
+ /* @__PURE__ */ p(
1203
+ se,
1204
+ {
1205
+ open: u,
1206
+ onOpenChange: m,
1207
+ maxWidth: "xl",
1208
+ children: [
1209
+ /* @__PURE__ */ p(ie, { className: "flex flex-col gap-4 my-4", children: [
1210
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Export data" }),
1211
+ /* @__PURE__ */ i("div", { children: "Download the the content of this table as a CSV" }),
1212
+ /* @__PURE__ */ p("div", { className: "flex flex-row gap-4", children: [
1213
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1214
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1215
+ /* @__PURE__ */ i(
1216
+ "input",
1217
+ {
1218
+ id: "radio-csv",
1219
+ type: "radio",
1220
+ value: "csv",
1221
+ name: "exportType",
1222
+ checked: l === "csv",
1223
+ onChange: () => o("csv"),
1224
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1225
+ }
1226
+ ),
1227
+ /* @__PURE__ */ i(
1228
+ "label",
1229
+ {
1230
+ htmlFor: "radio-csv",
1231
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1232
+ children: "CSV"
1233
+ }
1234
+ )
1235
+ ] }),
1236
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1237
+ /* @__PURE__ */ i(
1238
+ "input",
1239
+ {
1240
+ id: "radio-json",
1241
+ type: "radio",
1242
+ value: "json",
1243
+ name: "exportType",
1244
+ checked: l === "json",
1245
+ onChange: () => o("json"),
1246
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1247
+ }
1248
+ ),
1249
+ /* @__PURE__ */ i(
1250
+ "label",
1251
+ {
1252
+ htmlFor: "radio-json",
1253
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1254
+ children: "JSON"
1255
+ }
1256
+ )
1257
+ ] })
1258
+ ] }),
1259
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1260
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1261
+ /* @__PURE__ */ i(
1262
+ "input",
1263
+ {
1264
+ id: "radio-timestamp",
1265
+ type: "radio",
1266
+ value: "timestamp",
1267
+ name: "dateExportType",
1268
+ checked: c === "timestamp",
1269
+ onChange: () => d("timestamp"),
1270
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1271
+ }
1272
+ ),
1273
+ /* @__PURE__ */ p(
1274
+ "label",
1275
+ {
1276
+ htmlFor: "radio-timestamp",
1277
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1278
+ children: [
1279
+ "Dates as timestamps (",
1280
+ t.current.getTime(),
1281
+ ")"
1282
+ ]
1283
+ }
1284
+ )
1285
+ ] }),
1286
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1287
+ /* @__PURE__ */ i(
1288
+ "input",
1289
+ {
1290
+ id: "radio-string",
1291
+ type: "radio",
1292
+ value: "string",
1293
+ name: "dateExportType",
1294
+ checked: c === "string",
1295
+ onChange: () => d("string"),
1296
+ className: _(T, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1297
+ }
1298
+ ),
1299
+ /* @__PURE__ */ p(
1300
+ "label",
1301
+ {
1302
+ htmlFor: "radio-string",
1303
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1304
+ children: [
1305
+ "Dates as strings (",
1306
+ t.current.toISOString(),
1307
+ ")"
1308
+ ]
1309
+ }
1310
+ )
1311
+ ] })
1312
+ ] })
1313
+ ] }),
1314
+ /* @__PURE__ */ i(
1315
+ Y,
1316
+ {
1317
+ size: "small",
1318
+ disabled: l !== "csv",
1319
+ value: r,
1320
+ onValueChange: n,
1321
+ label: "Flatten arrays"
1322
+ }
1323
+ )
1324
+ ] }),
1325
+ /* @__PURE__ */ p(le, { children: [
1326
+ /* @__PURE__ */ i(
1327
+ S,
1328
+ {
1329
+ onClick: g,
1330
+ variant: "text",
1331
+ children: "Cancel"
1332
+ }
1333
+ ),
1334
+ /* @__PURE__ */ i(
1335
+ S,
1336
+ {
1337
+ variant: "filled",
1338
+ onClick: y,
1339
+ children: "Download"
1340
+ }
1341
+ )
1342
+ ] })
1343
+ ]
1344
+ }
1345
+ )
1346
+ ] });
1347
+ }
986
1348
  export {
987
- ot as DataNewPropertiesMapping,
988
- lt as ImportFileUpload,
989
- Dt as ImportNewPropertyFieldPreview,
990
- ct as ImportSaveInProgress,
991
- nt as convertDataToEntity,
992
- tt as convertFileToJson,
993
- we as flattenEntry,
994
- at as getInferenceType,
995
- it as getPropertiesMapping,
996
- Z as processValueMapping,
997
- Ce as unflattenObject,
998
- et as useImportConfig,
999
- Nt as useImportExportPlugin
1349
+ Jt as BasicExportAction,
1350
+ Ct as DataNewPropertiesMapping,
1351
+ Ft as ExportCollectionAction,
1352
+ Ot as ImportCollectionAction,
1353
+ It as ImportDataPreview,
1354
+ Nt as ImportFileUpload,
1355
+ Bt as ImportNewPropertyFieldPreview,
1356
+ St as ImportSaveInProgress,
1357
+ Ce as PropertySelectEntry,
1358
+ bt as convertDataToEntity,
1359
+ xt as convertFileToJson,
1360
+ De as downloadBlob,
1361
+ Be as downloadEntitiesExport,
1362
+ Pe as flattenEntry,
1363
+ _t as getEntityCSVExportableData,
1364
+ At as getEntityJsonExportableData,
1365
+ vt as getInferenceType,
1366
+ ae as processValueMapping,
1367
+ je as unflattenObject,
1368
+ ht as useImportConfig,
1369
+ Lt as useImportExportPlugin
1000
1370
  };
1001
1371
  //# sourceMappingURL=index.es.js.map