Skip to content

Commit 6ae5097

Browse files
committed
feat(sanity): hide workspace switcher inside Core UI rendering context
1 parent db834ef commit 6ae5097

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

packages/sanity/src/core/studio/components/navbar/workspace/WorkspaceMenuButton.tsx

+38-33
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {styled} from 'styled-components'
1111

1212
import {MenuButton, type MenuButtonProps, MenuItem, Tooltip} from '../../../../../ui-components'
13+
import {CapabilityGate} from '../../../../components/CapabilityGate'
1314
import {useTranslation} from '../../../../i18n'
1415
import {useActiveWorkspace} from '../../../activeWorkspaceMatcher'
1516
import {useWorkspaces} from '../../../workspaces'
@@ -53,9 +54,11 @@ export function WorkspaceMenuButton() {
5354
{activeWorkspace.title}
5455
</Text>
5556
</Box>
56-
<Text size={1}>
57-
<ChevronDownIcon />
58-
</Text>
57+
<CapabilityGate capability="globalWorkspaceControl">
58+
<Text size={1}>
59+
<ChevronDownIcon />
60+
</Text>
61+
</CapabilityGate>
5962
</Flex>
6063
</UIButton>
6164
</Tooltip>
@@ -64,39 +67,41 @@ export function WorkspaceMenuButton() {
6467
id="workspace-menu"
6568
menu={
6669
!disabled && authStates ? (
67-
<StyledMenu>
68-
{workspaces.map((workspace) => {
69-
const authState = authStates[workspace.name]
70+
<CapabilityGate capability="globalWorkspaceControl">
71+
<StyledMenu>
72+
{workspaces.map((workspace) => {
73+
const authState = authStates[workspace.name]
7074

71-
// eslint-disable-next-line no-nested-ternary
72-
const state = authState.authenticated
73-
? 'logged-in'
74-
: workspace.auth.LoginComponent
75-
? 'logged-out'
76-
: 'no-access'
75+
// eslint-disable-next-line no-nested-ternary
76+
const state = authState.authenticated
77+
? 'logged-in'
78+
: workspace.auth.LoginComponent
79+
? 'logged-out'
80+
: 'no-access'
7781

78-
const isSelected = workspace.name === activeWorkspace.name
82+
const isSelected = workspace.name === activeWorkspace.name
7983

80-
// we have a temporary need to make a hard direct link to the workspace
81-
// because of possibly shared context between workspaces. When this is resolved,
82-
// we can remove this and use setActiveWorkspace instead
83-
return (
84-
<MenuItem
85-
as="a"
86-
href={workspace.basePath}
87-
badgeText={STATE_TITLES[state]}
88-
iconRight={isSelected ? CheckmarkIcon : undefined}
89-
key={workspace.name}
90-
pressed={isSelected}
91-
preview={<WorkspacePreviewIcon icon={workspace.icon} size="small" />}
92-
selected={isSelected}
93-
__unstable_subtitle={workspace.subtitle}
94-
__unstable_space={1}
95-
text={workspace?.title || workspace.name}
96-
/>
97-
)
98-
})}
99-
</StyledMenu>
84+
// we have a temporary need to make a hard direct link to the workspace
85+
// because of possibly shared context between workspaces. When this is resolved,
86+
// we can remove this and use setActiveWorkspace instead
87+
return (
88+
<MenuItem
89+
as="a"
90+
href={workspace.basePath}
91+
badgeText={STATE_TITLES[state]}
92+
iconRight={isSelected ? CheckmarkIcon : undefined}
93+
key={workspace.name}
94+
pressed={isSelected}
95+
preview={<WorkspacePreviewIcon icon={workspace.icon} size="small" />}
96+
selected={isSelected}
97+
__unstable_subtitle={workspace.subtitle}
98+
__unstable_space={1}
99+
text={workspace?.title || workspace.name}
100+
/>
101+
)
102+
})}
103+
</StyledMenu>
104+
</CapabilityGate>
100105
) : undefined
101106
}
102107
popover={POPOVER_PROPS}

0 commit comments

Comments
 (0)