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