kokhlo commented on code in PR #44982:
URL: https://github.com/apache/superset/pull/44982#discussion_r4195896410


##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx:
##########
@@ -62,16 +72,73 @@ export const REFRESH_FREQUENCY_OPTIONS = [
   { value: 21600, label: t('6 hours') },
   { value: 43200, label: t('12 hours') },
   { value: 86400, label: t('24 hours') },
-  { value: -1, label: t('Custom') },
+  { value: CUSTOM_REFRESH_FREQUENCY, label: t('Custom') },
 ];
 
-const isPresetValue = (frequency: number) =>
-  REFRESH_FREQUENCY_OPTIONS.some(
-    option => option.value === frequency && option.value !== -1,
+const isPresetValue = (frequency: number, options: RefreshFrequencyOption[]) =>
+  options.some(
+    option =>
+      option.value === frequency && option.value !== CUSTOM_REFRESH_FREQUENCY,
+  );
+
+// `Number(null)`, `Number('')` and `Number([])` all yield 0, and 0 is a real
+// interval, so a bare Number() would smuggle malformed entries in as valid.
+const toIntervalSeconds = (value: unknown): number => {
+  const isNumeric = typeof value === 'number' || typeof value === 'string';
+  return isNumeric && String(value).trim() !== '' ? Number(value) : Number.NaN;
+};
+
+/**
+ * Builds the interval list from DASHBOARD_AUTO_REFRESH_INTERVALS, which 
reaches
+ * the browser as a list of `[seconds, label]` pairs. Labels stay verbatim: the
+ * deployment authored them, so translating them here would rewrite operator
+ * wording. Anything that is not a well-formed non-empty list falls back to the
+ * built-in options rather than rendering an empty selector.
+ */
+export const getRefreshFrequencyOptions = (
+  configuredIntervals?: unknown,
+): RefreshFrequencyOption[] => {
+  const options: RefreshFrequencyOption[] = [];
+  const seen = new Set<number>();
+
+  (Array.isArray(configuredIntervals) ? configuredIntervals : []).forEach(
+    pair => {
+      if (!Array.isArray(pair)) {
+        return;
+      }
+      const [value, label] = pair;
+      const seconds = toIntervalSeconds(value);
+      const isLabelled = typeof label === 'string' && label.trim() !== '';
+      if (!Number.isFinite(seconds) || seconds < 0 || !isLabelled) {
+        return;
+      }
+      // Deployment overrides are unvalidated; a repeated interval would render
+      // duplicate React keys and two simultaneously-checked radios.
+      if (seen.has(seconds)) {
+        return;
+      }
+      seen.add(seconds);
+      options.push({ value: seconds, label });

Review Comment:
   Done in c88a92769b — `options.push({ value: seconds, label: t(label) })`, 
matching how both prior selectors rendered these. Labels without a catalog 
entry come back unchanged, so custom non-English wording still survives 
verbatim.



##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.test.tsx:
##########
@@ -38,3 +41,95 @@ test('getRefreshWarningMessage normalizes refreshLimit', () 
=> {
   expect(getRefreshWarningMessage(5, 10, 'warn')).toBe('warn');
   expect(getRefreshWarningMessage(15, 10000, 'warn')).toBeNull();
 });
+
+test('getRefreshFrequencyOptions honours the configured intervals', () => {
+  const options = getRefreshFrequencyOptions([
+    [0, "Don't refresh"],
+    [600, '10 minutes'],
+    [1800, '30 minutes'],
+    [3600, '1 hour'],
+  ]);
+
+  expect(options).toEqual([
+    { value: 0, label: "Don't refresh" },
+    { value: 600, label: '10 minutes' },
+    { value: 1800, label: '30 minutes' },
+    { value: 3600, label: '1 hour' },
+    { value: CUSTOM_REFRESH_FREQUENCY, label: 'Custom' },
+  ]);
+});
+
+test('getRefreshFrequencyOptions falls back to the built-in list when the 
config is absent', () => {
+  expect(getRefreshFrequencyOptions(undefined)).toEqual(
+    REFRESH_FREQUENCY_OPTIONS,
+  );
+  expect(getRefreshFrequencyOptions([])).toEqual(REFRESH_FREQUENCY_OPTIONS);
+  expect(getRefreshFrequencyOptions('10 seconds')).toEqual(
+    REFRESH_FREQUENCY_OPTIONS,
+  );
+});
+
+test('getRefreshFrequencyOptions drops malformed entries instead of rendering 
them', () => {
+  const options = getRefreshFrequencyOptions([
+    [600],
+    ['not-a-number', 'Ten minutes'],
+    [-5, 'Negative'],
+    [1800, '   '],
+    [1800, null],
+    [3600, '1 hour'],
+  ]);
+
+  expect(options).toEqual([
+    { value: 3600, label: '1 hour' },
+    { value: CUSTOM_REFRESH_FREQUENCY, label: 'Custom' },
+  ]);
+});
+
+test('getRefreshFrequencyOptions keeps configured labels verbatim, including 
untranslated ones', () => {

Review Comment:
   Reworked in c88a92769b: the suite now mocks `t()` (the 
`jest.mock('@apache-superset/core/translation', ...)` pattern used elsewhere), 
and the test registers `10 seconds → 10 Sekunden` and asserts the translated 
label comes through while `10 Minuten` passes through untouched.



##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.test.tsx:
##########
@@ -38,3 +41,95 @@ test('getRefreshWarningMessage normalizes refreshLimit', () 
=> {
   expect(getRefreshWarningMessage(5, 10, 'warn')).toBe('warn');
   expect(getRefreshWarningMessage(15, 10000, 'warn')).toBeNull();
 });
+
+test('getRefreshFrequencyOptions honours the configured intervals', () => {
+  const options = getRefreshFrequencyOptions([
+    [0, "Don't refresh"],
+    [600, '10 minutes'],
+    [1800, '30 minutes'],
+    [3600, '1 hour'],
+  ]);
+
+  expect(options).toEqual([
+    { value: 0, label: "Don't refresh" },
+    { value: 600, label: '10 minutes' },
+    { value: 1800, label: '30 minutes' },
+    { value: 3600, label: '1 hour' },
+    { value: CUSTOM_REFRESH_FREQUENCY, label: 'Custom' },
+  ]);
+});
+
+test('getRefreshFrequencyOptions falls back to the built-in list when the 
config is absent', () => {
+  expect(getRefreshFrequencyOptions(undefined)).toEqual(
+    REFRESH_FREQUENCY_OPTIONS,
+  );
+  expect(getRefreshFrequencyOptions([])).toEqual(REFRESH_FREQUENCY_OPTIONS);
+  expect(getRefreshFrequencyOptions('10 seconds')).toEqual(
+    REFRESH_FREQUENCY_OPTIONS,
+  );
+});
+
+test('getRefreshFrequencyOptions drops malformed entries instead of rendering 
them', () => {
+  const options = getRefreshFrequencyOptions([
+    [600],
+    ['not-a-number', 'Ten minutes'],
+    [-5, 'Negative'],
+    [1800, '   '],
+    [1800, null],
+    [3600, '1 hour'],
+  ]);
+
+  expect(options).toEqual([
+    { value: 3600, label: '1 hour' },
+    { value: CUSTOM_REFRESH_FREQUENCY, label: 'Custom' },
+  ]);
+});
+
+test('getRefreshFrequencyOptions keeps configured labels verbatim, including 
untranslated ones', () => {
+  const options = getRefreshFrequencyOptions([[600, '10 Minuten']]);
+
+  expect(options[0].label).toBe('10 Minuten');
+});
+
+test('getRefreshFrequencyOptions does not append a second Custom entry', () => 
{
+  const options = getRefreshFrequencyOptions([
+    [600, '10 minutes'],
+    [CUSTOM_REFRESH_FREQUENCY, 'Custom'],

Review Comment:
   Right — `[-1, 'Custom']` died at the `seconds < 0` guard, so `hasCustom` was 
unreachable on the configured path. Dropped the branch in c88a92769b: a 
configured list now always gets exactly one built-in Custom appended, and the 
test pins that outcome directly.



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