codeant-ai-for-open-source[bot] commented on code in PR #45039:
URL: https://github.com/apache/superset/pull/45039#discussion_r4216871294
##########
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 `d94a14d`.
The value-sync effect now updates `customValue` only when the incoming value
is not a preset. Selecting a preset therefore preserves 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]