@nkhang1902/strapi-plugin-export-import-clsx 1.1.16 → 1.1.18

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.16",
3
+ "version": "1.1.18",
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": {
@@ -14,7 +14,7 @@ module.exports = ({ strapi }) => ({
14
14
  .plugin("export-import-clsx")
15
15
  .service("import-service");
16
16
 
17
- const { eventId } = ctx.request.query;
17
+ let { eventId } = ctx.request.query;
18
18
  if (eventId == "") {
19
19
  eventId = null;
20
20
  }
@@ -147,7 +147,7 @@ module.exports = ({ strapi }) => ({
147
147
  .map(([fieldName, attr]) => toCamel(fieldName));
148
148
  },
149
149
 
150
- async handleRelations(entry, contentType, row) {
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
- const event = eventId ? strapi.documents("api::event.event").findFirst({
394
- filters: { documentId: eventId },
395
- }) : null;
396
-
397
- await strapi.db.transaction(async ({ trx, rollback, onRollback }) => {
398
- onRollback(() => {
399
- strapi.log.error("Transaction rolled back due to an error!");
400
- strapi.log.error(results.errors);
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
- // Check if document exists
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
- // Handle relations & components
426
- data = await this.handleRelations(data, contentType, row, eventName);
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(`Data validation failed:\n${sanitizeErrors.join('\n')}`);
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
- // Create
447
- await strapi
448
- .documents(contentType)
449
- .create({ data }, { transaction: trx });
439
+ await strapi.documents(contentType).create(
440
+ { data },
441
+ { transaction: trx }
442
+ );
450
443
  results.created++;
451
444
  }
452
445
  } catch (err) {
453
- results.errors.push(
454
- `Row ${i + 2}: ${err.message || err.toString()}`
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
  });