Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sanity): hide workspace switcher inside Core UI rendering context #8838

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading