Skip to content
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

🐛 Use natural sort order #1918

Merged
merged 3 commits into from
May 23, 2024
Merged

🐛 Use natural sort order #1918

merged 3 commits into from
May 23, 2024

Conversation

rszwajko
Copy link
Collaborator

@rszwajko rszwajko commented May 16, 2024

Replace default alphabetical sort order (i.e. a, a11, a2)
with human friendly "natural" sort (i.e. a, a2, a11).
The change applies to all found cases of string sorting.
For convenience the comparator converts all values to strings (with
nulish values being converted to empty string).

In addition, the natural sort with string conversion (universal
comparator) was used as a replacement in sorting hooks. There a general
sorting algorithm was implemented with type-specific comparators.
Benefits of universal comparator:

  1. better handling of mixed types (i.e. string and number). String value
    most likely gets converted to NaN.
  2. better handling of undefined (numeric value NaN)
  3. simplified coercion logic compared to less than/greater then
    operators

Note that one functional change was introduced in the sorting hook:
space removal logic was dropped as it creates visually confusing results
for stable sorting.

Resolves: #1796

Reference-Url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than

@rszwajko rszwajko marked this pull request as ready for review May 20, 2024 19:13
@rszwajko rszwajko requested review from sjd78 and ibolton336 May 20, 2024 19:14
Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 31.57895% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 42.13%. Comparing base (b654645) to head (527d6eb).
Report is 143 commits behind head on main.

Files Patch % Lines
...table-controls/sorting/getLocalSortDerivedState.ts 20.00% 4 Missing ⚠️
client/src/app/utils/utils.ts 33.33% 4 Missing ⚠️
client/src/app/queries/tasks.ts 25.00% 3 Missing ⚠️
...pages/applications/analysis-wizard/set-options.tsx 50.00% 1 Missing ⚠️
client/src/app/queries/tags.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1918      +/-   ##
==========================================
+ Coverage   39.20%   42.13%   +2.93%     
==========================================
  Files         146      163      +17     
  Lines        4857     5236     +379     
  Branches     1164     1325     +161     
==========================================
+ Hits         1904     2206     +302     
+ Misses       2939     2913      -26     
- Partials       14      117     +103     
Flag Coverage Δ
client 42.13% <31.57%> (+2.93%) ⬆️
server ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

Look really good, just a handful of questions

client/src/app/queries/tasks.ts Outdated Show resolved Hide resolved
client/src/app/hooks/useLegacySortState.ts Show resolved Hide resolved
Replace default alphabetical sort order (i.e. a, a11, a2)
with human friendly "natural" sort (i.e. a, a2, a11).
The change applies to all found cases of string sorting.
For convenience the comparator converts all values to strings (with
nulish values being converted to empty string).

In addition, the natural sort with string conversion (universal
comparator) was used as a replacement in sorting hooks. There a general
sorting algorithm was implemented with type-specific comparators.
Benefits of universal comparator:
1. better handling of mixed types (i.e. string and number). String value
   most likely gets converted to NaN.
2. better handling of undefined (numeric value NaN)
2. simplified coercion logic compared to less than/greater then
   operators

Reference-Url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
@rszwajko rszwajko requested a review from sjd78 May 23, 2024 15:51
@sjd78 sjd78 added this to the v0.5.0 milestone May 23, 2024
Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Use natural sorting across the UI
3 participants