@wix/bex-core 2.425.0 → 2.427.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.
@@ -1,4 +1,6 @@
1
1
  {
2
+ "cairo.visual.customLayout.label": "Relationships",
3
+ "cairo.visual.customLayout.content": "Consumer-defined layout",
2
4
  "cairo.table.filter.button": "Filter",
3
5
  "cairo.table.listView": "List View",
4
6
  "cairo.table.gridView": "Cards Grid View",
@@ -10,6 +10,7 @@ function useCreateImport(params) {
10
10
  const {
11
11
  config,
12
12
  createFieldValidator,
13
+ createValueDeserializer,
13
14
  deserializeValue,
14
15
  schemaSource,
15
16
  importInputs,
@@ -32,6 +33,7 @@ function useCreateImport(params) {
32
33
  return new _state.ImportState({
33
34
  config,
34
35
  createFieldValidator,
36
+ createValueDeserializer,
35
37
  deserializeValue,
36
38
  getExistingIds: schemaSource ? (ids, signal) => (0, _findExistingImportIds.findExistingImportIds)(schemaSource, ids, signal, collection.query.asComputed.extra) : undefined,
37
39
  importInputs,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_providers","_state","_findExistingImportIds","useCreateImport","params","config","createFieldValidator","deserializeValue","schemaSource","importInputs","fieldsSource","detectColumnType","isValueCompatible","importModalState","reportBi","container","useWixPatternsContainer","showToast","translate","errorHandler","window","httpClient","collection","useCollectionContext","useCallback","ImportState","getExistingIds","ids","signal","findExistingImportIds","query","asComputed","extra","undefined","downloadCsv","content","fileName","download","encodeURIComponent"],"sources":["../../../src/hooks/useImport.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useWixPatternsContainer, useCollectionContext } from '../providers';\nimport {\n ModalState,\n ImportState,\n ResolvedImportConfig,\n ImportConfig,\n DetectColumnType,\n CreateImportFieldValidator,\n IsImportValueCompatible,\n ImportStateProps,\n} from '../state';\nimport { findExistingImportIds } from '../state/ImportState/findExistingImportIds';\nimport type { SchemaSource } from '../types/SchemaSource';\nimport type { FieldsSource } from '../types/FieldsSource';\nimport { FiltersMap } from '../model';\nimport type { ReportBI } from '../services';\n\nexport interface UseImportParams<T = unknown> {\n deserializeValue?: ImportStateProps['deserializeValue'];\n createFieldValidator?: CreateImportFieldValidator;\n schemaSource?: SchemaSource<T>;\n /** Consumer inputs (destination, extra fields, backup, …). The collection,\n * fields, and create-new-field are read from `fieldsSource`. */\n importInputs?: ImportConfig;\n /** The table's live fields source; `ImportState` builds the config from it. */\n fieldsSource?: FieldsSource;\n /** A fully pre-built config, used instead of building from the inputs/source. */\n config?: ResolvedImportConfig;\n detectColumnType?: DetectColumnType;\n isValueCompatible?: IsImportValueCompatible;\n importModalState: ModalState;\n /** BI reporter for the import funnel; defaults to the container's. */\n reportBi?: ReportBI;\n}\n\nexport function useCreateImport<T = unknown, F extends FiltersMap = FiltersMap>(\n params: UseImportParams<T>,\n) {\n const {\n config,\n createFieldValidator,\n deserializeValue,\n schemaSource,\n importInputs,\n fieldsSource,\n detectColumnType,\n isValueCompatible,\n importModalState,\n reportBi,\n } = params;\n const container = useWixPatternsContainer();\n const { showToast, translate, errorHandler, window, httpClient } = container;\n const collection = useCollectionContext<T, F>();\n\n return useCallback(() => {\n return new ImportState({\n config,\n createFieldValidator,\n deserializeValue,\n getExistingIds: schemaSource\n ? (ids, signal) =>\n findExistingImportIds(\n schemaSource,\n ids,\n signal,\n collection.query.asComputed.extra,\n )\n : undefined,\n importInputs,\n fieldsSource,\n httpClient,\n detectColumnType,\n isValueCompatible,\n collection,\n importModalState,\n showToast,\n translate,\n errorHandler,\n reportBi: reportBi ?? container.reportBi,\n downloadCsv: (content, fileName) => {\n window.download(\n `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`,\n fileName,\n );\n },\n });\n }, []);\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAUA,IAAAG,sBAAA,GAAAH,OAAA;AAwBO,SAASI,eAAeA,CAC7BC,MAA0B,EAC1B;EACA,MAAM;IACJC,MAAM;IACNC,oBAAoB;IACpBC,gBAAgB;IAChBC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,gBAAgB;IAChBC,iBAAiB;IACjBC,gBAAgB;IAChBC;EACF,CAAC,GAAGV,MAAM;EACV,MAAMW,SAAS,GAAG,IAAAC,kCAAuB,EAAC,CAAC;EAC3C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,YAAY;IAAEC,MAAM;IAAEC;EAAW,CAAC,GAAGN,SAAS;EAC5E,MAAMO,UAAU,GAAG,IAAAC,+BAAoB,EAAO,CAAC;EAE/C,OAAO,IAAAC,kBAAW,EAAC,MAAM;IACvB,OAAO,IAAIC,kBAAW,CAAC;MACrBpB,MAAM;MACNC,oBAAoB;MACpBC,gBAAgB;MAChBmB,cAAc,EAAElB,YAAY,GACxB,CAACmB,GAAG,EAAEC,MAAM,KACV,IAAAC,4CAAqB,EACnBrB,YAAY,EACZmB,GAAG,EACHC,MAAM,EACNN,UAAU,CAACQ,KAAK,CAACC,UAAU,CAACC,KAC9B,CAAC,GACHC,SAAS;MACbxB,YAAY;MACZC,YAAY;MACZW,UAAU;MACVV,gBAAgB;MAChBC,iBAAiB;MACjBU,UAAU;MACVT,gBAAgB;MAChBI,SAAS;MACTC,SAAS;MACTC,YAAY;MACZL,QAAQ,EAAEA,QAAQ,IAAIC,SAAS,CAACD,QAAQ;MACxCoB,WAAW,EAAEA,CAACC,OAAO,EAAEC,QAAQ,KAAK;QAClChB,MAAM,CAACiB,QAAQ,CACb,+BAA+BC,kBAAkB,CAACH,OAAO,CAAC,EAAE,EAC5DC,QACF,CAAC;MACH;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_providers","_state","_findExistingImportIds","useCreateImport","params","config","createFieldValidator","createValueDeserializer","deserializeValue","schemaSource","importInputs","fieldsSource","detectColumnType","isValueCompatible","importModalState","reportBi","container","useWixPatternsContainer","showToast","translate","errorHandler","window","httpClient","collection","useCollectionContext","useCallback","ImportState","getExistingIds","ids","signal","findExistingImportIds","query","asComputed","extra","undefined","downloadCsv","content","fileName","download","encodeURIComponent"],"sources":["../../../src/hooks/useImport.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useWixPatternsContainer, useCollectionContext } from '../providers';\nimport {\n ModalState,\n ImportState,\n ResolvedImportConfig,\n ImportConfig,\n DetectColumnType,\n CreateImportFieldValidator,\n CreateImportValueDeserializer,\n IsImportValueCompatible,\n ImportStateProps,\n} from '../state';\nimport { findExistingImportIds } from '../state/ImportState/findExistingImportIds';\nimport type { SchemaSource } from '../types/SchemaSource';\nimport type { FieldsSource } from '../types/FieldsSource';\nimport { FiltersMap } from '../model';\nimport type { ReportBI } from '../services';\n\nexport interface UseImportParams<T = unknown> {\n createValueDeserializer?: CreateImportValueDeserializer;\n /** @deprecated Use `createValueDeserializer`. */\n deserializeValue?: ImportStateProps['deserializeValue'];\n createFieldValidator?: CreateImportFieldValidator;\n schemaSource?: SchemaSource<T>;\n /** Consumer inputs (destination, extra fields, backup, …). The collection,\n * fields, and create-new-field are read from `fieldsSource`. */\n importInputs?: ImportConfig;\n /** The table's live fields source; `ImportState` builds the config from it. */\n fieldsSource?: FieldsSource;\n /** A fully pre-built config, used instead of building from the inputs/source. */\n config?: ResolvedImportConfig;\n detectColumnType?: DetectColumnType;\n isValueCompatible?: IsImportValueCompatible;\n importModalState: ModalState;\n /** BI reporter for the import funnel; defaults to the container's. */\n reportBi?: ReportBI;\n}\n\nexport function useCreateImport<T = unknown, F extends FiltersMap = FiltersMap>(\n params: UseImportParams<T>,\n) {\n const {\n config,\n createFieldValidator,\n createValueDeserializer,\n deserializeValue,\n schemaSource,\n importInputs,\n fieldsSource,\n detectColumnType,\n isValueCompatible,\n importModalState,\n reportBi,\n } = params;\n const container = useWixPatternsContainer();\n const { showToast, translate, errorHandler, window, httpClient } = container;\n const collection = useCollectionContext<T, F>();\n\n return useCallback(() => {\n return new ImportState({\n config,\n createFieldValidator,\n createValueDeserializer,\n deserializeValue,\n getExistingIds: schemaSource\n ? (ids, signal) =>\n findExistingImportIds(\n schemaSource,\n ids,\n signal,\n collection.query.asComputed.extra,\n )\n : undefined,\n importInputs,\n fieldsSource,\n httpClient,\n detectColumnType,\n isValueCompatible,\n collection,\n importModalState,\n showToast,\n translate,\n errorHandler,\n reportBi: reportBi ?? container.reportBi,\n downloadCsv: (content, fileName) => {\n window.download(\n `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`,\n fileName,\n );\n },\n });\n }, []);\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAWA,IAAAG,sBAAA,GAAAH,OAAA;AA0BO,SAASI,eAAeA,CAC7BC,MAA0B,EAC1B;EACA,MAAM;IACJC,MAAM;IACNC,oBAAoB;IACpBC,uBAAuB;IACvBC,gBAAgB;IAChBC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,gBAAgB;IAChBC,iBAAiB;IACjBC,gBAAgB;IAChBC;EACF,CAAC,GAAGX,MAAM;EACV,MAAMY,SAAS,GAAG,IAAAC,kCAAuB,EAAC,CAAC;EAC3C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,YAAY;IAAEC,MAAM;IAAEC;EAAW,CAAC,GAAGN,SAAS;EAC5E,MAAMO,UAAU,GAAG,IAAAC,+BAAoB,EAAO,CAAC;EAE/C,OAAO,IAAAC,kBAAW,EAAC,MAAM;IACvB,OAAO,IAAIC,kBAAW,CAAC;MACrBrB,MAAM;MACNC,oBAAoB;MACpBC,uBAAuB;MACvBC,gBAAgB;MAChBmB,cAAc,EAAElB,YAAY,GACxB,CAACmB,GAAG,EAAEC,MAAM,KACV,IAAAC,4CAAqB,EACnBrB,YAAY,EACZmB,GAAG,EACHC,MAAM,EACNN,UAAU,CAACQ,KAAK,CAACC,UAAU,CAACC,KAC9B,CAAC,GACHC,SAAS;MACbxB,YAAY;MACZC,YAAY;MACZW,UAAU;MACVV,gBAAgB;MAChBC,iBAAiB;MACjBU,UAAU;MACVT,gBAAgB;MAChBI,SAAS;MACTC,SAAS;MACTC,YAAY;MACZL,QAAQ,EAAEA,QAAQ,IAAIC,SAAS,CAACD,QAAQ;MACxCoB,WAAW,EAAEA,CAACC,OAAO,EAAEC,QAAQ,KAAK;QAClChB,MAAM,CAACiB,QAAQ,CACb,+BAA+BC,kBAAkB,CAACH,OAAO,CAAC,EAAE,EAC5DC,QACF,CAAC;MACH;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
@@ -268,6 +268,13 @@ const buildImportConfig = (fieldsSource, collection, inputs = {}) => {
268
268
  })
269
269
  };
270
270
  };
271
+
272
+ /**
273
+ * Called once per mapped column of a collection import, except the id
274
+ * column and system fields, with its resolved destination field.
275
+ * `getValues` returns every cell of the column. Returns the function that
276
+ * converts each of that column's cells before upload.
277
+ */
271
278
  exports.buildImportConfig = buildImportConfig;
272
279
  // How long to hold the completed (100%) progress bar on screen before moving to
273
280
  // the summary step (CAIRO-4476). The job reports counts only when it finishes,
@@ -363,6 +370,7 @@ class ImportState {
363
370
  (0, _defineProperty2.default)(this, "_createFieldValidator", void 0);
364
371
  (0, _defineProperty2.default)(this, "_fieldsSource", void 0);
365
372
  (0, _defineProperty2.default)(this, "_getExistingIds", void 0);
373
+ (0, _defineProperty2.default)(this, "_createValueDeserializer", void 0);
366
374
  (0, _defineProperty2.default)(this, "_deserializeValue", void 0);
367
375
  (0, _defineProperty2.default)(this, "_uploadedRows", undefined);
368
376
  (0, _defineProperty2.default)(this, "_validationFailures", []);
@@ -427,6 +435,7 @@ class ImportState {
427
435
  this._createFieldValidator = props.createFieldValidator;
428
436
  this._fieldsSource = props.fieldsSource;
429
437
  this._getExistingIds = props.getExistingIds;
438
+ this._createValueDeserializer = props.createValueDeserializer;
430
439
  this._deserializeValue = props.deserializeValue;
431
440
  this.errorHandler = props.errorHandler;
432
441
  this.showToast = props.showToast;
@@ -1463,14 +1472,14 @@ class ImportState {
1463
1472
  async _validateRows(mapping, signal) {
1464
1473
  var _this$_getExistingIds;
1465
1474
  const rows = [];
1466
- const values = 'collectionId' in this.config.dataSource && this._deserializeValue ? [] : undefined;
1475
+ const values = 'collectionId' in this.config.dataSource && (this._createValueDeserializer || this._deserializeValue) ? [] : undefined;
1467
1476
  const failedRows = [];
1468
1477
  const idIndex = this.csvHeaders.findIndex(header => mapping[header] === this.idFieldKey);
1469
1478
  const skipExisting = this.writePolicy === _types.WritePolicy.SKIP_EXISTING;
1470
1479
  const ids = [...new Set(this.csvRows.map(row => row[idIndex]).filter(Boolean))];
1471
1480
  const skippedIds = new Set(skipExisting && ids.length ? await ((_this$_getExistingIds = this._getExistingIds) == null ? void 0 : _this$_getExistingIds.call(this, ids, signal)) : []);
1472
- const columns = this.csvHeaders.map(header => {
1473
- var _this$_pendingFieldsM, _this$_fieldsSource, _sourceField$validati, _this$_createFieldVal;
1481
+ const columns = this.csvHeaders.map((header, columnIndex) => {
1482
+ var _this$_pendingFieldsM, _this$_fieldsSource, _sourceField$validati, _this$_createFieldVal, _this$_createValueDes;
1474
1483
  const fieldId = mapping[header];
1475
1484
  if (!fieldId || fieldId === this.idFieldKey) {
1476
1485
  return undefined;
@@ -1500,9 +1509,14 @@ class ImportState {
1500
1509
  fieldName: field.displayName
1501
1510
  })] : [];
1502
1511
  });
1512
+ const deserializeValue = this._deserializeValue;
1513
+ const deserialize = values && (((_this$_createValueDes = this._createValueDeserializer) == null ? void 0 : _this$_createValueDes.call(this, field, {
1514
+ getValues: () => this.csvRows.map(row => row[columnIndex] ?? '')
1515
+ })) ?? (deserializeValue && (raw => deserializeValue(field, raw))));
1503
1516
  return {
1504
1517
  field,
1505
- validate
1518
+ validate,
1519
+ deserialize
1506
1520
  };
1507
1521
  });
1508
1522
  this.csvRows.forEach((row, index) => {
@@ -1515,8 +1529,7 @@ class ImportState {
1515
1529
  const errors = (column == null ? void 0 : column.validate(raw)) ?? [];
1516
1530
  if (values && column && !errors.length) {
1517
1531
  try {
1518
- var _this$_deserializeVal;
1519
- converted[columnIndex] = (_this$_deserializeVal = this._deserializeValue) == null ? void 0 : _this$_deserializeVal.call(this, column.field, raw);
1532
+ converted[columnIndex] = column.deserialize == null ? void 0 : column.deserialize(raw);
1520
1533
  } catch {
1521
1534
  errors.push(`${column.field.displayName}: ${this.translate('cairo.editableTable.cell.validation.notCompatible')}`);
1522
1535
  }