Skip to content

Clean up sorting logic#20

Merged
Buuntu merged 4 commits intomasterfrom
gabud/sorting-preserve-bug
Sep 23, 2020
Merged

Clean up sorting logic#20
Buuntu merged 4 commits intomasterfrom
gabud/sorting-preserve-bug

Conversation

@Buuntu
Copy link
Copy Markdown
Owner

@Buuntu Buuntu commented Sep 23, 2020

No description provided.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #20 into master will increase coverage by 0.48%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
+ Coverage   96.87%   97.35%   +0.48%     
==========================================
  Files           4        4              
  Lines         224      227       +3     
  Branches       52       54       +2     
==========================================
+ Hits          217      221       +4     
+ Misses          7        6       -1     
Impacted Files Coverage Δ
src/hooks.tsx 96.84% <100.00%> (+0.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c3e918...bb4c305. Read the comment docs.

Comment thread src/hooks.tsx
Comment thread src/hooks.tsx
isAscending = column.sorted.asc;
// if it's undefined, start by setting to ascending, otherwise toggle
isAscending =
column.sorted.asc === undefined ? true : !column.sorted.asc;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If column.sorted.asc is already set to true, won't this set it to false? Seems like we should define column.sorted.asc as true/false earlier instead of letting it be undefined.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yeah because this is the toggle sort action (like when you click the header), so we want it to go from true -> false and false->true.

In the case that it's undefined (the default), we just want to start with ascending order, if that makes sense. Undefined marks the state before any sorting has happened. If you think this is more confusing I can set it to true/false only again.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah my mistake, I didn't realize we were in the TOGGLE_SORT case. I generally think it's better to not leave things undefined, but it's your call.

Copy link
Copy Markdown
Owner Author

@Buuntu Buuntu Sep 23, 2020

Choose a reason for hiding this comment

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

Yeah I generally agree, although here I'm not setting things to undefined explicitly. Just having a default "not set" state. I guess I could make it null | boolean which might be slightly better.

@Buuntu Buuntu merged commit 1846cd0 into master Sep 23, 2020
@Buuntu Buuntu deleted the gabud/sorting-preserve-bug branch September 23, 2020 19:06
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.

3 participants