contentoh-components-library 21.5.83 → 21.5.84

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,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.GeneralInput = void 0;
9
9
 
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
11
-
12
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
13
11
 
14
12
  var _react = require("react");
@@ -110,7 +108,7 @@ var GeneralInput = function GeneralInput(_ref) {
110
108
  aiSuggestionAccepted = _useState6[0],
111
109
  setAiSuggestionAccepted = _useState6[1];
112
110
 
113
- var _useState7 = (0, _react.useState)(textValue),
111
+ var _useState7 = (0, _react.useState)(inputValue),
114
112
  _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
115
113
  valueAccepted = _useState8[0],
116
114
  setValueAccepted = _useState8[1];
@@ -119,8 +117,8 @@ var GeneralInput = function GeneralInput(_ref) {
119
117
  setTextValue({
120
118
  value: generalValue
121
119
  });
122
- var similarity = (0, _compareStrings.getTextSimilarityPercentage)(valueAccepted, inputValue);
123
- var generatedWithAi = isAiAccepted || aiGenerated && similarity >= 50;
120
+ var similarity = (0, _compareStrings.getTextSimilarityPercentage)(valueAccepted, generalValue);
121
+ var generatedWithAi = (isAiAccepted || aiGenerated) && similarity >= 50;
124
122
 
125
123
  if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
126
124
  var dataSave = (updatedDatasheets === null || updatedDatasheets === void 0 ? void 0 : updatedDatasheets.slice()) || [];
@@ -188,10 +186,8 @@ var GeneralInput = function GeneralInput(_ref) {
188
186
  (0, _react.useEffect)(function () {
189
187
  var _suggestions$inputId;
190
188
 
191
- if (Object.keys(suggestions).length === 0) return; // Si ya existe una sugerencia actual generada, mantenla en su posicion
192
-
193
- if (currentSuggestion !== null && currentSuggestion !== void 0 && currentSuggestion[inputId]) return; // Si no hay una sugerencia actual generada, seteamos la primera nueva sugerencia como default
194
-
189
+ if (Object.keys(suggestions).length === 0) return;
190
+ if (currentSuggestion !== null && currentSuggestion !== void 0 && currentSuggestion[inputId]) return;
195
191
  var firstSuggestion = suggestions === null || suggestions === void 0 ? void 0 : (_suggestions$inputId = suggestions[inputId]) === null || _suggestions$inputId === void 0 ? void 0 : _suggestions$inputId[0];
196
192
  if (!firstSuggestion) return;
197
193
  setCurrentSuggestionValue({
@@ -200,11 +196,14 @@ var GeneralInput = function GeneralInput(_ref) {
200
196
  value: firstSuggestion === null || firstSuggestion === void 0 ? void 0 : firstSuggestion.value
201
197
  });
202
198
  }, [suggestions]);
199
+ (0, _react.useEffect)(function () {
200
+ if (!isAiActive) return;
201
+ setAiSuggestionAccepted(false);
202
+ }, [isAiActive]);
203
203
  (0, _react.useEffect)(function () {
204
204
  if (!isAiActive && !aiSuggestionAccepted) {
205
- var restoredValue = (0, _typeof2.default)(valueAccepted) === 'object' ? valueAccepted.value : valueAccepted;
206
205
  setTextValue({
207
- value: restoredValue
206
+ value: valueAccepted
208
207
  });
209
208
  }
210
209
  }, [suggestions, isAiActive]);
@@ -228,9 +227,7 @@ var GeneralInput = function GeneralInput(_ref) {
228
227
 
229
228
  var handleAcceptSuggestion = function handleAcceptSuggestion(suggestionValue) {
230
229
  if (!suggestionValue) return;
231
- setValueAccepted({
232
- value: suggestionValue
233
- });
230
+ setValueAccepted(suggestionValue);
234
231
  setAiSuggestionAccepted(true);
235
232
  setIsAiActive(false);
236
233
  updateParentData(suggestionValue, true);
@@ -335,33 +335,34 @@ var TagAndInput = function TagAndInput(_ref) {
335
335
  onChange && onChange(boxOnboardingList);
336
336
  }, [boxOnboardingList]);
337
337
  (0, _react.useEffect)(function () {
338
- if (Array.isArray(updatedDescriptions)) {
339
- var currentDescriptionUpdate = updatedDescriptions.find(function (description) {
340
- return (description === null || description === void 0 ? void 0 : description.attributeId) === inputId;
341
- });
342
- var calculatedIsAiGenerated = currentDescriptionUpdate ? !!currentDescriptionUpdate.aiSuggestionAccepted : aiGenerated;
343
- setInputsGeneratedWithAi(function (prev) {
344
- return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, "".concat(inputId, "-").concat(inputType, "-").concat(version), {
345
- inputType: inputType,
346
- inputId: inputId,
347
- version: version,
348
- isAiGenerated: calculatedIsAiGenerated,
349
- label: label
350
- }));
351
- });
338
+ var currentDescriptionUpdate = Array.isArray(updatedDescriptions) ? updatedDescriptions.find(function (desc) {
339
+ return (desc === null || desc === void 0 ? void 0 : desc.attributeId) === inputId;
340
+ }) : null;
341
+ var currentDatasheetUpdate = Array.isArray(updatedDatasheets) ? updatedDatasheets.find(function (data) {
342
+ return (data === null || data === void 0 ? void 0 : data.attributeId) === inputId;
343
+ }) : null;
344
+ var calculatedIsAiGenerated = aiGenerated;
345
+
346
+ if (currentDescriptionUpdate) {
347
+ calculatedIsAiGenerated = currentDescriptionUpdate.aiSuggestionAccepted;
348
+ } else if (currentDatasheetUpdate) {
349
+ calculatedIsAiGenerated = currentDatasheetUpdate.aiSuggestionAccepted;
352
350
  }
353
351
 
354
- if (Array.isArray(updatedDatasheets) && updatedDatasheets.length > 0) {
355
- console.log({
356
- isAiGenerated: isAiGenerated,
357
- updatedDatasheets: updatedDatasheets
358
- });
359
- }
352
+ setInputsGeneratedWithAi(function (prev) {
353
+ return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, "".concat(inputId, "-").concat(inputType, "-").concat(version !== null && version !== void 0 ? version : label), {
354
+ inputType: inputType,
355
+ inputId: inputId,
356
+ version: version,
357
+ isAiGenerated: !!calculatedIsAiGenerated,
358
+ label: label
359
+ }));
360
+ });
360
361
  }, [updatedDescriptions, updatedDatasheets, aiGenerated, inputId]);
361
362
  (0, _react.useEffect)(function () {
362
363
  var _inputsGeneratedWithA;
363
364
 
364
- setIsAiGenerated(!!((_inputsGeneratedWithA = inputsGeneratedWithAi["".concat(inputId, "-").concat(inputType, "-").concat(version)]) !== null && _inputsGeneratedWithA !== void 0 && _inputsGeneratedWithA.isAiGenerated));
365
+ setIsAiGenerated(!!((_inputsGeneratedWithA = inputsGeneratedWithAi["".concat(inputId, "-").concat(inputType, "-").concat(version !== null && version !== void 0 ? version : label)]) !== null && _inputsGeneratedWithA !== void 0 && _inputsGeneratedWithA.isAiGenerated));
365
366
  }, [inputsGeneratedWithAi]);
366
367
  (0, _react.useEffect)(function () {
367
368
  setInputsUsingAi(function (prev) {
@@ -184,7 +184,7 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
184
184
 
185
185
  function _generateProductSuggestions() {
186
186
  _generateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
187
- var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, articleId, versionId, descriptionId, attributeId, _JSON$parse$data, _JSON$parse, upc, productName, retailer, category, payload, _yield$axios$post, data, results, _error$message;
187
+ var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, articleId, versionId, descriptionId, attributeId, _state$product, _JSON$parse$data, _JSON$parse, upc, productName, retailer, category, version, payload, _yield$axios$post, data, results, _error$message;
188
188
 
189
189
  return _regenerator.default.wrap(function _callee2$(_context2) {
190
190
  while (1) {
@@ -226,15 +226,16 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
226
226
 
227
227
  case 10:
228
228
  upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
229
+ version = state === null || state === void 0 ? void 0 : (_state$product = state.product) === null || _state$product === void 0 ? void 0 : _state$product.version;
229
230
 
230
- if (!(!upc || !description || !productName || !category || !retailer || !articleId || !versionId || !descriptionId && !attributeId)) {
231
- _context2.next = 13;
231
+ if (!(!upc || !description || !productName || !category || !retailer || !articleId || !version || !descriptionId && !attributeId)) {
232
+ _context2.next = 14;
232
233
  break;
233
234
  }
234
235
 
235
236
  throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
236
237
 
237
- case 13:
238
+ case 14:
238
239
  payload = {
239
240
  upc: upc,
240
241
  attributeTitle: inputName,
@@ -248,24 +249,21 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
248
249
  maxChar: maxChar,
249
250
  articleId: articleId,
250
251
  retailerId: activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer,
251
- versionId: versionId,
252
+ versionId: version,
252
253
  descriptionId: descriptionId,
253
254
  attributeId: attributeId
254
255
  };
255
- _context2.next = 16;
256
+ _context2.next = 17;
256
257
  return _axios.default.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
257
258
  headers: {
258
259
  Authorization: token
259
260
  }
260
261
  });
261
262
 
262
- case 16:
263
+ case 17:
263
264
  _yield$axios$post = _context2.sent;
264
265
  data = _yield$axios$post.data;
265
266
  results = (_JSON$parse$data = (_JSON$parse = JSON.parse(data === null || data === void 0 ? void 0 : data.body)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.data) !== null && _JSON$parse$data !== void 0 ? _JSON$parse$data : [];
266
- console.log({
267
- results: results
268
- });
269
267
 
270
268
  if (results) {
271
269
  _context2.next = 22;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.5.83",
3
+ "version": "21.5.84",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -66,14 +66,15 @@ export const GeneralInput = ({
66
66
  const [requiredEmpty, setRequiredEmpty] = useState(false);
67
67
 
68
68
  const [aiSuggestionAccepted, setAiSuggestionAccepted] = useState(false);
69
- const [valueAccepted, setValueAccepted] = useState(textValue);
69
+ const [valueAccepted, setValueAccepted] = useState(inputValue);
70
70
 
71
71
  const updateParentData = (generalValue, isAiAccepted) => {
72
+
72
73
  setTextValue({ value: generalValue });
73
74
 
74
- const similarity = getTextSimilarityPercentage(valueAccepted, inputValue);
75
+ const similarity = getTextSimilarityPercentage(valueAccepted, generalValue);
75
76
 
76
- const generatedWithAi = (isAiAccepted) || aiGenerated && similarity >= 50;
77
+ const generatedWithAi = (isAiAccepted || aiGenerated) && similarity >= 50;
77
78
 
78
79
  if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
79
80
  let dataSave = updatedDatasheets?.slice() || [];
@@ -107,6 +108,7 @@ export const GeneralInput = ({
107
108
  });
108
109
  }
109
110
  }
111
+
110
112
  setUpdatedDatasheets(dataSave);
111
113
  }
112
114
  };
@@ -139,10 +141,8 @@ export const GeneralInput = ({
139
141
 
140
142
  if(Object.keys(suggestions).length === 0) return;
141
143
 
142
- // Si ya existe una sugerencia actual generada, mantenla en su posicion
143
144
  if(currentSuggestion?.[inputId]) return
144
145
 
145
- // Si no hay una sugerencia actual generada, seteamos la primera nueva sugerencia como default
146
146
 
147
147
  const firstSuggestion = suggestions?.[inputId]?.[0];
148
148
 
@@ -156,10 +156,14 @@ export const GeneralInput = ({
156
156
 
157
157
  }, [suggestions]);
158
158
 
159
- useEffect(() => {
159
+ useEffect(() => {
160
+ if(!isAiActive) return;
161
+ setAiSuggestionAccepted(false);
162
+ }, [isAiActive]);
163
+
164
+ useEffect(() => {
160
165
  if(!isAiActive && !aiSuggestionAccepted) {
161
- const restoredValue = typeof valueAccepted === 'object' ? valueAccepted.value : valueAccepted;
162
- setTextValue({ value: restoredValue });
166
+ setTextValue({ value: valueAccepted });
163
167
  }
164
168
  }, [suggestions, isAiActive]);
165
169
 
@@ -184,7 +188,7 @@ useEffect(() => {
184
188
  const handleAcceptSuggestion = (suggestionValue) => {
185
189
  if(!suggestionValue) return;
186
190
 
187
- setValueAccepted({ value: suggestionValue });
191
+ setValueAccepted(suggestionValue);
188
192
  setAiSuggestionAccepted(true);
189
193
  setIsAiActive(false);
190
194
 
@@ -235,39 +235,38 @@ export const TagAndInput = ({
235
235
 
236
236
  useEffect(() => {
237
237
 
238
- if(Array.isArray(updatedDescriptions)) {
238
+ const currentDescriptionUpdate = Array.isArray(updatedDescriptions)
239
+ ? updatedDescriptions.find(desc => desc?.attributeId === inputId)
240
+ : null;
239
241
 
240
- const currentDescriptionUpdate = updatedDescriptions.find(
241
- description => description?.attributeId === inputId
242
- );
243
-
244
- const calculatedIsAiGenerated = currentDescriptionUpdate
245
- ? !!currentDescriptionUpdate.aiSuggestionAccepted
246
- : aiGenerated;
242
+ const currentDatasheetUpdate = Array.isArray(updatedDatasheets)
243
+ ? updatedDatasheets.find(data => data?.attributeId === inputId)
244
+ : null;
247
245
 
248
- setInputsGeneratedWithAi(prev => ({
249
- ...prev,
250
- [`${inputId}-${inputType}-${version}`]: {
251
- inputType,
252
- inputId,
253
- version,
254
- isAiGenerated: calculatedIsAiGenerated,
255
- label
256
- }
257
- }))
246
+ let calculatedIsAiGenerated = aiGenerated;
258
247
 
248
+ if (currentDescriptionUpdate) {
249
+ calculatedIsAiGenerated = currentDescriptionUpdate.aiSuggestionAccepted;
250
+ } else if (currentDatasheetUpdate) {
251
+ calculatedIsAiGenerated = currentDatasheetUpdate.aiSuggestionAccepted;
259
252
  }
260
253
 
261
- if(Array.isArray(updatedDatasheets) && updatedDatasheets.length > 0) {
262
- console.log({isAiGenerated, updatedDatasheets});
263
- }
254
+ setInputsGeneratedWithAi(prev => ({
255
+ ...prev,
256
+ [`${inputId}-${inputType}-${version ?? label}`]: {
257
+ inputType,
258
+ inputId,
259
+ version,
260
+ isAiGenerated: !!calculatedIsAiGenerated,
261
+ label
262
+ }
263
+ }));
264
264
 
265
265
  }, [updatedDescriptions, updatedDatasheets, aiGenerated, inputId]);
266
266
 
267
-
268
267
  useEffect(() => {
269
268
 
270
- setIsAiGenerated(!!inputsGeneratedWithAi[`${inputId}-${inputType}-${version}`]?.isAiGenerated);
269
+ setIsAiGenerated(!!inputsGeneratedWithAi[`${inputId}-${inputType}-${version ?? label}`]?.isAiGenerated);
271
270
 
272
271
  }, [inputsGeneratedWithAi]);
273
272
 
@@ -135,7 +135,9 @@ export const AiProductEditionProvider = ({
135
135
  category
136
136
  } = product;
137
137
 
138
- if (!upc || !description || !productName || !category || !retailer || !articleId || !versionId || (!descriptionId && !attributeId))
138
+ const version = state?.product?.version;
139
+
140
+ if (!upc || !description || !productName || !category || !retailer || !articleId || !version || (!descriptionId && !attributeId))
139
141
  throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
140
142
 
141
143
  const payload = {
@@ -152,7 +154,7 @@ export const AiProductEditionProvider = ({
152
154
 
153
155
  articleId,
154
156
  retailerId: activeRetailer?.id_retailer,
155
- versionId,
157
+ versionId: version,
156
158
  descriptionId,
157
159
  attributeId
158
160
  }
@@ -165,8 +167,6 @@ export const AiProductEditionProvider = ({
165
167
 
166
168
  const results = JSON.parse(data?.body)?.data ?? [];
167
169
 
168
- console.log({results});
169
-
170
170
  if(!results)
171
171
  throw new Error("No se encontraron resultados");
172
172