refactor(ui): simplify workspace dropdown component structure (#11040)

Reorganized the workspace dropdown rendering logic for improved
readability and maintainability. Ensured consistent handling of
separators and dropdown items, while preserving the existing
functionality.

Fix #11034
This commit is contained in:
Antoine Moreaux
2025-03-20 12:38:10 +01:00
committed by GitHub
parent 8b7188e85b
commit 548597bfd0

View File

@ -127,41 +127,49 @@ export const MultiWorkspaceDropdownDefaultComponents = () => {
>
{currentWorkspace?.displayName}
</DropdownMenuHeader>
<StyledDropdownMenuItemsContainer>
{workspaces
.filter(({ id }) => id !== currentWorkspace?.id)
.slice(0, 3)
.map((workspace) => (
<UndecoratedLink
key={workspace.id}
to={buildWorkspaceUrl(getWorkspaceUrl(workspace.workspaceUrls))}
onClick={(event) => {
event?.preventDefault();
handleChange(workspace);
}}
>
<MenuItemSelectAvatar
text={workspace.displayName ?? '(No name)'}
avatar={
<Avatar
placeholder={workspace.displayName || ''}
avatarUrl={workspace.logo ?? DEFAULT_WORKSPACE_LOGO}
{workspaces.length > 1 && (
<>
<StyledDropdownMenuItemsContainer>
{workspaces
.filter(({ id }) => id !== currentWorkspace?.id)
.slice(0, 3)
.map((workspace) => (
<UndecoratedLink
key={workspace.id}
to={buildWorkspaceUrl(
getWorkspaceUrl(workspace.workspaceUrls),
)}
onClick={(event) => {
event?.preventDefault();
handleChange(workspace);
}}
>
<MenuItemSelectAvatar
text={workspace.displayName ?? '(No name)'}
avatar={
<Avatar
placeholder={workspace.displayName || ''}
avatarUrl={workspace.logo ?? DEFAULT_WORKSPACE_LOGO}
/>
}
selected={false}
/>
</UndecoratedLink>
))}
{workspaces.length > 4 && (
<MenuItem
LeftIcon={IconSwitchHorizontal}
text={t`Other workspaces`}
onClick={() =>
setMultiWorkspaceDropdownState('workspaces-list')
}
selected={false}
hasSubMenu={true}
/>
</UndecoratedLink>
))}
{workspaces.length > 4 && (
<MenuItem
LeftIcon={IconSwitchHorizontal}
text={t`Other workspaces`}
onClick={() => setMultiWorkspaceDropdownState('workspaces-list')}
hasSubMenu={true}
/>
)}
</StyledDropdownMenuItemsContainer>
{workspaces.length > 1 && <DropdownMenuSeparator />}
)}
</StyledDropdownMenuItemsContainer>
<DropdownMenuSeparator />
</>
)}
<StyledDropdownMenuItemsContainer>
<MenuItem
LeftIcon={colorSchemeList.find(({ id }) => id === colorScheme)?.icon}