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