frontend : lib : fix decimal CPU quantity formatting in normalizeUnit#6444
frontend : lib : fix decimal CPU quantity formatting in normalizeUnit#6444AarishMansur wants to merge 2 commits into
Conversation
|
|
|
Welcome @AarishMansur! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: AarishMansur The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
illume
left a comment
There was a problem hiding this comment.
Thanks for working on this.
The commit messages could use some tidying up to match our contribution guidelines. We use Linux kernel style — the contributing guide has the details, and git log shows good examples.
Commits that need attention
frontend : lib : fix decimal CPU quantity formatting in normalizeUnit— Missingarea: descriptionprefix — e.g.frontend: HomeButton: Fix so it navigates to homeorbackend: config: Add enable-dynamic-clusters flag.
Commit guidelines
- Use atomic commits focused on a single change.
- Use the title format
<area>: <Description of changes>— description must start with a capital letter. - Keep the title under 72 characters (soft requirement).
- Explain the intention and why the change is needed.
- Make commit titles meaningful and describe what changed.
- Do not add code that a later commit rewrites; squash or reorder commits instead.
- Do not include
Fixes #NNin commit messages.
Good examples:
frontend: HomeButton: Fix so it navigates to homebackend: config: Add enable-dynamic-clusters flag
There was a problem hiding this comment.
Pull request overview
This PR aims to fix CPU quantity display in normalizeUnit so decimal core strings like "2.0" render as "2 cores" rather than "2.0 cores".
Changes:
- Updates the CPU fallback formatting path in
normalizeUnitto coerce decimal strings viaNumber(...)before stringification.
Note: CI/check status and PR commit history are not available in the provided review context—please confirm CI is green and the PR history is linear (no merge commits in the PR range).
1072701 to
d923b23
Compare
|
@illume I've updated the commit messages to follow the Linux kernel style and addressed the Copilot suggestions as well. Could you please take another look when you have some time? Thanks! |
illume
left a comment
There was a problem hiding this comment.
Thanks for the contribution.
it looks like there's a merge-main commit in this PR — could you rebase onto main instead?
Why this matters
Merge commits from main make the PR history harder to review. Please rebase your branch on top of the latest main instead, then update the PR with the rebased commits.
Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.
Commits that need attention
frontend : lib : fix decimal CPU quantity formatting in normalizeUnit— Missingarea: descriptionprefix — e.g.frontend: HomeButton: Fix so it navigates to homeorbackend: config: Add enable-dynamic-clusters flag.frontend : lib : Added test to cover Normalize unit— Missingarea: descriptionprefix — e.g.frontend: HomeButton: Fix so it navigates to homeorbackend: config: Add enable-dynamic-clusters flag.
Commit guidelines
- Use atomic commits focused on a single change.
- Use the title format
<area>: <Description of changes>— description must start with a capital letter. - Keep the title under 72 characters (soft requirement).
- Explain the intention and why the change is needed.
- Make commit titles meaningful and describe what changed.
- Do not add code that a later commit rewrites; squash or reorder commits instead.
- Do not include
Fixes #NNin commit messages.
Good examples:
frontend: HomeButton: Fix so it navigates to homebackend: config: Add enable-dynamic-clusters flag
271ec43 to
c33832d
Compare
|
@illume Done I've rebased the branch and updated the commit messages to follow the project's commit message style. |
| case 'cpu': | ||
| normalizedQuantity = quantity?.endsWith('m') | ||
| ? `${Number(quantity.substring(0, quantity.length - 1)) / 1000}` | ||
| : `${quantity}`; | ||
| : `${(quantity ?? '').replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '')}`; | ||
| if (normalizedQuantity === '1') { |
Summary
This PR fixes a formatting bug in
normalizeUnitwhere CPU quantities passed as decimal strings (e.g."2.0") were displayed as"2.0 cores"instead of"2 cores", the current change trims trailing decimal zeros via regex replacementRelated Issue
Fixes #6443
Changes
normalizeUnit(frontend/src/lib/util.ts) to wrapquantityinNumber(), normalizing decimal strings like"2.0"to whole numbers before appending the unit label.Steps to Test
normalizeUnit('cpu', '2.0')in a local test script or unit test."2 cores"instead of"2.0 cores"."1000m"→"1 core","1"→"1 core","2000m"→"2 cores".Screenshots (if applicable)
N/A this is a pure logic fix with no UI changes.
Notes for the Reviewer
normalizeUnit."2000"(no suffix) is not a valid Kubernetes CPU input, so no handling was added for that case.