-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ui): Prevent negative zero and allow zero with decimal places #16439
Conversation
import {DecimalPlaces} from 'src/types/dashboards' | ||
|
||
// Constants | ||
import {MAX_DECIMAL_PLACES} from 'src/dashboards/constants' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job organizing these
export const preventNegativeZero = ( | ||
value: number | string | ||
): number | string => { | ||
if (Number(value) === -0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literally didn't know this was possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take control back from the machines!
no but seriously, go ahead and use overrides here to get more value out of our tests. in general, use an override like this for lint or prettier or whatever, whenever they get mouthy and you think what you're writing is valuable.
maximumFractionDigits: MAX_DECIMAL_PLACES, | ||
}) | ||
localeFormattedValue = | ||
Number(roundedValue) === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think of turning this code into a formatting function and including the negative zero check as part of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code is actually inside a formatting function already. The ternary is to allow positive zero to have decimal places when user-specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
import {preventNegativeZero} from 'src/shared/utils/preventNegativeZero' | ||
|
||
describe('preventNegativeZero', () => { | ||
it('should not alter non-zero numbers', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice test! was going to ask why you can't just use Math.abs
but this one answers it nicely.
…6439) * fix(ui): Prevent negative zero and allow zero with decimal places * chore: update CHANGELOG * fix(ui): Turn off lint rule no-compare-neg-zero * test: add more tests by overriding prettier * fix(ui): turn off lint rule for a specific usage, not universally
Closes #16306