contentoh-components-library 21.5.83 → 21.5.85
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/components/atoms/GeneralInput/index.js +14 -15
- package/dist/components/molecules/TagAndInput/index.js +21 -20
- package/dist/contexts/AiProductEdition.js +8 -10
- package/package.json +1 -1
- package/src/components/atoms/GeneralInput/index.js +19 -14
- package/src/components/molecules/TagAndInput/index.js +21 -25
- package/src/contexts/AiProductEdition.jsx +4 -4
|
@@ -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,17 +108,19 @@ 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];
|
|
117
115
|
|
|
118
116
|
var updateParentData = function updateParentData(generalValue, isAiAccepted) {
|
|
117
|
+
var newBaseValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
119
118
|
setTextValue({
|
|
120
119
|
value: generalValue
|
|
121
120
|
});
|
|
122
|
-
var
|
|
123
|
-
var
|
|
121
|
+
var baseToCompare = newBaseValue !== null ? newBaseValue : valueAccepted;
|
|
122
|
+
var similarity = (0, _compareStrings.getTextSimilarityPercentage)(baseToCompare, generalValue);
|
|
123
|
+
var generatedWithAi = (isAiAccepted || aiGenerated) && similarity >= 50;
|
|
124
124
|
|
|
125
125
|
if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
|
|
126
126
|
var dataSave = (updatedDatasheets === null || updatedDatasheets === void 0 ? void 0 : updatedDatasheets.slice()) || [];
|
|
@@ -188,10 +188,8 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
188
188
|
(0, _react.useEffect)(function () {
|
|
189
189
|
var _suggestions$inputId;
|
|
190
190
|
|
|
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
|
-
|
|
191
|
+
if (Object.keys(suggestions).length === 0) return;
|
|
192
|
+
if (currentSuggestion !== null && currentSuggestion !== void 0 && currentSuggestion[inputId]) return;
|
|
195
193
|
var firstSuggestion = suggestions === null || suggestions === void 0 ? void 0 : (_suggestions$inputId = suggestions[inputId]) === null || _suggestions$inputId === void 0 ? void 0 : _suggestions$inputId[0];
|
|
196
194
|
if (!firstSuggestion) return;
|
|
197
195
|
setCurrentSuggestionValue({
|
|
@@ -200,11 +198,14 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
200
198
|
value: firstSuggestion === null || firstSuggestion === void 0 ? void 0 : firstSuggestion.value
|
|
201
199
|
});
|
|
202
200
|
}, [suggestions]);
|
|
201
|
+
(0, _react.useEffect)(function () {
|
|
202
|
+
if (!isAiActive) return;
|
|
203
|
+
setAiSuggestionAccepted(false);
|
|
204
|
+
}, [isAiActive]);
|
|
203
205
|
(0, _react.useEffect)(function () {
|
|
204
206
|
if (!isAiActive && !aiSuggestionAccepted) {
|
|
205
|
-
var restoredValue = (0, _typeof2.default)(valueAccepted) === 'object' ? valueAccepted.value : valueAccepted;
|
|
206
207
|
setTextValue({
|
|
207
|
-
value:
|
|
208
|
+
value: valueAccepted
|
|
208
209
|
});
|
|
209
210
|
}
|
|
210
211
|
}, [suggestions, isAiActive]);
|
|
@@ -228,12 +229,10 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
228
229
|
|
|
229
230
|
var handleAcceptSuggestion = function handleAcceptSuggestion(suggestionValue) {
|
|
230
231
|
if (!suggestionValue) return;
|
|
231
|
-
setValueAccepted(
|
|
232
|
-
value: suggestionValue
|
|
233
|
-
});
|
|
232
|
+
setValueAccepted(suggestionValue);
|
|
234
233
|
setAiSuggestionAccepted(true);
|
|
235
234
|
setIsAiActive(false);
|
|
236
|
-
updateParentData(suggestionValue, true);
|
|
235
|
+
updateParentData(suggestionValue, true, suggestionValue);
|
|
237
236
|
};
|
|
238
237
|
|
|
239
238
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, {
|
|
@@ -335,28 +335,29 @@ 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), {
|
|
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;
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -66,14 +66,16 @@ 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
|
-
const updateParentData = (generalValue, isAiAccepted) => {
|
|
71
|
+
const updateParentData = (generalValue, isAiAccepted, newBaseValue = null) => {
|
|
72
72
|
setTextValue({ value: generalValue });
|
|
73
73
|
|
|
74
|
-
const
|
|
74
|
+
const baseToCompare = newBaseValue !== null ? newBaseValue : valueAccepted;
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const similarity = getTextSimilarityPercentage(baseToCompare, generalValue);
|
|
77
|
+
|
|
78
|
+
const generatedWithAi = (isAiAccepted || aiGenerated) && similarity >= 50;
|
|
77
79
|
|
|
78
80
|
if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
|
|
79
81
|
let dataSave = updatedDatasheets?.slice() || [];
|
|
@@ -107,6 +109,7 @@ export const GeneralInput = ({
|
|
|
107
109
|
});
|
|
108
110
|
}
|
|
109
111
|
}
|
|
112
|
+
|
|
110
113
|
setUpdatedDatasheets(dataSave);
|
|
111
114
|
}
|
|
112
115
|
};
|
|
@@ -139,10 +142,8 @@ export const GeneralInput = ({
|
|
|
139
142
|
|
|
140
143
|
if(Object.keys(suggestions).length === 0) return;
|
|
141
144
|
|
|
142
|
-
// Si ya existe una sugerencia actual generada, mantenla en su posicion
|
|
143
145
|
if(currentSuggestion?.[inputId]) return
|
|
144
146
|
|
|
145
|
-
// Si no hay una sugerencia actual generada, seteamos la primera nueva sugerencia como default
|
|
146
147
|
|
|
147
148
|
const firstSuggestion = suggestions?.[inputId]?.[0];
|
|
148
149
|
|
|
@@ -156,10 +157,14 @@ export const GeneralInput = ({
|
|
|
156
157
|
|
|
157
158
|
}, [suggestions]);
|
|
158
159
|
|
|
159
|
-
useEffect(() => {
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if(!isAiActive) return;
|
|
162
|
+
setAiSuggestionAccepted(false);
|
|
163
|
+
}, [isAiActive]);
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
160
166
|
if(!isAiActive && !aiSuggestionAccepted) {
|
|
161
|
-
|
|
162
|
-
setTextValue({ value: restoredValue });
|
|
167
|
+
setTextValue({ value: valueAccepted });
|
|
163
168
|
}
|
|
164
169
|
}, [suggestions, isAiActive]);
|
|
165
170
|
|
|
@@ -182,13 +187,13 @@ useEffect(() => {
|
|
|
182
187
|
//AI Generation
|
|
183
188
|
|
|
184
189
|
const handleAcceptSuggestion = (suggestionValue) => {
|
|
185
|
-
|
|
190
|
+
if(!suggestionValue) return;
|
|
186
191
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
setValueAccepted(suggestionValue);
|
|
193
|
+
setAiSuggestionAccepted(true);
|
|
194
|
+
setIsAiActive(false);
|
|
190
195
|
|
|
191
|
-
|
|
196
|
+
updateParentData(suggestionValue, true, suggestionValue);
|
|
192
197
|
}
|
|
193
198
|
|
|
194
199
|
return (
|
|
@@ -234,41 +234,37 @@ export const TagAndInput = ({
|
|
|
234
234
|
}, [boxOnboardingList]);
|
|
235
235
|
|
|
236
236
|
useEffect(() => {
|
|
237
|
+
const currentDescriptionUpdate = Array.isArray(updatedDescriptions)
|
|
238
|
+
? updatedDescriptions.find(desc => desc?.attributeId === inputId)
|
|
239
|
+
: null;
|
|
237
240
|
|
|
238
|
-
|
|
241
|
+
const currentDatasheetUpdate = Array.isArray(updatedDatasheets)
|
|
242
|
+
? updatedDatasheets.find(data => data?.attributeId === inputId)
|
|
243
|
+
: null;
|
|
239
244
|
|
|
240
|
-
|
|
241
|
-
description => description?.attributeId === inputId
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
const calculatedIsAiGenerated = currentDescriptionUpdate
|
|
245
|
-
? !!currentDescriptionUpdate.aiSuggestionAccepted
|
|
246
|
-
: aiGenerated;
|
|
247
|
-
|
|
248
|
-
setInputsGeneratedWithAi(prev => ({
|
|
249
|
-
...prev,
|
|
250
|
-
[`${inputId}-${inputType}-${version}`]: {
|
|
251
|
-
inputType,
|
|
252
|
-
inputId,
|
|
253
|
-
version,
|
|
254
|
-
isAiGenerated: calculatedIsAiGenerated,
|
|
255
|
-
label
|
|
256
|
-
}
|
|
257
|
-
}))
|
|
245
|
+
let calculatedIsAiGenerated = aiGenerated;
|
|
258
246
|
|
|
247
|
+
if (currentDescriptionUpdate) {
|
|
248
|
+
calculatedIsAiGenerated = currentDescriptionUpdate.aiSuggestionAccepted;
|
|
249
|
+
} else if (currentDatasheetUpdate) {
|
|
250
|
+
calculatedIsAiGenerated = currentDatasheetUpdate.aiSuggestionAccepted;
|
|
259
251
|
}
|
|
260
252
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
253
|
+
setInputsGeneratedWithAi(prev => ({
|
|
254
|
+
...prev,
|
|
255
|
+
[`${inputId}-${inputType}-${version}`]: {
|
|
256
|
+
inputType,
|
|
257
|
+
inputId,
|
|
258
|
+
version,
|
|
259
|
+
isAiGenerated: !!calculatedIsAiGenerated,
|
|
260
|
+
label
|
|
261
|
+
}
|
|
262
|
+
}));
|
|
264
263
|
|
|
265
264
|
}, [updatedDescriptions, updatedDatasheets, aiGenerated, inputId]);
|
|
266
265
|
|
|
267
|
-
|
|
268
266
|
useEffect(() => {
|
|
269
|
-
|
|
270
267
|
setIsAiGenerated(!!inputsGeneratedWithAi[`${inputId}-${inputType}-${version}`]?.isAiGenerated);
|
|
271
|
-
|
|
272
268
|
}, [inputsGeneratedWithAi]);
|
|
273
269
|
|
|
274
270
|
useEffect(() => {
|
|
@@ -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
|
|