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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/features/organizations/components/OrganizationTree.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import NextLink from 'next/link';
import ProceduralColorIcon from './ProceduralColorIcon';
import React from 'react';
import TreeItem from '@mui/lab/TreeItem';
import { TreeItemData } from '../types';
import TreeView from '@mui/lab/TreeView';
import { Box, Typography, useTheme } from '@mui/material';
import { ChevronRight, ExpandMore } from '@mui/icons-material';
import React, { useMemo } from 'react';

import ProceduralColorIcon from './ProceduralColorIcon';
import { TreeItemData } from '../types';

interface OrganizationTreeProps {
treeItemData: TreeItemData[];
Expand Down Expand Up @@ -53,6 +54,10 @@ function OrganizationTree({
orgId,
}: OrganizationTreeProps): JSX.Element {
const theme = useTheme();
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.


return (
<div>
Expand All @@ -76,7 +81,7 @@ function OrganizationTree({
},
}}
>
{renderTree({ onSwitchOrg, orgId, treeItemData })}
{renderTree({ onSwitchOrg, orgId, treeItemData: sortedTreeItems })}
</TreeView>
</div>
);
Expand Down
Loading