contentoh-components-library 21.6.22 → 21.6.23

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.
@@ -9,6 +9,10 @@ exports.LinkVariantsModal = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
13
+
14
+ var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
15
+
12
16
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
13
17
 
14
18
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
@@ -70,6 +74,8 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
70
74
  articleName = _ref.articleName,
71
75
  articleUpc = _ref.articleUpc,
72
76
  activeRetailerId = _ref.activeRetailerId,
77
+ retailersAvailable = _ref.retailersAvailable,
78
+ categoriesAvailable = _ref.categoriesAvailable,
73
79
  token = _ref.token,
74
80
  _ref$endpoint = _ref.endpoint,
75
81
  endpoint = _ref$endpoint === void 0 ? process.env.REACT_APP_VARIANTS_ENDPOINT : _ref$endpoint,
@@ -109,52 +115,71 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
109
115
  var _useState13 = (0, _react.useState)([]),
110
116
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
111
117
  selected = _useState14[0],
112
- setSelected = _useState14[1];
118
+ setSelected = _useState14[1]; // Lo que el padre ofrece en cada dimensión, y lo que el usuario eligió de
119
+ // cada una. Se guardan por separado porque se eligen por separado: heredar
120
+ // todos los atributos no dice nada sobre qué fotos quiere la variante.
113
121
 
114
- var _useState15 = (0, _react.useState)([]),
115
- _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
116
- attributes = _useState16[0],
117
- setAttributes = _useState16[1];
118
122
 
119
- var _useState17 = (0, _react.useState)(null),
123
+ var _useState15 = (0, _react.useState)({
124
+ attributes: [],
125
+ descriptions: [],
126
+ images: [],
127
+ categoryRetailers: []
128
+ }),
129
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
130
+ offered = _useState16[0],
131
+ setOffered = _useState16[1];
132
+
133
+ var _useState17 = (0, _react.useState)({
134
+ attributes: [],
135
+ descriptions: [],
136
+ images: [],
137
+ categoryRetailers: []
138
+ }),
120
139
  _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
121
- nameScope = _useState18[0],
122
- setNameScope = _useState18[1];
140
+ chosen = _useState18[0],
141
+ setChosen = _useState18[1];
123
142
 
124
- var _useState19 = (0, _react.useState)("all-filled"),
143
+ var _useState19 = (0, _react.useState)(null),
125
144
  _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
126
- inheritMode = _useState20[0],
127
- setInheritMode = _useState20[1];
145
+ nameScope = _useState20[0],
146
+ setNameScope = _useState20[1];
128
147
 
129
- var _useState21 = (0, _react.useState)([]),
148
+ var _useState21 = (0, _react.useState)("all-filled"),
130
149
  _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
131
- chosenAttributes = _useState22[0],
132
- setChosenAttributes = _useState22[1];
150
+ inheritMode = _useState22[0],
151
+ setInheritMode = _useState22[1];
133
152
 
134
- var _useState23 = (0, _react.useState)(true),
153
+ var _useState23 = (0, _react.useState)("attributes"),
135
154
  _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
136
- inheritImages = _useState24[0],
137
- setInheritImages = _useState24[1];
155
+ openSection = _useState24[0],
156
+ setOpenSection = _useState24[1]; // Cadenas que el padre NO tiene y el usuario decidió agregar a la variante.
157
+
138
158
 
139
- var _useState25 = (0, _react.useState)(true),
159
+ var _useState25 = (0, _react.useState)([]),
140
160
  _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
141
- inheritDescriptions = _useState26[0],
142
- setInheritDescriptions = _useState26[1];
161
+ extraRetailers = _useState26[0],
162
+ setExtraRetailers = _useState26[1];
143
163
 
144
- var _useState27 = (0, _react.useState)(true),
164
+ var _useState27 = (0, _react.useState)(""),
145
165
  _useState28 = (0, _slicedToArray2.default)(_useState27, 2),
146
- inheritCategoryRetailers = _useState28[0],
147
- setInheritCategoryRetailers = _useState28[1];
166
+ newRetailer = _useState28[0],
167
+ setNewRetailer = _useState28[1];
148
168
 
149
- var _useState29 = (0, _react.useState)(false),
169
+ var _useState29 = (0, _react.useState)(""),
150
170
  _useState30 = (0, _slicedToArray2.default)(_useState29, 2),
151
- loading = _useState30[0],
152
- setLoading = _useState30[1];
171
+ newCategory = _useState30[0],
172
+ setNewCategory = _useState30[1];
153
173
 
154
- var _useState31 = (0, _react.useState)(null),
174
+ var _useState31 = (0, _react.useState)(false),
155
175
  _useState32 = (0, _slicedToArray2.default)(_useState31, 2),
156
- error = _useState32[0],
157
- setError = _useState32[1];
176
+ loading = _useState32[0],
177
+ setLoading = _useState32[1];
178
+
179
+ var _useState33 = (0, _react.useState)(null),
180
+ _useState34 = (0, _slicedToArray2.default)(_useState33, 2),
181
+ error = _useState34[0],
182
+ setError = _useState34[1];
158
183
 
159
184
  var request = (0, _react.useCallback)( /*#__PURE__*/function () {
160
185
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(action, body) {
@@ -262,7 +287,7 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
262
287
 
263
288
  var goToInheritance = /*#__PURE__*/function () {
264
289
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
265
- var _data$nameScope, data;
290
+ var _data$nameScope, data, listas;
266
291
 
267
292
  return _regenerator.default.wrap(function _callee3$(_context3) {
268
293
  while (1) {
@@ -279,31 +304,51 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
279
304
 
280
305
  case 5:
281
306
  data = _context3.sent;
282
- setAttributes(data.attributes || []);
283
- setNameScope((_data$nameScope = data.nameScope) !== null && _data$nameScope !== void 0 ? _data$nameScope : null);
284
- setChosenAttributes((data.attributes || []).map(function (item) {
285
- return item.id;
286
- }));
307
+ listas = {
308
+ attributes: data.attributes || [],
309
+ descriptions: data.descriptions || [],
310
+ images: data.images || [],
311
+ categoryRetailers: data.categoryRetailers || []
312
+ };
313
+ setOffered(listas);
314
+ setNameScope((_data$nameScope = data.nameScope) !== null && _data$nameScope !== void 0 ? _data$nameScope : null); // Todo preseleccionado: heredar es el caso normal, y quitar lo que sobra
315
+ // es menos trabajo que marcar de cero lo que casi siempre se quiere.
316
+
317
+ setChosen({
318
+ attributes: listas.attributes.map(function (item) {
319
+ return item.id;
320
+ }),
321
+ descriptions: listas.descriptions.map(function (item) {
322
+ return item.id;
323
+ }),
324
+ images: listas.images.map(function (item) {
325
+ return item.id;
326
+ }),
327
+ categoryRetailers: listas.categoryRetailers.map(function (item) {
328
+ return "".concat(item.retailerId, "-").concat(item.categoryId);
329
+ })
330
+ });
331
+ setExtraRetailers([]);
287
332
  setStep("inherit");
288
- _context3.next = 15;
333
+ _context3.next = 17;
289
334
  break;
290
335
 
291
- case 12:
292
- _context3.prev = 12;
336
+ case 14:
337
+ _context3.prev = 14;
293
338
  _context3.t0 = _context3["catch"](2);
294
339
  setError(readError(_context3.t0));
295
340
 
296
- case 15:
297
- _context3.prev = 15;
341
+ case 17:
342
+ _context3.prev = 17;
298
343
  setLoading(false);
299
- return _context3.finish(15);
344
+ return _context3.finish(17);
300
345
 
301
- case 18:
346
+ case 20:
302
347
  case "end":
303
348
  return _context3.stop();
304
349
  }
305
350
  }
306
- }, _callee3, null, [[2, 12, 15, 18]]);
351
+ }, _callee3, null, [[2, 14, 17, 20]]);
307
352
  }));
308
353
 
309
354
  return function goToInheritance() {
@@ -311,28 +356,94 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
311
356
  };
312
357
  }();
313
358
 
314
- var toggleAttribute = function toggleAttribute(id) {
315
- setChosenAttributes(function (current) {
316
- return current.includes(id) ? current.filter(function (item) {
359
+ var toggleChoice = function toggleChoice(dimension, id) {
360
+ setChosen(function (current) {
361
+ var lista = current[dimension];
362
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, lista.includes(id) ? lista.filter(function (item) {
317
363
  return item !== id;
318
- }) : [].concat((0, _toConsumableArray2.default)(current), [id]);
364
+ }) : [].concat((0, _toConsumableArray2.default)(lista), [id])));
365
+ });
366
+ };
367
+
368
+ var toggleAll = function toggleAll(dimension, ids) {
369
+ setChosen(function (current) {
370
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, current[dimension].length === ids.length ? [] : ids));
319
371
  });
320
372
  };
321
373
 
374
+ var addRetailer = function addRetailer() {
375
+ var retailerId = Number(newRetailer);
376
+ var categoryId = Number(newCategory);
377
+ if (!retailerId || !categoryId) return;
378
+ var clave = "".concat(retailerId, "-").concat(categoryId);
379
+ var yaEsta = offered.categoryRetailers.some(function (item) {
380
+ return "".concat(item.retailerId, "-").concat(item.categoryId) === clave;
381
+ }) || extraRetailers.some(function (item) {
382
+ return item.clave === clave;
383
+ });
384
+ if (yaEsta) return;
385
+ var retailer = (retailersAvailable || []).find(function (item) {
386
+ var _item$id;
387
+
388
+ return Number((_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : item.value) === retailerId;
389
+ });
390
+ var category = (categoriesAvailable || []).find(function (item) {
391
+ var _item$id2;
392
+
393
+ return Number((_item$id2 = item.id) !== null && _item$id2 !== void 0 ? _item$id2 : item.value) === categoryId;
394
+ });
395
+ setExtraRetailers(function (current) {
396
+ var _ref5, _retailer$name, _ref6, _category$name;
397
+
398
+ return [].concat((0, _toConsumableArray2.default)(current), [{
399
+ clave: clave,
400
+ retailerId: retailerId,
401
+ categoryId: categoryId,
402
+ retailerName: (_ref5 = (_retailer$name = retailer === null || retailer === void 0 ? void 0 : retailer.name) !== null && _retailer$name !== void 0 ? _retailer$name : retailer === null || retailer === void 0 ? void 0 : retailer.label) !== null && _ref5 !== void 0 ? _ref5 : "Cadena ".concat(retailerId),
403
+ categoryName: (_ref6 = (_category$name = category === null || category === void 0 ? void 0 : category.name) !== null && _category$name !== void 0 ? _category$name : category === null || category === void 0 ? void 0 : category.label) !== null && _ref6 !== void 0 ? _ref6 : "Categor\xEDa ".concat(categoryId)
404
+ }]);
405
+ });
406
+ setChosen(function (current) {
407
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, {
408
+ categoryRetailers: [].concat((0, _toConsumableArray2.default)(current.categoryRetailers), [clave])
409
+ });
410
+ });
411
+ setNewRetailer("");
412
+ setNewCategory("");
413
+ };
414
+
322
415
  var submit = /*#__PURE__*/function () {
323
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
324
- var inherit, body, data;
416
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
417
+ var todasLasParejas, inherit, body, data;
325
418
  return _regenerator.default.wrap(function _callee4$(_context4) {
326
419
  while (1) {
327
420
  switch (_context4.prev = _context4.next) {
328
421
  case 0:
329
422
  setLoading(true);
330
- setError(null);
423
+ setError(null); // Las parejas cadena+categoría viajan como objetos, no como ids: pueden ser
424
+ // cadenas que el padre no tiene, y ahí no hay nada que "heredar" — se asigna.
425
+
426
+ todasLasParejas = [].concat((0, _toConsumableArray2.default)(offered.categoryRetailers.map(function (item) {
427
+ return {
428
+ clave: "".concat(item.retailerId, "-").concat(item.categoryId),
429
+ retailerId: item.retailerId,
430
+ categoryId: item.categoryId
431
+ };
432
+ })), (0, _toConsumableArray2.default)(extraRetailers));
331
433
  inherit = {
332
- attributes: inheritMode === "all-filled" ? "all-filled" : chosenAttributes,
333
- images: inheritImages,
334
- descriptions: inheritDescriptions,
335
- categoryRetailers: inheritCategoryRetailers
434
+ attributes: inheritMode === "all-filled" ? "all-filled" : chosen.attributes,
435
+ descriptions: chosen.descriptions,
436
+ images: chosen.images,
437
+ categoryRetailers: todasLasParejas.filter(function (par) {
438
+ return chosen.categoryRetailers.includes(par.clave);
439
+ }).map(function (_ref8) {
440
+ var retailerId = _ref8.retailerId,
441
+ categoryId = _ref8.categoryId;
442
+ return {
443
+ retailerId: retailerId,
444
+ categoryId: categoryId
445
+ };
446
+ })
336
447
  };
337
448
  body = mode === "parent" ? {
338
449
  mode: mode,
@@ -345,37 +456,43 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
345
456
  childrenArticleIds: selected,
346
457
  inherit: inherit
347
458
  };
348
- _context4.prev = 4;
349
- _context4.next = 7;
459
+ _context4.prev = 5;
460
+ _context4.next = 8;
350
461
  return request("link", body);
351
462
 
352
- case 7:
463
+ case 8:
353
464
  data = _context4.sent;
354
- onLinked === null || onLinked === void 0 ? void 0 : onLinked(data);
465
+ // El modo importa para quien escucha: en `children` este producto GANA
466
+ // variantes; en `parent` pasa a SER una. Son efectos opuestos sobre la
467
+ // misma ficha, así que quien refresque el estado necesita distinguirlos.
468
+ onLinked === null || onLinked === void 0 ? void 0 : onLinked((0, _objectSpread4.default)((0, _objectSpread4.default)({}, data), {}, {
469
+ mode: mode,
470
+ parentArticleId: mode === "parent" ? selected[0] : articleId
471
+ }));
355
472
  onClose === null || onClose === void 0 ? void 0 : onClose();
356
- _context4.next = 15;
473
+ _context4.next = 16;
357
474
  break;
358
475
 
359
- case 12:
360
- _context4.prev = 12;
361
- _context4.t0 = _context4["catch"](4);
476
+ case 13:
477
+ _context4.prev = 13;
478
+ _context4.t0 = _context4["catch"](5);
362
479
  setError(readError(_context4.t0));
363
480
 
364
- case 15:
365
- _context4.prev = 15;
481
+ case 16:
482
+ _context4.prev = 16;
366
483
  setLoading(false);
367
- return _context4.finish(15);
484
+ return _context4.finish(16);
368
485
 
369
- case 18:
486
+ case 19:
370
487
  case "end":
371
488
  return _context4.stop();
372
489
  }
373
490
  }
374
- }, _callee4, null, [[4, 12, 15, 18]]);
491
+ }, _callee4, null, [[5, 13, 16, 19]]);
375
492
  }));
376
493
 
377
494
  return function submit() {
378
- return _ref5.apply(this, arguments);
495
+ return _ref7.apply(this, arguments);
379
496
  };
380
497
  }();
381
498
 
@@ -467,7 +584,7 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
467
584
  }), step === "inherit" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
468
585
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
469
586
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
470
- children: "\xBFQu\xE9 se hereda del producto padre?"
587
+ children: "Atributos de la ficha t\xE9cnica"
471
588
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
472
589
  className: "choice",
473
590
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
@@ -477,9 +594,9 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
477
594
  return setInheritMode("all-filled");
478
595
  }
479
596
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
480
- children: ["Todos los atributos con valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
597
+ children: ["Todos los que tienen valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
481
598
  className: "hint",
482
- children: [attributes.length, " atributo(s) con informaci\xF3n en el padre."]
599
+ children: [offered.attributes.length, " atributo(s) con informaci\xF3n en el padre."]
483
600
  })]
484
601
  })]
485
602
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
@@ -500,14 +617,14 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
500
617
  }), inheritMode === "selected" && activeRetailerId && !nameScope && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
501
618
  children: "El producto padre no comparte la cadena que tienes abierta, as\xED que los nombres de abajo son los de otra de sus cadenas."
502
619
  }), inheritMode === "selected" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
503
- children: attributes.map(function (attribute) {
620
+ children: offered.attributes.map(function (attribute) {
504
621
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
505
622
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
506
623
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
507
624
  type: "checkbox",
508
- checked: chosenAttributes.includes(attribute.id),
625
+ checked: chosen.attributes.includes(attribute.id),
509
626
  onChange: function onChange() {
510
- return toggleAttribute(attribute.id);
627
+ return toggleChoice("attributes", attribute.id);
511
628
  }
512
629
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
513
630
  children: [attribute.name, attribute.unconfigured && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -526,48 +643,176 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
526
643
  }, attribute.id);
527
644
  })
528
645
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
529
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
530
- children: "Tambi\xE9n se hereda"
531
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
532
- className: "choice",
533
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
534
- type: "checkbox",
535
- checked: inheritImages,
536
- onChange: function onChange() {
537
- return setInheritImages(function (value) {
538
- return !value;
539
- });
540
- }
541
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
542
- children: "Im\xE1genes"
646
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SectionHead, {
647
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
648
+ type: "button",
649
+ className: "toggle",
650
+ "aria-expanded": openSection === "descriptions",
651
+ onClick: function onClick() {
652
+ return setOpenSection(openSection === "descriptions" ? null : "descriptions");
653
+ },
654
+ children: ["Descripciones", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
655
+ className: "count",
656
+ children: [chosen.descriptions.length, " de", " ", offered.descriptions.length]
657
+ })]
658
+ }), offered.descriptions.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
659
+ type: "button",
660
+ className: "all",
661
+ onClick: function onClick() {
662
+ return toggleAll("descriptions", offered.descriptions.map(function (item) {
663
+ return item.id;
664
+ }));
665
+ },
666
+ children: chosen.descriptions.length === offered.descriptions.length ? "Ninguna" : "Todas"
543
667
  })]
544
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
545
- className: "choice",
546
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
547
- type: "checkbox",
548
- checked: inheritDescriptions,
549
- onChange: function onChange() {
550
- return setInheritDescriptions(function (value) {
551
- return !value;
552
- });
553
- }
554
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
555
- children: "Descripciones"
668
+ }), openSection === "descriptions" && (offered.descriptions.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
669
+ children: offered.descriptions.map(function (item) {
670
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
671
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
672
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
673
+ type: "checkbox",
674
+ checked: chosen.descriptions.includes(item.id),
675
+ onChange: function onChange() {
676
+ return toggleChoice("descriptions", item.id);
677
+ }
678
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
679
+ children: item.name
680
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
681
+ className: "value",
682
+ title: item.value,
683
+ children: item.value
684
+ })]
685
+ })
686
+ }, item.id);
687
+ })
688
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
689
+ children: "El producto padre no tiene descripciones."
690
+ }))]
691
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
692
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SectionHead, {
693
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
694
+ type: "button",
695
+ className: "toggle",
696
+ "aria-expanded": openSection === "images",
697
+ onClick: function onClick() {
698
+ return setOpenSection(openSection === "images" ? null : "images");
699
+ },
700
+ children: ["Im\xE1genes", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
701
+ className: "count",
702
+ children: [chosen.images.length, " de ", offered.images.length]
703
+ })]
704
+ }), offered.images.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
705
+ type: "button",
706
+ className: "all",
707
+ onClick: function onClick() {
708
+ return toggleAll("images", offered.images.map(function (item) {
709
+ return item.id;
710
+ }));
711
+ },
712
+ children: chosen.images.length === offered.images.length ? "Ninguna" : "Todas"
556
713
  })]
557
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
558
- className: "choice",
559
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
560
- type: "checkbox",
561
- checked: inheritCategoryRetailers,
562
- onChange: function onChange() {
563
- return setInheritCategoryRetailers(function (value) {
564
- return !value;
714
+ }), openSection === "images" && (offered.images.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ImageGrid, {
715
+ children: offered.images.map(function (image) {
716
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
717
+ className: chosen.images.includes(image.id) ? "picked" : "",
718
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
719
+ type: "checkbox",
720
+ checked: chosen.images.includes(image.id),
721
+ onChange: function onChange() {
722
+ return toggleChoice("images", image.id);
723
+ }
724
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
725
+ src: image.src,
726
+ alt: image.imageType || ""
727
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
728
+ children: image.imageType || "Sin tipo"
729
+ })]
730
+ }, image.id);
731
+ })
732
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
733
+ children: "El producto padre no tiene im\xE1genes."
734
+ }))]
735
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
736
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.SectionHead, {
737
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
738
+ type: "button",
739
+ className: "toggle",
740
+ "aria-expanded": openSection === "retailers",
741
+ onClick: function onClick() {
742
+ return setOpenSection(openSection === "retailers" ? null : "retailers");
743
+ },
744
+ children: ["Cadenas y categor\xEDas", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
745
+ className: "count",
746
+ children: [chosen.categoryRetailers.length, " seleccionada(s)"]
747
+ })]
748
+ })
749
+ }), openSection === "retailers" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
750
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
751
+ children: [].concat((0, _toConsumableArray2.default)(offered.categoryRetailers.map(function (item) {
752
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, item), {}, {
753
+ clave: "".concat(item.retailerId, "-").concat(item.categoryId),
754
+ delPadre: true
565
755
  });
566
- }
567
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
568
- children: ["Cadenas y categor\xEDas", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
569
- className: "hint",
570
- children: "Las parejas cadena-categor\xEDa del padre se copian a la variante."
756
+ })), (0, _toConsumableArray2.default)(extraRetailers.map(function (item) {
757
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, item), {}, {
758
+ delPadre: false
759
+ });
760
+ }))).map(function (item) {
761
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
762
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
763
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
764
+ type: "checkbox",
765
+ checked: chosen.categoryRetailers.includes(item.clave),
766
+ onChange: function onChange() {
767
+ return toggleChoice("categoryRetailers", item.clave);
768
+ }
769
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
770
+ children: [item.retailerName, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
771
+ className: "meta",
772
+ children: [item.categoryName || "Sin categoría", !item.delPadre && " · no la tiene el padre"]
773
+ })]
774
+ })]
775
+ })
776
+ }, item.clave);
777
+ })
778
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.AddRetailer, {
779
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
780
+ value: newRetailer,
781
+ onChange: function onChange(event) {
782
+ return setNewRetailer(event.target.value);
783
+ },
784
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
785
+ value: "",
786
+ children: "Agregar otra cadena\u2026"
787
+ }), (retailersAvailable || []).map(function (item) {
788
+ var _item$id3, _item$id4, _item$name;
789
+
790
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
791
+ value: (_item$id4 = item.id) !== null && _item$id4 !== void 0 ? _item$id4 : item.value,
792
+ children: (_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : item.label
793
+ }, (_item$id3 = item.id) !== null && _item$id3 !== void 0 ? _item$id3 : item.value);
794
+ })]
795
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
796
+ value: newCategory,
797
+ onChange: function onChange(event) {
798
+ return setNewCategory(event.target.value);
799
+ },
800
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
801
+ value: "",
802
+ children: "Categor\xEDa\u2026"
803
+ }), (categoriesAvailable || []).map(function (item) {
804
+ var _item$id5, _item$id6, _item$name2;
805
+
806
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
807
+ value: (_item$id6 = item.id) !== null && _item$id6 !== void 0 ? _item$id6 : item.value,
808
+ children: (_item$name2 = item.name) !== null && _item$name2 !== void 0 ? _item$name2 : item.label
809
+ }, (_item$id5 = item.id) !== null && _item$id5 !== void 0 ? _item$id5 : item.value);
810
+ })]
811
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
812
+ type: "button",
813
+ onClick: addRetailer,
814
+ disabled: !newRetailer || !newCategory,
815
+ children: "Agregar"
571
816
  })]
572
817
  })]
573
818
  })]
@@ -608,7 +853,7 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
608
853
  disabled: loading || // Solo estorba cuando hay algo que elegir y no se eligió nada.
609
854
  // Con el padre sin atributos heredables, ligar sigue siendo
610
855
  // válido: se heredan imágenes, descripciones y cadenas.
611
- inheritMode === "selected" && attributes.length > 0 && !chosenAttributes.length,
856
+ inheritMode === "selected" && offered.attributes.length > 0 && !chosen.attributes.length,
612
857
  children: loading ? "Ligando…" : "Ligar"
613
858
  })]
614
859
  })]