bito-code-review[bot] commented on code in PR #40905:
URL: https://github.com/apache/superset/pull/40905#discussion_r3531135441


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/getControlItemsMap.tsx:
##########
@@ -64,6 +70,127 @@ const CleanFormItem = styled(FormItem)`
   margin-bottom: 0;
 `;
 
+/** Resolves the saved or default initial value for a control. */
+function resolveInitialValue(
+  controlItem: CustomControlItem,
+  filterToEdit?: ControlItemsProps['filterToEdit'],
+  customizationToEdit?: ControlItemsProps['customizationToEdit'],
+) {
+  return (
+    filterToEdit?.controlValues?.[controlItem.name] ??
+    customizationToEdit?.controlValues?.[controlItem.name] ??
+    controlItem?.config?.default ??
+    null
+  );
+}
+
+/** Renders a StyledLabel with an optional description tooltip. */
+function ControlLabel({
+  label,
+  description,
+  fallbackLabel,
+}: {
+  label?: BaseControlConfig['label'];
+  description?: BaseControlConfig['description'];
+  fallbackLabel?: ReactNode;
+}) {
+  // Only zero-argument label/description functions are safe to invoke here:
+  // (state, controlState, chartState) are supplied by the Explore control
+  // panel renderer (ControlPanelsContainer), which this filter-config-modal
+  // control list does not have access to.
+  const resolvedLabel =
+    (typeof label === 'function'
+      ? label.length === 0
+        ? (label as () => ReactNode)()
+        : undefined
+      : label) ?? fallbackLabel;
+  const resolvedDescription =
+    typeof description === 'function'
+      ? description.length === 0
+        ? (description as () => ReactNode)()
+        : undefined
+      : description;
+  return (
+    <StyledLabel>
+      {resolvedLabel}
+      {resolvedDescription != null && (
+        <>
+          &nbsp;
+          <InfoTooltip placement="top" tooltip={resolvedDescription} />
+        </>
+      )}
+    </StyledLabel>
+  );
+}
+
+function DatasetColumnSelect({
+  datasetId,
+  value,
+  onChange,
+}: {
+  datasetId?: number;
+  value?: string | null;
+  onChange?: (value: string | null) => void;
+}) {
+  const [{ loadedForId, fetchedColumns }, setFetchState] = useState<{
+    loadedForId?: number;
+    fetchedColumns: string[];
+  }>({ fetchedColumns: [] });
+
+  const loading = !!(datasetId && loadedForId !== datasetId);
+  const options = loadedForId === datasetId ? fetchedColumns : [];
+
+  useEffect(() => {
+    if (!datasetId) {
+      // dataset cleared — drop any stale selection immediately
+      if (value) {
+        onChange?.(null);
+      }
+      return undefined;
+    }
+    let cancelled = false;
+    cachedSupersetGet({
+      endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({
+        columns: ['columns.column_name'],
+      })}`,
+    })
+      .then(({ json: { result } }) => {
+        if (cancelled) return;
+        const columnNames: string[] = result.columns
+          .map((col: { column_name: string }) => col.column_name)
+          .filter(Boolean);
+        setFetchState({ loadedForId: datasetId, fetchedColumns: columnNames });
+        if (value && !columnNames.includes(value)) {
+          onChange?.(null);
+        }
+      })
+      .catch(() => {
+        if (cancelled) return;
+        setFetchState({ loadedForId: datasetId, fetchedColumns: [] });
+        if (value) {
+          onChange?.(null);
+        }
+      });
+    return () => {
+      cancelled = true;
+    };
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [datasetId]);

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing test coverage for new behavior</b></div>
   <div id="fix">
   
   New behavior introduced by this diff (clearing stale selections on dataset 
clear, column mismatch, and errors) lacks test coverage. Per testing 
guidelines, verify actual business logic in tests, not just component rendering.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #3c0345</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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