rtexelm commented on code in PR #27891:
URL: https://github.com/apache/superset/pull/27891#discussion_r1575404825


##########
superset-frontend/src/components/AlteredSliceTag/index.tsx:
##########
@@ -149,72 +180,39 @@ class AlteredSliceTag extends React.Component<
       if (['filters', 'having', 'where'].includes(fdKey)) {
         return;
       }
-      if (!this.isEqualish(ofd[fdKey], cfd[fdKey])) {
+      if (!isEqualish(ofd[fdKey], cfd[fdKey])) {
         diffs[fdKey] = { before: ofd[fdKey], after: cfd[fdKey] };
       }
     });
     return diffs;
-  }
+  }, [props.currentFormData, props.origFormData]);
 
-  isEqualish(val1: string, val2: string): boolean {
-    return isEqual(alterForComparison(val1), alterForComparison(val2));
-  }
+  useEffect(() => {
+    const diffs = getDiffs();
+    const controlsMap = getControlsForVizType(
+      props.origFormData?.viz_type,
+    ) as ControlMap;
+    setRows(getRowsFromDiffs(diffs, controlsMap));
+    setHasDiffs(!isEmpty(diffs));
+  }, [getDiffs, props]);
 
-  formatValue(
-    value: DiffItemType,
-    key: string,
-    controlsMap: ControlMap,
-  ): string | number {
-    if (value === undefined) {
-      return 'N/A';
-    }
-    if (value === null) {
-      return 'null';
-    }
-    if (
-      controlsMap[key]?.type === 'AdhocFilterControl' &&
-      Array.isArray(value)
-    ) {
-      if (!value.length) {
-        return '[]';
+  useEffect(() => {
+    const diffs = getDiffs();
+
+    const updateStateWithDiffs = () => {
+      if (isEqual(prevProps, props)) {
+        return;
       }
-      return value
-        .map((v: FilterItemType) => {
-          const filterVal =
-            v.comparator && v.comparator.constructor === Array
-              ? `[${v.comparator.join(', ')}]`
-              : v.comparator;
-          return `${v.subject} ${v.operator} ${filterVal}`;
-        })
-        .join(', ');
-    }
-    if (controlsMap[key]?.type === 'BoundsControl') {
-      return `Min: ${value[0]}, Max: ${value[1]}`;
-    }
-    if (
-      controlsMap[key]?.type === 'CollectionControl' &&
-      Array.isArray(value)
-    ) {
-      return value.map(v => safeStringify(v)).join(', ');
-    }
-    if (controlsMap[key]?.type === 'MetricsControl' && Array.isArray(value)) {
-      const formattedValue = value.map((v: FilterItemType) => v?.label ?? v);
-      return formattedValue.length ? formattedValue.join(', ') : '[]';
-    }
-    if (typeof value === 'boolean') {
-      return value ? 'true' : 'false';
-    }
-    if (Array.isArray(value)) {
-      const formattedValue = value.map((v: FilterItemType) => v?.label ?? v);
-      return formattedValue.length ? formattedValue.join(', ') : '[]';
-    }
-    if (typeof value === 'string' || typeof value === 'number') {
-      return value;
-    }
-    return safeStringify(value);
-  }
+      setRows(prevRows =>
+        getRowsFromDiffs(diffs, prevRows as unknown as ControlMap),
+      );
+      setHasDiffs(!isEmpty(diffs));
+    };
+
+    updateStateWithDiffs();
+  }, [getDiffs, props, prevProps]);

Review Comment:
   this is an oversight from trying to shoehorn all the changes from the AI 
into the file, the second seems useEffect like a less helpful approach so I'll 
delete it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to