Skip to content

Conversation

jcobis
Copy link
Collaborator

@jcobis jcobis commented Oct 1, 2025

Addresses followups from #7381

  • Centralize formatting helpers
    • Created packages/compass-components/src/utils/format.ts with compactBytes() and compactNumber() utilities
    • Replaced numeral usage in compass-collection, compass-crud, and compass-indexes with centralized helpers
    • Removed numeral dependency from 3 packages
  • Remove defensive check for schema analysis completed document count screen

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

- Create shared compactBytes() and compactNumber() utilities
- Remove numeral dependency from compass-collection, compass-crud, and compass-indexes
- Use centralized formatting for consistent SI notation across packages
- Update tests to match new formatting (e.g., '100.0 kB' instead of '100.0KB')
- Fix webpack-config-compass browserslist for Electron 37.6 compatibility
@jcobis jcobis added the no release notes Fix or feature not for release notes label Oct 1, 2025
@jcobis jcobis marked this pull request as ready for review October 1, 2025 21:37
@jcobis jcobis requested a review from a team as a code owner October 1, 2025 21:37
@jcobis jcobis requested review from lerouxb and Copilot October 1, 2025 21:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Centralizes formatting utilities and removes numeral dependency from multiple packages as part of Document Count Screen followups.

  • Centralizes byte and number formatting by creating shared utilities in compass-components
  • Replaces numeral usage across compass-collection, compass-crud, and compass-indexes packages
  • Removes defensive schema analysis check from document count screen

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/compass-components/src/utils/format.ts Adds centralized compactBytes and compactNumber formatting utilities
packages/compass-components/src/index.ts Exports new formatting utilities
packages/compass-indexes/src/plugin-title.tsx Replaces numeral with centralized formatting helpers
packages/compass-indexes/src/components/regular-indexes-table/size-field.tsx Updates size formatting to use compactBytes utility
packages/compass-crud/src/plugin-title.tsx Replaces numeral with centralized formatting helpers
packages/compass-collection/src/components/mock-data-generator-modal/document-count-screen.tsx Updates byte formatting and removes defensive schema check
Multiple package.json files Removes numeral dependency from 3 packages
Test files Updates test expectations to match new formatting output

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 14 to 19
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]}`;
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The 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
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]}`;

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

@jcobis jcobis Oct 2, 2025

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!

Copy link
Collaborator

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot has some good suggestions :)

"@types/leaflet": "^1.9.8",
"@types/leaflet-draw": "^1.0.11",
"@types/mocha": "^9.0.0",
"@types/numeral": "^2.0.5",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is needed because packages/compass-schema/src/components/type.tsx and packages/compass-schema/src/components/array-minichart.tsx use numeral

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants