contentoh-components-library 21.6.23 → 21.6.24

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.
@@ -11,7 +11,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
11
11
 
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
13
13
 
14
- var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
14
+ var _objectSpread6 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
15
15
 
16
16
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
17
17
 
@@ -25,6 +25,8 @@ var _axios = _interopRequireDefault(require("axios"));
25
25
 
26
26
  var _api = require("./api");
27
27
 
28
+ var _helper = require("../../../_utils/helper");
29
+
28
30
  var _styles = require("./styles");
29
31
 
30
32
  var _jsxRuntime = require("react/jsx-runtime");
@@ -74,11 +76,11 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
74
76
  articleName = _ref.articleName,
75
77
  articleUpc = _ref.articleUpc,
76
78
  activeRetailerId = _ref.activeRetailerId,
77
- retailersAvailable = _ref.retailersAvailable,
78
- categoriesAvailable = _ref.categoriesAvailable,
79
79
  token = _ref.token,
80
80
  _ref$endpoint = _ref.endpoint,
81
81
  endpoint = _ref$endpoint === void 0 ? process.env.REACT_APP_VARIANTS_ENDPOINT : _ref$endpoint,
82
+ _ref$filtersEndpoint = _ref.filtersEndpoint,
83
+ filtersEndpoint = _ref$filtersEndpoint === void 0 ? process.env.REACT_APP_CREATE_PRODUCTS_FILTERS : _ref$filtersEndpoint,
82
84
  onClose = _ref.onClose,
83
85
  onLinked = _ref.onLinked;
84
86
 
@@ -115,71 +117,135 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
115
117
  var _useState13 = (0, _react.useState)([]),
116
118
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
117
119
  selected = _useState14[0],
118
- setSelected = _useState14[1]; // Lo que el padre ofrece en cada dimensión, y lo que el usuario eligió de
120
+ setSelected = _useState14[1];
121
+
122
+ var _useState15 = (0, _react.useState)(0),
123
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
124
+ total = _useState16[0],
125
+ setTotal = _useState16[1];
126
+
127
+ var _useState17 = (0, _react.useState)(false),
128
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
129
+ hasMore = _useState18[0],
130
+ setHasMore = _useState18[1];
131
+
132
+ var _useState19 = (0, _react.useState)(false),
133
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
134
+ loadingMore = _useState20[0],
135
+ setLoadingMore = _useState20[1]; // Lo que el padre ofrece en cada dimensión, y lo que el usuario eligió de
119
136
  // cada una. Se guardan por separado porque se eligen por separado: heredar
120
137
  // todos los atributos no dice nada sobre qué fotos quiere la variante.
121
138
 
122
139
 
123
- var _useState15 = (0, _react.useState)({
140
+ var _useState21 = (0, _react.useState)({
124
141
  attributes: [],
125
142
  descriptions: [],
126
143
  images: [],
127
144
  categoryRetailers: []
128
145
  }),
129
- _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
130
- offered = _useState16[0],
131
- setOffered = _useState16[1];
146
+ _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
147
+ offered = _useState22[0],
148
+ setOffered = _useState22[1];
132
149
 
133
- var _useState17 = (0, _react.useState)({
150
+ var _useState23 = (0, _react.useState)({
134
151
  attributes: [],
135
152
  descriptions: [],
136
153
  images: [],
137
154
  categoryRetailers: []
138
155
  }),
139
- _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
140
- chosen = _useState18[0],
141
- setChosen = _useState18[1];
142
-
143
- var _useState19 = (0, _react.useState)(null),
144
- _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
145
- nameScope = _useState20[0],
146
- setNameScope = _useState20[1];
147
-
148
- var _useState21 = (0, _react.useState)("all-filled"),
149
- _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
150
- inheritMode = _useState22[0],
151
- setInheritMode = _useState22[1];
152
-
153
- var _useState23 = (0, _react.useState)("attributes"),
154
156
  _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
155
- openSection = _useState24[0],
156
- setOpenSection = _useState24[1]; // Cadenas que el padre NO tiene y el usuario decidió agregar a la variante.
157
+ chosen = _useState24[0],
158
+ setChosen = _useState24[1];
157
159
 
158
-
159
- var _useState25 = (0, _react.useState)([]),
160
+ var _useState25 = (0, _react.useState)(null),
160
161
  _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
161
- extraRetailers = _useState26[0],
162
- setExtraRetailers = _useState26[1];
163
-
164
- var _useState27 = (0, _react.useState)(""),
162
+ nameScope = _useState26[0],
163
+ setNameScope = _useState26[1]; // Un modo por dimensión, y ninguno decidido de entrada: el usuario tiene que
164
+ // pasar por las cuatro antes de poder ligar. Preseleccionar "todo" hacía que
165
+ // se pudiera ligar sin haber mirado nada, que es justo lo que hay que evitar
166
+ // en una operación que sobrescribe valores capturados.
167
+
168
+
169
+ var _useState27 = (0, _react.useState)({
170
+ categoryRetailers: null,
171
+ descriptions: null,
172
+ attributes: null,
173
+ images: null
174
+ }),
165
175
  _useState28 = (0, _slicedToArray2.default)(_useState27, 2),
166
- newRetailer = _useState28[0],
167
- setNewRetailer = _useState28[1];
168
-
169
- var _useState29 = (0, _react.useState)(""),
176
+ modes = _useState28[0],
177
+ setModes = _useState28[1];
178
+ /*
179
+ Al ligar varios productos, la herencia puede ser la misma para todos o
180
+ distinta para cada uno.
181
+ Por defecto es la misma: es lo que se quiere casi siempre y evita repetir
182
+ cuatro decisiones por producto. Al desmarcarlo aparecen las pestañas y cada
183
+ producto guarda su propia selección en `perChild`.
184
+ */
185
+
186
+
187
+ var _useState29 = (0, _react.useState)(true),
170
188
  _useState30 = (0, _slicedToArray2.default)(_useState29, 2),
171
- newCategory = _useState30[0],
172
- setNewCategory = _useState30[1];
189
+ applyToAll = _useState30[0],
190
+ setApplyToAll = _useState30[1];
173
191
 
174
- var _useState31 = (0, _react.useState)(false),
192
+ var _useState31 = (0, _react.useState)(null),
175
193
  _useState32 = (0, _slicedToArray2.default)(_useState31, 2),
176
- loading = _useState32[0],
177
- setLoading = _useState32[1];
194
+ activeChild = _useState32[0],
195
+ setActiveChild = _useState32[1];
178
196
 
179
- var _useState33 = (0, _react.useState)(null),
197
+ var _useState33 = (0, _react.useState)({}),
180
198
  _useState34 = (0, _slicedToArray2.default)(_useState33, 2),
181
- error = _useState34[0],
182
- setError = _useState34[1];
199
+ perChild = _useState34[0],
200
+ setPerChild = _useState34[1]; // Cadenas que el padre NO tiene y el usuario decidió agregar a la variante.
201
+
202
+
203
+ var _useState35 = (0, _react.useState)([]),
204
+ _useState36 = (0, _slicedToArray2.default)(_useState35, 2),
205
+ extraRetailers = _useState36[0],
206
+ setExtraRetailers = _useState36[1];
207
+
208
+ var _useState37 = (0, _react.useState)(""),
209
+ _useState38 = (0, _slicedToArray2.default)(_useState37, 2),
210
+ newRetailer = _useState38[0],
211
+ setNewRetailer = _useState38[1];
212
+
213
+ var _useState39 = (0, _react.useState)(""),
214
+ _useState40 = (0, _slicedToArray2.default)(_useState39, 2),
215
+ newDepartment = _useState40[0],
216
+ setNewDepartment = _useState40[1];
217
+
218
+ var _useState41 = (0, _react.useState)(""),
219
+ _useState42 = (0, _slicedToArray2.default)(_useState41, 2),
220
+ newCategory = _useState42[0],
221
+ setNewCategory = _useState42[1]; // Las categorías no son una lista plana: dependen de la cadena y del
222
+ // departamento. Es la misma cascada que usa el alta de productos, y se sirve
223
+ // del mismo endpoint para no acabar con dos árboles de categorías distintos.
224
+
225
+
226
+ var _useState43 = (0, _react.useState)({
227
+ retailers: [],
228
+ departments: [],
229
+ categories: []
230
+ }),
231
+ _useState44 = (0, _slicedToArray2.default)(_useState43, 2),
232
+ filters = _useState44[0],
233
+ setFilters = _useState44[1];
234
+
235
+ var _useState45 = (0, _react.useState)(false),
236
+ _useState46 = (0, _slicedToArray2.default)(_useState45, 2),
237
+ loadingFilters = _useState46[0],
238
+ setLoadingFilters = _useState46[1];
239
+
240
+ var _useState47 = (0, _react.useState)(false),
241
+ _useState48 = (0, _slicedToArray2.default)(_useState47, 2),
242
+ loading = _useState48[0],
243
+ setLoading = _useState48[1];
244
+
245
+ var _useState49 = (0, _react.useState)(null),
246
+ _useState50 = (0, _slicedToArray2.default)(_useState49, 2),
247
+ error = _useState50[0],
248
+ setError = _useState50[1];
183
249
 
184
250
  var request = (0, _react.useCallback)( /*#__PURE__*/function () {
185
251
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(action, body) {
@@ -223,13 +289,16 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
223
289
  setSelected([]);
224
290
  setRejected(null);
225
291
  setSearched(false);
292
+ setTotal(0);
293
+ setHasMore(false);
226
294
  setError(null);
227
295
  setStep("search");
228
296
  }, [mode]);
229
297
 
230
298
  var search = /*#__PURE__*/function () {
231
299
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(event) {
232
- var data;
300
+ var _data$total, data;
301
+
233
302
  return _regenerator.default.wrap(function _callee2$(_context2) {
234
303
  while (1) {
235
304
  switch (_context2.prev = _context2.next) {
@@ -249,32 +318,94 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
249
318
  data = _context2.sent;
250
319
  setCandidates(data.candidates || []);
251
320
  setRejected(data.rejected || null);
321
+ setTotal((_data$total = data.total) !== null && _data$total !== void 0 ? _data$total : (data.candidates || []).length);
322
+ setHasMore(!!data.hasMore);
252
323
  setSearched(true);
253
- _context2.next = 15;
324
+ _context2.next = 17;
254
325
  break;
255
326
 
256
- case 12:
257
- _context2.prev = 12;
327
+ case 14:
328
+ _context2.prev = 14;
258
329
  _context2.t0 = _context2["catch"](3);
259
330
  setError(readError(_context2.t0));
260
331
 
261
- case 15:
262
- _context2.prev = 15;
332
+ case 17:
333
+ _context2.prev = 17;
263
334
  setLoading(false);
264
- return _context2.finish(15);
335
+ return _context2.finish(17);
265
336
 
266
- case 18:
337
+ case 20:
267
338
  case "end":
268
339
  return _context2.stop();
269
340
  }
270
341
  }
271
- }, _callee2, null, [[3, 12, 15, 18]]);
342
+ }, _callee2, null, [[3, 14, 17, 20]]);
272
343
  }));
273
344
 
274
345
  return function search(_x3) {
275
346
  return _ref3.apply(this, arguments);
276
347
  };
277
348
  }();
349
+ /*
350
+ Trae la siguiente página y la agrega a la lista.
351
+ Se acumula en vez de reemplazar porque la selección vive en esta pantalla: si
352
+ la página 2 borrara la 1, lo marcado antes desaparecería de la vista sin
353
+ dejar de estar seleccionado, y el usuario acabaría ligando productos que ya
354
+ no ve.
355
+ */
356
+
357
+
358
+ var loadMore = /*#__PURE__*/function () {
359
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
360
+ var _data$total2, data;
361
+
362
+ return _regenerator.default.wrap(function _callee3$(_context3) {
363
+ while (1) {
364
+ switch (_context3.prev = _context3.next) {
365
+ case 0:
366
+ setLoadingMore(true);
367
+ setError(null);
368
+ _context3.prev = 2;
369
+ _context3.next = 5;
370
+ return request("search", {
371
+ mode: mode,
372
+ articleId: articleId,
373
+ query: query.trim(),
374
+ offset: candidates.length
375
+ });
376
+
377
+ case 5:
378
+ data = _context3.sent;
379
+ setCandidates(function (current) {
380
+ return [].concat((0, _toConsumableArray2.default)(current), (0, _toConsumableArray2.default)(data.candidates || []));
381
+ });
382
+ setTotal((_data$total2 = data.total) !== null && _data$total2 !== void 0 ? _data$total2 : total);
383
+ setHasMore(!!data.hasMore);
384
+ _context3.next = 14;
385
+ break;
386
+
387
+ case 11:
388
+ _context3.prev = 11;
389
+ _context3.t0 = _context3["catch"](2);
390
+ setError(readError(_context3.t0));
391
+
392
+ case 14:
393
+ _context3.prev = 14;
394
+ setLoadingMore(false);
395
+ return _context3.finish(14);
396
+
397
+ case 17:
398
+ case "end":
399
+ return _context3.stop();
400
+ }
401
+ }
402
+ }, _callee3, null, [[2, 11, 14, 17]]);
403
+ }));
404
+
405
+ return function loadMore() {
406
+ return _ref4.apply(this, arguments);
407
+ };
408
+ }();
278
409
 
279
410
  var toggle = function toggle(id) {
280
411
  setSelected(function (current) {
@@ -286,24 +417,24 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
286
417
  };
287
418
 
288
419
  var goToInheritance = /*#__PURE__*/function () {
289
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
420
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
290
421
  var _data$nameScope, data, listas;
291
422
 
292
- return _regenerator.default.wrap(function _callee3$(_context3) {
423
+ return _regenerator.default.wrap(function _callee4$(_context4) {
293
424
  while (1) {
294
- switch (_context3.prev = _context3.next) {
425
+ switch (_context4.prev = _context4.next) {
295
426
  case 0:
296
427
  setLoading(true);
297
428
  setError(null);
298
- _context3.prev = 2;
299
- _context3.next = 5;
429
+ _context4.prev = 2;
430
+ _context4.next = 5;
300
431
  return request("attributes", {
301
432
  parentArticleId: parentArticleId,
302
433
  retailerId: activeRetailerId
303
434
  });
304
435
 
305
436
  case 5:
306
- data = _context3.sent;
437
+ data = _context4.sent;
307
438
  listas = {
308
439
  attributes: data.attributes || [],
309
440
  descriptions: data.descriptions || [],
@@ -311,66 +442,155 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
311
442
  categoryRetailers: data.categoryRetailers || []
312
443
  };
313
444
  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
-
445
+ setNameScope((_data$nameScope = data.nameScope) !== null && _data$nameScope !== void 0 ? _data$nameScope : null);
317
446
  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
- })
447
+ attributes: [],
448
+ descriptions: [],
449
+ images: [],
450
+ categoryRetailers: []
451
+ });
452
+ setModes({
453
+ categoryRetailers: null,
454
+ descriptions: null,
455
+ attributes: null,
456
+ images: null
330
457
  });
331
458
  setExtraRetailers([]);
459
+ setPerChild({});
460
+ setApplyToAll(true);
461
+ setActiveChild(mode === "children" ? selected[0] : null);
332
462
  setStep("inherit");
333
- _context3.next = 17;
463
+ _context4.next = 21;
334
464
  break;
335
465
 
336
- case 14:
337
- _context3.prev = 14;
338
- _context3.t0 = _context3["catch"](2);
339
- setError(readError(_context3.t0));
466
+ case 18:
467
+ _context4.prev = 18;
468
+ _context4.t0 = _context4["catch"](2);
469
+ setError(readError(_context4.t0));
340
470
 
341
- case 17:
342
- _context3.prev = 17;
471
+ case 21:
472
+ _context4.prev = 21;
343
473
  setLoading(false);
344
- return _context3.finish(17);
474
+ return _context4.finish(21);
345
475
 
346
- case 20:
476
+ case 24:
347
477
  case "end":
348
- return _context3.stop();
478
+ return _context4.stop();
349
479
  }
350
480
  }
351
- }, _callee3, null, [[2, 14, 17, 20]]);
481
+ }, _callee4, null, [[2, 18, 21, 24]]);
352
482
  }));
353
483
 
354
484
  return function goToInheritance() {
355
- return _ref4.apply(this, arguments);
485
+ return _ref5.apply(this, arguments);
356
486
  };
357
487
  }();
358
488
 
359
489
  var toggleChoice = function toggleChoice(dimension, id) {
360
490
  setChosen(function (current) {
361
491
  var lista = current[dimension];
362
- return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, lista.includes(id) ? lista.filter(function (item) {
492
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, lista.includes(id) ? lista.filter(function (item) {
363
493
  return item !== id;
364
494
  }) : [].concat((0, _toConsumableArray2.default)(lista), [id])));
365
495
  });
366
496
  };
367
497
 
368
- var toggleAll = function toggleAll(dimension, ids) {
498
+ var chooseMode = function chooseMode(dimension, modo, ids) {
499
+ setModes(function (current) {
500
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, modo));
501
+ });
369
502
  setChosen(function (current) {
370
- return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, current[dimension].length === ids.length ? [] : ids));
503
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, (0, _defineProperty2.default)({}, dimension, modo === "all" ? ids : []));
371
504
  });
372
505
  };
373
506
 
507
+ var loadFilters = (0, _react.useCallback)( /*#__PURE__*/function () {
508
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(retailer, department) {
509
+ var _data, _ref7, res, _readPayload, body, lista;
510
+
511
+ return _regenerator.default.wrap(function _callee5$(_context5) {
512
+ while (1) {
513
+ switch (_context5.prev = _context5.next) {
514
+ case 0:
515
+ setLoadingFilters(true);
516
+ _context5.prev = 1;
517
+ _context5.next = 4;
518
+ return _axios.default.get("".concat(filtersEndpoint, "?retailerSelected=").concat(retailer !== null && retailer !== void 0 ? retailer : "", "&departmentSelected=").concat(department !== null && department !== void 0 ? department : ""), {
519
+ headers: {
520
+ Authorization: token
521
+ }
522
+ });
523
+
524
+ case 4:
525
+ res = _context5.sent;
526
+ _readPayload = (0, _api.readPayload)(res), body = _readPayload.body;
527
+ lista = (_data = (_ref7 = body ? JSON.parse(body) : res.data) === null || _ref7 === void 0 ? void 0 : _ref7.data) !== null && _data !== void 0 ? _data : [];
528
+ setFilters(function (current) {
529
+ if (!retailer) {
530
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, {
531
+ retailers: lista.map(function (item) {
532
+ return {
533
+ value: item.id,
534
+ label: item.name
535
+ };
536
+ })
537
+ });
538
+ }
539
+
540
+ if (!department) {
541
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, {
542
+ departments: lista.map(function (item) {
543
+ return {
544
+ value: item.category,
545
+ label: item.category
546
+ };
547
+ }),
548
+ categories: []
549
+ });
550
+ }
551
+
552
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, {
553
+ categories: lista.map(function (item) {
554
+ return {
555
+ value: item.id,
556
+ label: item.name
557
+ };
558
+ })
559
+ });
560
+ });
561
+ _context5.next = 13;
562
+ break;
563
+
564
+ case 10:
565
+ _context5.prev = 10;
566
+ _context5.t0 = _context5["catch"](1);
567
+ console.error("linkVariants/filters: ", _context5.t0);
568
+
569
+ case 13:
570
+ _context5.prev = 13;
571
+ setLoadingFilters(false);
572
+ return _context5.finish(13);
573
+
574
+ case 16:
575
+ case "end":
576
+ return _context5.stop();
577
+ }
578
+ }
579
+ }, _callee5, null, [[1, 10, 13, 16]]);
580
+ }));
581
+
582
+ return function (_x4, _x5) {
583
+ return _ref6.apply(this, arguments);
584
+ };
585
+ }(), [filtersEndpoint, token]); // Las cadenas del catálogo se piden al entrar al paso de herencia, no al abrir
586
+ // el modal: quien solo busca y cancela no llega a necesitarlas.
587
+
588
+ (0, _react.useEffect)(function () {
589
+ if (step === "inherit" && !filters.retailers.length) {
590
+ loadFilters(null, null);
591
+ }
592
+ }, [step, filters.retailers.length, loadFilters]);
593
+
374
594
  var addRetailer = function addRetailer() {
375
595
  var retailerId = Number(newRetailer);
376
596
  var categoryId = Number(newCategory);
@@ -382,120 +602,225 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
382
602
  return item.clave === clave;
383
603
  });
384
604
  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;
605
+ var retailer = filters.retailers.find(function (item) {
606
+ return Number(item.value) === retailerId;
389
607
  });
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;
608
+ var category = filters.categories.find(function (item) {
609
+ return Number(item.value) === categoryId;
394
610
  });
395
611
  setExtraRetailers(function (current) {
396
- var _ref5, _retailer$name, _ref6, _category$name;
612
+ var _retailer$label, _category$label;
397
613
 
398
614
  return [].concat((0, _toConsumableArray2.default)(current), [{
399
615
  clave: clave,
400
616
  retailerId: retailerId,
401
617
  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)
618
+ retailerName: (_retailer$label = retailer === null || retailer === void 0 ? void 0 : retailer.label) !== null && _retailer$label !== void 0 ? _retailer$label : "Cadena ".concat(retailerId),
619
+ categoryName: (_category$label = category === null || category === void 0 ? void 0 : category.label) !== null && _category$label !== void 0 ? _category$label : "Categor\xEDa ".concat(categoryId)
404
620
  }]);
405
621
  });
406
622
  setChosen(function (current) {
407
- return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, current), {}, {
623
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, {
408
624
  categoryRetailers: [].concat((0, _toConsumableArray2.default)(current.categoryRetailers), [clave])
409
625
  });
410
626
  });
411
627
  setNewRetailer("");
628
+ setNewDepartment("");
412
629
  setNewCategory("");
413
630
  };
631
+ /*
632
+ Convierte una selección de pantalla en el bloque `inherit` de la API.
633
+ Con el modo en "todos" se manda la palabra y no la lista que se pintó: si
634
+ entre la carga del modal y el guardado alguien agregó un valor al padre,
635
+ "todos" sigue significando todos. La lista sería una foto ya vieja.
636
+ Las parejas cadena+categoría viajan como objetos, no como ids, porque pueden
637
+ ser cadenas que el padre no tiene: ahí no hay nada que heredar, se asigna.
638
+ */
639
+
640
+
641
+ var buildInherit = function buildInherit(seleccion) {
642
+ var _seleccion$extraRetai;
643
+
644
+ var parejas = [].concat((0, _toConsumableArray2.default)(offered.categoryRetailers.map(function (item) {
645
+ return {
646
+ clave: "".concat(item.retailerId, "-").concat(item.categoryId),
647
+ retailerId: item.retailerId,
648
+ categoryId: item.categoryId
649
+ };
650
+ })), (0, _toConsumableArray2.default)((_seleccion$extraRetai = seleccion.extraRetailers) !== null && _seleccion$extraRetai !== void 0 ? _seleccion$extraRetai : []));
651
+ return {
652
+ attributes: seleccion.modes.attributes === "all" ? "all-filled" : seleccion.chosen.attributes,
653
+ descriptions: seleccion.modes.descriptions === "all" ? "all" : seleccion.chosen.descriptions,
654
+ images: seleccion.modes.images === "all" ? "all" : seleccion.chosen.images,
655
+ categoryRetailers: parejas.filter(function (par) {
656
+ return seleccion.chosen.categoryRetailers.includes(par.clave);
657
+ }).map(function (_ref8) {
658
+ var retailerId = _ref8.retailerId,
659
+ categoryId = _ref8.categoryId;
660
+ return {
661
+ retailerId: retailerId,
662
+ categoryId: categoryId
663
+ };
664
+ })
665
+ };
666
+ };
667
+
668
+ var seleccionVacia = function seleccionVacia() {
669
+ return {
670
+ modes: {
671
+ categoryRetailers: null,
672
+ descriptions: null,
673
+ attributes: null,
674
+ images: null
675
+ },
676
+ chosen: {
677
+ attributes: [],
678
+ descriptions: [],
679
+ images: [],
680
+ categoryRetailers: []
681
+ },
682
+ extraRetailers: []
683
+ };
684
+ };
685
+ /*
686
+ Cambia de pestaña conservando lo elegido en la anterior. Sin esto, moverse
687
+ entre productos borraría el trabajo hecho en cada uno.
688
+ */
689
+
690
+
691
+ var switchChild = function switchChild(id) {
692
+ var _perChild$id, _guardado$extraRetail;
693
+
694
+ setPerChild(function (current) {
695
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, current), {}, (0, _defineProperty2.default)({}, activeChild, {
696
+ modes: modes,
697
+ chosen: chosen,
698
+ extraRetailers: extraRetailers
699
+ }));
700
+ });
701
+ var guardado = (_perChild$id = perChild[id]) !== null && _perChild$id !== void 0 ? _perChild$id : seleccionVacia();
702
+ setModes(guardado.modes);
703
+ setChosen(guardado.chosen);
704
+ setExtraRetailers((_guardado$extraRetail = guardado.extraRetailers) !== null && _guardado$extraRetail !== void 0 ? _guardado$extraRetail : []);
705
+ setActiveChild(id);
706
+ };
414
707
 
415
708
  var submit = /*#__PURE__*/function () {
416
- var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
417
- var todasLasParejas, inherit, body, data;
418
- return _regenerator.default.wrap(function _callee4$(_context4) {
709
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
710
+ var inherit, inheritByChild, body, data;
711
+ return _regenerator.default.wrap(function _callee6$(_context6) {
419
712
  while (1) {
420
- switch (_context4.prev = _context4.next) {
713
+ switch (_context6.prev = _context6.next) {
421
714
  case 0:
422
715
  setLoading(true);
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));
433
- inherit = {
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
- })
447
- };
716
+ setError(null);
717
+ inherit = buildInherit({
718
+ modes: modes,
719
+ chosen: chosen,
720
+ extraRetailers: extraRetailers
721
+ }); // Con las pestañas abiertas cada producto manda la suya. La selección de la
722
+ // pestaña a la vista todavía no está en perChild, así que se agrega aquí: si
723
+ // no, lo último que tocó el usuario se perdería al guardar.
724
+
725
+ inheritByChild = !applyToAll && mode === "children" ? selected.reduce(function (acc, id) {
726
+ var guardado = id === activeChild ? {
727
+ modes: modes,
728
+ chosen: chosen,
729
+ extraRetailers: extraRetailers
730
+ } : perChild[id];
731
+ if (guardado) acc[id] = buildInherit(guardado);
732
+ return acc;
733
+ }, {}) : undefined;
448
734
  body = mode === "parent" ? {
449
735
  mode: mode,
450
736
  articleId: articleId,
451
737
  parentArticleId: selected[0],
452
738
  inherit: inherit
453
- } : {
739
+ } : (0, _objectSpread6.default)({
454
740
  mode: mode,
455
741
  parentArticleId: articleId,
456
742
  childrenArticleIds: selected,
457
743
  inherit: inherit
458
- };
459
- _context4.prev = 5;
460
- _context4.next = 8;
744
+ }, inheritByChild ? {
745
+ inheritByChild: inheritByChild
746
+ } : {});
747
+ _context6.prev = 5;
748
+ _context6.next = 8;
461
749
  return request("link", body);
462
750
 
463
751
  case 8:
464
- data = _context4.sent;
752
+ data = _context6.sent;
465
753
  // El modo importa para quien escucha: en `children` este producto GANA
466
754
  // variantes; en `parent` pasa a SER una. Son efectos opuestos sobre la
467
755
  // 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), {}, {
756
+ onLinked === null || onLinked === void 0 ? void 0 : onLinked((0, _objectSpread6.default)((0, _objectSpread6.default)({}, data), {}, {
469
757
  mode: mode,
470
758
  parentArticleId: mode === "parent" ? selected[0] : articleId
471
759
  }));
472
760
  onClose === null || onClose === void 0 ? void 0 : onClose();
473
- _context4.next = 16;
761
+ _context6.next = 16;
474
762
  break;
475
763
 
476
764
  case 13:
477
- _context4.prev = 13;
478
- _context4.t0 = _context4["catch"](5);
479
- setError(readError(_context4.t0));
765
+ _context6.prev = 13;
766
+ _context6.t0 = _context6["catch"](5);
767
+ setError(readError(_context6.t0));
480
768
 
481
769
  case 16:
482
- _context4.prev = 16;
770
+ _context6.prev = 16;
483
771
  setLoading(false);
484
- return _context4.finish(16);
772
+ return _context6.finish(16);
485
773
 
486
774
  case 19:
487
775
  case "end":
488
- return _context4.stop();
776
+ return _context6.stop();
489
777
  }
490
778
  }
491
- }, _callee4, null, [[5, 13, 16, 19]]);
779
+ }, _callee6, null, [[5, 13, 16, 19]]);
492
780
  }));
493
781
 
494
782
  return function submit() {
495
- return _ref7.apply(this, arguments);
783
+ return _ref9.apply(this, arguments);
496
784
  };
497
- }();
785
+ }(); // Una dimensión está decidida si el usuario eligió un modo, o si el padre no
786
+ // ofrece nada en ella —no se puede pedir que decida sobre una lista vacía—.
498
787
 
788
+
789
+ var decidida = function decidida(dimension) {
790
+ return modes[dimension] !== null || (dimension === "categoryRetailers" ? offered.categoryRetailers.length === 0 && extraRetailers.length === 0 : offered[dimension].length === 0);
791
+ };
792
+
793
+ var DIMENSIONES = ["categoryRetailers", "descriptions", "attributes", "images"]; // Con pestañas, que la que estoy viendo esté completa no basta: ligar escribe
794
+ // en todos, así que todos tienen que estar decididos. Si no, un producto se
795
+ // ligaría sin heredar nada solo porque nadie abrió su pestaña.
796
+
797
+ var decididoPara = function decididoPara(id) {
798
+ var guardado = id === activeChild ? {
799
+ modes: modes,
800
+ chosen: chosen,
801
+ extraRetailers: extraRetailers
802
+ } : perChild[id];
803
+ if (!guardado) return false;
804
+ return DIMENSIONES.every(function (dimension) {
805
+ var _guardado$extraRetail2;
806
+
807
+ if (guardado.modes[dimension] !== null) return true;
808
+ return dimension === "categoryRetailers" ? offered.categoryRetailers.length === 0 && ((_guardado$extraRetail2 = guardado.extraRetailers) !== null && _guardado$extraRetail2 !== void 0 ? _guardado$extraRetail2 : []).length === 0 : offered[dimension].length === 0;
809
+ });
810
+ };
811
+
812
+ var todoDecidido = step === "inherit" && (applyToAll || mode !== "children" ? DIMENSIONES.every(decidida) : selected.every(decididoPara));
813
+ var faltantes = [["categoryRetailers", "cadenas"], ["descriptions", "descripciones"], ["attributes", "atributos"], ["images", "imágenes"]].filter(function (_ref10) {
814
+ var _ref11 = (0, _slicedToArray2.default)(_ref10, 1),
815
+ clave = _ref11[0];
816
+
817
+ return !decidida(clave);
818
+ }).map(function (_ref12) {
819
+ var _ref13 = (0, _slicedToArray2.default)(_ref12, 2),
820
+ nombre = _ref13[1];
821
+
822
+ return nombre;
823
+ });
499
824
  var selectionLabel = mode === "parent" ? "Se elige un solo producto padre." : "".concat(selected.length, " producto(s) pasar\xE1n a ser variantes.");
500
825
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Overlay, {
501
826
  onClick: onClose,
@@ -580,241 +905,377 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
580
905
  })
581
906
  }, candidate.articleId);
582
907
  })
908
+ }), searched && candidates.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Paging, {
909
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
910
+ children: ["Mostrando ", candidates.length, " de ", total]
911
+ }), hasMore && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
912
+ type: "button",
913
+ onClick: loadMore,
914
+ disabled: loadingMore,
915
+ children: loadingMore ? "Cargando…" : "Cargar más"
916
+ })]
583
917
  })]
584
918
  }), step === "inherit" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
585
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
586
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
587
- children: "Atributos de la ficha t\xE9cnica"
588
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
589
- className: "choice",
919
+ children: [mode === "children" && selected.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
920
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
921
+ className: "apply-all",
590
922
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
591
- type: "radio",
592
- checked: inheritMode === "all-filled",
593
- onChange: function onChange() {
594
- return setInheritMode("all-filled");
923
+ type: "checkbox",
924
+ checked: applyToAll,
925
+ onChange: function onChange(event) {
926
+ setApplyToAll(event.target.checked);
927
+ if (event.target.checked) setPerChild({});
595
928
  }
596
929
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
597
- children: ["Todos los que tienen valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
930
+ children: ["Aplicar lo mismo a los ", selected.length, " productos", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
598
931
  className: "hint",
599
- children: [offered.attributes.length, " atributo(s) con informaci\xF3n en el padre."]
600
- })]
601
- })]
602
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
603
- className: "choice",
604
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
605
- type: "radio",
606
- checked: inheritMode === "selected",
607
- onChange: function onChange() {
608
- return setInheritMode("selected");
609
- }
610
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
611
- children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
612
- className: "hint",
613
- children: "Lo que no elijas conserva el valor que ya tiene la variante."
932
+ children: "Desm\xE1rcalo si alguno debe heredar algo distinto."
614
933
  })]
615
934
  })]
935
+ }), !applyToAll && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Tabs, {
936
+ children: selected.map(function (id, indice) {
937
+ var producto = candidates.find(function (item) {
938
+ return item.articleId === id;
939
+ });
940
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
941
+ type: "button",
942
+ className: id === activeChild ? "active" : "",
943
+ onClick: function onClick() {
944
+ return switchChild(id);
945
+ },
946
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
947
+ className: "orden",
948
+ children: indice + 1
949
+ }), (producto === null || producto === void 0 ? void 0 : producto.name) || "Producto ".concat(id), decididoPara(id) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
950
+ className: "listo",
951
+ "aria-label": "listo",
952
+ children: "\u2713"
953
+ })]
954
+ }, id);
955
+ })
616
956
  })]
617
- }), inheritMode === "selected" && activeRetailerId && !nameScope && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
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."
619
- }), inheritMode === "selected" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
620
- children: offered.attributes.map(function (attribute) {
621
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
622
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
623
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
624
- type: "checkbox",
625
- checked: chosen.attributes.includes(attribute.id),
626
- onChange: function onChange() {
627
- return toggleChoice("attributes", attribute.id);
628
- }
629
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
630
- children: [attribute.name, attribute.unconfigured && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
631
- className: "note",
632
- children: "sin configuraci\xF3n en las cadenas del padre"
633
- }), attribute.ambiguousName && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
634
- className: "note",
635
- children: "se llama distinto en otra cadena"
636
- })]
637
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
638
- className: "value",
639
- title: attribute.value,
640
- children: attribute.value
957
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Block, {
958
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
959
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
960
+ className: "paso",
961
+ children: "1"
962
+ }), " Cadenas y categor\xEDas"]
963
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
964
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
965
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
966
+ type: "radio",
967
+ checked: modes.categoryRetailers === "all",
968
+ onChange: function onChange() {
969
+ return chooseMode("categoryRetailers", "all", offered.categoryRetailers.map(function (item) {
970
+ return "".concat(item.retailerId, "-").concat(item.categoryId);
971
+ }));
972
+ }
973
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
974
+ children: ["Todas las del producto padre", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
975
+ className: "hint",
976
+ children: [offered.categoryRetailers.length, " cadena(s)."]
977
+ })]
978
+ })]
979
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
980
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
981
+ type: "radio",
982
+ checked: modes.categoryRetailers === "some",
983
+ onChange: function onChange() {
984
+ return chooseMode("categoryRetailers", "some", []);
985
+ }
986
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
987
+ children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
988
+ className: "hint",
989
+ children: "Tambi\xE9n puedes agregar una cadena que el padre no tenga."
641
990
  })]
642
- })
643
- }, attribute.id);
644
- })
645
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
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
991
  })]
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"
667
992
  })]
668
- }), openSection === "descriptions" && (offered.descriptions.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
669
- children: offered.descriptions.map(function (item) {
993
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
994
+ children: [].concat((0, _toConsumableArray2.default)(offered.categoryRetailers.map(function (item) {
995
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, item), {}, {
996
+ clave: "".concat(item.retailerId, "-").concat(item.categoryId),
997
+ delPadre: true
998
+ });
999
+ })), (0, _toConsumableArray2.default)(extraRetailers.map(function (item) {
1000
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, item), {}, {
1001
+ delPadre: false
1002
+ });
1003
+ }))).map(function (item) {
670
1004
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
671
1005
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
672
1006
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
673
1007
  type: "checkbox",
674
- checked: chosen.descriptions.includes(item.id),
1008
+ disabled: modes.categoryRetailers === "all",
1009
+ checked: chosen.categoryRetailers.includes(item.clave),
675
1010
  onChange: function onChange() {
676
- return toggleChoice("descriptions", item.id);
1011
+ return toggleChoice("categoryRetailers", item.clave);
677
1012
  }
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
1013
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
1014
+ className: "logo",
1015
+ src: (0, _helper.getRetailerPicture)(item.retailerId, 24, 24),
1016
+ alt: ""
1017
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1018
+ children: [item.retailerName, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1019
+ className: "meta",
1020
+ children: [item.categoryName || "Sin categoría", !item.delPadre && " · no la tiene el padre"]
1021
+ })]
684
1022
  })]
685
1023
  })
686
- }, item.id);
1024
+ }, item.clave);
687
1025
  })
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");
1026
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.AddRetailer, {
1027
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
1028
+ value: newRetailer,
1029
+ onChange: function onChange(event) {
1030
+ var valor = event.target.value;
1031
+ setNewRetailer(valor);
1032
+ setNewDepartment("");
1033
+ setNewCategory("");
1034
+ if (valor) loadFilters(valor, null);
699
1035
  },
700
- children: ["Im\xE1genes", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
701
- className: "count",
702
- children: [chosen.images.length, " de ", offered.images.length]
1036
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1037
+ value: "",
1038
+ children: "Agregar otra cadena\u2026"
1039
+ }), filters.retailers.map(function (item) {
1040
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1041
+ value: item.value,
1042
+ children: item.label
1043
+ }, item.value);
703
1044
  })]
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
- }));
1045
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
1046
+ value: newDepartment,
1047
+ disabled: !newRetailer || !filters.departments.length,
1048
+ onChange: function onChange(event) {
1049
+ var valor = event.target.value;
1050
+ setNewDepartment(valor);
1051
+ setNewCategory("");
1052
+ if (valor) loadFilters(newRetailer, valor);
1053
+ },
1054
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1055
+ value: "",
1056
+ children: "Departamento\u2026"
1057
+ }), filters.departments.map(function (item) {
1058
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1059
+ value: item.value,
1060
+ children: item.label
1061
+ }, item.value);
1062
+ })]
1063
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
1064
+ value: newCategory,
1065
+ disabled: !newDepartment || !filters.categories.length,
1066
+ onChange: function onChange(event) {
1067
+ return setNewCategory(event.target.value);
711
1068
  },
712
- children: chosen.images.length === offered.images.length ? "Ninguna" : "Todas"
1069
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1070
+ value: "",
1071
+ children: "Categor\xEDa\u2026"
1072
+ }), filters.categories.map(function (item) {
1073
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
1074
+ value: item.value,
1075
+ children: item.label
1076
+ }, item.value);
1077
+ })]
1078
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
1079
+ type: "button",
1080
+ onClick: addRetailer,
1081
+ disabled: !newRetailer || !newCategory || loadingFilters,
1082
+ children: loadingFilters ? "…" : "Agregar"
713
1083
  })]
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" : "",
1084
+ })]
1085
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Block, {
1086
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
1087
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1088
+ className: "paso",
1089
+ children: "2"
1090
+ }), " Descripciones"]
1091
+ }), offered.descriptions.length ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1092
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
1093
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
718
1094
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
719
- type: "checkbox",
720
- checked: chosen.images.includes(image.id),
1095
+ type: "radio",
1096
+ checked: modes.descriptions === "all",
721
1097
  onChange: function onChange() {
722
- return toggleChoice("images", image.id);
1098
+ return chooseMode("descriptions", "all", offered.descriptions.map(function (item) {
1099
+ return item.id;
1100
+ }));
723
1101
  }
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"
1102
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1103
+ children: ["Todas las que tienen valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1104
+ className: "hint",
1105
+ children: [offered.descriptions.length, " descripci\xF3n(es) con informaci\xF3n en el padre."]
1106
+ })]
729
1107
  })]
730
- }, image.id);
731
- })
1108
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1109
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1110
+ type: "radio",
1111
+ checked: modes.descriptions === "some",
1112
+ onChange: function onChange() {
1113
+ return chooseMode("descriptions", "some", []);
1114
+ }
1115
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1116
+ children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1117
+ className: "hint",
1118
+ children: "Lo que no elijas conserva el valor que ya tiene la variante."
1119
+ })]
1120
+ })]
1121
+ })]
1122
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
1123
+ children: offered.descriptions.map(function (item) {
1124
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
1125
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1126
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1127
+ type: "checkbox",
1128
+ disabled: modes.descriptions === "all",
1129
+ checked: chosen.descriptions.includes(item.id),
1130
+ onChange: function onChange() {
1131
+ return toggleChoice("descriptions", item.id);
1132
+ }
1133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1134
+ children: [item.name, item.duplicated && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1135
+ className: "note",
1136
+ children: ["el padre tiene ", item.rows, " versiones de este texto; se copian todas"]
1137
+ })]
1138
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1139
+ className: "value",
1140
+ title: item.value,
1141
+ children: item.value
1142
+ })]
1143
+ })
1144
+ }, item.id);
1145
+ })
1146
+ })]
732
1147
  }) : /*#__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)"]
1148
+ children: "El producto padre no tiene descripciones que heredar."
1149
+ })]
1150
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Block, {
1151
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
1152
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1153
+ className: "paso",
1154
+ children: "3"
1155
+ }), " Atributos de la ficha t\xE9cnica"]
1156
+ }), offered.attributes.length ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1157
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
1158
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1159
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1160
+ type: "radio",
1161
+ checked: modes.attributes === "all",
1162
+ onChange: function onChange() {
1163
+ return chooseMode("attributes", "all", offered.attributes.map(function (item) {
1164
+ return item.id;
1165
+ }));
1166
+ }
1167
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1168
+ children: ["Todos los que tienen valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1169
+ className: "hint",
1170
+ children: [offered.attributes.length, " atributo(s) con informaci\xF3n en el padre."]
1171
+ })]
1172
+ })]
1173
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1174
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1175
+ type: "radio",
1176
+ checked: modes.attributes === "some",
1177
+ onChange: function onChange() {
1178
+ return chooseMode("attributes", "some", []);
1179
+ }
1180
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1181
+ children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1182
+ className: "hint",
1183
+ children: "Lo que no elijas conserva el valor que ya tiene la variante."
1184
+ })]
1185
+ })]
747
1186
  })]
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
755
- });
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) {
1187
+ }), activeRetailerId && !nameScope && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
1188
+ 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."
1189
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
1190
+ children: offered.attributes.map(function (attribute) {
761
1191
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
762
1192
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
763
1193
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
764
1194
  type: "checkbox",
765
- checked: chosen.categoryRetailers.includes(item.clave),
1195
+ disabled: modes.attributes === "all",
1196
+ checked: chosen.attributes.includes(attribute.id),
766
1197
  onChange: function onChange() {
767
- return toggleChoice("categoryRetailers", item.clave);
1198
+ return toggleChoice("attributes", attribute.id);
768
1199
  }
769
1200
  }), /*#__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"]
1201
+ children: [attribute.name, attribute.unconfigured && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1202
+ className: "note",
1203
+ children: "sin configuraci\xF3n en las cadenas del padre"
1204
+ }), attribute.ambiguousName && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1205
+ className: "note",
1206
+ children: "se llama distinto en otra cadena"
773
1207
  })]
1208
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1209
+ className: "value",
1210
+ title: attribute.value,
1211
+ children: attribute.value
774
1212
  })]
775
1213
  })
776
- }, item.clave);
1214
+ }, attribute.id);
777
1215
  })
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);
1216
+ })]
1217
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
1218
+ children: "El producto padre no tiene atributos con valor que heredar."
1219
+ })]
1220
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Block, {
1221
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
1222
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1223
+ className: "paso",
1224
+ children: "4"
1225
+ }), " Im\xE1genes"]
1226
+ }), offered.images.length ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1227
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
1228
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1229
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1230
+ type: "radio",
1231
+ checked: modes.images === "all",
1232
+ onChange: function onChange() {
1233
+ return chooseMode("images", "all", offered.images.map(function (item) {
1234
+ return item.id;
1235
+ }));
1236
+ }
1237
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1238
+ children: ["Todas", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1239
+ className: "hint",
1240
+ children: [offered.images.length, " imagen(es) en el padre."]
1241
+ })]
794
1242
  })]
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);
1243
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1244
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1245
+ type: "radio",
1246
+ checked: modes.images === "some",
1247
+ onChange: function onChange() {
1248
+ return chooseMode("images", "some", []);
1249
+ }
1250
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
1251
+ children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1252
+ className: "hint",
1253
+ children: "\xDAtil cuando la variante cambia de color o de empaque."
1254
+ })]
810
1255
  })]
811
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
812
- type: "button",
813
- onClick: addRetailer,
814
- disabled: !newRetailer || !newCategory,
815
- children: "Agregar"
816
1256
  })]
1257
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ImageGrid, {
1258
+ children: offered.images.map(function (image) {
1259
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1260
+ className: [chosen.images.includes(image.id) ? "picked" : "", modes.images === "all" ? "locked" : ""].filter(Boolean).join(" "),
1261
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
1262
+ type: "checkbox",
1263
+ disabled: modes.images === "all",
1264
+ checked: chosen.images.includes(image.id),
1265
+ onChange: function onChange() {
1266
+ return toggleChoice("images", image.id);
1267
+ }
1268
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
1269
+ src: (0, _helper.getProductImage)(image.src),
1270
+ alt: image.imageType || "Imagen del producto"
1271
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1272
+ children: image.imageType || "Sin tipo de toma"
1273
+ })]
1274
+ }, image.id);
1275
+ })
817
1276
  })]
1277
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
1278
+ children: "El producto padre no tiene im\xE1genes que heredar."
818
1279
  })]
819
1280
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
820
1281
  children: "Lo que elijas heredar reemplaza el valor actual de la variante, incluso si alguien lo hab\xEDa capturado a mano."
@@ -823,7 +1284,9 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
823
1284
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Footer, {
824
1285
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
825
1286
  className: "summary",
826
- children: step === "search" ? selectionLabel : "Revisa la herencia antes de ligar."
1287
+ children: step === "search" ? selectionLabel : todoDecidido ? "Todo revisado. Puedes ligar." : !applyToAll && mode === "children" ? "Faltan ".concat(selected.filter(function (id) {
1288
+ return !decididoPara(id);
1289
+ }).length, " producto(s) por revisar.") : "Falta decidir: ".concat(faltantes.join(", "), ".")
827
1290
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
828
1291
  className: "actions",
829
1292
  children: [step === "inherit" && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
@@ -850,10 +1313,7 @@ var LinkVariantsModal = function LinkVariantsModal(_ref) {
850
1313
  type: "button",
851
1314
  className: "primary",
852
1315
  onClick: submit,
853
- disabled: loading || // Solo estorba cuando hay algo que elegir y no se eligió nada.
854
- // Con el padre sin atributos heredables, ligar sigue siendo
855
- // válido: se heredan imágenes, descripciones y cadenas.
856
- inheritMode === "selected" && offered.attributes.length > 0 && !chosen.attributes.length,
1316
+ disabled: loading || !todoDecidido,
857
1317
  children: loading ? "Ligando…" : "Ligar"
858
1318
  })]
859
1319
  })]