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.
@@ -109,7 +109,7 @@ var _material = require("@mui/material");
109
109
 
110
110
  var _jsxRuntime = require("react/jsx-runtime");
111
111
 
112
- var allowedAccountsToViewChangeStatus = ["mperez@contentoh.com", "gmorales@contentoh.com", "rvega@contentoh.com", "amora@contentoh.com", //PRODUCT DEV ACCOUNTS
112
+ var allowedAccountsToViewChangeStatus = ["mperez@contentoh.com", "gmorales@contentoh.com", "rvega@contentoh.com", "amora@contentoh.com", "maltamirano@contentoh.com", //PRODUCT DEV ACCOUNTS
113
113
  "oparra@contentoh.com", "zsegura@contentoh.com", "oserna@contentoh.com", "jalvarado@contentoh.com", //DEV ACCOUNTS
114
114
  "kikije1467@mtlcz.com", //IMÁGENES
115
115
  "karafe3218@mom2kid.com", //TEXTOS
@@ -238,7 +238,7 @@ function _regenerateVideoThumbnails() {
238
238
  }
239
239
 
240
240
  var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
241
- var _state$product10, _family$variants, _state$product11, _state$product15, _state$errors, _family$variants2, _state$product19, _state$product20, _state$product21, _state$active_retaile6, _state$product22, _state$product23, _state$product24, _variantGroup$group, _location$state, _location$state2, _state$active_retaile7, _state$active_retaile8, _state$images_values$2, _state$images_values10, _state$images_values11, _state$product25, _state$active_retaile9, _family$variants3, _family$variants4, _variantGroup$members, _variantGroup$members2, _state$active_percent, _state$active_percent2, _state$active_percent3, _state$active_retaile10, _state$active_retaile11, _state$active_retaile12, _state$product31, _state$services2, _state$services2$data, _state$product32, _state$product33, _state$datasheets_inp, _state$datasheets_inp2, _state$product34, _state$images_values12, _state$comment;
241
+ var _state$product10, _family$variants, _state$product11, _state$product15, _state$errors, _family$variants2, _variantGroup$members2, _variantGroup$group, _state$product19, _state$product20, _state$product21, _state$active_retaile6, _state$product22, _state$product23, _state$product24, _variantGroup$group2, _location$state, _location$state2, _state$active_retaile7, _state$active_retaile8, _state$images_values$2, _state$images_values10, _state$images_values11, _state$product25, _state$active_retaile9, _family$variants3, _family$variants4, _variantGroup$members3, _variantGroup$members4, _state$active_percent, _state$active_percent2, _state$active_percent3, _state$active_retaile10, _state$active_retaile11, _state$active_retaile12, _state$product31, _state$services2, _state$services2$data, _state$product32, _state$product33, _state$datasheets_inp, _state$datasheets_inp2, _state$product34, _state$images_values12, _state$comment;
242
242
 
243
243
  var tabsSections = _ref.tabsSections,
244
244
  _ref$productSelected = _ref.productSelected,
@@ -1811,7 +1811,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1811
1811
 
1812
1812
  var handleOnClickSave = /*#__PURE__*/function () {
1813
1813
  var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11() {
1814
- var _familia$variants, cambios, familia, hijos;
1814
+ var _familia$variants, _variantGroup$members, cambios, familia, hijos, companeras;
1815
1815
 
1816
1816
  return _regenerator.default.wrap(function _callee11$(_context11) {
1817
1817
  while (1) {
@@ -1826,7 +1826,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1826
1826
 
1827
1827
  case 2:
1828
1828
  _context11.t0 = state.active_tab;
1829
- _context11.next = _context11.t0 === "Descripción" ? 5 : _context11.t0 === "Ficha técnica" ? 8 : _context11.t0 === "Imágenes" ? 32 : 35;
1829
+ _context11.next = _context11.t0 === "Descripción" ? 5 : _context11.t0 === "Ficha técnica" ? 8 : _context11.t0 === "Imágenes" ? 33 : 36;
1830
1830
  break;
1831
1831
 
1832
1832
  case 5:
@@ -1834,7 +1834,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1834
1834
  return saveDescriptions(token);
1835
1835
 
1836
1836
  case 7:
1837
- return _context11.abrupt("break", 36);
1837
+ return _context11.abrupt("break", 37);
1838
1838
 
1839
1839
  case 8:
1840
1840
  cambios = cambiosDeFichaTecnica();
@@ -1848,7 +1848,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1848
1848
  return saveDatasheets(token);
1849
1849
 
1850
1850
  case 12:
1851
- return _context11.abrupt("break", 36);
1851
+ return _context11.abrupt("break", 37);
1852
1852
 
1853
1853
  case 13:
1854
1854
  /*
@@ -1924,9 +1924,18 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1924
1924
  hijos = ((_familia$variants = familia.variants) !== null && _familia$variants !== void 0 ? _familia$variants : []).filter(function (v) {
1925
1925
  return !v.isCurrent;
1926
1926
  });
1927
+ /*
1928
+ También cuentan las compañeras de grupo: un producto puede no tener
1929
+ hijos y aun así pertenecer a un grupo de variantes, y el cambio se les
1930
+ puede copiar igual. Si no se miraran, guardar no ofrecería nada.
1931
+ */
1932
+
1933
+ companeras = ((_variantGroup$members = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.members) !== null && _variantGroup$members !== void 0 ? _variantGroup$members : []).filter(function (m) {
1934
+ return !m.isCurrent;
1935
+ });
1927
1936
 
1928
- if (!(hijos.length > 0)) {
1929
- _context11.next = 29;
1937
+ if (!(hijos.length > 0 || companeras.length > 0)) {
1938
+ _context11.next = 30;
1930
1939
  break;
1931
1940
  }
1932
1941
 
@@ -1935,28 +1944,28 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
1935
1944
  });
1936
1945
  return _context11.abrupt("return");
1937
1946
 
1938
- case 29:
1939
- _context11.next = 31;
1947
+ case 30:
1948
+ _context11.next = 32;
1940
1949
  return saveDatasheets(token);
1941
1950
 
1942
- case 31:
1943
- return _context11.abrupt("break", 36);
1944
-
1945
1951
  case 32:
1946
- _context11.next = 34;
1947
- return updateImages(token);
1952
+ return _context11.abrupt("break", 37);
1948
1953
 
1949
- case 34:
1950
- return _context11.abrupt("break", 36);
1954
+ case 33:
1955
+ _context11.next = 35;
1956
+ return updateImages(token);
1951
1957
 
1952
1958
  case 35:
1953
- return _context11.abrupt("break", 36);
1959
+ return _context11.abrupt("break", 37);
1954
1960
 
1955
1961
  case 36:
1956
- _context11.next = 38;
1962
+ return _context11.abrupt("break", 37);
1963
+
1964
+ case 37:
1965
+ _context11.next = 39;
1957
1966
  return loadData(false);
1958
1967
 
1959
- case 38:
1968
+ case 39:
1960
1969
  case "end":
1961
1970
  return _context11.stop();
1962
1971
  }
@@ -2888,6 +2897,10 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
2888
2897
  variants: ((_family$variants2 = family === null || family === void 0 ? void 0 : family.variants) !== null && _family$variants2 !== void 0 ? _family$variants2 : []).filter(function (v) {
2889
2898
  return !v.isCurrent;
2890
2899
  }),
2900
+ groupMembers: ((_variantGroup$members2 = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.members) !== null && _variantGroup$members2 !== void 0 ? _variantGroup$members2 : []).filter(function (m) {
2901
+ return !m.isCurrent;
2902
+ }),
2903
+ groupCode: (_variantGroup$group = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.group) !== null && _variantGroup$group !== void 0 ? _variantGroup$group : null,
2891
2904
  saving: state.saving,
2892
2905
  onCancel: function onCancel() {
2893
2906
  return setPendingPropagation(null);
@@ -2910,7 +2923,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
2910
2923
  articleId: (_state$product22 = state.product) === null || _state$product22 === void 0 ? void 0 : _state$product22.id_article,
2911
2924
  articleName: (_state$product23 = state.product) === null || _state$product23 === void 0 ? void 0 : _state$product23.name,
2912
2925
  articleUpc: (_state$product24 = state.product) === null || _state$product24 === void 0 ? void 0 : _state$product24.upc,
2913
- currentGroup: (_variantGroup$group = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.group) !== null && _variantGroup$group !== void 0 ? _variantGroup$group : null,
2926
+ currentGroup: (_variantGroup$group2 = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.group) !== null && _variantGroup$group2 !== void 0 ? _variantGroup$group2 : null,
2914
2927
  token: token,
2915
2928
  onClose: function onClose() {
2916
2929
  return setShowGroupModal(false);
@@ -3251,7 +3264,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
3251
3264
  })]
3252
3265
  }), showGroup && (variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.group) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
3253
3266
  className: "variants-family",
3254
- children: [((_variantGroup$members = variantGroup.members) !== null && _variantGroup$members !== void 0 ? _variantGroup$members : []).filter(function (miembro) {
3267
+ children: [((_variantGroup$members3 = variantGroup.members) !== null && _variantGroup$members3 !== void 0 ? _variantGroup$members3 : []).filter(function (miembro) {
3255
3268
  return !miembro.isCurrent;
3256
3269
  }).map(function (miembro) {
3257
3270
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -3275,7 +3288,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
3275
3288
  })]
3276
3289
  })
3277
3290
  }, miembro.articleId);
3278
- }), ((_variantGroup$members2 = variantGroup.members) !== null && _variantGroup$members2 !== void 0 ? _variantGroup$members2 : []).filter(function (m) {
3291
+ }), ((_variantGroup$members4 = variantGroup.members) !== null && _variantGroup$members4 !== void 0 ? _variantGroup$members4 : []).filter(function (m) {
3279
3292
  return !m.isCurrent;
3280
3293
  }).length === 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
3281
3294
  className: "loading",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.6.46",
3
+ "version": "21.6.49",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -40,15 +40,50 @@ const UMBRAL_SEGUNDO_PLANO = 20;
40
40
  export const PropagateChangesModal = ({
41
41
  changedAttributes = [],
42
42
  variants = [],
43
+ groupMembers = [],
44
+ groupCode = null,
43
45
  onCancel,
44
46
  onConfirm,
45
47
  saving = false,
46
48
  }) => {
47
49
  const [chosenAttributes, setChosenAttributes] = useState([]);
48
- const [scope, setScope] = useState("all");
50
+
51
+ /*
52
+ DOS DESTINOS INDEPENDIENTES, y esa independencia es el punto.
53
+
54
+ hijos cuelgan de este producto y heredan de él. Hay jerarquía.
55
+ variantes comparten un código de grupo. No hay jerarquía; son el mismo
56
+ producto en otra presentación.
57
+
58
+ Elegir variantes NO debe alcanzar a los hijos ni al revés, así que cada uno
59
+ lleva su propio alcance y su propia selección. Un solo control con tres
60
+ opciones —hijos / variantes / ambos— no bastaría: el usuario también tiene
61
+ que poder decir "a estas dos variantes y a ese hijo".
62
+
63
+ Arrancan en "none" los dos: propagar sobrescribe, así que ningún destino se
64
+ da por elegido sin que alguien lo pida.
65
+ */
66
+ const [scopeChildren, setScopeChildren] = useState("none");
49
67
  const [chosenChildren, setChosenChildren] = useState([]);
68
+ const [scopeVariants, setScopeVariants] = useState("none");
69
+ const [chosenVariants, setChosenVariants] = useState([]);
50
70
 
51
- const destinatarios = scope === "all" ? variants.length : chosenChildren.length;
71
+ const seleccion = (scope, todos, elegidos) => {
72
+ if (scope === "none") return [];
73
+ if (scope === "all") return todos;
74
+ return todos.filter((item) => elegidos.includes(item.articleId));
75
+ };
76
+
77
+ const hijosDestino = seleccion(scopeChildren, variants, chosenChildren);
78
+ const variantesDestino = seleccion(scopeVariants, groupMembers, chosenVariants);
79
+
80
+ // Un producto puede ser hijo Y estar en el grupo: se cuenta una sola vez.
81
+ const idsDestino = new Set([
82
+ ...hijosDestino.map((x) => x.articleId),
83
+ ...variantesDestino.map((x) => x.articleId),
84
+ ]);
85
+
86
+ const destinatarios = idsDestino.size;
52
87
  const puedePropagar = chosenAttributes.length > 0 && destinatarios > 0;
53
88
  const enSegundoPlano = destinatarios > UMBRAL_SEGUNDO_PLANO;
54
89
 
@@ -64,9 +99,9 @@ export const PropagateChangesModal = ({
64
99
  desmarca el atributo conflictivo, el aviso desaparece — que es justo la
65
100
  salida que el aviso debería estar ofreciendo.
66
101
  */
67
- const destinos = scope === "all"
68
- ? variants
69
- : variants.filter((item) => chosenChildren.includes(item.articleId));
102
+ const destinos = [...hijosDestino, ...variantesDestino].filter(
103
+ (item, i, lista) => lista.findIndex((x) => x.articleId === item.articleId) === i
104
+ );
70
105
 
71
106
  const conValorPropio = destinos
72
107
  .map((hijo) => ({
@@ -85,18 +120,30 @@ export const PropagateChangesModal = ({
85
120
  );
86
121
  };
87
122
 
88
- const toggleChild = (id) => {
89
- setChosenChildren((current) =>
123
+ const toggleEn = (setter) => (id) => {
124
+ setter((current) =>
90
125
  current.includes(id)
91
126
  ? current.filter((item) => item !== id)
92
127
  : [...current, id]
93
128
  );
94
129
  };
95
130
 
131
+ const toggleChild = toggleEn(setChosenChildren);
132
+ const toggleVariant = toggleEn(setChosenVariants);
133
+
96
134
  const confirmar = () => {
135
+ // Se manda "none" explícito y no una lista vacía para que el servidor no
136
+ // tenga que adivinar si "sin ids" quiere decir "a ninguno" o "no me lo
137
+ // preguntaron". Cada destino viaja por su cuenta.
138
+ const comoLista = (scope, elegidos) => {
139
+ if (scope === "none") return "none";
140
+ return scope === "all" ? "all" : elegidos;
141
+ };
142
+
97
143
  onConfirm?.({
98
144
  attributes: chosenAttributes,
99
- targetChildren: scope === "all" ? "all" : chosenChildren,
145
+ targetChildren: comoLista(scopeChildren, chosenChildren),
146
+ targetVariants: comoLista(scopeVariants, chosenVariants),
100
147
  });
101
148
  };
102
149
 
@@ -105,18 +152,29 @@ export const PropagateChangesModal = ({
105
152
  <Panel onClick={(event) => event.stopPropagation()}>
106
153
  <Header>
107
154
  <h2>
108
- Este producto tiene {variants.length} hijo
109
- {variants.length === 1 ? "" : "s"}
155
+ {[
156
+ variants.length
157
+ ? `${variants.length} hijo${variants.length === 1 ? "" : "s"}`
158
+ : null,
159
+ groupMembers.length
160
+ ? `${groupMembers.length} variante${
161
+ groupMembers.length === 1 ? "" : "s"
162
+ }`
163
+ : null,
164
+ ]
165
+ .filter(Boolean)
166
+ .join(" y ")}
167
+ {" pueden recibir este cambio"}
110
168
  </h2>
111
169
  <p>
112
170
  Cambiaste {changedAttributes.length} atributo
113
- {changedAttributes.length === 1 ? "" : "s"}. Elige cuáles bajan a los
114
- hijos; el resto se guarda solo en este producto.
171
+ {changedAttributes.length === 1 ? "" : "s"}. Elige cuáles se copian y
172
+ a quiénes; el resto se guarda solo en este producto.
115
173
  </p>
116
174
  </Header>
117
175
 
118
176
  <Body>
119
- <h3>¿Qué se baja a los hijos?</h3>
177
+ <h3>¿Qué se copia?</h3>
120
178
  <List>
121
179
  {changedAttributes.map((attribute) => (
122
180
  <li key={attribute.id}>
@@ -135,52 +193,124 @@ export const PropagateChangesModal = ({
135
193
  ))}
136
194
  </List>
137
195
 
138
- <h3>¿A cuáles?</h3>
139
- <Choices>
140
- <label>
141
- <input
142
- type="radio"
143
- name="propagation-scope"
144
- checked={scope === "all"}
145
- onChange={() => setScope("all")}
146
- />
147
- <span>
148
- A todos
149
- <span className="hint">
150
- {variants.length} hijo{variants.length === 1 ? "" : "s"} activo
151
- {variants.length === 1 ? "" : "s"}.
152
- </span>
153
- </span>
154
- </label>
155
- <label>
156
- <input
157
- type="radio"
158
- name="propagation-scope"
159
- checked={scope === "some"}
160
- onChange={() => setScope("some")}
161
- />
162
- <span>Elegir cuáles</span>
163
- </label>
164
- </Choices>
165
-
166
- {scope === "some" && (
167
- <List>
168
- {variants.map((variant) => (
169
- <li key={variant.articleId}>
170
- <label>
171
- <input
172
- type="checkbox"
173
- checked={chosenChildren.includes(variant.articleId)}
174
- onChange={() => toggleChild(variant.articleId)}
175
- />
176
- <span>
177
- {variant.name}
178
- <span className="meta">UPC {variant.upc || "—"}</span>
179
- </span>
180
- </label>
181
- </li>
182
- ))}
183
- </List>
196
+ {/* Cada destino con su propio alcance. Van separados porque
197
+ propagar a las variantes NO debe alcanzar a los hijos: si fuera
198
+ un solo control, elegir "todos" mandaría a los dos lados. */}
199
+ {variants.length > 0 && (
200
+ <>
201
+ <h3>
202
+ ¿A cuáles de los {variants.length} hijo
203
+ {variants.length === 1 ? "" : "s"}?
204
+ </h3>
205
+ <Choices>
206
+ <label>
207
+ <input
208
+ type="radio"
209
+ name="scope-children"
210
+ checked={scopeChildren === "none"}
211
+ onChange={() => setScopeChildren("none")}
212
+ />
213
+ <span>A ninguno</span>
214
+ </label>
215
+ <label>
216
+ <input
217
+ type="radio"
218
+ name="scope-children"
219
+ checked={scopeChildren === "all"}
220
+ onChange={() => setScopeChildren("all")}
221
+ />
222
+ <span>A todos</span>
223
+ </label>
224
+ <label>
225
+ <input
226
+ type="radio"
227
+ name="scope-children"
228
+ checked={scopeChildren === "some"}
229
+ onChange={() => setScopeChildren("some")}
230
+ />
231
+ <span>Elegir cuáles</span>
232
+ </label>
233
+ </Choices>
234
+
235
+ {scopeChildren === "some" && (
236
+ <List>
237
+ {variants.map((variant) => (
238
+ <li key={variant.articleId}>
239
+ <label>
240
+ <input
241
+ type="checkbox"
242
+ checked={chosenChildren.includes(variant.articleId)}
243
+ onChange={() => toggleChild(variant.articleId)}
244
+ />
245
+ <span>
246
+ {variant.name}
247
+ <span className="meta">UPC {variant.upc || "—"}</span>
248
+ </span>
249
+ </label>
250
+ </li>
251
+ ))}
252
+ </List>
253
+ )}
254
+ </>
255
+ )}
256
+
257
+ {groupMembers.length > 0 && (
258
+ <>
259
+ <h3>
260
+ ¿A cuáles de las {groupMembers.length} variante
261
+ {groupMembers.length === 1 ? "" : "s"}
262
+ {groupCode ? ` del grupo ${groupCode}` : ""}?
263
+ </h3>
264
+ <Choices>
265
+ <label>
266
+ <input
267
+ type="radio"
268
+ name="scope-variants"
269
+ checked={scopeVariants === "none"}
270
+ onChange={() => setScopeVariants("none")}
271
+ />
272
+ <span>A ninguna</span>
273
+ </label>
274
+ <label>
275
+ <input
276
+ type="radio"
277
+ name="scope-variants"
278
+ checked={scopeVariants === "all"}
279
+ onChange={() => setScopeVariants("all")}
280
+ />
281
+ <span>A todas</span>
282
+ </label>
283
+ <label>
284
+ <input
285
+ type="radio"
286
+ name="scope-variants"
287
+ checked={scopeVariants === "some"}
288
+ onChange={() => setScopeVariants("some")}
289
+ />
290
+ <span>Elegir cuáles</span>
291
+ </label>
292
+ </Choices>
293
+
294
+ {scopeVariants === "some" && (
295
+ <List>
296
+ {groupMembers.map((miembro) => (
297
+ <li key={miembro.articleId}>
298
+ <label>
299
+ <input
300
+ type="checkbox"
301
+ checked={chosenVariants.includes(miembro.articleId)}
302
+ onChange={() => toggleVariant(miembro.articleId)}
303
+ />
304
+ <span>
305
+ {miembro.name}
306
+ <span className="meta">UPC {miembro.upc || "—"}</span>
307
+ </span>
308
+ </label>
309
+ </li>
310
+ ))}
311
+ </List>
312
+ )}
313
+ </>
184
314
  )}
185
315
 
186
316
  {/* Lo que sorprende si no se dice: aquí se pisa lo que el hijo
@@ -209,9 +339,11 @@ export const PropagateChangesModal = ({
209
339
 
210
340
  <Footer>
211
341
  <span className="resumen">
342
+ {/* Se cuentan los destinos DISTINTOS: un producto que es hijo y
343
+ además comparte grupo recibe el valor una sola vez. */}
212
344
  {puedePropagar
213
- ? `${chosenAttributes.length} atributo(s) a ${destinatarios} hijo(s).`
214
- : "No se bajará nada a los hijos."}
345
+ ? `${chosenAttributes.length} atributo(s) a ${destinatarios} producto(s).`
346
+ : "No se copiará nada: elige al menos un atributo y un destino."}
215
347
  </span>
216
348
  <button
217
349
  type="button"