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


##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx:
##########
@@ -141,7 +224,7 @@ export const RefreshFrequencySelect = ({
 
   return (
     <StyledRadioGroup value={radioSelection} onChange={handleRadioChange}>
-      {REFRESH_FREQUENCY_OPTIONS.slice(0, -1).map(option => (
+      {activeOptions.map((option) => (

Review Comment:
   The new `(option) =>` / `(e) =>` arrow parens (here, line 89 and line 243) 
conflict with `arrowParens: "avoid"` in `.oxfmtrc.json`. The `pre-commit` job 
is already red because the formatter rewrites this file, so the PR can't merge 
until the formatter output is committed. Could you run the repo formatter on 
this file and keep the pre-existing `option =>` / `e =>` style?



##########
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:
   Agreed—`state.common.conf` is the store slice populated from bootstrap data 
on the dashboard list and home pages, while `dashboardInfo.common` is only 
filled by dashboard hydration, so the Properties modal on those pages still 
shows the hardcoded presets. Could the selector read `state.common.conf` first 
and fall back to `dashboardInfo.common.conf`?



##########
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:
   Agreed—with a configured 1-second preset, clicking Custom emits 
`onChange(1)`, the controlled parent feeds `1` back, and the `[value, isPreset, 
getCustom]` effect re-selects the preset and disables the custom input, so 
Custom can't be edited on the first click. Could the effect skip re-syncing 
when the incoming value was just emitted by the Custom radio?



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