Skip to content

🌱 refactor(web): name drilldown display thresholds - #24735

Open
Karibhou wants to merge 1 commit into
kubestellar:mainfrom
Karibhou:fix/24734-drilldown-magic-numbers
Open

Karibhou wants to merge 1 commit into
kubestellar:mainfrom
Karibhou:fix/24734-drilldown-magic-numbers

Conversation

@Karibhou

Copy link
Copy Markdown
Contributor

📌 Fixes

Closes #24734


📝 Summary of Changes

Replaces the inline magic numbers flagged by Auto-QA in the drilldown views with named constants. Behaviour does not change.

Most entries in the issue (PERCENT_MULTIPLIER, MAX_LOG_SNIPPET_LENGTH, PAGE_SIZE, MAX_INSTANCES, REFRESH_SPINNER_MS, …) were already named constants, so they comply with the "no magic numbers" rule as they are. The ones still inline were:

File Before After
ComplianceFooter.parts.tsx cScore >= 80 ? … : cScore >= 60 ? … complianceScoreColor(cScore) using COMPLIANCE_SCORE_GOOD_PERCENT / COMPLIANCE_SCORE_WARN_PERCENT
ClusterResourceTree.tsx slice(0, 20) / > 20 / - 20, 15 for namespaces TREE_MAX_VISIBLE_NODES, TREE_MAX_VISIBLE_NAMESPACES
ClusterResourceTreeBranches.tsx 10 (pod issues), 10 (PVCs), 15 (services) TREE_MAX_VISIBLE_POD_ISSUES, TREE_MAX_VISIBLE_PVCS, TREE_MAX_VISIBLE_SERVICES
pod-drilldown/LabelsSection.tsx slice(0, 10) / > 10 COLLAPSED_LABEL_COUNT

Each tree limit was written two or three times (the slice(), the +N more check and the counter). Now each one has a single constant, so the visible list and the "+N more" row can't drift apart.


Changes Made

  • Refactored inline drilldown thresholds into named, documented constants (cluster-drilldown/types.ts, compliance-drilldown/types.ts, LabelsSection.tsx)
  • Added complianceScoreColor() helper (exported from compliance-drilldown)
  • Added tests for complianceScoreColor boundary values (compliance-drilldown/helpers.test.tsx)

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 (n/a, no new cards)
  • isDemoData is wired correctly (n/a, no data source change)
  • I have written unit tests for the changes (if applicable)
  • I have tested the changes locally and ensured they work as expected. Not run: the sandbox could not install web/node_modules. Per AGENTS.md, build/lint are validated by CI.
  • All commits are signed with DCO (git commit -s)

👀 Reviewer Notes

  • The size is small (~49 effective lines plus tests), and the change is pure refactoring.
  • ClusterResourceTree.tsx still checks filteredNamespaces.length for the "+N more" row while it slices filteredNamespaceStats. I kept that unchanged so behaviour stays the same.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HRH6kjr5Jt2DhFJcve1Lzi

— hive: backend=claude model=claude-opus-5-5

Replace inline magic numbers flagged by Auto-QA in the drilldown views
with named constants:

- compliance score colour cut-offs (80/60) -> COMPLIANCE_SCORE_GOOD_PERCENT
  / COMPLIANCE_SCORE_WARN_PERCENT, applied via a new tested
  complianceScoreColor() helper
- cluster resource tree "+N more" limits (nodes 20, namespaces 15,
  pod issues 10, PVCs 10, services 15) -> TREE_MAX_VISIBLE_* constants,
  so each slice() and its "+N more" counter share one value
- pod labels collapse limit (10) -> COLLAPSED_LABEL_COUNT

No behaviour change. The other entries in the issue were already named
constants.

Closes kubestellar#24734

Hive-Run: kubestellar#24734
Hive-Plan: auto-qa-magic-numbers
Hive-Spec: auto-qa-operator-usefulness#magic-numbers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRH6kjr5Jt2DhFJcve1Lzi
Signed-off-by: Karibhou <157208370+Karibhou@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 31, 2026
@netlify

netlify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kubestellarconsole ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 26d651b
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6ae642ee89bda34c39de537e
😎 Deploy Preview https://deploy-preview-24735.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

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 assign mikespreitzer for approval. 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 kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 31, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the diff against the tree at head — this looks correct to me.

  • Every extracted constant preserves the exact prior value: TREE_MAX_VISIBLE_NODES=20, TREE_MAX_VISIBLE_NAMESPACES=15, TREE_MAX_VISIBLE_POD_ISSUES=10, TREE_MAX_VISIBLE_PVCS=10, TREE_MAX_VISIBLE_SERVICES=15 (cluster-drilldown/types.ts:44-52), COMPLIANCE_SCORE_GOOD_PERCENT=80 / WARN=60 (compliance-drilldown/types.ts:26-29), COLLAPSED_LABEL_COUNT=10 (LabelsSection.tsx:9), and each slice() / > N / - N triple now reads the same constant, so the list and its "+N more" row can't drift.
  • complianceScoreColor() (compliance-drilldown/helpers.tsx:39-43) reproduces the inline ternary from ComplianceFooter.parts.tsx:123 exactly (>= 80 green, >= 60 yellow, else red), it's re-exported through the package index the same way the other helpers are, and the new boundary tests cover 80/79/60/59/100/0.
  • The PR body's claim that the remaining issue entries were already named constants checks out for the files touched here.

One pre-existing quirk the diff makes easier to see (not introduced here, no action needed): in ClusterResourceTree.tsx the namespaces branch slices filteredNamespaceStats but counts the "+N more" row from filteredNamespaces — same mismatch before and after this PR.

— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Ready for a human merge: verdict approved @26d651b, 37/37 checks green, DCO yes, soak 30m0s elapsed. Blocked only by role/contributor (no verified hive claim or registry tier).

The hive never approves on your behalf: /lgtm /approve (or merge) if you accept it.

This branch has not been deployed

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

Labels

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

1 participant