Skip to content

refactor(usage): one definition of the quota colour thresholds - #3917

Open
ntdatt812 wants to merge 1 commit into
decolua:masterfrom
ntdatt812:refactor/quota-status-thresholds
Open

ntdatt812 wants to merge 1 commit into
decolua:masterfrom
ntdatt812:refactor/quota-status-thresholds

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

What this is

> 70 green / >= 30 yellow / else red is the quota colour policy. It was written out four times:

file copy
ProviderLimits/QuotaProgressBar.js getColorClasses
ProviderLimits/QuotaTable.js getColorClasses
ProviderLimits/utils.js getStatusColor
ProviderLimits/utils.js getStatusEmoji

All four agree today. Nothing makes them: an edit to one would show a model green in the table and yellow in the progress bar directly above it, with no test and no type to catch it.

No user-visible behaviour changes. Every percentage maps to exactly the colour and emoji it did before — the first two tests sweep 0–100 in 0.5 steps to say so.

The change

quotaStatusLevel() in ./utils is now the only place the numbers appear, alongside the two named boundaries.

The two components keep their own class tables and map from the level. That split is deliberate: QuotaTable needs dark: text variants and the progress bar does not, so what legitimately differs between them stays separate from what should not. The two also had bg, bgLight and emoji duplicated verbatim; those are now one line each per level.

Net −18 lines, and an unreachable return left behind in getStatusEmoji goes with it.

Evidence

tests/unit/quota-status-thresholds.test.js, 5 tests.

The first three are arithmetic and would pass just as happily against four copies as against one — so the last two are the ones doing the work: they assert each component imports quotaStatusLevel and no longer contains a remainingPercentage > 70 of its own.

Two-way mutation, run locally:

Mutation Result
none 5 / 5 pass
QuotaTable.getColorClasses restates the thresholds inline 1 fail — "the table reads the shared policy instead of restating it"; the four others stay green

Caveat

This is a tidy-up, not a bug fix — the copies have not drifted yet. If you would rather not carry a source-level test that pins how a component is written, say so and I will drop the last two tests; the consolidation stands on its own.

`> 70` green / `>= 30` yellow was written out four times: QuotaProgressBar,
QuotaTable, getStatusColor and getStatusEmoji. All four agreed, but nothing
made them: an edit to one would have shown a model green in the table and
yellow in the progress bar above it, with no test and no type to catch it.

quotaStatusLevel() in ./utils is now the only place the boundaries appear.
The two components keep their own class tables -- QuotaTable needs dark-mode
text variants and the progress bar does not -- and map from the level, so
what legitimately differs stays separate from what should not.

Also drops an unreachable `return` left in getStatusEmoji.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant