-
Notifications
You must be signed in to change notification settings - Fork 2
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
Allow useOrderedRows to put all null elements at the bottom #1587
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1587 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 62 62
Lines 1041 1046 +5
Branches 397 402 +5
=========================================
+ Hits 1041 1046 +5 ☔ View full report in Codecov by Sentry. |
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.
This implements what we discussed, but on reflection I wonder if perhaps it would be less surprising if we kept the hook stateless and instead gave the caller an option to determine whether null
values sort before or after non-null values.
src/types.ts
Outdated
|
||
/** | ||
* Indicates entries where the value for `field` is null/undefined should go | ||
* last. Otherwise, they will get compared with non-null values normally. |
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.
Ah. My intention was that nulls would always sort either before or after non-null values. So we would never use <
/>
comparisons between null and non-null values. I think it makes sense to default to true, assuming strings are the most common data type in rows and we'd probably want to sort them last.
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.
Done
This PR changes
useOrderedRows
so that it can makenull
/undefined
values be put always at the bottom of the list, and makes this the default behavior.This is done by adding a new
nullsLast
option to theorder
object, which istrue
by default.Callers will need to explicitly switch from
nullsLast: true
tonullsLast: false
if they want this to change as the order direction changes:Previously we were comparing nulls normally with other non-null values, which produced unintuitive results, because in JS both
'some string' > null
andnull > 'some string'
arefalse
.