Skip to content

Commit

Permalink
feat(sanity): hide workspace switcher inside Core UI rendering context
Browse files Browse the repository at this point in the history
  • Loading branch information
juice49 committed Mar 6, 2025
1 parent b2df74b commit 987f0e5
Showing 1 changed file with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {styled} from 'styled-components'

import {MenuButton, type MenuButtonProps, MenuItem, Tooltip} from '../../../../../ui-components'
import {CapabilityGate} from '../../../../components/CapabilityGate'
import {useTranslation} from '../../../../i18n'
import {useActiveWorkspace} from '../../../activeWorkspaceMatcher'
import {useWorkspaces} from '../../../workspaces'
Expand Down Expand Up @@ -53,9 +54,11 @@ export function WorkspaceMenuButton() {
{activeWorkspace.title}
</Text>
</Box>
<Text size={1}>
<ChevronDownIcon />
</Text>
<CapabilityGate capability="globalWorkspaceControl">
<Text size={1}>
<ChevronDownIcon />
</Text>
</CapabilityGate>
</Flex>
</UIButton>
</Tooltip>
Expand All @@ -64,39 +67,41 @@ export function WorkspaceMenuButton() {
id="workspace-menu"
menu={
!disabled && authStates ? (
<StyledMenu>
{workspaces.map((workspace) => {
const authState = authStates[workspace.name]
<CapabilityGate capability="globalWorkspaceControl">
<StyledMenu>
{workspaces.map((workspace) => {
const authState = authStates[workspace.name]

// eslint-disable-next-line no-nested-ternary
const state = authState.authenticated
? 'logged-in'
: workspace.auth.LoginComponent
? 'logged-out'
: 'no-access'
// eslint-disable-next-line no-nested-ternary
const state = authState.authenticated
? 'logged-in'
: workspace.auth.LoginComponent
? 'logged-out'
: 'no-access'

const isSelected = workspace.name === activeWorkspace.name
const isSelected = workspace.name === activeWorkspace.name

// we have a temporary need to make a hard direct link to the workspace
// because of possibly shared context between workspaces. When this is resolved,
// we can remove this and use setActiveWorkspace instead
return (
<MenuItem
as="a"
href={workspace.basePath}
badgeText={STATE_TITLES[state]}
iconRight={isSelected ? CheckmarkIcon : undefined}
key={workspace.name}
pressed={isSelected}
preview={<WorkspacePreviewIcon icon={workspace.icon} size="small" />}
selected={isSelected}
__unstable_subtitle={workspace.subtitle}
__unstable_space={1}
text={workspace?.title || workspace.name}
/>
)
})}
</StyledMenu>
// we have a temporary need to make a hard direct link to the workspace
// because of possibly shared context between workspaces. When this is resolved,
// we can remove this and use setActiveWorkspace instead
return (
<MenuItem
as="a"
href={workspace.basePath}
badgeText={STATE_TITLES[state]}
iconRight={isSelected ? CheckmarkIcon : undefined}
key={workspace.name}
pressed={isSelected}
preview={<WorkspacePreviewIcon icon={workspace.icon} size="small" />}
selected={isSelected}
__unstable_subtitle={workspace.subtitle}
__unstable_space={1}
text={workspace?.title || workspace.name}
/>
)
})}
</StyledMenu>
</CapabilityGate>
) : undefined
}
popover={POPOVER_PROPS}
Expand Down

0 comments on commit 987f0e5

Please sign in to comment.