Skip to content
Snippets Groups Projects
Commit 854959a8 authored by deep1401's avatar deep1401
Browse files

Edit functionality doesn't work properly including the tab switch

parent c8b63d17
No related branches found
No related tags found
No related merge requests found
...@@ -15,54 +15,39 @@ type EvaluationField = { ...@@ -15,54 +15,39 @@ type EvaluationField = {
}; };
const CustomEvaluationWidget = (props: WidgetProps<any>) => { const CustomEvaluationWidget = (props: WidgetProps<any>) => {
const { id, value, onChange, disabled, readonly } = props; const { id, value, onChange, disabled, readonly } = props;
const valueSent = value;
console.log("Value", valueSent);
const parseValue = (val: any): EvaluationField[] => {
if (Array.isArray(val)) {
if (val.every(item => typeof item === "string")) {
// If every element is a string: join them and parse the result.
try {
const joined = val.join(',');
console.log("Joined", joined);
console.log("TYPE", typeof joined);
const parsed = JSON.parse(joined);
console.log("PARSED HERE", parsed);
return Array.isArray(parsed) ? parsed : [];
} catch (err) {
console.error("Error parsing evaluation widget value:", err);
return [];
}
} else {
// If not all elements are strings, assume it's already an array of EvaluationField.
return val;
}
} else if (typeof val === "string") {
try {
return JSON.parse(val);
} catch (err) {
console.error("Error parsing evaluation widget value string:", err);
return [];
}
}
return [];
};
// const parsed = parseValue(value); const [evalMetrics, setEvalMetrics] = React.useState<EvaluationField[]>([]);
// Initialize state by parsing the incoming value // let newValue = value;
const [evalMetrics, setEvalMetrics] = React.useState<EvaluationField[]>(parseValue(valueSent)); // if (typeof value === 'string') {
// try {
// newValue = [];
// } catch (e) {
// newValue = [];
// }
// Update state if a new default value is provided // } else if (Array.isArray(value) && value.length > 0) {
React.useEffect(() => { // if (typeof value[0] === 'string') {
const parsed = parseValue(valueSent); // newValue = JSON.parse(value.join(','));
if (JSON.stringify(parsed) !== JSON.stringify(evalMetrics)) { // }
setEvalMetrics(parsed); // }
}
}, [value]);
// console.log("newValue", newValue);
// Initialize the state as an empty array without using the value prop.
// console.log("value", value);
// // Update the state when the value prop changes.
// React.useEffect(() => {
// if (value && JSON.stringify(value) !== JSON.stringify(evalMetrics)) {
// setEvalMetrics(newValue);
// }
// }
// , [value]);
// Propagate state changes upstream. // Propagate state changes upstream.
React.useEffect(() => { React.useEffect(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment