-
Notifications
You must be signed in to change notification settings - Fork 233
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
545b5f7
c532a8d
1ee7592
6669622
803f772
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]}`; | ||||||||||||||||||||||||||||||
Comment on lines
14
to
22
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. Math.log(bytes) will throw an error or return -Infinity for bytes <= 0. The function should handle negative values and zero case consistently.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. 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 commentThe 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 |
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Format a number into a compact notation with appropriate suffix. | ||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||
* @param number - The number to format | ||||||||||||||||||||||||||||||
* @returns Formatted string with compact notation (e.g., "1.5 K", "2 M") | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
export function compactNumber(number: number): string { | ||||||||||||||||||||||||||||||
return new Intl.NumberFormat('en', { | ||||||||||||||||||||||||||||||
notation: 'compact', | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
.formatToParts(number) | ||||||||||||||||||||||||||||||
.reduce((acc, part) => { | ||||||||||||||||||||||||||||||
if (part.type === 'compact') { | ||||||||||||||||||||||||||||||
return `${acc} ${part.value}`; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return `${acc}${part.value}`; | ||||||||||||||||||||||||||||||
}, ''); | ||||||||||||||||||||||||||||||
} |
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.