contentoh-components-library 21.6.27 → 21.6.28

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.
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.PropagateChangesModal = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
13
+
14
+ var _react = require("react");
15
+
16
+ var _styles = require("./styles");
17
+
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+
20
+ /*
21
+ Diálogo de propagación al guardar un producto padre.
22
+
23
+ Aparece cuando se guardan cambios de ficha técnica en un producto que tiene
24
+ variantes. El backend NO propaga nada por su cuenta: solo baja a los hijos lo
25
+ que venga en `propagation`, y esa lista la arma esta pantalla. Guardar sin
26
+ abrirla, o cerrarla sin propagar, deja al padre modificado y a las variantes
27
+ como estaban.
28
+
29
+ props (* requerido):
30
+ - *changedAttributes: [{ id, name, value }] lo que se acaba de editar
31
+ - *variants: [{ articleId, name, upc }] las variantes activas del padre
32
+ - *onCancel: cerrar sin guardar nada
33
+ - *onConfirm: (propagation | null) => void
34
+ null → guardar solo el padre
35
+ { attributes, targetChildren } → guardar y propagar
36
+ - saving: deshabilita los botones mientras el guardado corre
37
+ */
38
+ // Por encima de este número el backend delega la propagación a una invocación
39
+ // en segundo plano. Se avisa aquí porque cambia lo que el usuario debe esperar:
40
+ // el guardado responde antes de que los hijos estén actualizados.
41
+ var UMBRAL_SEGUNDO_PLANO = 20;
42
+
43
+ var PropagateChangesModal = function PropagateChangesModal(_ref) {
44
+ var _ref$changedAttribute = _ref.changedAttributes,
45
+ changedAttributes = _ref$changedAttribute === void 0 ? [] : _ref$changedAttribute,
46
+ _ref$variants = _ref.variants,
47
+ variants = _ref$variants === void 0 ? [] : _ref$variants,
48
+ onCancel = _ref.onCancel,
49
+ onConfirm = _ref.onConfirm,
50
+ _ref$saving = _ref.saving,
51
+ saving = _ref$saving === void 0 ? false : _ref$saving;
52
+
53
+ var _useState = (0, _react.useState)([]),
54
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
55
+ chosenAttributes = _useState2[0],
56
+ setChosenAttributes = _useState2[1];
57
+
58
+ var _useState3 = (0, _react.useState)("all"),
59
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
60
+ scope = _useState4[0],
61
+ setScope = _useState4[1];
62
+
63
+ var _useState5 = (0, _react.useState)([]),
64
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
65
+ chosenChildren = _useState6[0],
66
+ setChosenChildren = _useState6[1];
67
+
68
+ var destinatarios = scope === "all" ? variants.length : chosenChildren.length;
69
+ var puedePropagar = chosenAttributes.length > 0 && destinatarios > 0;
70
+ var enSegundoPlano = destinatarios > UMBRAL_SEGUNDO_PLANO;
71
+
72
+ var toggleAttribute = function toggleAttribute(id) {
73
+ setChosenAttributes(function (current) {
74
+ return current.includes(id) ? current.filter(function (item) {
75
+ return item !== id;
76
+ }) : [].concat((0, _toConsumableArray2.default)(current), [id]);
77
+ });
78
+ };
79
+
80
+ var toggleChild = function toggleChild(id) {
81
+ setChosenChildren(function (current) {
82
+ return current.includes(id) ? current.filter(function (item) {
83
+ return item !== id;
84
+ }) : [].concat((0, _toConsumableArray2.default)(current), [id]);
85
+ });
86
+ };
87
+
88
+ var confirmar = function confirmar() {
89
+ onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm({
90
+ attributes: chosenAttributes,
91
+ targetChildren: scope === "all" ? "all" : chosenChildren
92
+ });
93
+ };
94
+
95
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Overlay, {
96
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Panel, {
97
+ onClick: function onClick(event) {
98
+ return event.stopPropagation();
99
+ },
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Header, {
101
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h2", {
102
+ children: ["Este producto tiene ", variants.length, " variante", variants.length === 1 ? "" : "s"]
103
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
104
+ children: ["Cambiaste ", changedAttributes.length, " atributo", changedAttributes.length === 1 ? "" : "s", ". Elige cu\xE1les bajan a las variantes; el resto se guarda solo en este producto."]
105
+ })]
106
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Body, {
107
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
108
+ children: "\xBFQu\xE9 se baja a las variantes?"
109
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
110
+ children: changedAttributes.map(function (attribute) {
111
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
112
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
113
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
114
+ type: "checkbox",
115
+ checked: chosenAttributes.includes(attribute.id),
116
+ onChange: function onChange() {
117
+ return toggleAttribute(attribute.id);
118
+ }
119
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
120
+ children: attribute.name
121
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
122
+ className: "valor",
123
+ title: attribute.value,
124
+ children: attribute.value
125
+ })]
126
+ })
127
+ }, attribute.id);
128
+ })
129
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
130
+ children: "\xBFA cu\xE1les?"
131
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Choices, {
132
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
133
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
134
+ type: "radio",
135
+ name: "propagation-scope",
136
+ checked: scope === "all",
137
+ onChange: function onChange() {
138
+ return setScope("all");
139
+ }
140
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
141
+ children: ["A todas", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
142
+ className: "hint",
143
+ children: [variants.length, " variante", variants.length === 1 ? "" : "s", " activa", variants.length === 1 ? "" : "s", "."]
144
+ })]
145
+ })]
146
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
147
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
148
+ type: "radio",
149
+ name: "propagation-scope",
150
+ checked: scope === "some",
151
+ onChange: function onChange() {
152
+ return setScope("some");
153
+ }
154
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
155
+ children: "Elegir cu\xE1les"
156
+ })]
157
+ })]
158
+ }), scope === "some" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
159
+ children: variants.map(function (variant) {
160
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
161
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
162
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
163
+ type: "checkbox",
164
+ checked: chosenChildren.includes(variant.articleId),
165
+ onChange: function onChange() {
166
+ return toggleChild(variant.articleId);
167
+ }
168
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
169
+ children: [variant.name, /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
170
+ className: "meta",
171
+ children: ["UPC ", variant.upc || "—"]
172
+ })]
173
+ })]
174
+ })
175
+ }, variant.articleId);
176
+ })
177
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Note, {
178
+ children: "Una variante que haya editado alguno de estos atributos por su cuenta conserva su valor. Para devolverlo al del padre est\xE1 la acci\xF3n \xABVolver a heredar\xBB en la ficha de esa variante."
179
+ }), enSegundoPlano && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Note, {
180
+ className: "accent",
181
+ children: ["Son m\xE1s de ", UMBRAL_SEGUNDO_PLANO, " variantes, as\xED que la propagaci\xF3n corre en segundo plano: el guardado termina antes de que todas est\xE9n actualizadas."]
182
+ })]
183
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Footer, {
184
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
185
+ className: "resumen",
186
+ children: puedePropagar ? "".concat(chosenAttributes.length, " atributo(s) a ").concat(destinatarios, " variante(s).") : "No se bajará nada a las variantes."
187
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
188
+ type: "button",
189
+ className: "secondary",
190
+ onClick: onCancel,
191
+ disabled: saving,
192
+ children: "Cancelar"
193
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
194
+ type: "button",
195
+ className: "secondary",
196
+ onClick: function onClick() {
197
+ return onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(null);
198
+ },
199
+ disabled: saving,
200
+ children: "Solo este producto"
201
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
202
+ type: "button",
203
+ className: "primary",
204
+ onClick: confirmar,
205
+ disabled: saving || !puedePropagar,
206
+ children: saving ? "Guardando…" : "Guardar y propagar"
207
+ })]
208
+ })]
209
+ })
210
+ });
211
+ };
212
+
213
+ exports.PropagateChangesModal = PropagateChangesModal;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Panel = exports.Overlay = exports.Note = exports.List = exports.Header = exports.Footer = exports.Choices = exports.Body = void 0;
9
+
10
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/taggedTemplateLiteral"));
11
+
12
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
14
+ require("../../../global-files/global-styles.css");
15
+
16
+ var _variables = require("../../../global-files/variables");
17
+
18
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
19
+
20
+ var PINK = "#E13AA8";
21
+ var PINK_RGB = "225, 58, 168";
22
+
23
+ var Overlay = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n position: fixed;\n inset: 0;\n z-index: 110;\n display: flex;\n align-items: center;\n justify-content: center;\n background-color: rgba(40, 31, 51, 0.45);\n"])));
24
+
25
+ exports.Overlay = Overlay;
26
+
27
+ var Panel = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n flex-direction: column;\n width: min(560px, 92vw);\n max-height: 86vh;\n border-radius: 10px;\n background-color: ", ";\n font-family: ", ";\n overflow: hidden;\n\n input[type=\"checkbox\"],\n input[type=\"radio\"] {\n accent-color: ", ";\n width: 15px;\n height: 15px;\n cursor: pointer;\n }\n"])), _variables.GlobalColors.white, _variables.FontFamily.Raleway, PINK);
28
+
29
+ exports.Panel = Panel;
30
+
31
+ var Header = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n padding: 20px 24px 8px;\n\n h2 {\n margin: 0;\n font-family: ", ";\n font-size: 17px;\n color: ", ";\n }\n\n p {\n margin: 6px 0 0;\n font-size: 13px;\n line-height: 1.4;\n color: ", ";\n }\n"])), _variables.FontFamily.Raleway_700, _variables.GlobalColors.deep_gray, _variables.GlobalColors.gray);
32
+
33
+ exports.Header = Header;
34
+
35
+ var Body = _styledComponents.default.div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n flex: 1;\n overflow-y: auto;\n padding: 12px 24px 0;\n\n h3 {\n margin: 0 0 8px;\n font-family: ", ";\n font-size: 13px;\n color: ", ";\n }\n"])), _variables.FontFamily.Raleway_600, _variables.GlobalColors.deep_gray);
36
+
37
+ exports.Body = Body;
38
+
39
+ var List = _styledComponents.default.ul(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n list-style: none;\n margin: 0 0 18px;\n padding: 0;\n border: 1px solid ", ";\n border-radius: 6px;\n max-height: 190px;\n overflow-y: auto;\n\n li + li {\n border-top: 1px solid ", ";\n }\n\n label {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 9px 12px;\n cursor: pointer;\n font-size: 13px;\n color: ", ";\n }\n\n .valor {\n margin-left: auto;\n max-width: 45%;\n font-size: 12px;\n color: ", ";\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .meta {\n display: block;\n font-size: 12px;\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, _variables.GlobalColors.gray, _variables.GlobalColors.gray);
40
+
41
+ exports.List = List;
42
+
43
+ var Choices = _styledComponents.default.div(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin-bottom: 10px;\n\n label {\n display: flex;\n align-items: flex-start;\n gap: 8px;\n padding: 4px 0;\n font-size: 13px;\n color: ", ";\n cursor: pointer;\n }\n\n .hint {\n display: block;\n font-size: 12px;\n color: ", ";\n }\n"])), _variables.GlobalColors.deep_gray, _variables.GlobalColors.gray);
44
+
45
+ exports.Choices = Choices;
46
+
47
+ var Note = _styledComponents.default.p(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n margin: 0 0 16px;\n padding: 10px 12px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.45;\n background-color: ", ";\n color: ", ";\n\n &.accent {\n background-color: rgba(", ", 0.1);\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK_RGB, PINK);
48
+
49
+ exports.Note = Note;
50
+
51
+ var Footer = _styledComponents.default.div(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 16px 24px;\n border-top: 1px solid ", ";\n\n .resumen {\n flex: 1;\n font-size: 12px;\n color: ", ";\n }\n\n button {\n height: 38px;\n padding: 0 16px;\n border-radius: 6px;\n font-family: ", ";\n font-size: 13px;\n cursor: pointer;\n }\n\n button.secondary {\n border: 1px solid ", ";\n background-color: ", ";\n color: ", ";\n }\n\n button.primary {\n border: none;\n background-color: ", ";\n color: ", ";\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: default;\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.gray, _variables.FontFamily.Raleway_600, _variables.GlobalColors.s2, _variables.GlobalColors.white, _variables.GlobalColors.gray, PINK, _variables.GlobalColors.white);
52
+
53
+ exports.Footer = Footer;
@@ -184,9 +184,16 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
184
184
  return _ref2.apply(this, arguments);
185
185
  };
186
186
  }();
187
+ /*
188
+ `propagation` es opcional y solo lo manda la ficha de un producto padre, con
189
+ lo que el usuario eligió en el diálogo: { attributes: [...], targetChildren }.
190
+ Sin ese bloque el backend no propaga nada. Es deliberado: bajar un cambio a
191
+ las variantes tiene que ser una decisión, no un efecto secundario de guardar.
192
+ */
193
+
187
194
 
188
195
  var saveDatasheets = /*#__PURE__*/function () {
189
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(token) {
196
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(token, propagation) {
190
197
  var _state$product4, _state$product5;
191
198
 
192
199
  var dataObject, _state$product6, res, _state$services$datas, _state$services, _state$services$datas2, _state$services$datas3, _state$product7, esVariante;
@@ -207,10 +214,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
207
214
  type: "SET_SAVING",
208
215
  payload: true
209
216
  });
210
- dataObject = {
217
+ dataObject = (0, _objectSpread2.default)({
211
218
  articleId: (_state$product4 = state.product) === null || _state$product4 === void 0 ? void 0 : _state$product4.id_article,
212
219
  articleData: state.updated_datasheets_inputs
213
- }; // Marcar todos los items como aprobados
220
+ }, propagation ? {
221
+ propagation: propagation
222
+ } : {}); // Marcar todos los items como aprobados
214
223
 
215
224
  dataObject.articleData = dataObject.articleData.map(function (item) {
216
225
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
@@ -292,7 +301,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
292
301
  }, _callee2, null, [[6, 13, 17, 20]]);
293
302
  }));
294
303
 
295
- return function saveDatasheets(_x2) {
304
+ return function saveDatasheets(_x2, _x3) {
296
305
  return _ref3.apply(this, arguments);
297
306
  };
298
307
  }();
@@ -458,7 +467,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
458
467
  }, _callee3, null, [[10, 20, 25, 28]]);
459
468
  }));
460
469
 
461
- return function updateImages(_x3) {
470
+ return function updateImages(_x4) {
462
471
  return _ref4.apply(this, arguments);
463
472
  };
464
473
  }();
@@ -570,7 +579,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
570
579
  }, _callee4, null, [[4, 10]]);
571
580
  }));
572
581
 
573
- return function deleteImages(_x4) {
582
+ return function deleteImages(_x5) {
574
583
  return _ref5.apply(this, arguments);
575
584
  };
576
585
  }();
@@ -607,7 +616,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
607
616
  }, _callee5);
608
617
  }));
609
618
 
610
- return function createComment(_x5, _x6) {
619
+ return function createComment(_x6, _x7) {
611
620
  return _ref6.apply(this, arguments);
612
621
  };
613
622
  }();