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(archive): Folders come before files when sorting #1171

Merged
merged 4 commits into from
Feb 6, 2020

Conversation

mxiao6
Copy link
Contributor

@mxiao6 mxiao6 commented Feb 5, 2020

image

@mxiao6 mxiao6 requested a review from a team as a code owner February 5, 2020 03:13
@boxcla
Copy link

boxcla commented Feb 5, 2020

Verified that @mxiao6 has signed the CLA. Thanks for the pull request!

}

// folders always come before files
sortedItems.sort((a, b) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like we should be able to collapse all of this into a single .sort call, with sortDirection controlling the comparator logic. Can we also check to see how webapp does this sorting? I don't see an equivalent complex sort function there.

jstoffan
jstoffan previously approved these changes Feb 6, 2020
@@ -180,17 +185,15 @@ class ArchiveExplorer extends React.Component {
}

if (typeof aItem === 'number' && typeof bItem === 'number') {
return aItem - bItem;
return sortDirection === SortDirection.ASC ? aItem - bItem : bItem - aItem;
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about flipping them at assignment to avoid the repeated logic?

const aItem = sortDirection === SortDirection.ASC ? a : b;
const bItem = sortdirection === SortDirection.ASC ? b : a;

Copy link
Contributor Author

@mxiao6 mxiao6 Feb 6, 2020

Choose a reason for hiding this comment

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

How about flipping them at assignment to avoid the repeated logic?

const aItem = sortDirection === SortDirection.ASC ? a : b;
const bItem = sortdirection === SortDirection.ASC ? b : a;

Cannot flip them before null check below, right?

Copy link
Collaborator

@jstoffan jstoffan left a comment

Choose a reason for hiding this comment

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

Nice job.

@mergify mergify bot merged commit 4a618fe into box:master Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants