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