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