-
Notifications
You must be signed in to change notification settings - Fork 244
feat(compass-collection): Document Count Screen followups – CLOUDP-348924 #7408
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
Changes from 3 commits
545b5f7
c532a8d
1ee7592
6669622
803f772
2fd5610
52f479a
70b7e2c
ed6fe85
d3166d3
2a667a2
a559338
c17a626
36116ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Format bytes into a human-readable string with appropriate units. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @param bytes - The number of bytes to format | ||||||||||||||||||||||||||||||
| * @param si - Use SI units (1000-based) if true, binary units (1024-based) if false | ||||||||||||||||||||||||||||||
| * @param decimals - Number of decimal places to show | ||||||||||||||||||||||||||||||
| * @returns Formatted string with units (e.g., "1.5 MB", "2.0 KiB") | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| export function compactBytes(bytes: number, si = true, decimals = 2): string { | ||||||||||||||||||||||||||||||
| const threshold = si ? 1000 : 1024; | ||||||||||||||||||||||||||||||
| if (bytes === 0) { | ||||||||||||||||||||||||||||||
| return `${bytes} B`; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| const units = si | ||||||||||||||||||||||||||||||
| ? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | ||||||||||||||||||||||||||||||
| : ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; | ||||||||||||||||||||||||||||||
| const i = Math.floor(Math.log(bytes) / Math.log(threshold)); | ||||||||||||||||||||||||||||||
| const num = bytes / Math.pow(threshold, i); | ||||||||||||||||||||||||||||||
| return `${num.toFixed(decimals)} ${units[i]}`; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| const units = si | |
| ? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | |
| : ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(threshold)); | |
| const num = bytes / Math.pow(threshold, i); | |
| return `${num.toFixed(decimals)} ${units[i]}`; | |
| const isNegative = bytes < 0; | |
| const absBytes = Math.abs(bytes); | |
| const units = si | |
| ? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | |
| : ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; | |
| const i = Math.floor(Math.log(absBytes) / Math.log(threshold)); | |
| const num = absBytes / Math.pow(threshold, i); | |
| return `${isNegative ? '-' : ''}${num.toFixed(decimals)} ${units[i]}`; |
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.
Do negative bytes make sense? If this is called with a negative value, my assumption is that that would indicate an error, and thus isn't something we should silently handle. Let me know if you feel otherwise though!
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.
I think what copilot suggested makes sense. Currently calling this function with negative bytes, returns NaN undefined. So we should handle this.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ | |
| "@types/leaflet": "^1.9.8", | ||
| "@types/leaflet-draw": "^1.0.11", | ||
| "@types/mocha": "^9.0.0", | ||
| "@types/numeral": "^2.0.5", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is needed because |
||
| "@types/react": "^17.0.5", | ||
| "@types/react-dom": "^17.0.10", | ||
| "chai": "^4.3.4", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.