@wix/bex-core 2.399.0 → 2.400.0

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.
Files changed (97) hide show
  1. package/dist/cjs/assets/locale/messages_ar.json +20 -20
  2. package/dist/cjs/assets/locale/messages_bg.json +20 -20
  3. package/dist/cjs/assets/locale/messages_ca.json +20 -20
  4. package/dist/cjs/assets/locale/messages_cs.json +20 -20
  5. package/dist/cjs/assets/locale/messages_da.json +20 -20
  6. package/dist/cjs/assets/locale/messages_de.json +20 -20
  7. package/dist/cjs/assets/locale/messages_el.json +20 -20
  8. package/dist/cjs/assets/locale/messages_en.json +20 -20
  9. package/dist/cjs/assets/locale/messages_es.json +20 -20
  10. package/dist/cjs/assets/locale/messages_fi.json +20 -20
  11. package/dist/cjs/assets/locale/messages_fr.json +20 -20
  12. package/dist/cjs/assets/locale/messages_he.json +20 -20
  13. package/dist/cjs/assets/locale/messages_hi.json +20 -20
  14. package/dist/cjs/assets/locale/messages_hu.json +20 -20
  15. package/dist/cjs/assets/locale/messages_id.json +20 -20
  16. package/dist/cjs/assets/locale/messages_it.json +20 -20
  17. package/dist/cjs/assets/locale/messages_ja.json +20 -20
  18. package/dist/cjs/assets/locale/messages_ko.json +20 -20
  19. package/dist/cjs/assets/locale/messages_lt.json +20 -20
  20. package/dist/cjs/assets/locale/messages_ms.json +20 -20
  21. package/dist/cjs/assets/locale/messages_nl.json +20 -20
  22. package/dist/cjs/assets/locale/messages_no.json +20 -20
  23. package/dist/cjs/assets/locale/messages_pl.json +20 -20
  24. package/dist/cjs/assets/locale/messages_pt.json +20 -20
  25. package/dist/cjs/assets/locale/messages_ro.json +20 -20
  26. package/dist/cjs/assets/locale/messages_ru.json +20 -20
  27. package/dist/cjs/assets/locale/messages_sk.json +20 -20
  28. package/dist/cjs/assets/locale/messages_sl.json +20 -20
  29. package/dist/cjs/assets/locale/messages_sv.json +20 -20
  30. package/dist/cjs/assets/locale/messages_th.json +20 -20
  31. package/dist/cjs/assets/locale/messages_tl.json +20 -20
  32. package/dist/cjs/assets/locale/messages_tr.json +20 -20
  33. package/dist/cjs/assets/locale/messages_uk.json +20 -20
  34. package/dist/cjs/assets/locale/messages_vi.json +20 -20
  35. package/dist/cjs/assets/locale/messages_zh.json +20 -20
  36. package/dist/cjs/assets/locale/version_file +1 -1
  37. package/dist/cjs/assets/visual-e2e-locale/messages_visuale2e.json +19 -19
  38. package/dist/cjs/hooks/useImport.js +5 -2
  39. package/dist/cjs/hooks/useImport.js.map +1 -1
  40. package/dist/cjs/state/ImportState/ImportState.js +120 -17
  41. package/dist/cjs/state/ImportState/ImportState.js.map +1 -1
  42. package/dist/cjs/state/ImportState/ImportStateBIReporter.js +279 -0
  43. package/dist/cjs/state/ImportState/ImportStateBIReporter.js.map +1 -0
  44. package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js +270 -14
  45. package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
  46. package/dist/esm/assets/locale/messages_ar.json +20 -20
  47. package/dist/esm/assets/locale/messages_bg.json +20 -20
  48. package/dist/esm/assets/locale/messages_ca.json +20 -20
  49. package/dist/esm/assets/locale/messages_cs.json +20 -20
  50. package/dist/esm/assets/locale/messages_da.json +20 -20
  51. package/dist/esm/assets/locale/messages_de.json +20 -20
  52. package/dist/esm/assets/locale/messages_el.json +20 -20
  53. package/dist/esm/assets/locale/messages_en.json +20 -20
  54. package/dist/esm/assets/locale/messages_es.json +20 -20
  55. package/dist/esm/assets/locale/messages_fi.json +20 -20
  56. package/dist/esm/assets/locale/messages_fr.json +20 -20
  57. package/dist/esm/assets/locale/messages_he.json +20 -20
  58. package/dist/esm/assets/locale/messages_hi.json +20 -20
  59. package/dist/esm/assets/locale/messages_hu.json +20 -20
  60. package/dist/esm/assets/locale/messages_id.json +20 -20
  61. package/dist/esm/assets/locale/messages_it.json +20 -20
  62. package/dist/esm/assets/locale/messages_ja.json +20 -20
  63. package/dist/esm/assets/locale/messages_ko.json +20 -20
  64. package/dist/esm/assets/locale/messages_lt.json +20 -20
  65. package/dist/esm/assets/locale/messages_ms.json +20 -20
  66. package/dist/esm/assets/locale/messages_nl.json +20 -20
  67. package/dist/esm/assets/locale/messages_no.json +20 -20
  68. package/dist/esm/assets/locale/messages_pl.json +20 -20
  69. package/dist/esm/assets/locale/messages_pt.json +20 -20
  70. package/dist/esm/assets/locale/messages_ro.json +20 -20
  71. package/dist/esm/assets/locale/messages_ru.json +20 -20
  72. package/dist/esm/assets/locale/messages_sk.json +20 -20
  73. package/dist/esm/assets/locale/messages_sl.json +20 -20
  74. package/dist/esm/assets/locale/messages_sv.json +20 -20
  75. package/dist/esm/assets/locale/messages_th.json +20 -20
  76. package/dist/esm/assets/locale/messages_tl.json +20 -20
  77. package/dist/esm/assets/locale/messages_tr.json +20 -20
  78. package/dist/esm/assets/locale/messages_uk.json +20 -20
  79. package/dist/esm/assets/locale/messages_vi.json +20 -20
  80. package/dist/esm/assets/locale/messages_zh.json +20 -20
  81. package/dist/esm/assets/locale/version_file +1 -1
  82. package/dist/esm/assets/visual-e2e-locale/messages_visuale2e.json +19 -19
  83. package/dist/esm/hooks/useImport.js +4 -2
  84. package/dist/esm/hooks/useImport.js.map +1 -1
  85. package/dist/esm/state/ImportState/ImportState.js +113 -19
  86. package/dist/esm/state/ImportState/ImportState.js.map +1 -1
  87. package/dist/esm/state/ImportState/ImportStateBIReporter.js +232 -0
  88. package/dist/esm/state/ImportState/ImportStateBIReporter.js.map +1 -0
  89. package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js +199 -8
  90. package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
  91. package/dist/types/hooks/useImport.d.ts +3 -0
  92. package/dist/types/hooks/useImport.d.ts.map +1 -1
  93. package/dist/types/state/ImportState/ImportState.d.ts +13 -3
  94. package/dist/types/state/ImportState/ImportState.d.ts.map +1 -1
  95. package/dist/types/state/ImportState/ImportStateBIReporter.d.ts +66 -0
  96. package/dist/types/state/ImportState/ImportStateBIReporter.d.ts.map +1 -0
  97. package/package.json +8 -5
@@ -16,6 +16,7 @@ var _importJobPoller = require("./importJobPoller");
16
16
  var _detectFieldType = require("./detectFieldType");
17
17
  var _fieldEdit = require("./fieldEdit");
18
18
  var _newFieldDraft = require("./newFieldDraft");
19
+ var _ImportStateBIReporter = require("./ImportStateBIReporter");
19
20
  /** Outcome of a server-side import job, derived from the job's progress. */
20
21
 
21
22
  /** A rejected row: its index into `csvRows` and the server's failure reason. */
@@ -257,6 +258,11 @@ exports.buildImportConfig = buildImportConfig;
257
258
  // so the bar sits at 0 for the whole import and would otherwise flip straight to
258
259
  // the summary without the user ever seeing it reach completion.
259
260
  const COMPLETION_LINGER_MS = 600;
261
+ const FILE_ERROR_MESSAGE_KEY = {
262
+ encoding_failed: 'cairo.import.encodingFailed',
263
+ process_failed: 'cairo.import.processFailed'
264
+ };
265
+ const NOOP_REPORT_BI = () => {};
260
266
 
261
267
  // The Wix Data collection's id field key. A CSV column mapped to this field lets
262
268
  // the user choose how rows that collide on `_id` are written (writePolicy).
@@ -307,6 +313,8 @@ class ImportState {
307
313
  (0, _defineProperty2.default)(this, "errorHandler", void 0);
308
314
  (0, _defineProperty2.default)(this, "showToast", void 0);
309
315
  (0, _defineProperty2.default)(this, "downloadCsv", void 0);
316
+ (0, _defineProperty2.default)(this, "reportBi", void 0);
317
+ (0, _defineProperty2.default)(this, "bi", void 0);
310
318
  (0, _defineProperty2.default)(this, "hubJobClient", void 0);
311
319
  (0, _defineProperty2.default)(this, "_detectColumnType", void 0);
312
320
  (0, _defineProperty2.default)(this, "discardChangesModal", new _ConditionalModalState.ConditionalModalState());
@@ -344,6 +352,8 @@ class ImportState {
344
352
  });
345
353
  (0, _defineProperty2.default)(this, "isBackingUp", false);
346
354
  (0, _defineProperty2.default)(this, "isRestoring", false);
355
+ (0, _defineProperty2.default)(this, "attempt", 0);
356
+ (0, _defineProperty2.default)(this, "importStartTime", 0);
347
357
  (0, _defineProperty2.default)(this, "restoreFn", null);
348
358
  (0, _defineProperty2.default)(this, "_cancelled", false);
349
359
  (0, _defineProperty2.default)(this, "_abortController", null);
@@ -369,6 +379,8 @@ class ImportState {
369
379
  this.errorHandler = props.errorHandler;
370
380
  this.showToast = props.showToast;
371
381
  this.downloadCsv = props.downloadCsv;
382
+ this.reportBi = props.reportBi ?? NOOP_REPORT_BI;
383
+ this.bi = new _ImportStateBIReporter.ImportStateBIReporter(this);
372
384
  this._detectColumnType = props.detectColumnType ?? _detectFieldType.detectColumnType;
373
385
  this.hubJobClient = (0, _hubJobClient.createHubJobClient)({
374
386
  httpClient: props.httpClient,
@@ -395,6 +407,7 @@ class ImportState {
395
407
  missingRequiredFields: _mobx.computed,
396
408
  hasMissingRequiredFields: _mobx.computed,
397
409
  idMappedHeader: _mobx.computed,
410
+ hasDuplicateIdsInFile: _mobx.computed,
398
411
  editingHeader: _mobx.observable.ref,
399
412
  editingMapping: _mobx.computed,
400
413
  endFieldEdit: _mobx.action.bound,
@@ -413,6 +426,7 @@ class ImportState {
413
426
  downloadFailedRows: _mobx.action.bound,
414
427
  onFileSelected: _mobx.action.bound,
415
428
  startImport: _mobx.action.bound,
429
+ retryImport: _mobx.action.bound,
416
430
  reset: _mobx.action.bound
417
431
  });
418
432
  }
@@ -473,7 +487,16 @@ class ImportState {
473
487
  return this.config.idFieldKey ?? ID_FIELD_KEY;
474
488
  }
475
489
  init() {
490
+ // This state mounts after `open` fired and unmounts on close, so each mount
491
+ // is one BI flow.
492
+ if (this.importModalState.isOpen) {
493
+ this.bi.onModalOpened();
494
+ }
495
+ const disposers = [(0, _mobx.reaction)(() => this.currentStep === 'configuration' && this.hasNoMappedData, shown => shown && this.bi.onMappingWarningShown('no_rows')), (0, _mobx.reaction)(() => this.currentStep === 'configuration' && this.hasMissingRequiredFields, shown => shown && this.bi.onMappingWarningShown('required_field_unmapped')), (0, _mobx.reaction)(() => this.currentStep === 'configuration' && this.canConfigureWritePolicy && this.idMappedHeader != null, shown => shown && this.bi.onDuplicateIdPolicyShown(), {
496
+ fireImmediately: true
497
+ })];
476
498
  return () => {
499
+ disposers.forEach(dispose => dispose());
477
500
  // Unmounting mid-import stops the poll loop (it checks `_cancelled`) so it
478
501
  // doesn't run to terminal holding references. We deliberately do NOT abort
479
502
  // the AbortController: during a cancel-triggered restore it holds the
@@ -545,8 +568,26 @@ class ImportState {
545
568
  const entry = Object.entries(this.mappingByHeader).find(([, mapping]) => (mapping == null ? void 0 : mapping.kind) === 'existing' && mapping.fieldId === idFieldKey);
546
569
  return entry ? entry[0] : null;
547
570
  }
571
+ get hasDuplicateIdsInFile() {
572
+ const header = this.idMappedHeader;
573
+ const index = header == null ? -1 : this.csvHeaders.indexOf(header);
574
+ if (index < 0) {
575
+ return false;
576
+ }
577
+ const seen = new Set();
578
+ return this.csvRows.some(row => {
579
+ const value = (row[index] ?? '').trim();
580
+ if (value === '' || !seen.has(value)) {
581
+ seen.add(value);
582
+ return false;
583
+ }
584
+ return true;
585
+ });
586
+ }
548
587
  setWritePolicy(policy) {
588
+ const prev = this.writePolicy;
549
589
  this.writePolicy = policy;
590
+ this.bi.onDuplicateIdPolicyChanged(prev, policy);
550
591
  }
551
592
 
552
593
  /**
@@ -601,14 +642,34 @@ class ImportState {
601
642
  this.restoreFn = null;
602
643
  this._cancelled = false;
603
644
  this._jobId = null;
645
+ this.attempt = 0;
604
646
  }
605
- async close() {
647
+
648
+ // The configuration step closes through `discardAndClose`, which reports it.
649
+ async close(origin = 'X Button') {
650
+ const {
651
+ bi,
652
+ currentStep,
653
+ importStatus
654
+ } = this;
655
+ const isCancellingImport = currentStep === 'progress' && !importStatus.isSuccess;
656
+ if (currentStep === 'upload') {
657
+ bi.onModalDismissed(origin, 'upload');
658
+ } else if (currentStep === 'summary') {
659
+ bi.onSummaryCtaClicked(origin === 'Cancel Button' ? 'Close' : 'X Button');
660
+ } else if (isCancellingImport && importStatus.isError) {
661
+ bi.onFailedModalCtaClicked(origin === 'Cancel Button' ? 'Cancel' : 'X Button');
662
+ } else if (isCancellingImport) {
663
+ bi.onCancelAttempt(origin);
664
+ bi.onProcessEnd('stopped by user');
665
+ }
666
+
606
667
  // While on the progress step we treat close as a cancel — terminate the job
607
668
  // and restore the backup — UNLESS the import already succeeded. On success
608
669
  // `startImport` moves straight to the 'summary' step, so a close from there
609
670
  // just closes the modal (the summary's own `done` is the normal exit); this
610
671
  // guard covers only closing mid-import.
611
- if (this.currentStep === 'progress' && !this.importStatus.isSuccess) {
672
+ if (isCancellingImport) {
612
673
  var _this$_abortControlle2;
613
674
  this._cancelled = true;
614
675
  (_this$_abortControlle2 = this._abortController) == null || _this$_abortControlle2.abort();
@@ -636,7 +697,8 @@ class ImportState {
636
697
  * Closes the summary step at the end of a completed import. The collection was
637
698
  * already refreshed when the summary opened, so this only dismisses the modal.
638
699
  */
639
- done() {
700
+ done(origin = 'Close') {
701
+ this.bi.onSummaryCtaClicked(origin);
640
702
  this.importModalState.close();
641
703
  }
642
704
  async _restoreBackup() {
@@ -665,17 +727,20 @@ class ImportState {
665
727
  const {
666
728
  result
667
729
  } = await this.discardChangesModal.modal.promise();
730
+ this.bi.onDiscardModalClosed(result);
668
731
  if (result === 'confirmed') {
669
732
  this.goToUpload();
670
733
  }
671
734
  }
672
- async discardAndClose() {
735
+ async discardAndClose(origin = 'X Button') {
736
+ this.bi.onModalDismissed(origin, 'configuration');
673
737
  this.discardChangesModal.open('close');
674
738
  const {
675
739
  result
676
740
  } = await this.discardChangesModal.modal.promise();
741
+ this.bi.onDiscardModalClosed(result);
677
742
  if (result === 'confirmed') {
678
- this.close();
743
+ this.close(origin);
679
744
  }
680
745
  }
681
746
  onUploadContinue() {
@@ -751,16 +816,18 @@ class ImportState {
751
816
  }
752
817
  const content = this._decodeUtf8(bytes);
753
818
  if (content == null) {
754
- this._rejectFile(file, 'cairo.import.encodingFailed');
819
+ this._rejectFile(file, 'encoding_failed');
755
820
  return;
756
821
  }
757
822
  const parsedCsv = (0, _parseCsv.parseCsv)(content);
758
823
  if ('code' in parsedCsv) {
759
- this._rejectFile(file, 'cairo.import.processFailed');
824
+ this._rejectFile(file, 'process_failed');
760
825
  return;
761
826
  }
762
827
  (0, _mobx.runInAction)(() => {
763
828
  this.applyParsedCsv(file.name, parsedCsv);
829
+ // Inside the action, so 144:28 goes out before the reactions it triggers.
830
+ this.bi.onFileSelected();
764
831
  });
765
832
  }
766
833
  async _readFileBytes(file) {
@@ -784,7 +851,7 @@ class ImportState {
784
851
  return null;
785
852
  }
786
853
  }
787
- _rejectFile(file, messageKey) {
854
+ _rejectFile(file, errorType) {
788
855
  var _this$showToast;
789
856
  (0, _mobx.runInAction)(() => {
790
857
  this.fileName = file.name;
@@ -796,11 +863,13 @@ class ImportState {
796
863
  });
797
864
  (_this$showToast = this.showToast) == null || _this$showToast.call(this, {
798
865
  type: 'ERROR',
799
- message: this.translate(messageKey)
866
+ message: this.translate(FILE_ERROR_MESSAGE_KEY[errorType])
800
867
  });
868
+ this.bi.onFileErrorDisplayed(errorType, file.name);
801
869
  }
802
870
  _showFileReadErrorToast(file) {
803
871
  var _this$showToast2;
872
+ this.bi.onFileErrorDisplayed('file_read_failed', file.name);
804
873
  (_this$showToast2 = this.showToast) == null || _this$showToast2.call(this, {
805
874
  type: 'ERROR',
806
875
  message: this.translate('cairo.import.fileReadFailed'),
@@ -821,6 +890,7 @@ class ImportState {
821
890
  */
822
891
  async downloadFailedRows() {
823
892
  var _this$downloadCsv;
893
+ this.bi.onSummaryCtaClicked('Download failed items CSV');
824
894
  const jobId = this._jobId;
825
895
  if (!jobId) {
826
896
  return;
@@ -887,24 +957,30 @@ class ImportState {
887
957
  return failures;
888
958
  }
889
959
  setMapping(header, fieldId) {
960
+ const prev = this.mappingByHeader[header] ?? null;
961
+ const next = fieldId == null ? null : {
962
+ kind: 'existing',
963
+ fieldId
964
+ };
890
965
  this.mappingByHeader = {
891
966
  ...this.mappingByHeader,
892
- [header]: fieldId == null ? null : {
893
- kind: 'existing',
894
- fieldId
895
- }
967
+ [header]: next
896
968
  };
969
+ this.bi.onMappingChanged(header, prev, next);
897
970
  }
898
971
  setNewFieldMapping(header) {
899
972
  const index = this.csvHeaders.indexOf(header);
900
973
  const fieldType = index >= 0 ? this._detectColumnType(this._columnValues(index)) : 'text';
974
+ const prev = this.mappingByHeader[header] ?? null;
975
+ const next = {
976
+ kind: 'new',
977
+ fieldType
978
+ };
901
979
  this.mappingByHeader = {
902
980
  ...this.mappingByHeader,
903
- [header]: {
904
- kind: 'new',
905
- fieldType
906
- }
981
+ [header]: next
907
982
  };
983
+ this.bi.onMappingChanged(header, prev, next);
908
984
  }
909
985
 
910
986
  /**
@@ -1154,6 +1230,7 @@ class ImportState {
1154
1230
  error
1155
1231
  };
1156
1232
  });
1233
+ this.bi.onProcessEnd('fail');
1157
1234
  return true;
1158
1235
  }
1159
1236
  (0, _mobx.runInAction)(() => {
@@ -1312,6 +1389,13 @@ class ImportState {
1312
1389
  (_this$config$onItemsL = (_this$config2 = this.config).onItemsLimitExceeded) == null || _this$config$onItemsL.call(_this$config2);
1313
1390
  return;
1314
1391
  }
1392
+
1393
+ // Retries come through `retryImport`, which reports its own CTA.
1394
+ this.attempt += 1;
1395
+ this.importStartTime = performance.now();
1396
+ if (this.attempt === 1) {
1397
+ this.bi.onImportConfirmed();
1398
+ }
1315
1399
  this._cancelled = false;
1316
1400
  this._abortController = new AbortController();
1317
1401
 
@@ -1336,6 +1420,9 @@ class ImportState {
1336
1420
  };
1337
1421
  this._jobId = null;
1338
1422
  });
1423
+ if (this.backup) {
1424
+ this.bi.onProcessStart('backup');
1425
+ }
1339
1426
  const backupFailed = await this._runBackup();
1340
1427
  if (backupFailed) {
1341
1428
  return;
@@ -1344,6 +1431,9 @@ class ImportState {
1344
1431
  return;
1345
1432
  }
1346
1433
 
1434
+ // Before field creation, so a creation failure's process end has a start.
1435
+ this.bi.onProcessStart('import');
1436
+
1347
1437
  // Create any new fields and resolve every column to its destination key
1348
1438
  // before uploading. A creation failure surfaces as the error state with a
1349
1439
  // "Try again" CTA, like an upload/job failure.
@@ -1357,6 +1447,10 @@ class ImportState {
1357
1447
  error
1358
1448
  };
1359
1449
  });
1450
+ // A cancelled import already reported its end as "stopped by user".
1451
+ if (!this._cancelled) {
1452
+ this.bi.onProcessEnd('fail');
1453
+ }
1360
1454
  return;
1361
1455
  }
1362
1456
  if (this._cancelled) {
@@ -1390,6 +1484,7 @@ class ImportState {
1390
1484
  this.processedCount = this.totalCount;
1391
1485
  });
1392
1486
  this._notifyImportCompleted();
1487
+ this.bi.onProcessEnd(this.result.failed > 0 ? 'partial' : 'success');
1393
1488
 
1394
1489
  // Keep the completed bar on screen briefly before moving on. `importStatus`
1395
1490
  // is already success, so a close during this window just dismisses the
@@ -1412,6 +1507,7 @@ class ImportState {
1412
1507
  force: true
1413
1508
  });
1414
1509
  });
1510
+ this.bi.onSummaryDisplayed();
1415
1511
  } catch (error) {
1416
1512
  (0, _mobx.runInAction)(() => {
1417
1513
  this.importStatus = {
@@ -1419,6 +1515,9 @@ class ImportState {
1419
1515
  error
1420
1516
  };
1421
1517
  });
1518
+ if (!this._cancelled) {
1519
+ this.bi.onProcessEnd('fail');
1520
+ }
1422
1521
  }
1423
1522
 
1424
1523
  // Merge the created fields into the table so the new columns appear with no
@@ -1436,6 +1535,10 @@ class ImportState {
1436
1535
  }
1437
1536
  }
1438
1537
  }
1538
+ retryImport() {
1539
+ this.bi.onFailedModalCtaClicked('Try Again');
1540
+ return this.startImport();
1541
+ }
1439
1542
  }
1440
1543
  exports.ImportState = ImportState;
1441
1544
  //# sourceMappingURL=ImportState.js.map