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