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

issue-1687/sorted orgs in menu #1706

Merged
merged 3 commits into from
Dec 23, 2023
Merged

issue-1687/sorted orgs in menu #1706

merged 3 commits into from
Dec 23, 2023

Conversation

kaulfield23
Copy link
Contributor

Description

This PR sorts organizations alphabetically in menu

Screenshots

image

Changes

  • Adds useMemo and sort list

Notes to reviewer

used useMemo to prevent the sorting from being triggered every time user moves a cursor to the sidebar.

Related issues

Resolves #1687

@richardolsson richardolsson self-requested a review December 13, 2023 16:04
Comment on lines 57 to 60
const sortedTreeItems = useMemo(() => {
const sorted = treeItemData.sort((a, b) => a.title.localeCompare(b.title));
return sorted;
}, [treeItemData.length]);
Copy link
Member

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I believe this only sorts the top-level, which is not enough. We also want to sort the children of each organization, and all of the children of those children, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aaaah yeah you are right. I will add more logic to it!

Copy link
Member

Choose a reason for hiding this comment

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

I believe the best solution would be to handle the sorting in the rendering of each "level", rather than here in the top-level.

richardolsson
richardolsson previously approved these changes Dec 22, 2023
Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

Nice work! The code looks mostly good and I have verified that it works as expected. You can decide if you want to merge or change the variable name issue I've pointed out below.

I foresee this code being refactored in the near future, so you don't have to fix the problem below if you struggle to find the time for it.

src/features/organizations/components/OrganizationTree.tsx Outdated Show resolved Hide resolved
Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

LGTM!

@richardolsson richardolsson merged commit 09aaa7f into main Dec 23, 2023
4 checks passed
@richardolsson richardolsson deleted the issue-1687/sorted-orgs branch December 23, 2023 14:31
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.

Organizations not sorted in menu
2 participants