Skip to content

Commit a257119

Browse files
committed
fix(sidebar): show route workspace identity fallback
1 parent ccf1ce7 commit a257119

3 files changed

Lines changed: 56 additions & 36 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const WORKSPACES = [
7575
let container: HTMLDivElement
7676
let root: Root
7777

78-
function render() {
78+
function render(overrides: Partial<Parameters<typeof WorkspaceHeader>[0]> = {}) {
7979
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
8080
container = document.createElement('div')
8181
document.body.appendChild(container)
@@ -98,6 +98,7 @@ function render() {
9898
onUploadLogo={() => {}}
9999
onLeaveWorkspace={async () => {}}
100100
isLeavingWorkspace={false}
101+
{...overrides}
101102
/>
102103
)
103104
})
@@ -147,6 +148,21 @@ afterEach(() => {
147148
})
148149

149150
describe('WorkspaceHeader workspace switcher highlight', () => {
151+
it('shows the route workspace identity while the switcher list is unavailable', () => {
152+
render({
153+
activeWorkspace: { name: 'Brightwave' },
154+
workspaceId: 'ws-brightwave',
155+
workspaces: [],
156+
isWorkspaceMenuOpen: false,
157+
})
158+
159+
const switcher = container.querySelector('button[aria-label="Switch workspace"]')
160+
expect(switcher).toBeDisabled()
161+
expect(switcher).toHaveTextContent('Brightwave')
162+
expect(switcher).toHaveTextContent('B')
163+
expect(switcher?.querySelector('.animate-pulse')).toBeNull()
164+
})
165+
150166
it('leaves Enter unarmed until a cursor is on screen', () => {
151167
render()
152168

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -413,31 +413,35 @@ function WorkspaceHeaderImpl({
413413
className={chipVariants({ fullWidth: true })}
414414
>
415415
<div className='relative flex size-[16px] flex-shrink-0 items-center justify-center'>
416-
{!activeWorkspaceFull ? (
417-
<Skeleton className='size-[16px] rounded-sm' />
418-
) : (
416+
{activeWorkspaceFull?.logoUrl ? (
419417
<>
420-
{activeWorkspaceFull.logoUrl ? (
421-
<img
422-
src={activeWorkspaceFull.logoUrl}
423-
alt={activeWorkspaceFull.name || 'Workspace logo'}
424-
className='size-[16px] rounded-sm object-cover group-hover:invisible'
425-
/>
426-
) : (
427-
<div
428-
className='flex size-[16px] items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none group-hover:invisible'
429-
style={{
430-
backgroundColor: activeWorkspaceFull.color ?? 'var(--brand-accent)',
431-
}}
432-
>
433-
{workspaceInitial}
434-
</div>
435-
)}
418+
<img
419+
src={activeWorkspaceFull.logoUrl}
420+
alt={activeWorkspaceFull.name || 'Workspace logo'}
421+
className='size-[16px] rounded-sm object-cover group-hover:invisible'
422+
/>
436423
<PanelLeft
437424
aria-hidden
438425
className='pointer-events-none invisible absolute inset-0 m-auto size-[16px] rotate-180 text-[var(--text-icon)] group-hover:visible'
439426
/>
440427
</>
428+
) : activeWorkspace ? (
429+
<>
430+
<div
431+
className='flex size-[16px] items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none group-hover:invisible'
432+
style={{
433+
backgroundColor: activeWorkspaceFull?.color ?? 'var(--brand-accent)',
434+
}}
435+
>
436+
{workspaceInitial}
437+
</div>
438+
<PanelLeft
439+
aria-hidden
440+
className='pointer-events-none invisible absolute inset-0 m-auto size-[16px] rotate-180 text-[var(--text-icon)] group-hover:visible'
441+
/>
442+
</>
443+
) : (
444+
<Skeleton className='size-[16px] rounded-sm' />
441445
)}
442446
</div>
443447
</button>
@@ -800,21 +804,19 @@ function WorkspaceHeaderImpl({
800804
title={activeWorkspace?.name}
801805
disabled
802806
>
803-
{activeWorkspaceFull ? (
804-
activeWorkspaceFull.logoUrl ? (
805-
<img
806-
src={activeWorkspaceFull.logoUrl}
807-
alt={activeWorkspaceFull.name || 'Workspace logo'}
808-
className='size-[16px] flex-shrink-0 rounded-sm object-cover'
809-
/>
810-
) : (
811-
<div
812-
className='flex size-[16px] flex-shrink-0 items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none'
813-
style={{ backgroundColor: activeWorkspaceFull.color ?? 'var(--brand-accent)' }}
814-
>
815-
{workspaceInitial}
816-
</div>
817-
)
807+
{activeWorkspaceFull?.logoUrl ? (
808+
<img
809+
src={activeWorkspaceFull.logoUrl}
810+
alt={activeWorkspaceFull.name || 'Workspace logo'}
811+
className='size-[16px] flex-shrink-0 rounded-sm object-cover'
812+
/>
813+
) : activeWorkspace ? (
814+
<div
815+
className='flex size-[16px] flex-shrink-0 items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none'
816+
style={{ backgroundColor: activeWorkspaceFull?.color ?? 'var(--brand-accent)' }}
817+
>
818+
{workspaceInitial}
819+
</div>
818820
) : (
819821
<Skeleton className='size-[16px] flex-shrink-0 rounded-sm' />
820822
)}

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { isMacPlatform } from '@/lib/core/utils/platform'
4343
import { buildFolderTree, getFolderPathNames } from '@/lib/folders/tree'
4444
import { captureEvent } from '@/lib/posthog/client'
4545
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
46+
import { useWorkspaceHostContext } from '@/app/workspace/[workspaceId]/providers/workspace-host-provider'
4647
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
4748
import type { SettingsSection } from '@/app/workspace/[workspaceId]/settings/navigation'
4849
import { createCommands } from '@/app/workspace/[workspaceId]/utils/commands-utils'
@@ -411,6 +412,7 @@ export const Sidebar = memo(function Sidebar({
411412

412413
const posthog = usePostHog()
413414
const { data: sessionData, isPending: sessionLoading } = useSession()
415+
const { workspace: routeWorkspace } = useWorkspaceHostContext()
414416
const { canEdit, isLoading: permissionsLoading } = useUserPermissionsContext()
415417
const { config: permissionConfig, filterBlocks } = usePermissionConfig()
416418
const { navigateToSettings } = useSettingsNavigation()
@@ -1327,7 +1329,7 @@ export const Sidebar = memo(function Sidebar({
13271329
)}
13281330
>
13291331
<WorkspaceHeader
1330-
activeWorkspace={activeWorkspace}
1332+
activeWorkspace={activeWorkspace ?? routeWorkspace}
13311333
workspaceId={workspaceId}
13321334
workspaces={workspaces}
13331335
workspaceCreationPolicy={workspaceCreationPolicy}

0 commit comments

Comments
 (0)