@firecms/data_import_export 3.0.0-canary.49 → 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.
package/dist/index.es.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
import y, { useState as S, useRef as Je, useEffect as De, useCallback as v, useMemo as He } from "react";
|
2
2
|
import { jsxs as p, Fragment as M, jsx as i } from "react/jsx-runtime";
|
3
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
|
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
5
|
import { inferTypeFromValue as ct, buildEntityPropertiesFromData as dt } from "@firecms/schema_inference";
|
6
6
|
import * as V from "xlsx";
|
7
7
|
import { getIn as Te, setIn as pt } from "@firecms/formex";
|
8
8
|
const ut = () => {
|
9
|
-
const [e,
|
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({});
|
10
10
|
return {
|
11
11
|
inUse: e,
|
12
|
-
setInUse:
|
12
|
+
setInUse: n,
|
13
13
|
idColumn: r,
|
14
|
-
setIdColumn:
|
14
|
+
setIdColumn: a,
|
15
15
|
entities: c,
|
16
16
|
setEntities: d,
|
17
17
|
importData: l,
|
@@ -27,27 +27,27 @@ const ut = () => {
|
|
27
27
|
};
|
28
28
|
};
|
29
29
|
function mt(e) {
|
30
|
-
let
|
30
|
+
let n = 0;
|
31
31
|
const s = [], t = {};
|
32
32
|
if (e == null || e["!ref"] == null)
|
33
33
|
return [];
|
34
34
|
const r = t.range !== void 0 ? t.range : e["!ref"];
|
35
|
-
let
|
36
|
-
switch (t.header === 1 ?
|
35
|
+
let a;
|
36
|
+
switch (t.header === 1 ? n = 1 : t.header === "A" ? n = 2 : Array.isArray(t.header) && (n = 3), typeof r) {
|
37
37
|
case "string":
|
38
|
-
|
38
|
+
a = be(r);
|
39
39
|
break;
|
40
40
|
case "number":
|
41
|
-
|
41
|
+
a = be(e["!ref"]), a.s.r = r;
|
42
42
|
break;
|
43
43
|
default:
|
44
|
-
|
44
|
+
a = r;
|
45
45
|
}
|
46
|
-
const l = V.utils.encode_row(
|
47
|
-
for (let c =
|
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
48
|
o[c] = V.utils.encode_col(c);
|
49
49
|
const d = e[o[c] + l];
|
50
|
-
switch (
|
50
|
+
switch (n) {
|
51
51
|
case 1:
|
52
52
|
s.push(c);
|
53
53
|
break;
|
@@ -55,7 +55,7 @@ function mt(e) {
|
|
55
55
|
s.push(o[c]);
|
56
56
|
break;
|
57
57
|
case 3:
|
58
|
-
s.push(t.header[c -
|
58
|
+
s.push(t.header[c - a.s.c]);
|
59
59
|
break;
|
60
60
|
default:
|
61
61
|
if (d === void 0)
|
@@ -66,7 +66,7 @@ function mt(e) {
|
|
66
66
|
return s;
|
67
67
|
}
|
68
68
|
function be(e) {
|
69
|
-
const
|
69
|
+
const n = {
|
70
70
|
s: {
|
71
71
|
c: 0,
|
72
72
|
r: 0
|
@@ -77,50 +77,50 @@ function be(e) {
|
|
77
77
|
}
|
78
78
|
};
|
79
79
|
let s = 0, t = 0, r = 0;
|
80
|
-
const
|
81
|
-
for (s = 0; t <
|
80
|
+
const a = e.length;
|
81
|
+
for (s = 0; t < a && !((r = e.charCodeAt(t) - 64) < 1 || r > 26); ++t)
|
82
82
|
s = 26 * s + r;
|
83
|
-
for (
|
83
|
+
for (n.s.c = --s, s = 0; t < a && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
|
84
84
|
s = 10 * s + r;
|
85
|
-
if (
|
86
|
-
return
|
87
|
-
for (s = 0; t !==
|
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
88
|
s = 26 * s + r;
|
89
|
-
for (
|
89
|
+
for (n.e.c = --s, s = 0; t !== a && !((r = e.charCodeAt(t) - 48) < 0 || r > 9); ++t)
|
90
90
|
s = 10 * s + r;
|
91
|
-
return
|
91
|
+
return n.e.r = --s, n;
|
92
92
|
}
|
93
93
|
function ft(e) {
|
94
|
-
return new Promise((
|
94
|
+
return new Promise((n, s) => {
|
95
95
|
if (e.type === "application/json") {
|
96
96
|
console.debug("Converting JSON file to JSON", e.name);
|
97
97
|
const t = new FileReader();
|
98
98
|
t.onload = function(r) {
|
99
99
|
try {
|
100
|
-
const
|
100
|
+
const a = r.target?.result, l = JSON.parse(a);
|
101
101
|
if (!Array.isArray(l))
|
102
102
|
s(new Error("JSON file should contain an array of objects"));
|
103
103
|
else {
|
104
104
|
const o = l.length > 0 ? Object.keys(l[0]) : [];
|
105
|
-
|
105
|
+
n({
|
106
106
|
data: l,
|
107
107
|
propertiesOrder: o
|
108
108
|
});
|
109
109
|
}
|
110
|
-
} catch (
|
111
|
-
console.error("Error parsing JSON file",
|
110
|
+
} catch (a) {
|
111
|
+
console.error("Error parsing JSON file", a), s(a);
|
112
112
|
}
|
113
113
|
}, t.readAsText(e);
|
114
114
|
} else {
|
115
115
|
console.debug("Converting Excel file to JSON", e.name);
|
116
116
|
const t = new FileReader();
|
117
117
|
t.onload = function(r) {
|
118
|
-
const
|
118
|
+
const a = new Uint8Array(r.target?.result), l = V.read(a, {
|
119
119
|
type: "array",
|
120
120
|
codepage: 65001,
|
121
121
|
cellDates: !0
|
122
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
|
-
|
123
|
+
n({
|
124
124
|
data: h,
|
125
125
|
propertiesOrder: u
|
126
126
|
});
|
@@ -129,70 +129,70 @@ function ft(e) {
|
|
129
129
|
});
|
130
130
|
}
|
131
131
|
function ht(e) {
|
132
|
-
return Object.keys(e).reduce((
|
132
|
+
return Object.keys(e).reduce((n, s) => {
|
133
133
|
try {
|
134
|
-
|
134
|
+
n[s] = JSON.parse(e[s]);
|
135
135
|
} catch {
|
136
|
-
|
136
|
+
n[s] = e[s];
|
137
137
|
}
|
138
|
-
return
|
138
|
+
return n;
|
139
139
|
}, {});
|
140
140
|
}
|
141
141
|
function je(e) {
|
142
|
-
return Object.keys(e).reduce((
|
143
|
-
let t =
|
142
|
+
return Object.keys(e).reduce((n, s) => {
|
143
|
+
let t = n;
|
144
144
|
const r = s.split(".");
|
145
|
-
return r.forEach((
|
146
|
-
if (/^[\w]+\[\d+\]$/.test(
|
147
|
-
const o =
|
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
148
|
t[o] || (t[o] = []), l !== r.length - 1 ? (t[o][c] = t[o][c] || {}, t = t[o][c]) : t[o][c] = e[s];
|
149
149
|
} else
|
150
|
-
l !== r.length - 1 ? (t[
|
151
|
-
}),
|
150
|
+
l !== r.length - 1 ? (t[a] = t[a] || {}, t = t[a]) : t[a] = e[s];
|
151
|
+
}), n;
|
152
152
|
}, {});
|
153
153
|
}
|
154
|
-
function gt(e,
|
154
|
+
function gt(e, n, s, t, r, a) {
|
155
155
|
const l = Fe(e);
|
156
|
-
|
156
|
+
n && delete l[n];
|
157
157
|
const o = Object.entries(l).map(([u, m]) => {
|
158
158
|
const h = Te(s, u) ?? u, g = J(t, h);
|
159
159
|
if (!g)
|
160
160
|
return {};
|
161
|
-
const x =
|
161
|
+
const x = ne(m, g);
|
162
162
|
return {
|
163
163
|
[h]: x
|
164
164
|
};
|
165
|
-
}).reduce((u, m) => ({ ...u, ...m }), {}), c = Ve(
|
166
|
-
let d =
|
165
|
+
}).reduce((u, m) => ({ ...u, ...m }), {}), c = Ve(a ?? {}, je(o));
|
166
|
+
let d = n ? e[n] : void 0;
|
167
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
168
|
id: d,
|
169
169
|
values: c,
|
170
170
|
path: r
|
171
171
|
};
|
172
172
|
}
|
173
|
-
function Fe(e,
|
173
|
+
function Fe(e, n = "") {
|
174
174
|
return Object.keys(e).reduce((s, t) => {
|
175
|
-
const r =
|
175
|
+
const r = n ? `${n}.${t}` : t;
|
176
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;
|
177
177
|
}, {});
|
178
178
|
}
|
179
|
-
function
|
179
|
+
function ne(e, n) {
|
180
180
|
if (e === null)
|
181
181
|
return null;
|
182
|
-
if (
|
182
|
+
if (n === void 0)
|
183
183
|
return e;
|
184
184
|
const s = ze({
|
185
|
-
propertyOrBuilder:
|
185
|
+
propertyOrBuilder: n
|
186
186
|
});
|
187
187
|
if (s === null)
|
188
188
|
return e;
|
189
189
|
const t = ct(e), r = s.dataType;
|
190
190
|
if (t === "array" && r === "array" && Array.isArray(e) && s.of && !ue(s.of))
|
191
|
-
return e.map((
|
191
|
+
return e.map((a) => ne(a, s.of));
|
192
192
|
if (t === "string" && r === "number" && typeof e == "string")
|
193
193
|
return Number(e);
|
194
194
|
if (t === "string" && r === "array" && typeof e == "string" && s.of && !ue(s.of))
|
195
|
-
return e.split(",").map((
|
195
|
+
return e.split(",").map((a) => ne(a, s.of));
|
196
196
|
if (t === "string" && r === "boolean")
|
197
197
|
return e === "true";
|
198
198
|
if (t === "number" && r === "boolean")
|
@@ -204,7 +204,7 @@ function ae(e, a) {
|
|
204
204
|
if (t === "number" && r === "string" && typeof e == "number")
|
205
205
|
return e.toString();
|
206
206
|
if (t === "string" && r === "array" && typeof e == "string")
|
207
|
-
return e.split(",").map((
|
207
|
+
return e.split(",").map((a) => a.trim());
|
208
208
|
if (t === "string" && r === "date" && typeof e == "string")
|
209
209
|
try {
|
210
210
|
return new Date(e);
|
@@ -221,8 +221,8 @@ function ae(e, a) {
|
|
221
221
|
return e;
|
222
222
|
}
|
223
223
|
else if (t === "string" && r === "reference" && typeof e == "string") {
|
224
|
-
const
|
225
|
-
return new Ue(l,
|
224
|
+
const a = e.split("/").slice(0, -1).join("/"), l = e.split("/").slice(-1)[0];
|
225
|
+
return new Ue(l, a);
|
226
226
|
} else {
|
227
227
|
if (t === r)
|
228
228
|
return e;
|
@@ -237,15 +237,15 @@ function xt(e) {
|
|
237
237
|
}
|
238
238
|
function yt({
|
239
239
|
importConfig: e,
|
240
|
-
destinationProperties:
|
240
|
+
destinationProperties: n,
|
241
241
|
buildPropertyView: s
|
242
242
|
}) {
|
243
|
-
const t = e.headersMapping, r = e.headingsOrder,
|
243
|
+
const t = e.headersMapping, r = e.headingsOrder, a = e.idColumn, l = e.originProperties;
|
244
244
|
return /* @__PURE__ */ p(M, { children: [
|
245
245
|
/* @__PURE__ */ i(
|
246
246
|
bt,
|
247
247
|
{
|
248
|
-
idColumn:
|
248
|
+
idColumn: a,
|
249
249
|
headersMapping: t,
|
250
250
|
onChange: (o) => e.setIdColumn(o ?? void 0)
|
251
251
|
}
|
@@ -259,9 +259,9 @@ function yt({
|
|
259
259
|
/* @__PURE__ */ i(w, { header: !0 }),
|
260
260
|
/* @__PURE__ */ i(w, { header: !0, style: { width: "75%" }, children: "Map to Property" })
|
261
261
|
] }),
|
262
|
-
/* @__PURE__ */ i(he, { children:
|
262
|
+
/* @__PURE__ */ i(he, { children: n && r.map(
|
263
263
|
(o) => {
|
264
|
-
const c = t[o], d = t[o], u = c ? J(
|
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
265
|
return /* @__PURE__ */ p(ge, { style: { height: "90px" }, children: [
|
266
266
|
/* @__PURE__ */ p(w, { style: { width: "20%" }, children: [
|
267
267
|
/* @__PURE__ */ i(f, { variant: "body2", children: o }),
|
@@ -278,10 +278,10 @@ function yt({
|
|
278
278
|
/* @__PURE__ */ i(
|
279
279
|
w,
|
280
280
|
{
|
281
|
-
className: o ===
|
281
|
+
className: o === a ? "text-center" : void 0,
|
282
282
|
style: { width: "75%" },
|
283
283
|
children: s?.({
|
284
|
-
isIdColumn: o ===
|
284
|
+
isIdColumn: o === a,
|
285
285
|
property: u,
|
286
286
|
propertyKey: d,
|
287
287
|
importKey: o
|
@@ -302,16 +302,16 @@ function yt({
|
|
302
302
|
/* @__PURE__ */ i(w, { header: !0 }),
|
303
303
|
/* @__PURE__ */ i(w, { header: !0, style: { width: "65%" }, children: "Default value" })
|
304
304
|
] }),
|
305
|
-
/* @__PURE__ */ i(he, { children:
|
305
|
+
/* @__PURE__ */ i(he, { children: n && Pe(n).map(
|
306
306
|
(o) => {
|
307
|
-
const c = J(
|
307
|
+
const c = J(n, o);
|
308
308
|
return typeof c != "object" || c === null || !["number", "string", "boolean", "map"].includes(c.dataType) ? null : /* @__PURE__ */ p(ge, { style: { height: "70px" }, children: [
|
309
309
|
/* @__PURE__ */ i(w, { style: { width: "20%" }, children: /* @__PURE__ */ i(f, { variant: "body2", children: o }) }),
|
310
310
|
/* @__PURE__ */ i(w, { children: /* @__PURE__ */ i(xe, {}) }),
|
311
311
|
/* @__PURE__ */ i(
|
312
312
|
w,
|
313
313
|
{
|
314
|
-
className: o ===
|
314
|
+
className: o === a ? "text-center" : void 0,
|
315
315
|
style: { width: "75%" },
|
316
316
|
children: /* @__PURE__ */ i(
|
317
317
|
vt,
|
@@ -333,19 +333,19 @@ function yt({
|
|
333
333
|
] })
|
334
334
|
] });
|
335
335
|
}
|
336
|
-
function Pe(e,
|
336
|
+
function Pe(e, n) {
|
337
337
|
return Object.entries(e).reduce((s, [t, r]) => {
|
338
|
-
const
|
338
|
+
const a = n ? `${n}.${t}` : t;
|
339
339
|
if (typeof r != "function" && r.dataType === "map" && r.properties) {
|
340
|
-
const l = Pe(r.properties,
|
340
|
+
const l = Pe(r.properties, a);
|
341
341
|
return [...s, ...l];
|
342
342
|
}
|
343
|
-
return [...s,
|
343
|
+
return [...s, a];
|
344
344
|
}, []);
|
345
345
|
}
|
346
346
|
function bt({
|
347
347
|
idColumn: e,
|
348
|
-
headersMapping:
|
348
|
+
headersMapping: n,
|
349
349
|
onChange: s
|
350
350
|
}) {
|
351
351
|
return /* @__PURE__ */ i("div", { children: /* @__PURE__ */ p(
|
@@ -362,14 +362,14 @@ function bt({
|
|
362
362
|
label: "Column that will be used as ID for each document",
|
363
363
|
children: [
|
364
364
|
/* @__PURE__ */ i(H, { value: "__none__", children: "Autogenerate ID" }),
|
365
|
-
Object.entries(
|
365
|
+
Object.entries(n).map(([t, r]) => /* @__PURE__ */ i(H, { value: t, children: t }, t))
|
366
366
|
]
|
367
367
|
}
|
368
368
|
) });
|
369
369
|
}
|
370
370
|
function vt({
|
371
371
|
property: e,
|
372
|
-
onValueChange:
|
372
|
+
onValueChange: n,
|
373
373
|
defaultValue: s
|
374
374
|
}) {
|
375
375
|
return e.dataType === "string" ? /* @__PURE__ */ i(
|
@@ -378,7 +378,7 @@ function vt({
|
|
378
378
|
size: "small",
|
379
379
|
placeholder: "Default value",
|
380
380
|
value: s ?? "",
|
381
|
-
onChange: (t) =>
|
381
|
+
onChange: (t) => n(t.target.value)
|
382
382
|
}
|
383
383
|
) : e.dataType === "number" ? /* @__PURE__ */ i(
|
384
384
|
re,
|
@@ -387,7 +387,7 @@ function vt({
|
|
387
387
|
type: "number",
|
388
388
|
value: s ?? "",
|
389
389
|
placeholder: "Default value",
|
390
|
-
onChange: (t) =>
|
390
|
+
onChange: (t) => n(t.target.value)
|
391
391
|
}
|
392
392
|
) : e.dataType === "boolean" ? /* @__PURE__ */ i(
|
393
393
|
se,
|
@@ -395,7 +395,7 @@ function vt({
|
|
395
395
|
value: s ?? null,
|
396
396
|
allowIndeterminate: !0,
|
397
397
|
size: "small",
|
398
|
-
onValueChange: (t) =>
|
398
|
+
onValueChange: (t) => n(t === null ? void 0 : t),
|
399
399
|
label: s === void 0 ? "Do not set value" : s === !0 ? "Set value to true" : "Set value to false"
|
400
400
|
}
|
401
401
|
) : e.dataType === "date" ? /* @__PURE__ */ i(
|
@@ -405,16 +405,16 @@ function vt({
|
|
405
405
|
size: "small",
|
406
406
|
value: s ?? void 0,
|
407
407
|
onChange: (t) => {
|
408
|
-
|
408
|
+
n(t);
|
409
409
|
},
|
410
410
|
clearable: !0
|
411
411
|
}
|
412
412
|
) : null;
|
413
413
|
}
|
414
414
|
function Ct({ onDataAdded: e }) {
|
415
|
-
const
|
415
|
+
const n = Ne();
|
416
416
|
return /* @__PURE__ */ i(
|
417
|
-
|
417
|
+
nt,
|
418
418
|
{
|
419
419
|
accept: {
|
420
420
|
"text/*": [".csv", ".xls", ".xlsx"],
|
@@ -430,7 +430,7 @@ function Ct({ onDataAdded: e }) {
|
|
430
430
|
size: "small",
|
431
431
|
maxFiles: 1,
|
432
432
|
uploadDescription: /* @__PURE__ */ p(M, { children: [
|
433
|
-
/* @__PURE__ */ i(
|
433
|
+
/* @__PURE__ */ i(at, {}),
|
434
434
|
"Drag and drop a file here or click to upload"
|
435
435
|
] }),
|
436
436
|
onFilesAdded: (s) => {
|
@@ -440,7 +440,7 @@ function Ct({ onDataAdded: e }) {
|
|
440
440
|
}) => {
|
441
441
|
e(t, r);
|
442
442
|
}).catch((t) => {
|
443
|
-
console.error("Error parsing file", t),
|
443
|
+
console.error("Error parsing file", t), n.open({
|
444
444
|
type: "error",
|
445
445
|
message: t.message
|
446
446
|
});
|
@@ -451,26 +451,26 @@ function Ct({ onDataAdded: e }) {
|
|
451
451
|
}
|
452
452
|
function Rt({
|
453
453
|
propertyKey: e,
|
454
|
-
property:
|
454
|
+
property: n,
|
455
455
|
onEditClick: s,
|
456
456
|
includeName: t = !0,
|
457
457
|
onPropertyNameChanged: r,
|
458
|
-
propertyTypeView:
|
458
|
+
propertyTypeView: a
|
459
459
|
}) {
|
460
|
-
const { propertyConfigs: l } = G(), o =
|
460
|
+
const { propertyConfigs: l } = G(), o = n ? Se(n, l) : null;
|
461
461
|
return /* @__PURE__ */ i(We, { children: /* @__PURE__ */ p(
|
462
462
|
"div",
|
463
463
|
{
|
464
464
|
className: "flex flex-row w-full items-center",
|
465
465
|
children: [
|
466
|
-
/* @__PURE__ */ i("div", { className: "mx-4", children:
|
466
|
+
/* @__PURE__ */ i("div", { className: "mx-4", children: a ?? /* @__PURE__ */ i(Oe, { propertyConfig: o ?? void 0 }) }),
|
467
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
468
|
t && /* @__PURE__ */ i(
|
469
469
|
re,
|
470
470
|
{
|
471
471
|
size: "small",
|
472
472
|
className: "text-base grow",
|
473
|
-
value:
|
473
|
+
value: n?.name ?? "",
|
474
474
|
onChange: (c) => {
|
475
475
|
r && e && r(e, c.target.value);
|
476
476
|
}
|
@@ -484,24 +484,24 @@ function Rt({
|
|
484
484
|
}
|
485
485
|
function wt({
|
486
486
|
path: e,
|
487
|
-
importConfig:
|
487
|
+
importConfig: n,
|
488
488
|
collection: s,
|
489
489
|
onImportSuccess: t
|
490
490
|
}) {
|
491
|
-
const [r,
|
491
|
+
const [r, a] = S(void 0), l = ke(), o = Je(!1), [c, d] = S(0);
|
492
492
|
function u() {
|
493
493
|
o.current || (o.current = !0, Me(
|
494
494
|
l,
|
495
495
|
s,
|
496
496
|
e,
|
497
|
-
|
497
|
+
n.entities,
|
498
498
|
0,
|
499
499
|
25,
|
500
500
|
d
|
501
501
|
).then(() => {
|
502
502
|
t(s), o.current = !1;
|
503
503
|
}).catch((m) => {
|
504
|
-
|
504
|
+
a(m), o.current = !1;
|
505
505
|
}));
|
506
506
|
}
|
507
507
|
return De(() => {
|
@@ -523,30 +523,30 @@ function wt({
|
|
523
523
|
/* @__PURE__ */ p(f, { variant: "body2", children: [
|
524
524
|
c,
|
525
525
|
"/",
|
526
|
-
|
526
|
+
n.entities.length,
|
527
527
|
" entities saved"
|
528
528
|
] }),
|
529
529
|
/* @__PURE__ */ i(f, { variant: "caption", children: "Do not close this tab or the import will be interrupted." })
|
530
530
|
] });
|
531
531
|
}
|
532
|
-
function Me(e,
|
533
|
-
console.debug("Saving imported data", r,
|
534
|
-
const o = t.slice(r, 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
535
|
return Promise.all(o.map((c) => e.saveEntity({
|
536
536
|
path: s,
|
537
537
|
values: c.values,
|
538
538
|
entityId: c.id,
|
539
|
-
collection:
|
539
|
+
collection: n,
|
540
540
|
status: "new"
|
541
|
-
}))).then(() => r +
|
541
|
+
}))).then(() => r + a < t.length ? (l(r + a), Me(e, n, s, t, r + a, a, l)) : (l(t.length), Promise.resolve()));
|
542
542
|
}
|
543
543
|
function Dt({
|
544
544
|
collection: e,
|
545
|
-
path:
|
545
|
+
path: n,
|
546
546
|
collectionEntitiesCount: s,
|
547
547
|
onAnalyticsEvent: t
|
548
548
|
}) {
|
549
|
-
const r = G(),
|
549
|
+
const r = G(), a = Ne(), [l, o] = y.useState(!1), [c, d] = y.useState("initial"), u = ut(), m = v(() => {
|
550
550
|
o(!0), t?.("import_open"), d("initial");
|
551
551
|
}, [t]), h = v(() => {
|
552
552
|
o(!1);
|
@@ -568,7 +568,7 @@ function Dt({
|
|
568
568
|
}, 100);
|
569
569
|
}, A = Ie({
|
570
570
|
collection: e,
|
571
|
-
path:
|
571
|
+
path: n,
|
572
572
|
fields: r.propertyConfigs
|
573
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
574
|
return e.collectionGroup ? null : /* @__PURE__ */ p(M, { children: [
|
@@ -632,9 +632,9 @@ function Dt({
|
|
632
632
|
{
|
633
633
|
importConfig: u,
|
634
634
|
collection: e,
|
635
|
-
path:
|
635
|
+
path: n,
|
636
636
|
onImportSuccess: (b) => {
|
637
|
-
h(),
|
637
|
+
h(), a.open({
|
638
638
|
type: "info",
|
639
639
|
message: "Data imported successfully"
|
640
640
|
});
|
@@ -692,13 +692,13 @@ function Dt({
|
|
692
692
|
const W = "__internal_id__";
|
693
693
|
function Nt({
|
694
694
|
selectedPropertyKey: e,
|
695
|
-
properties:
|
695
|
+
properties: n,
|
696
696
|
onPropertySelected: s,
|
697
697
|
onIdSelected: t,
|
698
698
|
propertiesAndLevel: r,
|
699
|
-
isIdColumn:
|
699
|
+
isIdColumn: a
|
700
700
|
}) {
|
701
|
-
const l = e ? J(
|
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
702
|
ve,
|
703
703
|
{
|
704
704
|
propertyKey: d,
|
@@ -708,7 +708,7 @@ function Nt({
|
|
708
708
|
return /* @__PURE__ */ p(
|
709
709
|
_e,
|
710
710
|
{
|
711
|
-
value:
|
711
|
+
value: a ? W : e ?? void 0,
|
712
712
|
onValueChange: (d) => {
|
713
713
|
d === W ? (t(), s(null)) : s(d === "__do_not_import" ? null : d);
|
714
714
|
},
|
@@ -740,28 +740,28 @@ function Nt({
|
|
740
740
|
}
|
741
741
|
);
|
742
742
|
}
|
743
|
-
function Re(e,
|
743
|
+
function Re(e, n, s) {
|
744
744
|
const t = [];
|
745
745
|
return t.push({
|
746
|
-
property:
|
746
|
+
property: n,
|
747
747
|
level: s,
|
748
748
|
propertyKey: e
|
749
|
-
}),
|
750
|
-
t.push(...Re(`${e}.${r}`,
|
749
|
+
}), n.dataType === "map" && n.properties && Object.entries(n.properties).forEach(([r, a]) => {
|
750
|
+
t.push(...Re(`${e}.${r}`, a, s + 1));
|
751
751
|
}), t;
|
752
752
|
}
|
753
753
|
function ve({
|
754
754
|
propertyKey: e,
|
755
|
-
property:
|
755
|
+
property: n,
|
756
756
|
level: s = 0
|
757
757
|
}) {
|
758
|
-
const { propertyConfigs: t } = G(), r = Se(
|
758
|
+
const { propertyConfigs: t } = G(), r = Se(n, t);
|
759
759
|
return /* @__PURE__ */ p(
|
760
760
|
"div",
|
761
761
|
{
|
762
762
|
className: "flex flex-row w-full text-start items-center h-full",
|
763
763
|
children: [
|
764
|
-
new Array(s).fill(0).map((
|
764
|
+
new Array(s).fill(0).map((a, l) => /* @__PURE__ */ i("div", { className: k(lt, "ml-8 border-l h-12") }, l)),
|
765
765
|
/* @__PURE__ */ i("div", { className: "m-4", children: /* @__PURE__ */ i(q, { title: r?.name, children: /* @__PURE__ */ i(Oe, { propertyConfig: r }) }) }),
|
766
766
|
/* @__PURE__ */ p("div", { className: "flex flex-col flex-grow p-2 pl-2", children: [
|
767
767
|
/* @__PURE__ */ i(
|
@@ -770,7 +770,7 @@ function ve({
|
|
770
770
|
variant: "body1",
|
771
771
|
component: "span",
|
772
772
|
className: "flex-grow pr-2",
|
773
|
-
children:
|
773
|
+
children: n.name ? n.name : " "
|
774
774
|
}
|
775
775
|
),
|
776
776
|
/* @__PURE__ */ i(
|
@@ -790,15 +790,12 @@ function ve({
|
|
790
790
|
}
|
791
791
|
function St({
|
792
792
|
importConfig: e,
|
793
|
-
properties:
|
793
|
+
properties: n,
|
794
794
|
propertiesOrder: s
|
795
795
|
}) {
|
796
796
|
De(() => {
|
797
|
-
const r = e.importData.map((
|
798
|
-
|
799
|
-
importConfig: e,
|
800
|
-
mappedData: r
|
801
|
-
}), e.setEntities(r);
|
797
|
+
const r = e.importData.map((a) => gt(a, e.idColumn, e.headersMapping, n, "TEMP_PATH", e.defaultValues));
|
798
|
+
e.setEntities(r);
|
802
799
|
}, []);
|
803
800
|
const t = Ge();
|
804
801
|
return /* @__PURE__ */ i(
|
@@ -818,128 +815,128 @@ function St({
|
|
818
815
|
filterable: !1,
|
819
816
|
sortable: !1,
|
820
817
|
selectionController: t,
|
821
|
-
properties:
|
818
|
+
properties: n
|
822
819
|
}
|
823
820
|
);
|
824
821
|
}
|
825
|
-
function $e(e,
|
822
|
+
function $e(e, n) {
|
826
823
|
const s = {};
|
827
824
|
return e.filter(Boolean).forEach((t) => {
|
828
825
|
Object.keys(t).forEach((r) => {
|
829
|
-
const
|
830
|
-
if (typeof
|
831
|
-
const l =
|
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);
|
832
829
|
Object.entries(c).forEach(([d, u]) => {
|
833
830
|
s[`${r}.${d}`] = `${r}.${u}`;
|
834
831
|
});
|
835
832
|
}
|
836
|
-
if (!
|
833
|
+
if (!n)
|
837
834
|
s[r] = r;
|
838
|
-
else if (r in
|
835
|
+
else if (r in n)
|
839
836
|
s[r] = r;
|
840
837
|
else {
|
841
838
|
const l = qe(r);
|
842
|
-
l in
|
839
|
+
l in n ? s[r] = l : s[r] = r;
|
843
840
|
}
|
844
841
|
});
|
845
842
|
}), s;
|
846
843
|
}
|
847
|
-
function Be(e,
|
844
|
+
function Be(e, n, s, t, r, a, l, o, c) {
|
848
845
|
if (console.debug("Downloading export", {
|
849
846
|
dataLength: e.length,
|
850
847
|
properties: s,
|
851
848
|
exportType: o,
|
852
849
|
dateExportType: c
|
853
850
|
}), o === "csv") {
|
854
|
-
const d =
|
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));
|
855
852
|
we([h, ...g], `${r}.csv`, "text/csv");
|
856
853
|
} else {
|
857
|
-
const d = kt(e,
|
854
|
+
const d = kt(e, n, s, c), u = JSON.stringify(d, null, 2);
|
858
855
|
we([u], `${r}.json`, "application/json");
|
859
856
|
}
|
860
857
|
}
|
861
|
-
function Ot(e,
|
862
|
-
const
|
858
|
+
function Ot(e, n, s, t, r) {
|
859
|
+
const a = e.map((l) => ({
|
863
860
|
id: l.id,
|
864
861
|
...ce(l.values, s, "csv", r)
|
865
862
|
}));
|
866
|
-
return
|
867
|
-
|
868
|
-
}),
|
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)));
|
869
866
|
}
|
870
|
-
function kt(e,
|
871
|
-
const r = e.map((
|
872
|
-
id:
|
873
|
-
...ce(
|
867
|
+
function kt(e, n, s, t) {
|
868
|
+
const r = e.map((a) => ({
|
869
|
+
id: a.id,
|
870
|
+
...ce(a.values, s, "json", t)
|
874
871
|
}));
|
875
|
-
return
|
876
|
-
r[l] = { ...r[l], ...
|
872
|
+
return n && n.forEach((a, l) => {
|
873
|
+
r[l] = { ...r[l], ...a };
|
877
874
|
}), r;
|
878
875
|
}
|
879
|
-
function It(e,
|
876
|
+
function It(e, n, s, t) {
|
880
877
|
const r = [
|
881
878
|
{
|
882
879
|
label: "id",
|
883
880
|
key: "id"
|
884
881
|
},
|
885
|
-
...(
|
886
|
-
const l = e[
|
887
|
-
return t && t[
|
888
|
-
{ length: t[
|
889
|
-
(o, c) =>
|
890
|
-
).flat() :
|
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), []);
|
891
888
|
})
|
892
889
|
];
|
893
|
-
return s && r.push(...s.map((
|
894
|
-
label:
|
895
|
-
key:
|
890
|
+
return s && r.push(...s.map((a) => ({
|
891
|
+
label: a,
|
892
|
+
key: a
|
896
893
|
}))), r;
|
897
894
|
}
|
898
|
-
function
|
899
|
-
const t = s ? `${s}.${
|
900
|
-
return e.dataType === "map" && e.properties ? Object.entries(e.properties).map(([r,
|
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() : [{
|
901
898
|
label: t,
|
902
899
|
key: t
|
903
900
|
}];
|
904
901
|
}
|
905
|
-
function X(e,
|
902
|
+
function X(e, n, s, t) {
|
906
903
|
let r;
|
907
|
-
if (
|
908
|
-
r = ce(e,
|
909
|
-
else if (
|
910
|
-
|
911
|
-
else if (
|
912
|
-
const
|
913
|
-
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;
|
914
911
|
} else
|
915
|
-
|
912
|
+
n.dataType === "date" && e instanceof Date ? r = e ? t === "timestamp" ? e.getTime() : e.toISOString() : null : r = e;
|
916
913
|
return r;
|
917
914
|
}
|
918
|
-
function ce(e,
|
919
|
-
const r = Object.entries(
|
920
|
-
const o = e && e[
|
921
|
-
return c === void 0 ? {} : { [
|
922
|
-
}).reduce((
|
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 }), {});
|
923
920
|
return { ...e, ...r };
|
924
921
|
}
|
925
922
|
function Ce(e) {
|
926
|
-
return e.map((
|
923
|
+
return e.map((n) => n == null ? "" : Array.isArray(n) ? '"' + JSON.stringify(n).replaceAll('"', '\\"') + '"' : '"' + String(n).replaceAll('"', '""') + '"').join(",") + `\r
|
927
924
|
`;
|
928
925
|
}
|
929
|
-
function we(e,
|
930
|
-
const t = new Blob(e, { type: s }), r = URL.createObjectURL(t),
|
931
|
-
|
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();
|
932
929
|
}
|
933
930
|
const _t = 500;
|
934
931
|
function At({
|
935
932
|
collection: e,
|
936
|
-
path:
|
933
|
+
path: n,
|
937
934
|
collectionEntitiesCount: s,
|
938
935
|
onAnalyticsEvent: t,
|
939
936
|
exportAllowed: r,
|
940
|
-
notAllowedView:
|
937
|
+
notAllowedView: a
|
941
938
|
}) {
|
942
|
-
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(
|
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({
|
943
940
|
collectionEntitiesCount: s,
|
944
941
|
path: E,
|
945
942
|
collection: e
|
@@ -1114,7 +1111,7 @@ function At({
|
|
1114
1111
|
label: "Flatten arrays"
|
1115
1112
|
}
|
1116
1113
|
),
|
1117
|
-
!z &&
|
1114
|
+
!z && a
|
1118
1115
|
] }),
|
1119
1116
|
/* @__PURE__ */ p(oe, { children: [
|
1120
1117
|
T && /* @__PURE__ */ i(Ae, { size: "small" }),
|
@@ -1152,15 +1149,15 @@ function $t(e) {
|
|
1152
1149
|
}
|
1153
1150
|
function Bt({
|
1154
1151
|
data: e,
|
1155
|
-
properties:
|
1152
|
+
properties: n,
|
1156
1153
|
propertiesOrder: s
|
1157
1154
|
}) {
|
1158
|
-
const t = y.useRef(/* @__PURE__ */ new Date()), [r,
|
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(() => {
|
1159
1156
|
m(!0);
|
1160
1157
|
}, [m]), g = v(() => {
|
1161
1158
|
m(!1);
|
1162
1159
|
}, [m]), x = v(() => {
|
1163
|
-
Be(e, [],
|
1160
|
+
Be(e, [], n, s, "export.csv", r, [], l, c), g();
|
1164
1161
|
}, []);
|
1165
1162
|
return /* @__PURE__ */ p(M, { children: [
|
1166
1163
|
/* @__PURE__ */ i(q, { title: "Export", children: /* @__PURE__ */ i(Y, { color: "primary", onClick: h, children: /* @__PURE__ */ i(Ee, {}) }) }),
|
@@ -1282,7 +1279,7 @@ function Bt({
|
|
1282
1279
|
size: "small",
|
1283
1280
|
disabled: l !== "csv",
|
1284
1281
|
value: r,
|
1285
|
-
onValueChange:
|
1282
|
+
onValueChange: a,
|
1286
1283
|
label: "Flatten arrays"
|
1287
1284
|
}
|
1288
1285
|
)
|
@@ -1328,7 +1325,7 @@ export {
|
|
1328
1325
|
Ot as getEntityCSVExportableData,
|
1329
1326
|
kt as getEntityJsonExportableData,
|
1330
1327
|
xt as getInferenceType,
|
1331
|
-
|
1328
|
+
ne as processValueMapping,
|
1332
1329
|
je as unflattenObject,
|
1333
1330
|
ut as useImportConfig,
|
1334
1331
|
$t as useImportExportPlugin
|