-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(editor): enhance string comparison handling in eval.ts #14233
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
feat(editor): enhance string comparison handling in eval.ts #14233
Conversation
Refactor compareString function to handle null/undefined inputs and improve string comparison logic.
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @blocksuite/affine/data-view/src/core/sort/eval.ts:
- Around line 51-52: The code incorrectly uses logical OR when normalizing
values to strings, so falsy-but-valid values like 0 and false become empty
strings; change the normalization in eval.ts to use nullish coalescing for both
variables (replace the expressions that set strA and strB from String(a || '') /
String(b || '') with String(a ?? '') and String(b ?? '')) so only null/undefined
map to empty strings and other falsy values are preserved.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
blocksuite/affine/data-view/src/core/sort/eval.ts
🔇 Additional comments (3)
blocksuite/affine/data-view/src/core/sort/eval.ts (3)
54-62: Empty string handling looks correct (after fixing the??issue above).The logic consistently treats empty strings as "greater than" non-empty strings, ensuring they sort last. This aligns with the PR objective of "consistent ordering when comparing mixed or missing values" and matches the null handling pattern in
compareNumber(lines 89-94).
67-68: Good defensive coding practice.While
split()returns a string array, explicitly coercing to strings before callingtoLowerCase()adds robustness. This prevents potential runtime errors if the function's input handling changes in the future.
75-86: Numeric vs non-numeric comparison logic is correct.The implementation correctly prioritizes numeric parts before non-numeric parts, with clear comments. Using
localeComparefor string parts provides locale-aware sorting, which is good for internationalization.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## canary #14233 +/- ##
==========================================
+ Coverage 56.40% 56.50% +0.09%
==========================================
Files 2762 2775 +13
Lines 141590 142448 +858
Branches 21745 21703 -42
==========================================
+ Hits 79868 80491 +623
- Misses 59487 59623 +136
- Partials 2235 2334 +99
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d515d29
Refactors the compareString function to safely handle null and undefined inputs and improves overall string comparison logic. This prevents incorrect sort behavior and ensures consistent ordering when comparing mixed or missing values, particularly in table view sorting scenarios.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.