konveyor / tackle2-ui

Tackle (2nd generation) UI component.
Apache License 2.0
8 stars 43 forks source link

:bug: Use natural sort order #1918

Closed rszwajko closed 6 months ago

rszwajko commented 6 months ago

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

codecov[bot] commented 6 months ago

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 :warning:
client/src/app/utils/utils.ts 33.33% 4 Missing :warning:
client/src/app/queries/tasks.ts 25.00% 3 Missing :warning:
...pages/applications/analysis-wizard/set-options.tsx 50.00% 1 Missing :warning:
client/src/app/queries/tags.ts 50.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/konveyor/tackle2-ui/pull/1918/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=konveyor) | Coverage Δ | | |---|---|---| | [client](https://app.codecov.io/gh/konveyor/tackle2-ui/pull/1918/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=konveyor) | `42.13% <31.57%> (+2.93%)` | :arrow_up: | | [server](https://app.codecov.io/gh/konveyor/tackle2-ui/pull/1918/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=konveyor) | `?` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=konveyor#carryforward-flags-in-the-pull-request-comment) to find out more.

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