-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ref(search): normalize parsed values #69198
Conversation
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
case 'kb': | ||
number *= 1000; | ||
break; | ||
case 'mb': | ||
number *= 1000 ** 2; | ||
break; | ||
case 'gb': | ||
number *= 1000 ** 3; | ||
break; | ||
case 'tb': | ||
number *= 1000 ** 4; | ||
break; | ||
case 'pb': | ||
number *= 1000 ** 5; | ||
break; | ||
case 'eb': | ||
number *= 1000 ** 6; | ||
break; | ||
case 'zb': | ||
number *= 1000 ** 7; | ||
break; | ||
case 'yb': | ||
number *= 1000 ** 8; | ||
break; | ||
case 'kib': | ||
number *= 1024; | ||
break; | ||
case 'mib': | ||
number *= 1024 ** 2; | ||
break; | ||
case 'gib': | ||
number *= 1024 ** 3; | ||
break; | ||
case 'tib': | ||
number *= 1024 ** 4; | ||
break; | ||
case 'pib': | ||
number *= 1024 ** 5; | ||
break; | ||
case 'eib': | ||
number *= 1024 ** 6; | ||
break; | ||
case 'zib': | ||
number *= 1024 ** 7; | ||
break; | ||
case 'yib': | ||
number *= 1024 ** 8; | ||
break; |
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.
more of a nit, but you could pretty easily write this with a lookup table no?
const factor = {
kb: 1000,
mb: 1000 ** 2,
...
kib: 1024,
mib: 1024 ** 2,
...
}
number *= factor[unit.toLowerCase()]
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.
Yeah, I know. I copied as the exact same code from the backend so that the flow is the same. We could update it on both ends tbh
unit: | ||
| 'bit' | ||
| 'nb' | ||
| 'bytes' | ||
| 'kb' | ||
| 'mb' | ||
| 'gb' | ||
| 'tb' | ||
| 'pb' | ||
| 'eb' | ||
| 'zb' | ||
| 'yb' | ||
| 'kib' | ||
| 'mib' | ||
| 'gib' | ||
| 'tib' | ||
| 'pib' | ||
| 'eib' | ||
| 'zib' | ||
| 'yib' |
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.
Are we using this type in multiple places? should it be pulled up?
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.
its just in two places. Tbh the better way to type here might be "string" and then just make sure we handle 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.
sgtm
Bundle ReportChanges will increase total bundle size by 69.27kB ⬆️
|
Normalize parsed values. Durations to ms, sizes to bytes, numbers to spoiler alert (numbers), dates to dates and bools to "duh" bools