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


##########
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:
   **Suggestion:** `setup` accepts only `value` and `onChange`, so this call's 
`options` property is an excess property and fails TypeScript checking for the 
included test file.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Often` ยท ๐Ÿท๏ธ `Type error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=be24eb2fc1004fc9880ed666cea7c7af&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=be24eb2fc1004fc9880ed666cea7c7af&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.test.tsx
   **Line:** 123:123
   **Comment:**
        *Type Error: `setup` accepts only `value` and `onChange`, so this 
call's `options` property is an excess property and fails TypeScript checking 
for the included test file.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45039&comment_hash=0e89d455c31a101cec7a6a8b050e937dd1d03f78c362917b3fd2301104201ee9&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45039&comment_hash=0e89d455c31a101cec7a6a8b050e937dd1d03f78c362917b3fd2301104201ee9&reaction=dislike'>๐Ÿ‘Ž</a>



##########
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:
   **Suggestion:** After a custom value is entered, choosing a preset updates 
`value` and this effect clears it; switching back to Custom then loses the 
user's interval.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Logic error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aa8e2735fdd84fd29dd3cf7734b899d0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aa8e2735fdd84fd29dd3cf7734b899d0&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx
   **Line:** 196:196
   **Comment:**
        *Logic Error: After a custom value is entered, choosing a preset 
updates `value` and this effect clears it; switching back to Custom then loses 
the user's interval.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45039&comment_hash=05bdc7f3ece21b648dcadc356dbb79122490bde7ab2e5083a31d5dca5ec037b3&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45039&comment_hash=05bdc7f3ece21b648dcadc356dbb79122490bde7ab2e5083a31d5dca5ec037b3&reaction=dislike'>๐Ÿ‘Ž</a>



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