From 854959a83644911a2c3046a08ffd9116a3f91f66 Mon Sep 17 00:00:00 2001
From: deep1401 <gandhi0869@gmail.com>
Date: Tue, 25 Feb 2025 16:05:54 -0800
Subject: [PATCH] Edit functionality doesn't work properly including the tab
 switch

---
 .../Widgets/CustomEvaluationWidget.tsx        | 71 ++++++++-----------
 1 file changed, 28 insertions(+), 43 deletions(-)

diff --git a/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx b/src/renderer/components/Experiment/Widgets/CustomEvaluationWidget.tsx
index 396c57e3..a7308958 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(() => {
-- 
GitLab