Copilot commented on code in PR #45039:
URL: https://github.com/apache/superset/pull/45039#discussion_r4210410189


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

Review Comment:
   PropertiesModal also uses this selector on the dashboard list and home page. 
Those routes store configuration in `state.common.conf` 
(`src/views/store.ts:149`), while `dashboardInfo` starts empty. Its legacy 
`common` alias is populated by dashboard hydration 
(`src/dashboard/actions/hydrate.ts:379-381`). As a result, these editors still 
show hardcoded intervals. Read the top-level configuration first, retain the 
legacy fallback, and add a test with the list-page store shape.



##########
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:
   When configured intervals include a 1-second preset, selecting Custom from 0 
emits `onChange(1)`. The production parents feed that value back, so this 
effect immediately selects the preset, clears the custom value, and disables 
the input. Preserve explicitly selected Custom mode when receiving locally 
emitted values, while still synchronizing external value or option changes. Add 
a controlled-parent regression test: the new callback-only mocks do not feed 
updated values back and miss this failure.



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