contentoh-components-library 21.6.46 → 21.6.49

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.
@@ -7,10 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.PropagateChangesModal = void 0;
9
9
 
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
11
-
12
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
13
11
 
12
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
13
+
14
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
15
15
 
16
16
  var _react = require("react");
@@ -49,6 +49,10 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
49
49
  changedAttributes = _ref$changedAttribute === void 0 ? [] : _ref$changedAttribute,
50
50
  _ref$variants = _ref.variants,
51
51
  variants = _ref$variants === void 0 ? [] : _ref$variants,
52
+ _ref$groupMembers = _ref.groupMembers,
53
+ groupMembers = _ref$groupMembers === void 0 ? [] : _ref$groupMembers,
54
+ _ref$groupCode = _ref.groupCode,
55
+ groupCode = _ref$groupCode === void 0 ? null : _ref$groupCode,
52
56
  onCancel = _ref.onCancel,
53
57
  onConfirm = _ref.onConfirm,
54
58
  _ref$saving = _ref.saving,
@@ -58,18 +62,57 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
58
62
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
59
63
  chosenAttributes = _useState2[0],
60
64
  setChosenAttributes = _useState2[1];
65
+ /*
66
+ DOS DESTINOS INDEPENDIENTES, y esa independencia es el punto.
67
+ hijos cuelgan de este producto y heredan de él. Hay jerarquía.
68
+ variantes comparten un código de grupo. No hay jerarquía; son el mismo
69
+ producto en otra presentación.
70
+ Elegir variantes NO debe alcanzar a los hijos ni al revés, así que cada uno
71
+ lleva su propio alcance y su propia selección. Un solo control con tres
72
+ opciones —hijos / variantes / ambos— no bastaría: el usuario también tiene
73
+ que poder decir "a estas dos variantes y a ese hijo".
74
+ Arrancan en "none" los dos: propagar sobrescribe, así que ningún destino se
75
+ da por elegido sin que alguien lo pida.
76
+ */
77
+
61
78
 
62
- var _useState3 = (0, _react.useState)("all"),
79
+ var _useState3 = (0, _react.useState)("none"),
63
80
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
64
- scope = _useState4[0],
65
- setScope = _useState4[1];
81
+ scopeChildren = _useState4[0],
82
+ setScopeChildren = _useState4[1];
66
83
 
67
84
  var _useState5 = (0, _react.useState)([]),
68
85
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
69
86
  chosenChildren = _useState6[0],
70
87
  setChosenChildren = _useState6[1];
71
88
 
72
- var destinatarios = scope === "all" ? variants.length : chosenChildren.length;
89
+ var _useState7 = (0, _react.useState)("none"),
90
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
91
+ scopeVariants = _useState8[0],
92
+ setScopeVariants = _useState8[1];
93
+
94
+ var _useState9 = (0, _react.useState)([]),
95
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
96
+ chosenVariants = _useState10[0],
97
+ setChosenVariants = _useState10[1];
98
+
99
+ var seleccion = function seleccion(scope, todos, elegidos) {
100
+ if (scope === "none") return [];
101
+ if (scope === "all") return todos;
102
+ return todos.filter(function (item) {
103
+ return elegidos.includes(item.articleId);
104
+ });
105
+ };
106
+
107
+ var hijosDestino = seleccion(scopeChildren, variants, chosenChildren);
108
+ var variantesDestino = seleccion(scopeVariants, groupMembers, chosenVariants); // Un producto puede ser hijo Y estar en el grupo: se cuenta una sola vez.
109
+
110
+ var idsDestino = new Set([].concat((0, _toConsumableArray2.default)(hijosDestino.map(function (x) {
111
+ return x.articleId;
112
+ })), (0, _toConsumableArray2.default)(variantesDestino.map(function (x) {
113
+ return x.articleId;
114
+ }))));
115
+ var destinatarios = idsDestino.size;
73
116
  var puedePropagar = chosenAttributes.length > 0 && destinatarios > 0;
74
117
  var enSegundoPlano = destinatarios > UMBRAL_SEGUNDO_PLANO;
75
118
  /*
@@ -83,8 +126,10 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
83
126
  salida que el aviso debería estar ofreciendo.
84
127
  */
85
128
 
86
- var destinos = scope === "all" ? variants : variants.filter(function (item) {
87
- return chosenChildren.includes(item.articleId);
129
+ var destinos = [].concat((0, _toConsumableArray2.default)(hijosDestino), (0, _toConsumableArray2.default)(variantesDestino)).filter(function (item, i, lista) {
130
+ return lista.findIndex(function (x) {
131
+ return x.articleId === item.articleId;
132
+ }) === i;
88
133
  });
89
134
  var conValorPropio = destinos.map(function (hijo) {
90
135
  var _hijo$overriddenAttri;
@@ -106,18 +151,32 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
106
151
  });
107
152
  };
108
153
 
109
- var toggleChild = function toggleChild(id) {
110
- setChosenChildren(function (current) {
111
- return current.includes(id) ? current.filter(function (item) {
112
- return item !== id;
113
- }) : [].concat((0, _toConsumableArray2.default)(current), [id]);
114
- });
154
+ var toggleEn = function toggleEn(setter) {
155
+ return function (id) {
156
+ setter(function (current) {
157
+ return current.includes(id) ? current.filter(function (item) {
158
+ return item !== id;
159
+ }) : [].concat((0, _toConsumableArray2.default)(current), [id]);
160
+ });
161
+ };
115
162
  };
116
163
 
164
+ var toggleChild = toggleEn(setChosenChildren);
165
+ var toggleVariant = toggleEn(setChosenVariants);
166
+
117
167
  var confirmar = function confirmar() {
168
+ // Se manda "none" explícito y no una lista vacía para que el servidor no
169
+ // tenga que adivinar si "sin ids" quiere decir "a ninguno" o "no me lo
170
+ // preguntaron". Cada destino viaja por su cuenta.
171
+ var comoLista = function comoLista(scope, elegidos) {
172
+ if (scope === "none") return "none";
173
+ return scope === "all" ? "all" : elegidos;
174
+ };
175
+
118
176
  onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm({
119
177
  attributes: chosenAttributes,
120
- targetChildren: scope === "all" ? "all" : chosenChildren
178
+ targetChildren: comoLista(scopeChildren, chosenChildren),
179
+ targetVariants: comoLista(scopeVariants, chosenVariants)
121
180
  });
122
181
  };
123
182
 
@@ -128,13 +187,13 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
128
187
  },
129
188
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Header, {
130
189
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h2", {
131
- children: ["Este producto tiene ", variants.length, " hijo", variants.length === 1 ? "" : "s"]
190
+ children: [[variants.length ? "".concat(variants.length, " hijo").concat(variants.length === 1 ? "" : "s") : null, groupMembers.length ? "".concat(groupMembers.length, " variante").concat(groupMembers.length === 1 ? "" : "s") : null].filter(Boolean).join(" y "), " pueden recibir este cambio"]
132
191
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
133
- children: ["Cambiaste ", changedAttributes.length, " atributo", changedAttributes.length === 1 ? "" : "s", ". Elige cu\xE1les bajan a los hijos; el resto se guarda solo en este producto."]
192
+ children: ["Cambiaste ", changedAttributes.length, " atributo", changedAttributes.length === 1 ? "" : "s", ". Elige cu\xE1les se copian y a qui\xE9nes; el resto se guarda solo en este producto."]
134
193
  })]
135
194
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Body, {
136
195
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
137
- children: "\xBFQu\xE9 se baja a los hijos?"
196
+ children: "\xBFQu\xE9 se copia?"
138
197
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
139
198
  children: changedAttributes.map(function (attribute) {
140
199
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
@@ -155,54 +214,122 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
155
214
  })
156
215
  }, attribute.id);
157
216
  })
158
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
159
- children: "\xBFA cu\xE1les?"
160
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
161
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
162
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
163
- type: "radio",
164
- name: "propagation-scope",
165
- checked: scope === "all",
166
- onChange: function onChange() {
167
- return setScope("all");
168
- }
169
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
170
- children: ["A todos", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
171
- className: "hint",
172
- children: [variants.length, " hijo", variants.length === 1 ? "" : "s", " activo", variants.length === 1 ? "" : "s", "."]
217
+ }), variants.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
218
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
219
+ children: ["\xBFA cu\xE1les de los ", variants.length, " hijo", variants.length === 1 ? "" : "s", "?"]
220
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
221
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
222
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
223
+ type: "radio",
224
+ name: "scope-children",
225
+ checked: scopeChildren === "none",
226
+ onChange: function onChange() {
227
+ return setScopeChildren("none");
228
+ }
229
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
230
+ children: "A ninguno"
231
+ })]
232
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
233
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
234
+ type: "radio",
235
+ name: "scope-children",
236
+ checked: scopeChildren === "all",
237
+ onChange: function onChange() {
238
+ return setScopeChildren("all");
239
+ }
240
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
241
+ children: "A todos"
242
+ })]
243
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
244
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
245
+ type: "radio",
246
+ name: "scope-children",
247
+ checked: scopeChildren === "some",
248
+ onChange: function onChange() {
249
+ return setScopeChildren("some");
250
+ }
251
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
252
+ children: "Elegir cu\xE1les"
173
253
  })]
174
254
  })]
175
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
176
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
177
- type: "radio",
178
- name: "propagation-scope",
179
- checked: scope === "some",
180
- onChange: function onChange() {
181
- return setScope("some");
182
- }
183
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
184
- children: "Elegir cu\xE1les"
185
- })]
255
+ }), scopeChildren === "some" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
256
+ children: variants.map(function (variant) {
257
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
258
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
259
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
260
+ type: "checkbox",
261
+ checked: chosenChildren.includes(variant.articleId),
262
+ onChange: function onChange() {
263
+ return toggleChild(variant.articleId);
264
+ }
265
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
266
+ children: [variant.name, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
267
+ className: "meta",
268
+ children: ["UPC ", variant.upc || "—"]
269
+ })]
270
+ })]
271
+ })
272
+ }, variant.articleId);
273
+ })
186
274
  })]
187
- }), scope === "some" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
188
- children: variants.map(function (variant) {
189
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
190
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
191
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
192
- type: "checkbox",
193
- checked: chosenChildren.includes(variant.articleId),
194
- onChange: function onChange() {
195
- return toggleChild(variant.articleId);
196
- }
197
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
198
- children: [variant.name, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
199
- className: "meta",
200
- children: ["UPC ", variant.upc || "—"]
275
+ }), groupMembers.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
276
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
277
+ children: ["\xBFA cu\xE1les de las ", groupMembers.length, " variante", groupMembers.length === 1 ? "" : "s", groupCode ? " del grupo ".concat(groupCode) : "", "?"]
278
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
279
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
280
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
281
+ type: "radio",
282
+ name: "scope-variants",
283
+ checked: scopeVariants === "none",
284
+ onChange: function onChange() {
285
+ return setScopeVariants("none");
286
+ }
287
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
288
+ children: "A ninguna"
289
+ })]
290
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
291
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
292
+ type: "radio",
293
+ name: "scope-variants",
294
+ checked: scopeVariants === "all",
295
+ onChange: function onChange() {
296
+ return setScopeVariants("all");
297
+ }
298
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
299
+ children: "A todas"
300
+ })]
301
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
302
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
303
+ type: "radio",
304
+ name: "scope-variants",
305
+ checked: scopeVariants === "some",
306
+ onChange: function onChange() {
307
+ return setScopeVariants("some");
308
+ }
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
310
+ children: "Elegir cu\xE1les"
311
+ })]
312
+ })]
313
+ }), scopeVariants === "some" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
314
+ children: groupMembers.map(function (miembro) {
315
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
316
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
317
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
318
+ type: "checkbox",
319
+ checked: chosenVariants.includes(miembro.articleId),
320
+ onChange: function onChange() {
321
+ return toggleVariant(miembro.articleId);
322
+ }
323
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
324
+ children: [miembro.name, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
325
+ className: "meta",
326
+ children: ["UPC ", miembro.upc || "—"]
327
+ })]
201
328
  })]
202
- })]
203
- })
204
- }, variant.articleId);
205
- })
329
+ })
330
+ }, miembro.articleId);
331
+ })
332
+ })]
206
333
  }), conValorPropio.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Note, {
207
334
  className: "accent",
208
335
  children: [conValorPropio.length === 1 ? "Un hijo tiene un valor propio en lo que elegiste y se va a reemplazar: " : "".concat(conValorPropio.length, " hijos tienen valores propios en lo que elegiste y se van a reemplazar: "), conValorPropio.map(function (hijo) {
@@ -215,7 +342,7 @@ var PropagateChangesModal = function PropagateChangesModal(_ref) {
215
342
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Footer, {
216
343
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
217
344
  className: "resumen",
218
- children: puedePropagar ? "".concat(chosenAttributes.length, " atributo(s) a ").concat(destinatarios, " hijo(s).") : "No se bajará nada a los hijos."
345
+ children: puedePropagar ? "".concat(chosenAttributes.length, " atributo(s) a ").concat(destinatarios, " producto(s).") : "No se copiará nada: elige al menos un atributo y un destino."
219
346
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
220
347
  type: "button",
221
348
  className: "secondary",