h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.9k stars 323 forks source link

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

Closed marek-mihok closed 4 months ago

marek-mihok commented 4 months ago

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

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