@wix/bex-core 2.398.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.
- package/dist/cjs/assets/locale/messages_ar.json +20 -20
- package/dist/cjs/assets/locale/messages_bg.json +20 -20
- package/dist/cjs/assets/locale/messages_ca.json +20 -20
- package/dist/cjs/assets/locale/messages_cs.json +20 -20
- package/dist/cjs/assets/locale/messages_da.json +20 -20
- package/dist/cjs/assets/locale/messages_de.json +20 -20
- package/dist/cjs/assets/locale/messages_el.json +20 -20
- package/dist/cjs/assets/locale/messages_en.json +20 -20
- package/dist/cjs/assets/locale/messages_es.json +20 -20
- package/dist/cjs/assets/locale/messages_fi.json +20 -20
- package/dist/cjs/assets/locale/messages_fr.json +20 -20
- package/dist/cjs/assets/locale/messages_he.json +20 -20
- package/dist/cjs/assets/locale/messages_hi.json +20 -20
- package/dist/cjs/assets/locale/messages_hu.json +20 -20
- package/dist/cjs/assets/locale/messages_id.json +20 -20
- package/dist/cjs/assets/locale/messages_it.json +20 -20
- package/dist/cjs/assets/locale/messages_ja.json +20 -20
- package/dist/cjs/assets/locale/messages_ko.json +20 -20
- package/dist/cjs/assets/locale/messages_lt.json +20 -20
- package/dist/cjs/assets/locale/messages_ms.json +20 -20
- package/dist/cjs/assets/locale/messages_nl.json +20 -20
- package/dist/cjs/assets/locale/messages_no.json +20 -20
- package/dist/cjs/assets/locale/messages_pl.json +20 -20
- package/dist/cjs/assets/locale/messages_pt.json +20 -20
- package/dist/cjs/assets/locale/messages_ro.json +20 -20
- package/dist/cjs/assets/locale/messages_ru.json +20 -20
- package/dist/cjs/assets/locale/messages_sk.json +20 -20
- package/dist/cjs/assets/locale/messages_sl.json +20 -20
- package/dist/cjs/assets/locale/messages_sv.json +20 -20
- package/dist/cjs/assets/locale/messages_th.json +20 -20
- package/dist/cjs/assets/locale/messages_tl.json +20 -20
- package/dist/cjs/assets/locale/messages_tr.json +20 -20
- package/dist/cjs/assets/locale/messages_uk.json +20 -20
- package/dist/cjs/assets/locale/messages_vi.json +20 -20
- package/dist/cjs/assets/locale/messages_zh.json +20 -20
- package/dist/cjs/assets/locale/version_file +1 -1
- package/dist/cjs/assets/visual-e2e-locale/messages_visuale2e.json +20 -19
- package/dist/cjs/hooks/useImport.js +5 -2
- package/dist/cjs/hooks/useImport.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportState.js +120 -17
- package/dist/cjs/state/ImportState/ImportState.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportStateBIReporter.js +279 -0
- package/dist/cjs/state/ImportState/ImportStateBIReporter.js.map +1 -0
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js +270 -14
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/esm/assets/locale/messages_ar.json +20 -20
- package/dist/esm/assets/locale/messages_bg.json +20 -20
- package/dist/esm/assets/locale/messages_ca.json +20 -20
- package/dist/esm/assets/locale/messages_cs.json +20 -20
- package/dist/esm/assets/locale/messages_da.json +20 -20
- package/dist/esm/assets/locale/messages_de.json +20 -20
- package/dist/esm/assets/locale/messages_el.json +20 -20
- package/dist/esm/assets/locale/messages_en.json +20 -20
- package/dist/esm/assets/locale/messages_es.json +20 -20
- package/dist/esm/assets/locale/messages_fi.json +20 -20
- package/dist/esm/assets/locale/messages_fr.json +20 -20
- package/dist/esm/assets/locale/messages_he.json +20 -20
- package/dist/esm/assets/locale/messages_hi.json +20 -20
- package/dist/esm/assets/locale/messages_hu.json +20 -20
- package/dist/esm/assets/locale/messages_id.json +20 -20
- package/dist/esm/assets/locale/messages_it.json +20 -20
- package/dist/esm/assets/locale/messages_ja.json +20 -20
- package/dist/esm/assets/locale/messages_ko.json +20 -20
- package/dist/esm/assets/locale/messages_lt.json +20 -20
- package/dist/esm/assets/locale/messages_ms.json +20 -20
- package/dist/esm/assets/locale/messages_nl.json +20 -20
- package/dist/esm/assets/locale/messages_no.json +20 -20
- package/dist/esm/assets/locale/messages_pl.json +20 -20
- package/dist/esm/assets/locale/messages_pt.json +20 -20
- package/dist/esm/assets/locale/messages_ro.json +20 -20
- package/dist/esm/assets/locale/messages_ru.json +20 -20
- package/dist/esm/assets/locale/messages_sk.json +20 -20
- package/dist/esm/assets/locale/messages_sl.json +20 -20
- package/dist/esm/assets/locale/messages_sv.json +20 -20
- package/dist/esm/assets/locale/messages_th.json +20 -20
- package/dist/esm/assets/locale/messages_tl.json +20 -20
- package/dist/esm/assets/locale/messages_tr.json +20 -20
- package/dist/esm/assets/locale/messages_uk.json +20 -20
- package/dist/esm/assets/locale/messages_vi.json +20 -20
- package/dist/esm/assets/locale/messages_zh.json +20 -20
- package/dist/esm/assets/locale/version_file +1 -1
- package/dist/esm/assets/visual-e2e-locale/messages_visuale2e.json +20 -19
- package/dist/esm/hooks/useImport.js +4 -2
- package/dist/esm/hooks/useImport.js.map +1 -1
- package/dist/esm/state/ImportState/ImportState.js +113 -19
- package/dist/esm/state/ImportState/ImportState.js.map +1 -1
- package/dist/esm/state/ImportState/ImportStateBIReporter.js +232 -0
- package/dist/esm/state/ImportState/ImportStateBIReporter.js.map +1 -0
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js +199 -8
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/types/hooks/useImport.d.ts +3 -0
- package/dist/types/hooks/useImport.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportState.d.ts +13 -3
- package/dist/types/state/ImportState/ImportState.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportStateBIReporter.d.ts +66 -0
- package/dist/types/state/ImportState/ImportStateBIReporter.d.ts.map +1 -0
- package/package.json +8 -5
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.ImportStateBIReporter = void 0;
|
|
6
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
|
+
var _uuid = require("uuid");
|
|
8
|
+
var _types = require("@wix/bex-utils/@wix/ambassador-hub-v1-job/types");
|
|
9
|
+
var _v = require("@wix/bex-utils/@wix/bi-logger-os-data/v2");
|
|
10
|
+
/** Which control dismissed the import modal (or one of its steps). */
|
|
11
|
+
|
|
12
|
+
/** The summary step's close controls. */
|
|
13
|
+
|
|
14
|
+
const WRITE_POLICY_TO_BI = {
|
|
15
|
+
[_types.WritePolicy.OVERWRITE]: 'update_existing',
|
|
16
|
+
[_types.WritePolicy.SKIP_EXISTING]: 'skip_imported'
|
|
17
|
+
};
|
|
18
|
+
const mappingType = mapping => mapping == null ? 'skip' : mapping.kind;
|
|
19
|
+
const isSameMapping = (a, b) => a == null || b == null ? a === b : a.kind === 'existing' ? b.kind === 'existing' && a.fieldId === b.fieldId : b.kind === 'new' && a.fieldType === b.fieldType;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reports the import funnel (src 144, evids 27–44). Every event carries the
|
|
23
|
+
* same `importId`, regenerated each time the modal opens, so one flow's events
|
|
24
|
+
* can be joined. Standard Cairo context (artifact, csid, version, fqdn…) is
|
|
25
|
+
* attached by the container's `reportBi`; `filteredListSize` and the other
|
|
26
|
+
* collection params come from the toolbar's wrapper, as for export.
|
|
27
|
+
*/
|
|
28
|
+
class ImportStateBIReporter {
|
|
29
|
+
constructor(state) {
|
|
30
|
+
(0, _defineProperty2.default)(this, "state", void 0);
|
|
31
|
+
(0, _defineProperty2.default)(this, "importId", (0, _uuid.v4)());
|
|
32
|
+
// 144:43 fires once per flow, the first time the policy control shows.
|
|
33
|
+
(0, _defineProperty2.default)(this, "duplicateIdPolicyReported", false);
|
|
34
|
+
this.state = state;
|
|
35
|
+
}
|
|
36
|
+
report(log) {
|
|
37
|
+
this.state.reportBi({
|
|
38
|
+
...log,
|
|
39
|
+
params: {
|
|
40
|
+
...log.params,
|
|
41
|
+
importId: this.importId
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
get duplicateIdPolicy() {
|
|
46
|
+
const {
|
|
47
|
+
state
|
|
48
|
+
} = this;
|
|
49
|
+
return state.canConfigureWritePolicy && state.idMappedHeader != null ? WRITE_POLICY_TO_BI[state.writePolicy] : undefined;
|
|
50
|
+
}
|
|
51
|
+
get mappingCounts() {
|
|
52
|
+
const mappings = Object.values(this.state.mappingByHeader);
|
|
53
|
+
return {
|
|
54
|
+
numMappedColumns: mappings.filter(m => m != null).length,
|
|
55
|
+
numNewFields: mappings.filter(m => (m == null ? void 0 : m.kind) === 'new').length
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
get durationSinceStart() {
|
|
59
|
+
return Math.round(performance.now() - this.state.importStartTime);
|
|
60
|
+
}
|
|
61
|
+
get summaryResult() {
|
|
62
|
+
return this.state.result.failed > 0 ? 'partial' : 'success';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 144:27 — the modal opened; starts a new flow (new `importId`). */
|
|
66
|
+
onModalOpened() {
|
|
67
|
+
this.importId = (0, _uuid.v4)();
|
|
68
|
+
this.duplicateIdPolicyReported = false;
|
|
69
|
+
this.report((0, _v.wixPatternsImportCtaClickedSrc144Evid27)({}));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 144:28 */
|
|
73
|
+
onFileSelected() {
|
|
74
|
+
const {
|
|
75
|
+
fileName,
|
|
76
|
+
csvHeaders,
|
|
77
|
+
csvRows
|
|
78
|
+
} = this.state;
|
|
79
|
+
this.report((0, _v.wixPatternsImportFileSelectedSrc144Evid28)({
|
|
80
|
+
fileName,
|
|
81
|
+
numColumns: csvHeaders.length,
|
|
82
|
+
numRows: csvRows.length,
|
|
83
|
+
step: 'upload'
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 144:42 */
|
|
88
|
+
onFileErrorDisplayed(errorType, fileName) {
|
|
89
|
+
this.report((0, _v.wixPatternsImportFileErrorDisplayedSrc144Evid42)({
|
|
90
|
+
errorType,
|
|
91
|
+
fileName
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 144:29 — Cancel / X on the upload or configuration step. */
|
|
96
|
+
onModalDismissed(origin, step) {
|
|
97
|
+
this.report((0, _v.wixPatternsImportModalCtaClickedSrc144Evid29)({
|
|
98
|
+
action: 'dismiss',
|
|
99
|
+
origin,
|
|
100
|
+
ctaName: origin === 'Cancel Button' ? 'Cancel' : 'X Button',
|
|
101
|
+
step,
|
|
102
|
+
...(step === 'configuration' && {
|
|
103
|
+
...this.mappingCounts,
|
|
104
|
+
canCreateNewField: this.state.canCreateNewField,
|
|
105
|
+
duplicateIdPolicy: this.duplicateIdPolicy
|
|
106
|
+
})
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 144:29 — the "Learn more" link on the upload step. */
|
|
111
|
+
onLearnMoreClicked() {
|
|
112
|
+
this.report((0, _v.wixPatternsImportModalCtaClickedSrc144Evid29)({
|
|
113
|
+
action: 'dismiss',
|
|
114
|
+
origin: 'Learn More',
|
|
115
|
+
ctaName: 'Learn More',
|
|
116
|
+
step: 'upload'
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 144:29 — "Edit field" under a new-field mapping. */
|
|
121
|
+
onEditFieldClicked() {
|
|
122
|
+
this.report((0, _v.wixPatternsImportModalCtaClickedSrc144Evid29)({
|
|
123
|
+
action: 'dismiss',
|
|
124
|
+
origin: 'Edit Field',
|
|
125
|
+
ctaName: 'Edit Field',
|
|
126
|
+
step: 'configuration',
|
|
127
|
+
canCreateNewField: this.state.canCreateNewField
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 144:29 — the Import button on the configuration step. */
|
|
132
|
+
onImportConfirmed() {
|
|
133
|
+
this.report((0, _v.wixPatternsImportModalCtaClickedSrc144Evid29)({
|
|
134
|
+
action: 'import',
|
|
135
|
+
origin: 'Import Button',
|
|
136
|
+
ctaName: 'Import',
|
|
137
|
+
step: 'configuration',
|
|
138
|
+
...this.mappingCounts,
|
|
139
|
+
canCreateNewField: this.state.canCreateNewField,
|
|
140
|
+
duplicateIdPolicy: this.duplicateIdPolicy
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 144:33 — only when the mapping actually changed. */
|
|
145
|
+
onMappingChanged(header, prev, next) {
|
|
146
|
+
if (isSameMapping(prev, next)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.report((0, _v.wixPatternsImportColumnMappingChangedSrc144Evid33)({
|
|
150
|
+
columnName: header,
|
|
151
|
+
prevMappingType: mappingType(prev),
|
|
152
|
+
newMappingType: mappingType(next),
|
|
153
|
+
...((next == null ? void 0 : next.kind) === 'existing' && {
|
|
154
|
+
fieldId: next.fieldId
|
|
155
|
+
}),
|
|
156
|
+
...((next == null ? void 0 : next.kind) === 'new' && {
|
|
157
|
+
fieldType: next.fieldType
|
|
158
|
+
}),
|
|
159
|
+
canCreateNewField: this.state.canCreateNewField
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 144:34 — maps the discard modal's close result to the CTA the user hit. */
|
|
164
|
+
onDiscardModalClosed(result) {
|
|
165
|
+
this.report((0, _v.wixPatternsImportDiscardModalCtaClickedSrc144Evid34)({
|
|
166
|
+
ctaName: result === 'confirmed' ? 'Discard' : result === 'declined' ? 'Keep editing' : 'X Button'
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 144:41 */
|
|
171
|
+
onMappingWarningShown(warningType) {
|
|
172
|
+
this.report((0, _v.wixPatternsImportMappingWarningShownSrc144Evid41)({
|
|
173
|
+
warningType
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 144:43 — once per flow. */
|
|
178
|
+
onDuplicateIdPolicyShown() {
|
|
179
|
+
const policy = this.duplicateIdPolicy;
|
|
180
|
+
if (this.duplicateIdPolicyReported || policy == null) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.duplicateIdPolicyReported = true;
|
|
184
|
+
this.report((0, _v.wixPatternsImportDuplicateIdPolicyShownSrc144Evid43)({
|
|
185
|
+
duplicateIdPolicy: policy,
|
|
186
|
+
hasDuplicateIdsInFile: this.state.hasDuplicateIdsInFile
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** 144:44 — only when the policy actually changed. */
|
|
191
|
+
onDuplicateIdPolicyChanged(prev, next) {
|
|
192
|
+
const prevPolicy = WRITE_POLICY_TO_BI[prev];
|
|
193
|
+
const nextPolicy = WRITE_POLICY_TO_BI[next];
|
|
194
|
+
if (prev === next || prevPolicy == null || nextPolicy == null) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.report((0, _v.wixPatternsImportDuplicateIdPolicyChangedSrc144Evid44)({
|
|
198
|
+
duplicateIdPolicy: nextPolicy,
|
|
199
|
+
prevDuplicateIdPolicy: prevPolicy,
|
|
200
|
+
hasDuplicateIdsInFile: this.state.hasDuplicateIdsInFile
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** 144:36 */
|
|
205
|
+
onProcessStart(phase) {
|
|
206
|
+
const {
|
|
207
|
+
state
|
|
208
|
+
} = this;
|
|
209
|
+
this.report((0, _v.wixPatternsImportProcessStartSrc144Evid36)({
|
|
210
|
+
phase,
|
|
211
|
+
try: state.attempt,
|
|
212
|
+
numRows: state.csvRows.length,
|
|
213
|
+
...this.mappingCounts,
|
|
214
|
+
duplicateIdPolicy: this.duplicateIdPolicy
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** 144:37 */
|
|
219
|
+
onProcessEnd(result) {
|
|
220
|
+
const {
|
|
221
|
+
state
|
|
222
|
+
} = this;
|
|
223
|
+
this.report((0, _v.wixPatternsImportProcessEndSrc144Evid37)({
|
|
224
|
+
result,
|
|
225
|
+
duration: this.durationSinceStart,
|
|
226
|
+
try: state.attempt,
|
|
227
|
+
fileName: state.fileName,
|
|
228
|
+
numItemsCreated: state.result.created,
|
|
229
|
+
numItemsUpdated: state.result.updated,
|
|
230
|
+
numItemsFailed: state.result.failed,
|
|
231
|
+
duplicateIdPolicy: this.duplicateIdPolicy
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 144:35 — Cancel / X while the import is running. */
|
|
236
|
+
onCancelAttempt(origin) {
|
|
237
|
+
const {
|
|
238
|
+
state
|
|
239
|
+
} = this;
|
|
240
|
+
this.report((0, _v.wixPatternsUserAttemptsToCancelImportSrc144Evid35)({
|
|
241
|
+
origin,
|
|
242
|
+
duration: this.durationSinceStart,
|
|
243
|
+
try: state.attempt,
|
|
244
|
+
numItemsProcessed: state.processedCount
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 144:38 */
|
|
249
|
+
onFailedModalCtaClicked(ctaName) {
|
|
250
|
+
this.report((0, _v.wixPatternsImportFailedModalCtaClickedSrc144Evid38)({
|
|
251
|
+
ctaName,
|
|
252
|
+
try: this.state.attempt
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** 144:39 */
|
|
257
|
+
onSummaryDisplayed() {
|
|
258
|
+
const {
|
|
259
|
+
result
|
|
260
|
+
} = this.state;
|
|
261
|
+
this.report((0, _v.wixPatternsImportSummaryDisplayedSrc144Evid39)({
|
|
262
|
+
result: this.summaryResult,
|
|
263
|
+
numItemsCreated: result.created,
|
|
264
|
+
numItemsUpdated: result.updated,
|
|
265
|
+
numItemsFailed: result.failed,
|
|
266
|
+
numItemsImported: result.succeeded
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 144:40 */
|
|
271
|
+
onSummaryCtaClicked(ctaName) {
|
|
272
|
+
this.report((0, _v.wixPatternsImportSummaryCtaClickedSrc144Evid40)({
|
|
273
|
+
ctaName,
|
|
274
|
+
result: this.summaryResult
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.ImportStateBIReporter = ImportStateBIReporter;
|
|
279
|
+
//# sourceMappingURL=ImportStateBIReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_uuid","require","_types","_v","WRITE_POLICY_TO_BI","WritePolicy","OVERWRITE","SKIP_EXISTING","mappingType","mapping","kind","isSameMapping","a","b","fieldId","fieldType","ImportStateBIReporter","constructor","state","_defineProperty2","default","uuid","report","log","reportBi","params","importId","duplicateIdPolicy","canConfigureWritePolicy","idMappedHeader","writePolicy","undefined","mappingCounts","mappings","Object","values","mappingByHeader","numMappedColumns","filter","m","length","numNewFields","durationSinceStart","Math","round","performance","now","importStartTime","summaryResult","result","failed","onModalOpened","duplicateIdPolicyReported","wixPatternsImportCtaClickedSrc144Evid27","onFileSelected","fileName","csvHeaders","csvRows","wixPatternsImportFileSelectedSrc144Evid28","numColumns","numRows","step","onFileErrorDisplayed","errorType","wixPatternsImportFileErrorDisplayedSrc144Evid42","onModalDismissed","origin","wixPatternsImportModalCtaClickedSrc144Evid29","action","ctaName","canCreateNewField","onLearnMoreClicked","onEditFieldClicked","onImportConfirmed","onMappingChanged","header","prev","next","wixPatternsImportColumnMappingChangedSrc144Evid33","columnName","prevMappingType","newMappingType","onDiscardModalClosed","wixPatternsImportDiscardModalCtaClickedSrc144Evid34","onMappingWarningShown","warningType","wixPatternsImportMappingWarningShownSrc144Evid41","onDuplicateIdPolicyShown","policy","wixPatternsImportDuplicateIdPolicyShownSrc144Evid43","hasDuplicateIdsInFile","onDuplicateIdPolicyChanged","prevPolicy","nextPolicy","wixPatternsImportDuplicateIdPolicyChangedSrc144Evid44","prevDuplicateIdPolicy","onProcessStart","phase","wixPatternsImportProcessStartSrc144Evid36","try","attempt","onProcessEnd","wixPatternsImportProcessEndSrc144Evid37","duration","numItemsCreated","created","numItemsUpdated","updated","numItemsFailed","onCancelAttempt","wixPatternsUserAttemptsToCancelImportSrc144Evid35","numItemsProcessed","processedCount","onFailedModalCtaClicked","wixPatternsImportFailedModalCtaClickedSrc144Evid38","onSummaryDisplayed","wixPatternsImportSummaryDisplayedSrc144Evid39","numItemsImported","succeeded","onSummaryCtaClicked","wixPatternsImportSummaryCtaClickedSrc144Evid40","exports"],"sources":["../../../../src/state/ImportState/ImportStateBIReporter.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid';\nimport { WritePolicy } from '@wix/bex-utils/@wix/ambassador-hub-v1-job/types';\nimport type { ReportProps } from '@wix/fe-essentials/bi';\nimport {\n wixPatternsImportColumnMappingChangedSrc144Evid33,\n wixPatternsImportCtaClickedSrc144Evid27,\n wixPatternsImportDiscardModalCtaClickedSrc144Evid34,\n wixPatternsImportDuplicateIdPolicyChangedSrc144Evid44,\n wixPatternsImportDuplicateIdPolicyShownSrc144Evid43,\n wixPatternsImportFailedModalCtaClickedSrc144Evid38,\n wixPatternsImportFileErrorDisplayedSrc144Evid42,\n wixPatternsImportFileSelectedSrc144Evid28,\n wixPatternsImportMappingWarningShownSrc144Evid41,\n wixPatternsImportModalCtaClickedSrc144Evid29,\n wixPatternsImportProcessEndSrc144Evid37,\n wixPatternsImportProcessStartSrc144Evid36,\n wixPatternsImportSummaryCtaClickedSrc144Evid40,\n wixPatternsImportSummaryDisplayedSrc144Evid39,\n wixPatternsUserAttemptsToCancelImportSrc144Evid35,\n} from '@wix/bex-utils/@wix/bi-logger-os-data/v2';\nimport type { ColumnMapping, ImportState } from './ImportState';\n\ntype ImportBiStep = 'upload' | 'configuration' | 'progress';\ntype ImportBiMappingType = 'existing' | 'new' | 'skip';\ntype ImportBiDuplicateIdPolicy = 'update_existing' | 'skip_imported';\ntype ImportBiProcessResult = 'success' | 'partial' | 'fail' | 'stopped by user';\ntype ImportBiSummaryResult = 'success' | 'partial';\ntype ImportBiWarningType = 'no_rows' | 'required_field_unmapped';\nexport type ImportBiFileErrorType =\n | 'file_read_failed'\n | 'encoding_failed'\n | 'process_failed';\n\n/** Which control dismissed the import modal (or one of its steps). */\nexport type ImportDismissOrigin = 'Cancel Button' | 'X Button';\n\n/** The summary step's close controls. */\nexport type ImportSummaryCloseOrigin = 'Close' | 'X Button';\n\nconst WRITE_POLICY_TO_BI: Partial<\n Record<WritePolicy, ImportBiDuplicateIdPolicy>\n> = {\n [WritePolicy.OVERWRITE]: 'update_existing',\n [WritePolicy.SKIP_EXISTING]: 'skip_imported',\n};\n\nconst mappingType = (mapping: ColumnMapping): ImportBiMappingType =>\n mapping == null ? 'skip' : mapping.kind;\n\nconst isSameMapping = (a: ColumnMapping, b: ColumnMapping) =>\n a == null || b == null\n ? a === b\n : a.kind === 'existing'\n ? b.kind === 'existing' && a.fieldId === b.fieldId\n : b.kind === 'new' && a.fieldType === b.fieldType;\n\n/**\n * Reports the import funnel (src 144, evids 27–44). Every event carries the\n * same `importId`, regenerated each time the modal opens, so one flow's events\n * can be joined. Standard Cairo context (artifact, csid, version, fqdn…) is\n * attached by the container's `reportBi`; `filteredListSize` and the other\n * collection params come from the toolbar's wrapper, as for export.\n */\nexport class ImportStateBIReporter {\n private readonly state: ImportState;\n private importId = uuid();\n // 144:43 fires once per flow, the first time the policy control shows.\n private duplicateIdPolicyReported = false;\n\n constructor(state: ImportState) {\n this.state = state;\n }\n\n private report(log: ReportProps) {\n this.state.reportBi({\n ...log,\n params: { ...log.params, importId: this.importId },\n });\n }\n\n private get duplicateIdPolicy(): ImportBiDuplicateIdPolicy | undefined {\n const { state } = this;\n return state.canConfigureWritePolicy && state.idMappedHeader != null\n ? WRITE_POLICY_TO_BI[state.writePolicy]\n : undefined;\n }\n\n private get mappingCounts() {\n const mappings = Object.values(this.state.mappingByHeader);\n return {\n numMappedColumns: mappings.filter((m) => m != null).length,\n numNewFields: mappings.filter((m) => m?.kind === 'new').length,\n };\n }\n\n private get durationSinceStart() {\n return Math.round(performance.now() - this.state.importStartTime);\n }\n\n private get summaryResult(): ImportBiSummaryResult {\n return this.state.result.failed > 0 ? 'partial' : 'success';\n }\n\n /** 144:27 — the modal opened; starts a new flow (new `importId`). */\n onModalOpened() {\n this.importId = uuid();\n this.duplicateIdPolicyReported = false;\n this.report(wixPatternsImportCtaClickedSrc144Evid27({}));\n }\n\n /** 144:28 */\n onFileSelected() {\n const { fileName, csvHeaders, csvRows } = this.state;\n this.report(\n wixPatternsImportFileSelectedSrc144Evid28({\n fileName,\n numColumns: csvHeaders.length,\n numRows: csvRows.length,\n step: 'upload',\n }),\n );\n }\n\n /** 144:42 */\n onFileErrorDisplayed(errorType: ImportBiFileErrorType, fileName: string) {\n this.report(\n wixPatternsImportFileErrorDisplayedSrc144Evid42({ errorType, fileName }),\n );\n }\n\n /** 144:29 — Cancel / X on the upload or configuration step. */\n onModalDismissed(origin: ImportDismissOrigin, step: ImportBiStep) {\n this.report(\n wixPatternsImportModalCtaClickedSrc144Evid29({\n action: 'dismiss',\n origin,\n ctaName: origin === 'Cancel Button' ? 'Cancel' : 'X Button',\n step,\n ...(step === 'configuration' && {\n ...this.mappingCounts,\n canCreateNewField: this.state.canCreateNewField,\n duplicateIdPolicy: this.duplicateIdPolicy,\n }),\n }),\n );\n }\n\n /** 144:29 — the \"Learn more\" link on the upload step. */\n onLearnMoreClicked() {\n this.report(\n wixPatternsImportModalCtaClickedSrc144Evid29({\n action: 'dismiss',\n origin: 'Learn More',\n ctaName: 'Learn More',\n step: 'upload',\n }),\n );\n }\n\n /** 144:29 — \"Edit field\" under a new-field mapping. */\n onEditFieldClicked() {\n this.report(\n wixPatternsImportModalCtaClickedSrc144Evid29({\n action: 'dismiss',\n origin: 'Edit Field',\n ctaName: 'Edit Field',\n step: 'configuration',\n canCreateNewField: this.state.canCreateNewField,\n }),\n );\n }\n\n /** 144:29 — the Import button on the configuration step. */\n onImportConfirmed() {\n this.report(\n wixPatternsImportModalCtaClickedSrc144Evid29({\n action: 'import',\n origin: 'Import Button',\n ctaName: 'Import',\n step: 'configuration',\n ...this.mappingCounts,\n canCreateNewField: this.state.canCreateNewField,\n duplicateIdPolicy: this.duplicateIdPolicy,\n }),\n );\n }\n\n /** 144:33 — only when the mapping actually changed. */\n onMappingChanged(header: string, prev: ColumnMapping, next: ColumnMapping) {\n if (isSameMapping(prev, next)) {\n return;\n }\n this.report(\n wixPatternsImportColumnMappingChangedSrc144Evid33({\n columnName: header,\n prevMappingType: mappingType(prev),\n newMappingType: mappingType(next),\n ...(next?.kind === 'existing' && { fieldId: next.fieldId }),\n ...(next?.kind === 'new' && { fieldType: next.fieldType }),\n canCreateNewField: this.state.canCreateNewField,\n }),\n );\n }\n\n /** 144:34 — maps the discard modal's close result to the CTA the user hit. */\n onDiscardModalClosed(result: 'confirmed' | 'declined' | 'dismissed') {\n this.report(\n wixPatternsImportDiscardModalCtaClickedSrc144Evid34({\n ctaName:\n result === 'confirmed'\n ? 'Discard'\n : result === 'declined'\n ? 'Keep editing'\n : 'X Button',\n }),\n );\n }\n\n /** 144:41 */\n onMappingWarningShown(warningType: ImportBiWarningType) {\n this.report(\n wixPatternsImportMappingWarningShownSrc144Evid41({ warningType }),\n );\n }\n\n /** 144:43 — once per flow. */\n onDuplicateIdPolicyShown() {\n const policy = this.duplicateIdPolicy;\n if (this.duplicateIdPolicyReported || policy == null) {\n return;\n }\n this.duplicateIdPolicyReported = true;\n this.report(\n wixPatternsImportDuplicateIdPolicyShownSrc144Evid43({\n duplicateIdPolicy: policy,\n hasDuplicateIdsInFile: this.state.hasDuplicateIdsInFile,\n }),\n );\n }\n\n /** 144:44 — only when the policy actually changed. */\n onDuplicateIdPolicyChanged(prev: WritePolicy, next: WritePolicy) {\n const prevPolicy = WRITE_POLICY_TO_BI[prev];\n const nextPolicy = WRITE_POLICY_TO_BI[next];\n if (prev === next || prevPolicy == null || nextPolicy == null) {\n return;\n }\n this.report(\n wixPatternsImportDuplicateIdPolicyChangedSrc144Evid44({\n duplicateIdPolicy: nextPolicy,\n prevDuplicateIdPolicy: prevPolicy,\n hasDuplicateIdsInFile: this.state.hasDuplicateIdsInFile,\n }),\n );\n }\n\n /** 144:36 */\n onProcessStart(phase: 'backup' | 'import') {\n const { state } = this;\n this.report(\n wixPatternsImportProcessStartSrc144Evid36({\n phase,\n try: state.attempt,\n numRows: state.csvRows.length,\n ...this.mappingCounts,\n duplicateIdPolicy: this.duplicateIdPolicy,\n }),\n );\n }\n\n /** 144:37 */\n onProcessEnd(result: ImportBiProcessResult) {\n const { state } = this;\n this.report(\n wixPatternsImportProcessEndSrc144Evid37({\n result,\n duration: this.durationSinceStart,\n try: state.attempt,\n fileName: state.fileName,\n numItemsCreated: state.result.created,\n numItemsUpdated: state.result.updated,\n numItemsFailed: state.result.failed,\n duplicateIdPolicy: this.duplicateIdPolicy,\n }),\n );\n }\n\n /** 144:35 — Cancel / X while the import is running. */\n onCancelAttempt(origin: ImportDismissOrigin) {\n const { state } = this;\n this.report(\n wixPatternsUserAttemptsToCancelImportSrc144Evid35({\n origin,\n duration: this.durationSinceStart,\n try: state.attempt,\n numItemsProcessed: state.processedCount,\n }),\n );\n }\n\n /** 144:38 */\n onFailedModalCtaClicked(ctaName: 'Try Again' | 'Cancel' | 'X Button') {\n this.report(\n wixPatternsImportFailedModalCtaClickedSrc144Evid38({\n ctaName,\n try: this.state.attempt,\n }),\n );\n }\n\n /** 144:39 */\n onSummaryDisplayed() {\n const { result } = this.state;\n this.report(\n wixPatternsImportSummaryDisplayedSrc144Evid39({\n result: this.summaryResult,\n numItemsCreated: result.created,\n numItemsUpdated: result.updated,\n numItemsFailed: result.failed,\n numItemsImported: result.succeeded,\n }),\n );\n }\n\n /** 144:40 */\n onSummaryCtaClicked(\n ctaName: ImportSummaryCloseOrigin | 'Download failed items CSV',\n ) {\n this.report(\n wixPatternsImportSummaryCtaClickedSrc144Evid40({\n ctaName,\n result: this.summaryResult,\n }),\n );\n }\n}\n"],"mappings":";;;;;;AAAA,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BC,eAAe,EAAEzD,MAAM,CAAC0D,OAAO;MAC/BC,cAAc,EAAE3D,MAAM,CAACC,MAAM;MAC7BmE,gBAAgB,EAAEpE,MAAM,CAACqE;IAC3B,CAAC,CACH,CAAC;EACH;;EAEA;EACAC,mBAAmBA,CACjBlD,OAA+D,EAC/D;IACA,IAAI,CAAC/C,MAAM,CACT,IAAAkG,iDAA8C,EAAC;MAC7CnD,OAAO;MACPpB,MAAM,EAAE,IAAI,CAACD;IACf,CAAC,CACH,CAAC;EACH;AACF;AAACyE,OAAA,CAAAzG,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -42,7 +42,8 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
42
42
|
};
|
|
43
43
|
_hubJobClient.createHubJobClient.mockReturnValue(client);
|
|
44
44
|
const importModalState = {
|
|
45
|
-
close: jest.fn()
|
|
45
|
+
close: jest.fn(),
|
|
46
|
+
isOpen: false
|
|
46
47
|
};
|
|
47
48
|
const showToast = jest.fn();
|
|
48
49
|
const downloadCsv = jest.fn();
|
|
@@ -59,7 +60,9 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
59
60
|
fields,
|
|
60
61
|
idFieldKey,
|
|
61
62
|
backup,
|
|
62
|
-
jobApplicationErrorMap
|
|
63
|
+
jobApplicationErrorMap,
|
|
64
|
+
reportBi,
|
|
65
|
+
noSeed
|
|
63
66
|
} = extra;
|
|
64
67
|
const collection = {
|
|
65
68
|
clearResultAndMoveToStart: jest.fn(),
|
|
@@ -114,22 +117,27 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
114
117
|
},
|
|
115
118
|
showToast: showToast,
|
|
116
119
|
downloadCsv,
|
|
117
|
-
detectColumnType
|
|
120
|
+
detectColumnType,
|
|
121
|
+
...(reportBi && {
|
|
122
|
+
reportBi
|
|
123
|
+
})
|
|
118
124
|
};
|
|
119
125
|
const state = new _ImportState.ImportState(props);
|
|
120
126
|
|
|
121
127
|
// Seed a parsed CSV mapped to an existing field.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
if (!noSeed) {
|
|
129
|
+
(0, _mobx.runInAction)(() => {
|
|
130
|
+
state.fileName = 'data.csv';
|
|
131
|
+
state.csvHeaders = ['Name'];
|
|
132
|
+
state.csvRows = [['Apple'], ['Pear']];
|
|
133
|
+
state.mappingByHeader = {
|
|
134
|
+
Name: {
|
|
135
|
+
kind: 'existing',
|
|
136
|
+
fieldId: 'name'
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
133
141
|
return {
|
|
134
142
|
state,
|
|
135
143
|
client,
|
|
@@ -1566,4 +1574,252 @@ describe('ImportState items limit and completion hooks', () => {
|
|
|
1566
1574
|
expect(onImportCompleted).toHaveBeenCalledTimes(expectedCalls);
|
|
1567
1575
|
});
|
|
1568
1576
|
});
|
|
1577
|
+
describe('ImportState BI reporting', () => {
|
|
1578
|
+
beforeEach(() => {
|
|
1579
|
+
jest.useRealTimers();
|
|
1580
|
+
});
|
|
1581
|
+
const CAIRO_SRC = 144;
|
|
1582
|
+
|
|
1583
|
+
/** The reported events with the given evid, as `[params]`. */
|
|
1584
|
+
const eventsOf = (reportBi, evid) => reportBi.mock.calls.map(([log]) => log).filter(log => log.src === CAIRO_SRC && log.evid === evid).map(log => log.params);
|
|
1585
|
+
const setupWithBi = (clientOverrides = {}, extra = {}) => {
|
|
1586
|
+
const reportBi = jest.fn();
|
|
1587
|
+
return {
|
|
1588
|
+
...setup(clientOverrides, {
|
|
1589
|
+
...extra,
|
|
1590
|
+
reportBi
|
|
1591
|
+
}),
|
|
1592
|
+
reportBi
|
|
1593
|
+
};
|
|
1594
|
+
};
|
|
1595
|
+
const csvFile = (content, name = 'data.csv') => ({
|
|
1596
|
+
name,
|
|
1597
|
+
arrayBuffer: async () => new _util.TextEncoder().encode(content).buffer
|
|
1598
|
+
});
|
|
1599
|
+
it('reports the backup phase before the import phase when a backup is configured', async () => {
|
|
1600
|
+
const {
|
|
1601
|
+
state,
|
|
1602
|
+
reportBi
|
|
1603
|
+
} = setupWithBi({}, {
|
|
1604
|
+
backup: async () => ({
|
|
1605
|
+
restore: async () => {}
|
|
1606
|
+
})
|
|
1607
|
+
});
|
|
1608
|
+
await state.startImport();
|
|
1609
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['backup', 'import']);
|
|
1610
|
+
});
|
|
1611
|
+
it('reports a partial result and the failed-rows download CTA', async () => {
|
|
1612
|
+
const {
|
|
1613
|
+
state,
|
|
1614
|
+
reportBi
|
|
1615
|
+
} = setupWithBi({
|
|
1616
|
+
getJob: jest.fn(async () => ({
|
|
1617
|
+
...COMPLETED_JOB,
|
|
1618
|
+
status: _types.JobStatus.PARTIALLY_SUCCESSFUL,
|
|
1619
|
+
progress: {
|
|
1620
|
+
itemsSuccessful: 1,
|
|
1621
|
+
itemsRejected: 1,
|
|
1622
|
+
total: 2,
|
|
1623
|
+
current: 2,
|
|
1624
|
+
itemsSuccessfulInfo: {
|
|
1625
|
+
itemsCreated: 1,
|
|
1626
|
+
itemsUpdated: 0
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
})),
|
|
1630
|
+
listMovementLogs: jest.fn(async () => ({
|
|
1631
|
+
logs: []
|
|
1632
|
+
}))
|
|
1633
|
+
});
|
|
1634
|
+
await state.startImport();
|
|
1635
|
+
await state.downloadFailedRows();
|
|
1636
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1637
|
+
result: 'partial',
|
|
1638
|
+
numItemsFailed: 1
|
|
1639
|
+
})]);
|
|
1640
|
+
expect(eventsOf(reportBi, 39)).toEqual([expect.objectContaining({
|
|
1641
|
+
result: 'partial',
|
|
1642
|
+
numItemsImported: 1
|
|
1643
|
+
})]);
|
|
1644
|
+
expect(eventsOf(reportBi, 40)).toEqual([expect.objectContaining({
|
|
1645
|
+
ctaName: 'Download failed items CSV',
|
|
1646
|
+
result: 'partial'
|
|
1647
|
+
})]);
|
|
1648
|
+
});
|
|
1649
|
+
it('reports a failed job, then the retry with an incremented try', async () => {
|
|
1650
|
+
const getJob = jest.fn().mockResolvedValueOnce({
|
|
1651
|
+
...COMPLETED_JOB,
|
|
1652
|
+
status: _types.JobStatus.FAILED,
|
|
1653
|
+
error: {
|
|
1654
|
+
code: 'boom'
|
|
1655
|
+
}
|
|
1656
|
+
}).mockResolvedValue(COMPLETED_JOB);
|
|
1657
|
+
const {
|
|
1658
|
+
state,
|
|
1659
|
+
reportBi
|
|
1660
|
+
} = setupWithBi({
|
|
1661
|
+
getJob
|
|
1662
|
+
});
|
|
1663
|
+
await state.startImport();
|
|
1664
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1665
|
+
result: 'fail',
|
|
1666
|
+
try: 1
|
|
1667
|
+
})]);
|
|
1668
|
+
await state.retryImport();
|
|
1669
|
+
expect(eventsOf(reportBi, 38)).toEqual([expect.objectContaining({
|
|
1670
|
+
ctaName: 'Try Again',
|
|
1671
|
+
try: 1
|
|
1672
|
+
})]);
|
|
1673
|
+
// The retry is not a second "Import" confirmation.
|
|
1674
|
+
expect(eventsOf(reportBi, 29)).toHaveLength(1);
|
|
1675
|
+
expect(eventsOf(reportBi, 36).map(e => e.try)).toEqual([1, 2]);
|
|
1676
|
+
expect(eventsOf(reportBi, 37).map(e => [e.result, e.try])).toEqual([['fail', 1], ['success', 2]]);
|
|
1677
|
+
});
|
|
1678
|
+
it('reports a backup failure as a failed process', async () => {
|
|
1679
|
+
const {
|
|
1680
|
+
state,
|
|
1681
|
+
reportBi
|
|
1682
|
+
} = setupWithBi({}, {
|
|
1683
|
+
backup: () => Promise.reject(new Error('backup failed'))
|
|
1684
|
+
});
|
|
1685
|
+
await state.startImport();
|
|
1686
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['backup']);
|
|
1687
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1688
|
+
result: 'fail',
|
|
1689
|
+
try: 1
|
|
1690
|
+
})]);
|
|
1691
|
+
});
|
|
1692
|
+
it('reports the import phase start before a new field fails to be created', async () => {
|
|
1693
|
+
const {
|
|
1694
|
+
state,
|
|
1695
|
+
reportBi
|
|
1696
|
+
} = setupWithBi({}, {
|
|
1697
|
+
updateSchema: jest.fn(() => Promise.reject(new Error('create failed')))
|
|
1698
|
+
});
|
|
1699
|
+
(0, _mobx.runInAction)(() => {
|
|
1700
|
+
state.csvHeaders = ['Name', 'Color'];
|
|
1701
|
+
state.csvRows = [['Apple', 'Red']];
|
|
1702
|
+
state.mappingByHeader = {
|
|
1703
|
+
Name: {
|
|
1704
|
+
kind: 'existing',
|
|
1705
|
+
fieldId: 'name'
|
|
1706
|
+
},
|
|
1707
|
+
Color: {
|
|
1708
|
+
kind: 'new',
|
|
1709
|
+
fieldType: 'text'
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
});
|
|
1713
|
+
await state.startImport();
|
|
1714
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['import']);
|
|
1715
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1716
|
+
result: 'fail',
|
|
1717
|
+
try: 1
|
|
1718
|
+
})]);
|
|
1719
|
+
});
|
|
1720
|
+
it('does not report a failed process end for an import the user cancelled', async () => {
|
|
1721
|
+
let failCreation;
|
|
1722
|
+
const updateSchema = jest.fn(() => new Promise((_resolve, reject) => {
|
|
1723
|
+
failCreation = reject;
|
|
1724
|
+
}));
|
|
1725
|
+
const {
|
|
1726
|
+
state,
|
|
1727
|
+
reportBi
|
|
1728
|
+
} = setupWithBi({}, {
|
|
1729
|
+
updateSchema
|
|
1730
|
+
});
|
|
1731
|
+
(0, _mobx.runInAction)(() => {
|
|
1732
|
+
state.csvHeaders = ['Name', 'Color'];
|
|
1733
|
+
state.csvRows = [['Apple', 'Red']];
|
|
1734
|
+
state.mappingByHeader = {
|
|
1735
|
+
Name: {
|
|
1736
|
+
kind: 'existing',
|
|
1737
|
+
fieldId: 'name'
|
|
1738
|
+
},
|
|
1739
|
+
Color: {
|
|
1740
|
+
kind: 'new',
|
|
1741
|
+
fieldType: 'text'
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
});
|
|
1745
|
+
const run = state.startImport();
|
|
1746
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
1747
|
+
expect(updateSchema).toHaveBeenCalledTimes(1);
|
|
1748
|
+
await state.close('Cancel Button');
|
|
1749
|
+
failCreation(new Error('create failed'));
|
|
1750
|
+
await run;
|
|
1751
|
+
expect(eventsOf(reportBi, 37).map(e => e.result)).toEqual(['stopped by user']);
|
|
1752
|
+
});
|
|
1753
|
+
it('reports the selected file and file errors', async () => {
|
|
1754
|
+
const {
|
|
1755
|
+
state,
|
|
1756
|
+
reportBi
|
|
1757
|
+
} = setupWithBi({}, {
|
|
1758
|
+
noSeed: true
|
|
1759
|
+
});
|
|
1760
|
+
await state.onFileSelected(csvFile('Name,Price\nA,1\nB,2\n', 'ok.csv'));
|
|
1761
|
+
expect(eventsOf(reportBi, 28)).toEqual([expect.objectContaining({
|
|
1762
|
+
fileName: 'ok.csv',
|
|
1763
|
+
numColumns: 2,
|
|
1764
|
+
numRows: 2,
|
|
1765
|
+
step: 'upload'
|
|
1766
|
+
})]);
|
|
1767
|
+
await state.onFileSelected(csvFile('a,b\n"broken,1\n', 'broken.csv'));
|
|
1768
|
+
const unreadable = csvFile('x', 'unreadable.csv');
|
|
1769
|
+
jest.spyOn(unreadable, 'arrayBuffer').mockRejectedValue(new Error('io'));
|
|
1770
|
+
await state.onFileSelected(unreadable);
|
|
1771
|
+
expect(eventsOf(reportBi, 42)).toEqual([expect.objectContaining({
|
|
1772
|
+
errorType: 'process_failed',
|
|
1773
|
+
fileName: 'broken.csv'
|
|
1774
|
+
}), expect.objectContaining({
|
|
1775
|
+
errorType: 'file_read_failed',
|
|
1776
|
+
fileName: 'unreadable.csv'
|
|
1777
|
+
})]);
|
|
1778
|
+
});
|
|
1779
|
+
it('reports the selected file before the mapping warning it causes', async () => {
|
|
1780
|
+
const {
|
|
1781
|
+
state,
|
|
1782
|
+
reportBi
|
|
1783
|
+
} = setupWithBi({}, {
|
|
1784
|
+
noSeed: true
|
|
1785
|
+
});
|
|
1786
|
+
const dispose = state.init();
|
|
1787
|
+
await state.onFileSelected(csvFile('Name,Price\n', 'empty.csv'));
|
|
1788
|
+
dispose();
|
|
1789
|
+
const evids = reportBi.mock.calls.map(([log]) => log.evid);
|
|
1790
|
+
expect(evids.indexOf(28)).toBeGreaterThan(-1);
|
|
1791
|
+
expect(evids.indexOf(28)).toBeLessThan(evids.indexOf(41));
|
|
1792
|
+
expect(eventsOf(reportBi, 41)).toEqual([expect.objectContaining({
|
|
1793
|
+
warningType: 'no_rows'
|
|
1794
|
+
})]);
|
|
1795
|
+
});
|
|
1796
|
+
it('reports the duplicate-id policy change and whether the file repeats ids', () => {
|
|
1797
|
+
const {
|
|
1798
|
+
state,
|
|
1799
|
+
reportBi
|
|
1800
|
+
} = setupWithBi({}, {
|
|
1801
|
+
fields: [{
|
|
1802
|
+
id: '_id',
|
|
1803
|
+
header: 'ID'
|
|
1804
|
+
}]
|
|
1805
|
+
});
|
|
1806
|
+
(0, _mobx.runInAction)(() => {
|
|
1807
|
+
state.csvHeaders = ['ID'];
|
|
1808
|
+
state.csvRows = [['1'], ['1']];
|
|
1809
|
+
state.mappingByHeader = {
|
|
1810
|
+
ID: {
|
|
1811
|
+
kind: 'existing',
|
|
1812
|
+
fieldId: '_id'
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
});
|
|
1816
|
+
state.setWritePolicy(_types.WritePolicy.SKIP_EXISTING);
|
|
1817
|
+
state.setWritePolicy(_types.WritePolicy.SKIP_EXISTING);
|
|
1818
|
+
expect(eventsOf(reportBi, 44)).toEqual([expect.objectContaining({
|
|
1819
|
+
duplicateIdPolicy: 'skip_imported',
|
|
1820
|
+
prevDuplicateIdPolicy: 'update_existing',
|
|
1821
|
+
hasDuplicateIdsInFile: true
|
|
1822
|
+
})]);
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1569
1825
|
//# sourceMappingURL=ImportState.engine.spec.js.map
|