diff --git a/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx b/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx index 396c57e3eefcee0dc1b887a0af83c835c4afa53a..a730895851db86a8ad2a4087ac27a0a15eeae065 100644 --- a/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx +++ b/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx @@ -15,54 +15,39 @@ type EvaluationField = { }; + const CustomEvaluationWidget = (props: WidgetProps<any>) => { 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 - const [evalMetrics, setEvalMetrics] = React.useState<EvaluationField[]>(parseValue(valueSent)); + // let newValue = value; + // if (typeof value === 'string') { + // try { + // newValue = []; + // } catch (e) { + // newValue = []; + // } - // Update state if a new default value is provided - React.useEffect(() => { - const parsed = parseValue(valueSent); - if (JSON.stringify(parsed) !== JSON.stringify(evalMetrics)) { - setEvalMetrics(parsed); - } - }, [value]); + // } else if (Array.isArray(value) && value.length > 0) { + // if (typeof value[0] === 'string') { + // newValue = JSON.parse(value.join(',')); + // } + // } + + + // 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. React.useEffect(() => {