@firecms/data_import_export 3.0.0-canary.7 → 3.0.0-canary.70

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