Skip to content

refactor: extract hardcoded thresholds and magic numbers to named constants#4024

Merged
clubanderson merged 2 commits intomainfrom
copilot/auto-qa-configurable-thresholds
Mar 31, 2026
Merged

refactor: extract hardcoded thresholds and magic numbers to named constants#4024
clubanderson merged 2 commits intomainfrom
copilot/auto-qa-configurable-thresholds

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Auto-QA flagged raw numeric literals scattered across five files that would be difficult to tune or reason about at a glance. All numbers are replaced with named, commented constants at the top of their respective files — zero behaviour change.

📌 Fixes


📝 Summary of Changes

Five files had inline magic numbers replaced with named module-level constants:

File Constants added
CardHistory.tsx MS_PER_MINUTE, MS_PER_HOUR, MS_PER_DAY, MS_PER_WEEK
Tour.tsx TOOLTIP_GAP (was inline 12), NEAR_TOP_THRESHOLD (was inline 100)
RunbookProgress.tsx MS_PER_SECOND
GPUDetailModal.tsx GPU_UTIL_HIGH = 90, GPU_UTIL_WARN = 70 — used in getUtilizationColor() and both progress-bar JSX expressions
ClusterGrid.tsx MIN_SPIN_DURATION_MS (default param for useMinSpin)

AlertRuleEditor.tsx and AlertDetail.tsx already had their numbers in named constants; no changes needed there.

Example — GPUDetailModal.tsx before/after:

// Before — same threshold repeated three times
if (percentage >= 90) return 'text-red-400'
if (percentage >= 70) return 'text-yellow-400'

// After — single source of truth
const GPU_UTIL_HIGH = 90 // Utilization % threshold for critical (red) status
const GPU_UTIL_WARN = 70 // Utilization % threshold for warning (yellow) status

if (percentage >= GPU_UTIL_HIGH) return 'text-red-400'
if (percentage >= GPU_UTIL_WARN) return 'text-yellow-400'

Changes Made

  • Extracted raw ms time-interval literals in CardHistory.tsx to MS_PER_* constants
  • Promoted gap = 12 local var and inline 100 threshold in Tour.tsx to module-level constants
  • Added MS_PER_SECOND to RunbookProgress.tsx for duration display threshold
  • Extracted GPU utilization thresholds in GPUDetailModal.tsx to GPU_UTIL_HIGH/GPU_UTIL_WARN
  • Replaced useMinSpin default parameter literal in ClusterGrid.tsx with MIN_SPIN_DURATION_MS

Checklist

  • I used a coding agent (Claude Code, Copilot, Gemini, or Codex) to generate/review this code
  • I have reviewed the project's contribution guidelines
  • New cards target console-marketplace, not this repo
  • isDemoData is wired correctly (cards show Demo badge when using demo data)
  • I have written unit tests for the changes (if applicable)
  • I have tested the changes locally and ensured they work as expected
  • All commits are signed with DCO (git commit -s)

Screenshots or Logs (if applicable)

N/A — pure refactor, no visual changes.


👀 Reviewer Notes

Pure rename refactor — no logic changes. Each constant is co-located with the code that uses it (not moved to a central file) since they are domain-specific to their component.

@kubestellar-prow kubestellar-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: no Indicates the PR's author has not signed the DCO. labels Mar 31, 2026
Copilot AI linked an issue Mar 31, 2026 that may be closed by this pull request
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit dd661c6
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69cc26dba54cae00085f9c81
😎 Deploy Preview https://deploy-preview-4024.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubestellar-prow kubestellar-prow bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey @Copilot — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

❌ PR Title Verification Failed

Your PR title does not follow the required format.

Current title: refactor: extract hardcoded thresholds and magic numbers to named constants

Required Format

PR titles must start with one of these emoji prefixes:

Emoji Meaning
⚠️ Breaking change
Non-breaking feature
🐛 Patch fix / Bug fix
📖 Documentation
🚀 Release
🌱 Infra/Tests/Other

How to Fix

Edit your PR title to start with the appropriate emoji. For example:

  • ✨ Add new feature for user authentication
  • 🐛 Fix crash when loading empty config
  • 📖 Update installation guide

You can edit the title by clicking the Edit button next to your PR title.


This comment was automatically posted by the PR Title Verifier workflow.

@github-actions github-actions bot added copilot dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Mar 31, 2026
@clubanderson clubanderson changed the title [WIP] Refactor hardcoded thresholds and magic numbers 🐛 Refactor hardcoded thresholds and magic numbers Mar 31, 2026
@clubanderson clubanderson removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 31, 2026
@clubanderson clubanderson marked this pull request as ready for review March 31, 2026 19:47
Copilot AI review requested due to automatic review settings March 31, 2026 19:47
@kubestellar-prow kubestellar-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Mar 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@github-actions github-actions bot mentioned this pull request Mar 31, 2026
…onstants

Fixes #3476

- CardHistory.tsx: MS_PER_MINUTE/HOUR/DAY/WEEK replace raw ms literals
- Tour.tsx: TOOLTIP_GAP and NEAR_TOP_THRESHOLD replace inline numbers
- RunbookProgress.tsx: MS_PER_SECOND replaces literal 1000
- GPUDetailModal.tsx: GPU_UTIL_HIGH/WARN replace repeated 90/70 thresholds
- ClusterGrid.tsx: MIN_SPIN_DURATION_MS replaces default param literal 1000

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Agent-Logs-Url: https://github.com/kubestellar/console/sessions/863a8e7c-ce05-4f76-9a06-80c9542a9e7d

Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
@kubestellar-prow kubestellar-prow bot added dco-signoff: no Indicates the PR's author has not signed the DCO. and removed dco-signoff: yes Indicates the PR's author has signed the DCO. labels Mar 31, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from clubanderson. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow
Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kubestellar-prow kubestellar-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 31, 2026
@kubestellar-prow kubestellar-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 31, 2026
@github-actions github-actions bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Mar 31, 2026
Copilot AI changed the title 🐛 Refactor hardcoded thresholds and magic numbers refactor: extract hardcoded thresholds and magic numbers to named constants Mar 31, 2026
Copilot AI requested a review from clubanderson March 31, 2026 19:58
@clubanderson clubanderson merged commit becf14c into main Mar 31, 2026
21 of 27 checks passed
@kubestellar-prow kubestellar-prow bot deleted the copilot/auto-qa-configurable-thresholds branch March 31, 2026 23:55
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Auto-QA] Hardcoded thresholds and magic numbers

3 participants