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


##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx:
##########
@@ -134,6 +141,88 @@ export const getRefreshFrequencyOptions = (
     : REFRESH_FREQUENCY_OPTIONS;
 };
 
+const BOUND_UNIT_SECONDS: Record<string, number> = {
+  seconds: 1,
+  minutes: 60,
+  hours: 3600,
+};
+
+// Must match `_bound_seconds` in superset/dashboards/refresh_policy.py, which
+// `check_refresh_policy` uses on the server.
+/** Parse a positive whole duration using the server policy contract. */
+export const getBoundSeconds = (bound: unknown): number | null => {
+  if (!bound || typeof bound !== 'object' || Array.isArray(bound)) {
+    return null;
+  }
+  const keys = Object.keys(bound);
+  if (keys.length !== 2 || !keys.includes('value') || !keys.includes('unit')) {
+    return null;
+  }
+  const { value, unit } = bound as { value: unknown; unit: unknown };
+  if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
+    return null;
+  }
+  if (typeof unit !== 'string' || !Object.hasOwn(BOUND_UNIT_SECONDS, unit)) {
+    return null;
+  }
+  return value * BOUND_UNIT_SECONDS[unit];
+};
+
+/** Filter standard runtime choices by the saved dashboard policy. */
+export const getAllowedRefreshOptions = (
+  policy: unknown,
+  configuredIntervals?: unknown,
+): RefreshFrequencyOption[] => {
+  const options = getRefreshFrequencyOptions(configuredIntervals);
+  if (policy === null || policy === undefined) {
+    return options;
+  }
+  if (typeof policy !== 'object' || Array.isArray(policy)) {
+    return [];
+  }
+  const {
+    auto_refresh_allowed: autoRefreshAllowed,
+    minimum_refresh_interval: minimumBound,
+    maximum_refresh_interval: maximumBound,
+  } = policy as Record<string, unknown>;
+  if (autoRefreshAllowed === false) {
+    return [];
+  }
+  const minimum = getBoundSeconds(minimumBound);
+  const maximum = getBoundSeconds(maximumBound);
+  const dontRefresh = options.find(option => option.value === 0) ?? {
+    value: 0,
+    label: t("Don't refresh"),
+  };
+  if (minimum !== null && maximum !== null && minimum > maximum) {
+    return [dontRefresh];
+  }
+  return [
+    dontRefresh,
+    ...options.filter(
+      ({ value }) =>
+        value > 0 &&
+        Number.isInteger(value) &&
+        (minimum === null || value >= minimum) &&
+        (maximum === null || value <= maximum),

Review Comment:
   **Suggestion:** A malformed bound saved while the feature flag was off 
becomes `null` here and is treated as unbounded, letting viewers refresh 
outside the intended policy.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Incorrect condition 
logic`
   
   [![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=04128f152265432792fd682121ba59dd&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=04128f152265432792fd682121ba59dd&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:** 206:207
   **Comment:**
        *Incorrect Condition Logic: A malformed bound saved while the feature 
flag was off becomes `null` here and is treated as unbounded, letting viewers 
refresh outside the intended policy.
   
   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%2F46037&comment_hash=73466f4be6b7f6c38b9d441731b30abbfcb5a90799adfce2868550c3c59c3248&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F46037&comment_hash=73466f4be6b7f6c38b9d441731b30abbfcb5a90799adfce2868550c3c59c3248&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]

  • [PR] feat(d... DamianPendrak (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codecov[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... netlify[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications

Reply via email to