codeant-ai-for-open-source[bot] commented on code in PR #45039:
URL: https://github.com/apache/superset/pull/45039#discussion_r4252611238


##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.test.tsx:
##########
@@ -38,3 +45,210 @@ test('getRefreshWarningMessage normalizes refreshLimit', () 
=> {
   expect(getRefreshWarningMessage(5, 10, 'warn')).toBe('warn');
   expect(getRefreshWarningMessage(15, 10000, 'warn')).toBeNull();
 });
+
+const mockConfiguredIntervals: [number, string][] = [
+  [0, "Don't refresh"],
+  [15, '15 seconds'],
+  [45, '45 seconds'],
+  [90, '90 seconds'],
+];
+
+const createInitialState = (
+  intervals?: [number, string][],
+  extraConf?: Record<string, unknown>,
+) => ({
+  dashboardInfo: {
+    common: {
+      conf: {
+        ...(intervals !== undefined
+          ? { DASHBOARD_AUTO_REFRESH_INTERVALS: intervals }
+          : {}),
+        ...extraConf,
+      },
+    },
+  },
+});
+
+const defaultTestProps = {
+  value: 0,
+  onChange: jest.fn(),
+};
+
+const setup = (
+  props: Partial<typeof defaultTestProps> = {},
+  initialState?: object,
+) =>
+  render(<RefreshFrequencySelect {...defaultTestProps} {...props} />, {
+    useRedux: true,
+    ...(initialState ? { initialState } : {}),
+  });
+
+test('renders configured auto refresh intervals from redux store', () => {
+  setup({}, createInitialState(mockConfiguredIntervals));
+
+  expect(screen.getByRole('radio', { name: '15 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '45 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '90 seconds' 
})).toBeInTheDocument();
+  expect(
+    screen.queryByRole('radio', { name: '10 seconds' }),
+  ).not.toBeInTheDocument();
+});
+
+test('renders default options when config is not present', () => {
+  setup({}, createInitialState(undefined));
+
+  expect(
+    screen.getByRole('radio', { name: "Don't refresh" }),
+  ).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '10 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '30 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '1 minute' })).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '24 hours' })).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: /Custom/i })).toBeInTheDocument();
+});
+
+test('renders default options when configured intervals is empty array', () => 
{
+  setup({}, createInitialState([]));
+
+  expect(screen.getByRole('radio', { name: '10 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '30 seconds' 
})).toBeInTheDocument();
+});
+
+test('options prop takes precedence over redux store configured intervals', () 
=> {
+  const propOptions: [number, string][] = [
+    [5, '5 seconds'],
+    [25, '25 seconds'],
+  ];
+
+  setup({ options: propOptions }, createInitialState(mockConfiguredIntervals));

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `44f8e86`.
   
   The test now directly checks the options returned by 
`getRefreshFrequencyOptions`; the `setup` call with an unsupported `options` 
property is gone.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx:
##########
@@ -87,31 +120,81 @@ const normalizeRefreshLimitSeconds = (
   return refreshLimit;
 };
 
-interface RefreshFrequencySelectProps {
+/**
+ * Props for the RefreshFrequencySelect component.
+ */
+export interface RefreshFrequencySelectProps {
+  /** The currently selected refresh frequency in seconds. */
   value: number;
+  /** Callback fired when a new refresh frequency is selected or typed. */
   onChange: (value: number) => void;
+  /** Optional override for available interval options as [seconds, label] 
tuples. */
+  options?: [number, string][];
 }
 
 /**
- * Shared refresh frequency select component
- * Used in both PropertiesModal and RefreshIntervalModal
+ * Shared refresh frequency select component.
+ *
+ * Renders radio buttons for available auto refresh frequencies.
+ * Reads configured intervals dynamically from Redux store
+ * (state.dashboardInfo.common.conf.DASHBOARD_AUTO_REFRESH_INTERVALS)
+ * with a fallback to REFRESH_FREQUENCY_OPTIONS if unconfigured.
+ * Also supports direct options prop override and custom numeric interval 
entry.
  */
 export const RefreshFrequencySelect = ({
   value,
   onChange,
+  options: optionsProp,
 }: RefreshFrequencySelectProps) => {
+  const configuredIntervals = useSelector(
+    (state: RootState) =>
+      state.dashboardInfo?.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS,
+  );
+
+  const activeOptions = useMemo(() => {
+    const rawOptions = optionsProp ?? configuredIntervals;
+    if (Array.isArray(rawOptions) && rawOptions.length > 0) {
+      const validOptions = rawOptions
+        .filter(
+          (item) =>
+            Array.isArray(item) &&
+            typeof item[0] === 'number' &&
+            !Number.isNaN(item[0]) &&
+            typeof item[1] === 'string',
+        )
+        .map(([interval, label]) => ({
+          value: interval,
+          label: t(label),
+        }));
+      if (validOptions.length > 0) {
+        return validOptions;
+      }
+    }
+    return REFRESH_FREQUENCY_OPTIONS.slice(0, -1);
+  }, [optionsProp, configuredIntervals]);
+
+  const isPreset = useCallback(
+    (frequency: number) => isPresetValue(frequency, activeOptions),
+    [activeOptions],
+  );
+
+  const getCustom = useCallback(
+    (frequency: number) => getCustomValue(frequency, activeOptions),
+    [activeOptions],
+  );
+
   // Separate radio selection state from value state
   const [radioSelection, setRadioSelection] = useState(() =>
-    isPresetValue(value) ? value : -1,
+    isPreset(value) ? value : -1,
   );
 
-  const [customValue, setCustomValue] = useState(() => getCustomValue(value));
+  const [customValue, setCustomValue] = useState(() => getCustom(value));
 
   useEffect(() => {
-    const selection = isPresetValue(value) ? value : -1;
+    const selection = isPreset(value) ? value : -1;
     setRadioSelection(selection);
-    setCustomValue(selection === -1 ? getCustomValue(value) : '');
-  }, [value]);
+    setCustomValue(selection === -1 ? getCustom(value) : '');

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `44f8e86`.
   
   The effect updates `customValue` only when Custom is selected, so selecting 
a preset no longer clears the previously entered custom interval.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



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