hypothesis / frontend-shared

UI components and styles for Hypothesis front-end applications
https://patterns.hypothes.is
5 stars 2 forks source link

Allow useOrderedRows to put all null elements at the bottom #1587

Closed acelaya closed 2 months ago

acelaya commented 2 months ago

This PR changes useOrderedRows so that it can make null/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 the order object, which is true by default.

Callers will need to explicitly switch from nullsLast: true to nullsLast: false if they want this to change as the order direction changes:

const direction = 'descending';
const order = {
  field: 'display_name',
  direction,
  nullFirst: direction === 'descending',
}

Previously we were comparing nulls normally with other non-null values, which produced unintuitive results, because in JS both 'some string' > null and null > 'some string' are false.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (ea267fe) to head (0d300bc).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1587 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 62 62 Lines 1041 1046 +5 Branches 397 402 +5 ========================================= + Hits 1041 1046 +5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.