Skip to content

Commit

Permalink
refactor getFilteredWorkspaceList function
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws committed Aug 16, 2023
1 parent 8cfdd39 commit c87a581
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/core/public/chrome/ui/header/collapsible_nav_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ function getFilteredWorkspaceList(
workspaceList: WorkspaceAttribute[],
currentWorkspace: WorkspaceAttribute | null
): WorkspaceAttribute[] {
// list top5 workspaces except management workspace
let filteredWorkspaceList = workspaceList
.filter((workspace) => workspace.id !== MANAGEMENT_WORKSPACE)
.slice(0, 5);
if (currentWorkspace) {
// current workspace located at the top of workspace list
filteredWorkspaceList = filteredWorkspaceList.filter(
(workspace) => workspace.id !== currentWorkspace.id
);
filteredWorkspaceList.unshift(currentWorkspace);
if (filteredWorkspaceList.length > 5) {
filteredWorkspaceList.pop();
}
}
return filteredWorkspaceList;
// list top5 workspaces except management workspace, place current workspace at the top
return [
...(currentWorkspace ? [currentWorkspace] : []),
...workspaceList.filter(
(workspace) => workspace.id !== MANAGEMENT_WORKSPACE && workspace.id !== currentWorkspace?.id
),
].slice(0, 5);
}

export function CollapsibleNavHeader({ workspaces, getUrlForApp, basePath }: Props) {
Expand Down

0 comments on commit c87a581

Please sign in to comment.