@nkhang1902/strapi-plugin-export-import-clsx 1.1.16 → 1.1.17
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.
|
@@ -95,6 +95,46 @@ const ExportImportButtons = (props) => {
|
|
|
95
95
|
return filters;
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
+
function showLongNotification(toggle, {
|
|
99
|
+
title,
|
|
100
|
+
message,
|
|
101
|
+
type = 'warning',
|
|
102
|
+
duration = 15000,
|
|
103
|
+
maxLines = 8,
|
|
104
|
+
}) {
|
|
105
|
+
const lines = String(message).split('\n');
|
|
106
|
+
|
|
107
|
+
let displayText = message;
|
|
108
|
+
let extraCount = 0;
|
|
109
|
+
|
|
110
|
+
if (lines.length > maxLines) {
|
|
111
|
+
extraCount = lines.length - maxLines;
|
|
112
|
+
displayText =
|
|
113
|
+
lines.slice(0, maxLines).join('\n') +
|
|
114
|
+
`\n... (+${extraCount} more errors)`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
toggle({
|
|
118
|
+
type,
|
|
119
|
+
title,
|
|
120
|
+
message: (
|
|
121
|
+
<div
|
|
122
|
+
style={{
|
|
123
|
+
maxHeight: 260,
|
|
124
|
+
overflowY: 'auto',
|
|
125
|
+
whiteSpace: 'pre-wrap',
|
|
126
|
+
fontSize: 13,
|
|
127
|
+
lineHeight: 1.5,
|
|
128
|
+
paddingRight: 4,
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
{displayText}
|
|
132
|
+
</div>
|
|
133
|
+
),
|
|
134
|
+
timeout: duration,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
98
138
|
const handleExport = async () => {
|
|
99
139
|
const contentType = getContentType();
|
|
100
140
|
if (!contentType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkhang1902/strapi-plugin-export-import-clsx",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "A powerful Strapi plugin for exporting and importing data with Excel support and advanced filtering",
|
|
5
5
|
"main": "./strapi-server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -147,7 +147,7 @@ module.exports = ({ strapi }) => ({
|
|
|
147
147
|
.map(([fieldName, attr]) => toCamel(fieldName));
|
|
148
148
|
},
|
|
149
149
|
|
|
150
|
-
async handleRelations(entry, contentType
|
|
150
|
+
async handleRelations(entry, contentType) {
|
|
151
151
|
const resolveRelationValue = async (field, value, target) => {
|
|
152
152
|
const targetAttr = strapi.contentTypes[target].attributes;
|
|
153
153
|
for (const field of SHORTCUT_FIELDS) {
|
|
@@ -390,78 +390,74 @@ module.exports = ({ strapi }) => ({
|
|
|
390
390
|
|
|
391
391
|
async importEntries(entries, contentType, eventId) {
|
|
392
392
|
const results = { created: 0, updated: 0, errors: [] };
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
393
|
+
|
|
394
|
+
await strapi.db.transaction(async ({ trx }) => {
|
|
395
|
+
let event = null;
|
|
396
|
+
|
|
397
|
+
if (eventId) {
|
|
398
|
+
event = await strapi.documents("api::event.event").findFirst(
|
|
399
|
+
{ filters: { documentId: eventId } },
|
|
400
|
+
{ transaction: trx }
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
let shouldRollback = false;
|
|
405
|
+
|
|
403
406
|
for (let i = 0; i < entries.length; i++) {
|
|
404
407
|
const entry = entries[i];
|
|
405
408
|
let existing = null;
|
|
406
|
-
|
|
409
|
+
|
|
407
410
|
try {
|
|
408
411
|
let { id, ...data } = entry;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (id && id !== "null" && id !== "undefined") {
|
|
412
|
+
|
|
413
|
+
if (id) {
|
|
412
414
|
existing = await strapi.documents(contentType).findFirst(
|
|
413
|
-
{
|
|
414
|
-
filters: { id },
|
|
415
|
-
populate: "*",
|
|
416
|
-
},
|
|
415
|
+
{ filters: { id }, populate: "*" },
|
|
417
416
|
{ transaction: trx }
|
|
418
417
|
);
|
|
419
|
-
if (!existing) {
|
|
420
|
-
throw new Error(`Document with id ${id} not found`);
|
|
421
|
-
}
|
|
418
|
+
if (!existing) throw new Error(`Document with id ${id} not found`);
|
|
422
419
|
}
|
|
423
|
-
data["event"] = event ? event.name : "";
|
|
424
420
|
|
|
425
|
-
|
|
426
|
-
|
|
421
|
+
if (event) data.event = event.name;
|
|
422
|
+
|
|
423
|
+
data = await this.handleRelations(data, contentType);
|
|
427
424
|
data = await this.handleComponents(data, existing, contentType);
|
|
425
|
+
|
|
428
426
|
const sanitizeErrors = [];
|
|
429
427
|
data = this.sanitizeEntryBeforeWrite(data, contentType, '', sanitizeErrors);
|
|
430
|
-
|
|
431
428
|
if (sanitizeErrors.length) {
|
|
432
|
-
throw new Error(
|
|
429
|
+
throw new Error(sanitizeErrors.join('\n'));
|
|
433
430
|
}
|
|
434
431
|
|
|
435
|
-
// Update
|
|
436
432
|
if (existing) {
|
|
437
433
|
await strapi.documents(contentType).update(
|
|
438
|
-
{
|
|
439
|
-
documentId: existing.documentId,
|
|
440
|
-
data,
|
|
441
|
-
},
|
|
434
|
+
{ documentId: existing.documentId, data },
|
|
442
435
|
{ transaction: trx }
|
|
443
436
|
);
|
|
444
437
|
results.updated++;
|
|
445
438
|
} else {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
439
|
+
await strapi.documents(contentType).create(
|
|
440
|
+
{ data },
|
|
441
|
+
{ transaction: trx }
|
|
442
|
+
);
|
|
450
443
|
results.created++;
|
|
451
444
|
}
|
|
452
445
|
} catch (err) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
);
|
|
456
|
-
results.created = 0;
|
|
457
|
-
results.updated = 0;
|
|
458
|
-
|
|
459
|
-
// IMPORTANT: force rollback
|
|
460
|
-
throw err;
|
|
446
|
+
shouldRollback = true;
|
|
447
|
+
results.errors.push(`Row ${i + 2}: ${err.message}`);
|
|
461
448
|
}
|
|
462
449
|
}
|
|
450
|
+
|
|
451
|
+
if (shouldRollback) {
|
|
452
|
+
await trx.rollback();
|
|
453
|
+
}
|
|
463
454
|
});
|
|
464
455
|
|
|
456
|
+
if (results.errors.length) {
|
|
457
|
+
results.created = 0;
|
|
458
|
+
results.updated = 0;
|
|
459
|
+
}
|
|
460
|
+
|
|
465
461
|
return results;
|
|
466
462
|
},
|
|
467
463
|
});
|