@firecms/data_import_export 3.0.0-canary.5 → 3.0.0-canary.50

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 +4 -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 +901 -546
  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 +20 -18
  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 +137 -0
  28. package/src/export_import/ExportCollectionAction.tsx +15 -7
  29. package/src/export_import/ImportCollectionAction.tsx +52 -31
  30. package/src/export_import/export.ts +50 -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 y, { useState as S, useRef as Je, useEffect as De, useCallback as v, useMemo as He } from "react";
2
+ import { jsxs as p, Fragment as M, jsx as i } from "react/jsx-runtime";
3
+ import { getPropertyInPath as J, mergeDeep as Ve, resolveProperty as ze, isPropertyBuilder as ue, EntityReference as Ue, useSnackbarController as Ne, useCustomizationController as G, getFieldConfig as Se, ErrorBoundary as We, PropertyConfigBadge as Oe, useDataSource as ke, resolveCollection as Ie, getPropertiesWithPropertiesOrder as Xe, useSelectionController as Ge, EntityCollectionTable as Ye, slugify as qe, getArrayValuesCount as Qe, getValueInPath as Ze, useFireCMSContext as Ke, useNavigationController as et } from "@firecms/core";
4
+ import { Table as me, TableHeader as fe, TableCell as w, TableBody as he, TableRow as ge, Typography as f, ChevronRightIcon as xe, ExpandablePanel as tt, Select as _e, SelectItem as H, TextField as re, BooleanSwitchWithLabel as se, DateTimeField as rt, FileUpload as nt, UploadIcon as at, IconButton as Y, EditIcon as st, CenteredView as ye, Button as O, CircularProgress as Ae, Tooltip as q, FileUploadIcon as it, Dialog as ie, DialogContent as le, DialogActions as oe, cn as k, defaultBorderMixin as lt, GetAppIcon as Ee, Alert as ot, focusedMixin as _ } from "@firecms/ui";
5
+ import { inferTypeFromValue as ct, buildEntityPropertiesFromData as dt } from "@firecms/schema_inference";
6
+ import * as V from "xlsx";
7
+ import { getIn as Te, setIn as pt } from "@firecms/formex";
8
+ const ut = () => {
9
+ const [e, n] = S(!1), [s, t] = S({}), [r, a] = S(), [l, o] = S([]), [c, d] = S([]), [u, m] = S({}), [h, g] = S([]), [x, R] = S({});
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: n,
13
+ idColumn: r,
14
+ setIdColumn: a,
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: x,
24
+ setOriginProperties: R,
25
+ defaultValues: s,
26
+ setDefaultValues: t
22
27
  };
23
28
  };
24
- function et(e) {
25
- return new Promise((r, n) => {
29
+ function mt(e) {
30
+ let n = 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 a;
36
+ switch (t.header === 1 ? n = 1 : t.header === "A" ? n = 2 : Array.isArray(t.header) && (n = 3), typeof r) {
37
+ case "string":
38
+ a = be(r);
39
+ break;
40
+ case "number":
41
+ a = be(e["!ref"]), a.s.r = r;
42
+ break;
43
+ default:
44
+ a = r;
45
+ }
46
+ const l = V.utils.encode_row(a.s.r), o = new Array(a.e.c - a.s.c + 1);
47
+ for (let c = a.s.c; c <= a.e.c; ++c) {
48
+ o[c] = V.utils.encode_col(c);
49
+ const d = e[o[c] + l];
50
+ switch (n) {
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 - a.s.c]);
59
+ break;
60
+ default:
61
+ if (d === void 0)
62
+ continue;
63
+ s.push(V.utils.format_cell(d));
64
+ }
65
+ }
66
+ return s;
67
+ }
68
+ function be(e) {
69
+ const n = {
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 a = e.length;
81
+ for (s = 0; t < a && !((r = e.charCodeAt(t) - 64) < 1 || r > 26); ++t)
82
+ s = 26 * s + r;
83
+ for (n.s.c = --s, s = 0; t < a && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
84
+ s = 10 * s + r;
85
+ if (n.s.r = --s, t === a || e.charCodeAt(++t) === 58)
86
+ return n.e.c = n.s.c, n.e.r = n.s.r, n;
87
+ for (s = 0; t !== a && !((r = e.charCodeAt(t) - 64) < 1 || r > 26); ++t)
88
+ s = 26 * s + r;
89
+ for (n.e.c = --s, s = 0; t !== a && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
90
+ s = 10 * s + r;
91
+ return n.e.r = --s, n;
92
+ }
93
+ function ft(e) {
94
+ return new Promise((n, 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 a = r.target?.result, l = JSON.parse(a);
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
+ n({
106
+ data: l,
107
+ propertiesOrder: o
108
+ });
109
+ }
110
+ } catch (a) {
111
+ console.error("Error parsing JSON file", a), s(a);
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 a = new Uint8Array(r.target?.result), l = V.read(a, {
119
+ type: "array",
120
+ codepage: 65001,
121
+ cellDates: !0
122
+ }), o = l.SheetNames[0], c = l.Sheets[o], d = V.utils.sheet_to_json(c), u = mt(c), h = d.map(ht).map(je);
123
+ n({
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 ht(e) {
132
+ return Object.keys(e).reduce((n, s) => {
52
133
  try {
53
- r[n] = JSON.parse(e[n]);
134
+ n[s] = JSON.parse(e[s]);
54
135
  } catch {
55
- r[n] = e[n];
136
+ n[s] = e[s];
56
137
  }
57
- return r;
138
+ return n;
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((n, s) => {
143
+ let t = n;
144
+ const r = s.split(".");
145
+ return r.forEach((a, l) => {
146
+ if (/^[\w]+\[\d+\]$/.test(a)) {
147
+ const o = a.slice(0, a.indexOf("[")), c = parseInt(a.slice(a.indexOf("[") + 1, a.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[a] = t[a] || {}, t = t[a]) : t[a] = e[s];
151
+ }), n;
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 gt(e, n, s, t, r, a) {
155
+ const l = Fe(e);
156
+ n && delete l[n];
157
+ const o = Object.entries(l).map(([u, m]) => {
158
+ const h = Te(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 x = ne(m, g);
162
+ return {
163
+ [h]: x
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 = Ve(a ?? {}, je(o));
166
+ let d = n ? e[n] : 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 Fe(e, n = "") {
174
+ return Object.keys(e).reduce((s, t) => {
175
+ const r = n ? `${n}.${t}` : t;
176
+ return typeof e[t] == "object" && !(e[t] instanceof Date) && e[t] !== null && !Array.isArray(e[t]) ? Object.assign(s, Fe(e[t], r)) : s[r] = e[t], s;
96
177
  }, {});
97
178
  }
98
- function Z(e, r) {
99
- if (r === void 0)
179
+ function ne(e, n) {
180
+ if (e === null)
181
+ return null;
182
+ if (n === 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 = ze({
185
+ propertyOrBuilder: n
186
+ });
187
+ if (s === null)
188
+ return e;
189
+ const t = ct(e), r = s.dataType;
190
+ if (t === "array" && r === "array" && Array.isArray(e) && s.of && !ue(s.of))
191
+ return e.map((a) => ne(a, 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 && !ue(s.of))
195
+ return e.split(",").map((a) => ne(a, 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")
206
+ if (t === "string" && r === "array" && typeof e == "string")
128
207
  return e.split(",").map((a) => a.trim());
129
- if (n === "string" && t === "date" && typeof e == "string")
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 a = e.split("/").slice(0, -1).join("/"), l = e.split("/").slice(-1)[0];
225
+ return new Ue(l, a);
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 xt(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 yt({
239
+ importConfig: e,
240
+ destinationProperties: n,
241
+ buildPropertyView: s
194
242
  }) {
195
- return /* @__PURE__ */ p($, { children: [
196
- /* @__PURE__ */ s(
197
- st,
243
+ const t = e.headersMapping, r = e.headingsOrder, a = e.idColumn, l = e.originProperties;
244
+ return /* @__PURE__ */ p(M, { children: [
245
+ /* @__PURE__ */ i(
246
+ bt,
198
247
  {
199
- idColumn: e,
200
- headersMapping: r,
201
- onChange: a
248
+ idColumn: a,
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(me, { 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(fe, { 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(he, { children: n && r.map(
263
+ (o) => {
264
+ const c = t[o], d = t[o], u = c ? J(n, 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(ge, { 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(xe, {}) }),
278
+ /* @__PURE__ */ i(
279
+ w,
230
280
  {
231
- className: o === e ? "text-center" : void 0,
281
+ className: o === a ? "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 === a,
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(tt, { 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(me, { style: {
298
+ tableLayout: "fixed"
299
+ }, children: [
300
+ /* @__PURE__ */ p(fe, { 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(he, { children: n && Pe(n).map(
306
+ (o) => {
307
+ const c = J(n, o);
308
+ return typeof c != "object" || c === null || !["number", "string", "boolean", "map"].includes(c.dataType) ? null : /* @__PURE__ */ p(ge, { 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(xe, {}) }),
311
+ /* @__PURE__ */ i(
312
+ w,
313
+ {
314
+ className: o === a ? "text-center" : void 0,
315
+ style: { width: "75%" },
316
+ children: /* @__PURE__ */ i(
317
+ vt,
318
+ {
319
+ property: c,
320
+ defaultValue: Te(e.defaultValues, o),
321
+ onValueChange: (d) => {
322
+ const u = pt(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 Pe(e, n) {
337
+ return Object.entries(e).reduce((s, [t, r]) => {
338
+ const a = n ? `${n}.${t}` : t;
339
+ if (typeof r != "function" && r.dataType === "map" && r.properties) {
340
+ const l = Pe(r.properties, a);
341
+ return [...s, ...l];
342
+ }
343
+ return [...s, a];
344
+ }, []);
345
+ }
346
+ function bt({
248
347
  idColumn: e,
249
- headersMapping: r,
250
- onChange: n
348
+ headersMapping: n,
349
+ onChange: s
251
350
  }) {
252
- return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ p(
253
- he,
351
+ return /* @__PURE__ */ i("div", { children: /* @__PURE__ */ p(
352
+ _e,
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(n).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 vt({
371
+ property: e,
372
+ onValueChange: n,
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) => n(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) => n(t.target.value)
391
+ }
392
+ ) : e.dataType === "boolean" ? /* @__PURE__ */ i(
393
+ se,
394
+ {
395
+ value: s ?? null,
396
+ allowIndeterminate: !0,
397
+ size: "small",
398
+ onValueChange: (t) => n(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
+ rt,
403
+ {
404
+ mode: e.mode ?? "date",
405
+ size: "small",
406
+ value: s ?? void 0,
407
+ onChange: (t) => {
408
+ n(t);
409
+ },
410
+ clearable: !0
411
+ }
412
+ ) : null;
413
+ }
414
+ function Ct({ onDataAdded: e }) {
415
+ const n = Ne();
416
+ return /* @__PURE__ */ i(
417
+ nt,
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(at, {}),
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 && ft(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), n.open({
444
+ type: "error",
445
+ message: t.message
446
+ });
296
447
  });
297
448
  }
298
449
  }
299
450
  );
300
451
  }
301
- function Dt({
452
+ function Rt({
302
453
  propertyKey: e,
303
- property: r,
304
- onEditClick: n,
454
+ property: n,
455
+ onEditClick: s,
305
456
  includeName: t = !0,
306
- onPropertyNameChanged: a,
307
- propertyTypeView: i
457
+ onPropertyNameChanged: r,
458
+ propertyTypeView: a
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 } = G(), o = n ? Se(n, l) : null;
461
+ return /* @__PURE__ */ i(We, { 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: a ?? /* @__PURE__ */ i(Oe, { 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: n?.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(Y, { onClick: s, size: "small", children: /* @__PURE__ */ i(st, { size: "small" }) })
329
480
  ] }) })
330
481
  ]
331
482
  }
332
483
  ) });
333
484
  }
334
- function lt({
485
+ function wt({
335
486
  path: e,
336
- importConfig: r,
337
- collection: n,
487
+ importConfig: n,
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, a] = S(void 0), l = ke(), o = Je(!1), [c, d] = S(0);
492
+ function u() {
493
+ o.current || (o.current = !0, Me(
494
+ l,
495
+ s,
346
496
  e,
347
- r.entities,
497
+ n.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
+ a(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 De(() => {
508
+ u();
509
+ }, []), r ? /* @__PURE__ */ p(ye, { 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
+ O,
514
+ {
515
+ onClick: u,
516
+ variant: "outlined",
517
+ children: "Retry"
518
+ }
519
+ )
520
+ ] }) : /* @__PURE__ */ p(ye, { className: "flex flex-col gap-4 items-center", children: [
521
+ /* @__PURE__ */ i(Ae, {}),
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
+ n.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 Me(e, n, s, t, r = 0, a = 25, l) {
533
+ console.debug("Saving imported data", r, a);
534
+ const o = t.slice(r, r + a);
535
+ return Promise.all(o.map((c) => e.saveEntity({
536
+ path: s,
537
+ values: c.values,
538
+ entityId: c.id,
539
+ collection: n,
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 + a < t.length ? (l(r + a), Me(e, n, s, t, r + a, a, l)) : (l(t.length), Promise.resolve()));
379
542
  }
380
- function ct({
543
+ function Dt({
381
544
  collection: e,
382
- path: r,
383
- collectionEntitiesCount: n
545
+ path: n,
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 = G(), a = Ne(), [l, o] = y.useState(!1), [c, d] = y.useState("initial"), u = ut(), m = v(() => {
550
+ o(!0), t?.("import_open"), d("initial");
551
+ }, [t]), h = v(() => {
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 = v(() => {
554
+ t?.("import_mapping_complete"), d("preview");
555
+ }, [t]), x = v(() => {
556
+ t?.("import_data_save"), d("import_data_saving");
557
+ }, [t]), R = async (b) => {
558
+ if (u.setImportData(b), b.length > 0) {
559
+ const T = await dt(b, xt);
560
+ u.setOriginProperties(T);
561
+ const j = $e(b, e?.properties);
562
+ u.setHeadersMapping(j);
563
+ const F = Object.keys(j)?.[0];
564
+ (F?.includes("id") || F?.includes("key")) && u.setIdColumn(F);
404
565
  }
405
566
  setTimeout(() => {
406
- d("mapping");
567
+ t?.("import_data_added"), d("mapping");
407
568
  }, 100);
408
- }, N = ue({
569
+ }, A = Ie({
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: n,
572
+ fields: r.propertyConfigs
573
+ }), L = Xe(A.properties, A.propertiesOrder), E = Object.entries(L).flatMap(([b, T]) => Re(b, T, 0)), z = A.propertiesOrder ?? Object.keys(A.properties);
574
+ return e.collectionGroup ? null : /* @__PURE__ */ p(M, { children: [
575
+ /* @__PURE__ */ i(q, { title: "Import", children: /* @__PURE__ */ i(Y, { color: "primary", onClick: m, children: /* @__PURE__ */ i(it, {}) }) }),
415
576
  /* @__PURE__ */ p(
416
- ye,
577
+ ie,
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(le, { 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(Ct, { onDataAdded: R })
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
+ yt,
433
594
  {
434
- headersMapping: c.headersMapping,
435
- idColumn: c.idColumn,
436
- originProperties: c.originProperties,
595
+ importConfig: u,
437
596
  destinationProperties: L,
438
- onIdPropertyChanged: (g) => c.setIdColumn(g),
439
597
  buildPropertyView: ({
440
- isIdColumn: g,
441
- property: I,
442
- propertyKey: E,
443
- importKey: A
444
- }) => /* @__PURE__ */ s(
445
- dt,
598
+ isIdColumn: b,
599
+ property: T,
600
+ propertyKey: j,
601
+ importKey: F
602
+ }) => /* @__PURE__ */ i(
603
+ Nt,
446
604
  {
447
- selectedPropertyKey: E ?? "",
605
+ selectedPropertyKey: j ?? "",
448
606
  properties: L,
449
- propertiesAndLevel: O,
450
- isIdColumn: g,
607
+ propertiesAndLevel: E,
608
+ isIdColumn: b,
451
609
  onIdSelected: () => {
452
- c.setIdColumn(A);
610
+ u.setIdColumn(F);
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: ($) => {
613
+ t?.("import_mapping_field_updated");
614
+ const Q = Object.entries(u.headersMapping).map(([C, B]) => B === $ ? { [C]: null } : C === F ? { [C]: $ } : { [C]: B }).reduce((C, B) => ({ ...C, ...B }), {});
615
+ u.setHeadersMapping(Q), $ === 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
+ St,
465
624
  {
466
- importConfig: c,
625
+ importConfig: u,
467
626
  properties: L,
468
- propertiesOrder: J
627
+ propertiesOrder: z
469
628
  }
470
629
  ),
471
- l === "import_data_saving" && c && /* @__PURE__ */ s(
472
- lt,
630
+ c === "import_data_saving" && u && /* @__PURE__ */ i(
631
+ wt,
473
632
  {
474
- importConfig: c,
633
+ importConfig: u,
475
634
  collection: e,
476
- path: r,
477
- onImportSuccess: (g) => {
478
- m(), a.open({
635
+ path: n,
636
+ onImportSuccess: (b) => {
637
+ h(), a.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(oe, { children: [
646
+ c === "mapping" && /* @__PURE__ */ i(
647
+ O,
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
+ O,
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
+ O,
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
+ O,
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
+ O,
521
680
  {
522
681
  variant: "filled",
523
- onClick: h,
682
+ onClick: x,
524
683
  children: "Save data"
525
684
  }
526
685
  )
@@ -531,47 +690,47 @@ function ct({
531
690
  ] });
532
691
  }
533
692
  const W = "__internal_id__";
534
- function dt({
693
+ function Nt({
535
694
  selectedPropertyKey: e,
536
- properties: r,
537
- onPropertySelected: n,
695
+ properties: n,
696
+ onPropertySelected: s,
538
697
  onIdSelected: t,
539
- propertiesAndLevel: a,
540
- isIdColumn: i
698
+ propertiesAndLevel: r,
699
+ isIdColumn: a
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(n, e) : null, o = v((d) => d === W ? /* @__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
+ ve,
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
+ _e,
553
710
  {
554
- value: i ? W : e ?? void 0,
555
- onValueChange: d,
556
- renderValue: l,
711
+ value: a ? W : e ?? void 0,
712
+ onValueChange: (d) => {
713
+ d === W ? (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: W, 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
+ ve,
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 Re(e, n, s) {
585
744
  const t = [];
586
745
  return t.push({
587
- property: r,
588
- level: n,
746
+ property: n,
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
+ }), n.dataType === "map" && n.properties && Object.entries(n.properties).forEach(([r, a]) => {
750
+ t.push(...Re(`${e}.${r}`, a, s + 1));
592
751
  }), t;
593
752
  }
594
- function se({
753
+ function ve({
595
754
  propertyKey: e,
596
- property: r,
597
- level: n = 0
755
+ property: n,
756
+ level: s = 0
598
757
  }) {
599
- const { propertyConfigs: t } = V(), a = pe(r, t);
758
+ const { propertyConfigs: t } = G(), r = Se(n, 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((a, l) => /* @__PURE__ */ i("div", { className: k(lt, "ml-8 border-l h-12") }, l)),
765
+ /* @__PURE__ */ i("div", { className: "m-4", children: /* @__PURE__ */ i(q, { title: r?.name, children: /* @__PURE__ */ i(Oe, { 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: n.name ? n.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,259 @@ function se({
629
788
  }
630
789
  );
631
790
  }
632
- function pt({
791
+ function St({
633
792
  importConfig: e,
634
- properties: r,
635
- propertiesOrder: n
793
+ properties: n,
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
+ De(() => {
797
+ const r = e.importData.map((a) => gt(a, e.idColumn, e.headersMapping, n, "TEMP_PATH", e.defaultValues));
798
+ e.setEntities(r);
640
799
  }, []);
641
- const t = je();
642
- return /* @__PURE__ */ s(
643
- ke,
800
+ const t = Ge();
801
+ return /* @__PURE__ */ i(
802
+ Ye,
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: n
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, n) {
823
+ const s = {};
824
+ return e.filter(Boolean).forEach((t) => {
825
+ Object.keys(t).forEach((r) => {
826
+ const a = t[r];
827
+ if (typeof a == "object" && !Array.isArray(a)) {
828
+ const l = n?.[r], o = l && "properties" in l ? l.properties : void 0, c = $e([a], o);
829
+ Object.entries(c).forEach(([d, u]) => {
830
+ s[`${r}.${d}`] = `${r}.${u}`;
831
+ });
832
+ }
833
+ if (!n)
834
+ s[r] = r;
835
+ else if (r in n)
836
+ s[r] = r;
837
+ else {
838
+ const l = qe(r);
839
+ l in n ? 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(e, n, s, t, r, a, l, o, c) {
845
+ if (console.debug("Downloading export", {
846
+ dataLength: e.length,
847
+ properties: s,
848
+ exportType: o,
849
+ dateExportType: c
850
+ }), o === "csv") {
851
+ const d = a ? Qe(e.map((x) => x.values)) : {}, u = It(s, t, l, d), m = Ot(e, n, s, u, c), h = Ce(u.map((x) => x.label)), g = m.map((x) => Ce(x));
852
+ we([h, ...g], `${r}.csv`, "text/csv");
683
853
  } else {
684
- const d = ut(e, r, l, o), c = JSON.stringify(d, null, 2);
685
- le([c], `${n.name}.json`, "application/json");
854
+ const d = kt(e, n, s, c), u = JSON.stringify(d, null, 2);
855
+ we([u], `${r}.json`, "application/json");
686
856
  }
687
857
  }
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)
858
+ function Ot(e, n, s, t, r) {
859
+ const a = e.map((l) => ({
860
+ id: l.id,
861
+ ...ce(l.values, s, "csv", r)
692
862
  }));
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)
863
+ return n && n.forEach((l, o) => {
864
+ a[o] = { ...a[o], ...l };
865
+ }), a && a.map((l) => t.map((o) => Ze(l, o.key)));
866
+ }
867
+ function kt(e, n, s, t) {
868
+ const r = e.map((a) => ({
869
+ id: a.id,
870
+ ...ce(a.values, s, "json", t)
701
871
  }));
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, ""))
872
+ return n && n.forEach((a, l) => {
873
+ r[l] = { ...r[l], ...a };
874
+ }), r;
875
+ }
876
+ function It(e, n, s, t) {
877
+ const r = [
878
+ {
879
+ label: "id",
880
+ key: "id"
881
+ },
882
+ ...(n ?? Object.keys(e)).flatMap((a) => {
883
+ const l = e[a];
884
+ return l ? t && t[a] > 1 ? Array.from(
885
+ { length: t[a] },
886
+ (o, c) => ae(l, `${a}[${c}]`, "")
887
+ ).flat() : ae(l, a, "") : (console.warn("Property not found", a, e), []);
888
+ })
713
889
  ];
714
- return r && t.push(...r.map((a) => ({ label: a, key: a }))), t;
890
+ return s && r.push(...s.map((a) => ({
891
+ label: a,
892
+ key: a
893
+ }))), r;
715
894
  }
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 }];
895
+ function ae(e, n, s = "") {
896
+ const t = s ? `${s}.${n}` : n;
897
+ return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([r, a]) => ae(a, r, t)).flat() : [{
898
+ label: t,
899
+ key: t
900
+ }];
719
901
  }
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;
902
+ function X(e, n, s, t) {
903
+ let r;
904
+ if (n.dataType === "map" && n.properties)
905
+ r = ce(e, n.properties, s, t);
906
+ else if (n.dataType === "array")
907
+ n.of && Array.isArray(e) ? Array.isArray(n.of) ? r = n.of.map((a, l) => X(e[l], a, s, t)) : n.of.dataType === "map" ? r = s === "csv" ? e.map((a) => JSON.stringify(a)) : e.map((a) => X(a, n.of, s, t)) : r = e.map((a) => X(a, n.of, s, t)) : r = e;
908
+ else if (n.dataType === "reference" && e && e.isEntityReference && e.isEntityReference()) {
909
+ const a = e || void 0;
910
+ r = a ? a.pathWithId : null;
729
911
  } 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
912
+ n.dataType === "date" && e instanceof Date ? r = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : r = e;
913
+ return r;
914
+ }
915
+ function ce(e, n, s, t) {
916
+ const r = Object.entries(n).map(([a, l]) => {
917
+ const o = e && e[a], c = X(o, l, s, t);
918
+ return c === void 0 ? {} : { [a]: c };
919
+ }).reduce((a, l) => ({ ...a, ...l }), {});
920
+ return { ...e, ...r };
921
+ }
922
+ function Ce(e) {
923
+ return e.map((n) => n == null ? "" : Array.isArray(n) ? '"' + JSON.stringify(n).replaceAll('"', '\\"') + '"' : '"' + String(n).replaceAll('"', '""') + '"').join(",") + `\r
742
924
  `;
743
925
  }
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();
926
+ function we(e, n, s) {
927
+ const t = new Blob(e, { type: s }), r = URL.createObjectURL(t), a = document.createElement("a");
928
+ a.href = r, a.setAttribute("download", n), a.click();
747
929
  }
748
- const gt = 500;
749
- function yt({
930
+ const _t = 500;
931
+ function At({
750
932
  collection: e,
751
- path: r,
752
- collectionEntitiesCount: n,
753
- exportAllowed: t,
933
+ path: n,
934
+ collectionEntitiesCount: s,
935
+ onAnalyticsEvent: t,
936
+ exportAllowed: r,
754
937
  notAllowedView: a
755
938
  }) {
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,
939
+ const l = G(), o = typeof e.exportable == "object" ? e.exportable : void 0, c = y.useRef(/* @__PURE__ */ new Date()), [d, u] = y.useState(!0), [m, h] = y.useState("csv"), [g, x] = y.useState("string"), R = Ke(), A = ke(), E = et().resolveAliasesFrom(n), z = !r || r({
940
+ collectionEntitiesCount: s,
941
+ path: E,
759
942
  collection: e
760
- }), g = C.useMemo(() => ue({
943
+ }), b = y.useMemo(() => Ie({
761
944
  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
945
+ path: E,
946
+ fields: l.propertyConfigs
947
+ }), [e, E]), [T, j] = y.useState(!1), [F, $] = y.useState(), [Q, C] = y.useState(!1), B = v(() => {
948
+ C(!0);
949
+ }, [C]), Z = v(() => {
950
+ C(!1);
951
+ }, [C]), de = v(async (D) => {
952
+ const U = o?.additionalFields, I = b.additionalFields, K = U ? await Promise.all(D.map(async (P) => (await Promise.all(U.map(async (N) => ({
953
+ [N.key]: await N.builder({
954
+ entity: P,
955
+ context: R
773
956
  })
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
957
+ })))).reduce((N, te) => ({ ...N, ...te }), {}))) : [], ee = I ? await Promise.all(D.map(async (P) => (await Promise.all(I.map(async (N) => N.value ? {
958
+ [N.key]: await N.value({
959
+ entity: P,
960
+ context: R
778
961
  })
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) ?? []
962
+ } : {}))).reduce((N, te) => ({ ...N, ...te }), {}))) : [];
963
+ return [...K, ...ee];
964
+ }, [o?.additionalFields]), pe = v(async (D, U) => {
965
+ t?.("export_collection", {
966
+ collection: D.path
967
+ }), j(!0), A.fetchCollection({
968
+ path: E,
969
+ collection: D
970
+ }).then(async (I) => {
971
+ $(void 0);
972
+ const K = await de(I), ee = [
973
+ ...U?.additionalFields?.map((P) => P.key) ?? [],
974
+ ...D.additionalFields?.map((P) => P.key) ?? []
790
975
  ];
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, {}) }) }),
976
+ Be(I, K, D.properties, D.propertiesOrder, D.name, d, ee, m, g), t?.("export_collection_success", {
977
+ collection: D.path
978
+ });
979
+ }).catch((I) => {
980
+ console.error("Error loading export data", I), $(I);
981
+ }).finally(() => j(!1));
982
+ }, [t, A, E, de, d, m, g]), Le = v(() => {
983
+ pe(b, o), Z();
984
+ }, [pe, b, o, Z]);
985
+ return /* @__PURE__ */ p(M, { children: [
986
+ /* @__PURE__ */ i(q, { title: "Export", children: /* @__PURE__ */ i(Y, { color: "primary", onClick: B, children: /* @__PURE__ */ i(Ee, {}) }) }),
800
987
  /* @__PURE__ */ p(
801
- ye,
988
+ ie,
802
989
  {
803
- open: G,
804
- onOpenChange: b,
990
+ open: Q,
991
+ onOpenChange: C,
805
992
  maxWidth: "xl",
806
993
  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: [
994
+ /* @__PURE__ */ p(le, { className: "flex flex-col gap-4 my-4", children: [
995
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Export data" }),
996
+ /* @__PURE__ */ i("div", { children: "Download the the content of this table as a CSV" }),
997
+ s > _t && /* @__PURE__ */ i(ot, { color: "warning", children: /* @__PURE__ */ p("div", { children: [
811
998
  "This collections has a large number of documents (",
812
- n,
999
+ s,
813
1000
  ")."
814
1001
  ] }) }),
815
1002
  /* @__PURE__ */ p("div", { className: "flex flex-row gap-4", children: [
816
1003
  /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
817
1004
  /* @__PURE__ */ p("div", { className: "flex items-center", children: [
818
- /* @__PURE__ */ s(
1005
+ /* @__PURE__ */ i(
819
1006
  "input",
820
1007
  {
821
1008
  id: "radio-csv",
822
1009
  type: "radio",
823
1010
  value: "csv",
824
1011
  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")
1012
+ checked: m === "csv",
1013
+ onChange: () => h("csv"),
1014
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
828
1015
  }
829
1016
  ),
830
- /* @__PURE__ */ s(
1017
+ /* @__PURE__ */ i(
831
1018
  "label",
832
1019
  {
833
1020
  htmlFor: "radio-csv",
834
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
1021
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
835
1022
  children: "CSV"
836
1023
  }
837
1024
  )
838
1025
  ] }),
839
1026
  /* @__PURE__ */ p("div", { className: "flex items-center", children: [
840
- /* @__PURE__ */ s(
1027
+ /* @__PURE__ */ i(
841
1028
  "input",
842
1029
  {
843
1030
  id: "radio-json",
844
1031
  type: "radio",
845
1032
  value: "json",
846
1033
  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")
1034
+ checked: m === "json",
1035
+ onChange: () => h("json"),
1036
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
850
1037
  }
851
1038
  ),
852
- /* @__PURE__ */ s(
1039
+ /* @__PURE__ */ i(
853
1040
  "label",
854
1041
  {
855
1042
  htmlFor: "radio-json",
856
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
1043
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
857
1044
  children: "JSON"
858
1045
  }
859
1046
  )
@@ -861,52 +1048,52 @@ function yt({
861
1048
  ] }),
862
1049
  /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
863
1050
  /* @__PURE__ */ p("div", { className: "flex items-center", children: [
864
- /* @__PURE__ */ s(
1051
+ /* @__PURE__ */ i(
865
1052
  "input",
866
1053
  {
867
1054
  id: "radio-timestamp",
868
1055
  type: "radio",
869
1056
  value: "timestamp",
870
1057
  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")
1058
+ checked: g === "timestamp",
1059
+ onChange: () => x("timestamp"),
1060
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
874
1061
  }
875
1062
  ),
876
1063
  /* @__PURE__ */ p(
877
1064
  "label",
878
1065
  {
879
1066
  htmlFor: "radio-timestamp",
880
- className: "p-2 text-sm font-medium text-gray-900 dark:text-gray-300",
1067
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
881
1068
  children: [
882
1069
  "Dates as timestamps (",
883
- l.current.getTime(),
1070
+ c.current.getTime(),
884
1071
  ")"
885
1072
  ]
886
1073
  }
887
1074
  )
888
1075
  ] }),
889
1076
  /* @__PURE__ */ p("div", { className: "flex items-center", children: [
890
- /* @__PURE__ */ s(
1077
+ /* @__PURE__ */ i(
891
1078
  "input",
892
1079
  {
893
1080
  id: "radio-string",
894
1081
  type: "radio",
895
1082
  value: "string",
896
1083
  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")
1084
+ checked: g === "string",
1085
+ onChange: () => x("string"),
1086
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
900
1087
  }
901
1088
  ),
902
1089
  /* @__PURE__ */ p(
903
1090
  "label",
904
1091
  {
905
1092
  htmlFor: "radio-string",
906
- 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",
907
1094
  children: [
908
1095
  "Dates as strings (",
909
- l.current.toISOString(),
1096
+ c.current.toISOString(),
910
1097
  ")"
911
1098
  ]
912
1099
  }
@@ -914,34 +1101,34 @@ function yt({
914
1101
  ] })
915
1102
  ] })
916
1103
  ] }),
917
- /* @__PURE__ */ s(
918
- Ye,
1104
+ /* @__PURE__ */ i(
1105
+ se,
919
1106
  {
920
1107
  size: "small",
921
- disabled: f !== "csv",
1108
+ disabled: m !== "csv",
922
1109
  value: d,
923
- onValueChange: c,
1110
+ onValueChange: u,
924
1111
  label: "Flatten arrays"
925
1112
  }
926
1113
  ),
927
- !J && a
1114
+ !z && a
928
1115
  ] }),
929
- /* @__PURE__ */ p(xe, { children: [
930
- I && /* @__PURE__ */ s(ge, { size: "small" }),
931
- /* @__PURE__ */ s(
932
- k,
1116
+ /* @__PURE__ */ p(oe, { children: [
1117
+ T && /* @__PURE__ */ i(Ae, { size: "small" }),
1118
+ /* @__PURE__ */ i(
1119
+ O,
933
1120
  {
934
- onClick: X,
1121
+ onClick: Z,
935
1122
  variant: "text",
936
1123
  children: "Cancel"
937
1124
  }
938
1125
  ),
939
- /* @__PURE__ */ s(
940
- k,
1126
+ /* @__PURE__ */ i(
1127
+ O,
941
1128
  {
942
1129
  variant: "filled",
943
- onClick: Ne,
944
- disabled: I || !J,
1130
+ onClick: Le,
1131
+ disabled: T || !z,
945
1132
  children: "Download"
946
1133
  }
947
1134
  )
@@ -951,28 +1138,196 @@ function yt({
951
1138
  )
952
1139
  ] });
953
1140
  }
954
- function St(e) {
955
- return Ie(() => ({
956
- name: "Import/Export",
957
- collections: {
958
- CollectionActions: [ct, yt],
1141
+ function $t(e) {
1142
+ return He(() => ({
1143
+ key: "import_export",
1144
+ collectionView: {
1145
+ CollectionActions: [Dt, At],
959
1146
  collectionActionsProps: e
960
1147
  }
961
1148
  }), [e]);
962
1149
  }
1150
+ function Bt({
1151
+ data: e,
1152
+ properties: n,
1153
+ propertiesOrder: s
1154
+ }) {
1155
+ const t = y.useRef(/* @__PURE__ */ new Date()), [r, a] = y.useState(!0), [l, o] = y.useState("csv"), [c, d] = y.useState("string"), [u, m] = y.useState(!1), h = v(() => {
1156
+ m(!0);
1157
+ }, [m]), g = v(() => {
1158
+ m(!1);
1159
+ }, [m]), x = v(() => {
1160
+ Be(e, [], n, s, "export.csv", r, [], l, c), g();
1161
+ }, []);
1162
+ return /* @__PURE__ */ p(M, { children: [
1163
+ /* @__PURE__ */ i(q, { title: "Export", children: /* @__PURE__ */ i(Y, { color: "primary", onClick: h, children: /* @__PURE__ */ i(Ee, {}) }) }),
1164
+ /* @__PURE__ */ p(
1165
+ ie,
1166
+ {
1167
+ open: u,
1168
+ onOpenChange: m,
1169
+ maxWidth: "xl",
1170
+ children: [
1171
+ /* @__PURE__ */ p(le, { className: "flex flex-col gap-4 my-4", children: [
1172
+ /* @__PURE__ */ i(f, { variant: "h6", children: "Export data" }),
1173
+ /* @__PURE__ */ i("div", { children: "Download the the content of this table as a CSV" }),
1174
+ /* @__PURE__ */ p("div", { className: "flex flex-row gap-4", children: [
1175
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1176
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1177
+ /* @__PURE__ */ i(
1178
+ "input",
1179
+ {
1180
+ id: "radio-csv",
1181
+ type: "radio",
1182
+ value: "csv",
1183
+ name: "exportType",
1184
+ checked: l === "csv",
1185
+ onChange: () => o("csv"),
1186
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1187
+ }
1188
+ ),
1189
+ /* @__PURE__ */ i(
1190
+ "label",
1191
+ {
1192
+ htmlFor: "radio-csv",
1193
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1194
+ children: "CSV"
1195
+ }
1196
+ )
1197
+ ] }),
1198
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1199
+ /* @__PURE__ */ i(
1200
+ "input",
1201
+ {
1202
+ id: "radio-json",
1203
+ type: "radio",
1204
+ value: "json",
1205
+ name: "exportType",
1206
+ checked: l === "json",
1207
+ onChange: () => o("json"),
1208
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1209
+ }
1210
+ ),
1211
+ /* @__PURE__ */ i(
1212
+ "label",
1213
+ {
1214
+ htmlFor: "radio-json",
1215
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1216
+ children: "JSON"
1217
+ }
1218
+ )
1219
+ ] })
1220
+ ] }),
1221
+ /* @__PURE__ */ p("div", { className: "p-4 flex flex-col", children: [
1222
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1223
+ /* @__PURE__ */ i(
1224
+ "input",
1225
+ {
1226
+ id: "radio-timestamp",
1227
+ type: "radio",
1228
+ value: "timestamp",
1229
+ name: "dateExportType",
1230
+ checked: c === "timestamp",
1231
+ onChange: () => d("timestamp"),
1232
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1233
+ }
1234
+ ),
1235
+ /* @__PURE__ */ p(
1236
+ "label",
1237
+ {
1238
+ htmlFor: "radio-timestamp",
1239
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1240
+ children: [
1241
+ "Dates as timestamps (",
1242
+ t.current.getTime(),
1243
+ ")"
1244
+ ]
1245
+ }
1246
+ )
1247
+ ] }),
1248
+ /* @__PURE__ */ p("div", { className: "flex items-center", children: [
1249
+ /* @__PURE__ */ i(
1250
+ "input",
1251
+ {
1252
+ id: "radio-string",
1253
+ type: "radio",
1254
+ value: "string",
1255
+ name: "dateExportType",
1256
+ checked: c === "string",
1257
+ onChange: () => d("string"),
1258
+ className: k(_, "w-4 text-primary-dark bg-gray-100 border-gray-300 dark:bg-gray-700 dark:border-gray-600")
1259
+ }
1260
+ ),
1261
+ /* @__PURE__ */ p(
1262
+ "label",
1263
+ {
1264
+ htmlFor: "radio-string",
1265
+ className: "p-2 text-sm font-medium text-gray-900 dark:text-slate-300",
1266
+ children: [
1267
+ "Dates as strings (",
1268
+ t.current.toISOString(),
1269
+ ")"
1270
+ ]
1271
+ }
1272
+ )
1273
+ ] })
1274
+ ] })
1275
+ ] }),
1276
+ /* @__PURE__ */ i(
1277
+ se,
1278
+ {
1279
+ size: "small",
1280
+ disabled: l !== "csv",
1281
+ value: r,
1282
+ onValueChange: a,
1283
+ label: "Flatten arrays"
1284
+ }
1285
+ )
1286
+ ] }),
1287
+ /* @__PURE__ */ p(oe, { children: [
1288
+ /* @__PURE__ */ i(
1289
+ O,
1290
+ {
1291
+ onClick: g,
1292
+ variant: "text",
1293
+ children: "Cancel"
1294
+ }
1295
+ ),
1296
+ /* @__PURE__ */ i(
1297
+ O,
1298
+ {
1299
+ variant: "filled",
1300
+ onClick: x,
1301
+ children: "Download"
1302
+ }
1303
+ )
1304
+ ] })
1305
+ ]
1306
+ }
1307
+ )
1308
+ ] });
1309
+ }
963
1310
  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
1311
+ Bt as BasicExportAction,
1312
+ yt as DataNewPropertiesMapping,
1313
+ At as ExportCollectionAction,
1314
+ Dt as ImportCollectionAction,
1315
+ St as ImportDataPreview,
1316
+ Ct as ImportFileUpload,
1317
+ Rt as ImportNewPropertyFieldPreview,
1318
+ wt as ImportSaveInProgress,
1319
+ ve as PropertySelectEntry,
1320
+ gt as convertDataToEntity,
1321
+ ft as convertFileToJson,
1322
+ we as downloadBlob,
1323
+ Be as downloadEntitiesExport,
1324
+ Fe as flattenEntry,
1325
+ Ot as getEntityCSVExportableData,
1326
+ kt as getEntityJsonExportableData,
1327
+ xt as getInferenceType,
1328
+ ne as processValueMapping,
1329
+ je as unflattenObject,
1330
+ ut as useImportConfig,
1331
+ $t as useImportExportPlugin
977
1332
  };
978
1333
  //# sourceMappingURL=index.es.js.map