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

fix: Sort items correctly when empty custom group is present #2268 #2274

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

marek-mihok
Copy link
Contributor

The PR fulfills these requirements: (check all the apply)

  • It's submitted to the main branch.
  • When resolving a specific issue, it's referenced in the PR's title (e.g. feat: Add a button #xxx, where "xxx" is the issue number).
  • When resolving a specific issue, the PR description includes Closes #xxx, where "xxx" is the issue number.
  • If changes were made to ui folder, unit tests (make test) still pass.
  • New/updated tests are included

The problem was in reducer inside onSortChange function

setFilteredItems(filteredItems => [...groups]
     // sorts groups by startIndex to match its order in filteredItems
     .sort((group1, group2) => group1.startIndex - group2.startIndex)
     .reduce((acc, group) => [...acc, ...filteredItems.slice(group.startIndex, acc.length + group.count).sort(sortingF(column, sortAsc))],
     [] as any[]) || [])

adding acc.length + group.count filtered items into the final array even in case of empty group present (group.count equal to 0) but acc.length having non-zero value most of the time.

Fixed by conditional adding of items:

group.count
       ? [...acc, ...filteredItems.slice(group.startIndex, acc.length + group.count).sort(sortingF(column, sortAsc))]
       : acc

Closes #2268

Copy link
Collaborator

@mturoci mturoci left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @marek-mihok!

@mturoci mturoci merged commit c84784b into main Feb 26, 2024
2 checks passed
@mturoci mturoci deleted the feat/issue-2268 branch February 26, 2024 07:57
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.

Sort is not working for table custom groups
2 participants