contentoh-components-library 21.5.82 → 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.
- package/dist/ai/utils/compare-strings.js +2 -0
- package/dist/components/atoms/GeneralInput/index.js +11 -14
- package/dist/components/molecules/TagAndInput/index.js +22 -21
- package/dist/contexts/AiProductEdition.js +11 -11
- package/package.json +1 -1
- package/src/ai/utils/compare-strings.js +2 -0
- package/src/components/atoms/GeneralInput/index.js +13 -9
- package/src/components/molecules/TagAndInput/index.js +22 -23
- package/src/contexts/AiProductEdition.jsx +5 -5
|
@@ -7,6 +7,8 @@ exports.getTextSimilarityPercentage = getTextSimilarityPercentage;
|
|
|
7
7
|
|
|
8
8
|
//Calcula el porcentaje de similitud entre la descripción generada por IA y la versión editada por el usuario.
|
|
9
9
|
function getTextSimilarityPercentage(originalText, candidateText) {
|
|
10
|
+
if (!originalText || !candidateText) return;
|
|
11
|
+
|
|
10
12
|
var normalize = function normalize(text) {
|
|
11
13
|
return text.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
12
14
|
};
|
|
@@ -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)(
|
|
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,
|
|
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;
|
|
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:
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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 || !
|
|
231
|
-
_context2.next =
|
|
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
|
|
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:
|
|
252
|
+
versionId: version,
|
|
252
253
|
descriptionId: descriptionId,
|
|
253
254
|
attributeId: attributeId
|
|
254
255
|
};
|
|
255
|
-
_context2.next =
|
|
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
|
|
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;
|
|
@@ -321,7 +319,9 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
321
319
|
var _currentRetailerPerce2 = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.images,
|
|
322
320
|
imagesRequiredPercent = _currentRetailerPerce2.required;
|
|
323
321
|
|
|
324
|
-
var aiServiceAvailable = datasheetRequiredPercent >= 100 && imagesRequiredPercent >= 100 &&
|
|
322
|
+
var aiServiceAvailable = datasheetRequiredPercent >= 100 && imagesRequiredPercent >= 100 && [1, 4, 6, 7].some(function (allowed) {
|
|
323
|
+
return allowed = user === null || user === void 0 ? void 0 : user.id_role;
|
|
324
|
+
});
|
|
325
325
|
setIsAiAvailable(aiServiceAvailable);
|
|
326
326
|
setProduct({
|
|
327
327
|
upc: upc,
|
package/package.json
CHANGED
|
@@ -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(
|
|
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,
|
|
75
|
+
const similarity = getTextSimilarityPercentage(valueAccepted, generalValue);
|
|
75
76
|
|
|
76
|
-
const generatedWithAi = (isAiAccepted
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
238
|
+
const currentDescriptionUpdate = Array.isArray(updatedDescriptions)
|
|
239
|
+
? updatedDescriptions.find(desc => desc?.attributeId === inputId)
|
|
240
|
+
: null;
|
|
239
241
|
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -216,7 +216,7 @@ export const AiProductEditionProvider = ({
|
|
|
216
216
|
required: imagesRequiredPercent,
|
|
217
217
|
} = currentRetailerPercentages?.images;
|
|
218
218
|
|
|
219
|
-
const aiServiceAvailable = (datasheetRequiredPercent >= 100) && (imagesRequiredPercent >= 100) && user?.id_role
|
|
219
|
+
const aiServiceAvailable = (datasheetRequiredPercent >= 100) && (imagesRequiredPercent >= 100) && [1,4,6,7].some(allowed => allowed = user?.id_role);
|
|
220
220
|
|
|
221
221
|
setIsAiAvailable(aiServiceAvailable);
|
|
222
222
|
|