Skip to content

Commit 04f0ffc

Browse files
committed
fix(sidebar): show route workspace identity fallback
1 parent 2ddd441 commit 04f0ffc

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
@@ -80,7 +80,7 @@ const NO_PINS: ReadonlySet<string> = new Set()
8080
let container: HTMLDivElement
8181
let root: Root
8282

83-
function render() {
83+
function render(overrides: Partial<Parameters<typeof WorkspaceHeader>[0]> = {}) {
8484
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
8585
container = document.createElement('div')
8686
document.body.appendChild(container)
@@ -105,6 +105,7 @@ function render() {
105105
onUploadLogo={() => {}}
106106
onLeaveWorkspace={async () => {}}
107107
isLeavingWorkspace={false}
108+
{...overrides}
108109
/>
109110
)
110111
})
@@ -154,6 +155,21 @@ afterEach(() => {
154155
})
155156

156157
describe('WorkspaceHeader workspace switcher highlight', () => {
158+
it('shows the route workspace identity while the switcher list is unavailable', () => {
159+
render({
160+
activeWorkspace: { name: 'Brightwave' },
161+
workspaceId: 'ws-brightwave',
162+
workspaces: [],
163+
isWorkspaceMenuOpen: false,
164+
})
165+
166+
const switcher = container.querySelector('button[aria-label="Switch workspace"]')
167+
expect(switcher).toBeDisabled()
168+
expect(switcher).toHaveTextContent('Brightwave')
169+
expect(switcher).toHaveTextContent('B')
170+
expect(switcher?.querySelector('.animate-pulse')).toBeNull()
171+
})
172+
157173
it('leaves Enter unarmed until a cursor is on screen', () => {
158174
render()
159175

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
@@ -445,31 +445,35 @@ function WorkspaceHeaderImpl({
445445
className={chipVariants({ fullWidth: true })}
446446
>
447447
<div className='relative flex size-[16px] flex-shrink-0 items-center justify-center'>
448-
{!activeWorkspaceFull ? (
449-
<Skeleton className='size-[16px] rounded-sm' />
450-
) : (
448+
{activeWorkspaceFull?.logoUrl ? (
451449
<>
452-
{activeWorkspaceFull.logoUrl ? (
453-
<img
454-
src={activeWorkspaceFull.logoUrl}
455-
alt={activeWorkspaceFull.name || 'Workspace logo'}
456-
className='size-[16px] rounded-sm object-cover group-hover:invisible'
457-
/>
458-
) : (
459-
<div
460-
className='flex size-[16px] items-center justify-center rounded-sm text-[9px] text-white leading-none group-hover:invisible'
461-
style={{
462-
backgroundColor: activeWorkspaceFull.color ?? 'var(--brand-accent)',
463-
}}
464-
>
465-
{workspaceInitial}
466-
</div>
467-
)}
450+
<img
451+
src={activeWorkspaceFull.logoUrl}
452+
alt={activeWorkspaceFull.name || 'Workspace logo'}
453+
className='size-[16px] rounded-sm object-cover group-hover:invisible'
454+
/>
468455
<PanelLeft
469456
aria-hidden
470457
className='pointer-events-none invisible absolute inset-0 m-auto size-[16px] rotate-180 text-[var(--text-icon)] group-hover:visible'
471458
/>
472459
</>
460+
) : activeWorkspace ? (
461+
<>
462+
<div
463+
className='flex size-[16px] items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none group-hover:invisible'
464+
style={{
465+
backgroundColor: activeWorkspaceFull?.color ?? 'var(--brand-accent)',
466+
}}
467+
>
468+
{workspaceInitial}
469+
</div>
470+
<PanelLeft
471+
aria-hidden
472+
className='pointer-events-none invisible absolute inset-0 m-auto size-[16px] rotate-180 text-[var(--text-icon)] group-hover:visible'
473+
/>
474+
</>
475+
) : (
476+
<Skeleton className='size-[16px] rounded-sm' />
473477
)}
474478
</div>
475479
</button>
@@ -852,21 +856,19 @@ function WorkspaceHeaderImpl({
852856
title={activeWorkspace?.name}
853857
disabled
854858
>
855-
{activeWorkspaceFull ? (
856-
activeWorkspaceFull.logoUrl ? (
857-
<img
858-
src={activeWorkspaceFull.logoUrl}
859-
alt={activeWorkspaceFull.name || 'Workspace logo'}
860-
className='size-[16px] flex-shrink-0 rounded-sm object-cover'
861-
/>
862-
) : (
863-
<div
864-
className='flex size-[16px] flex-shrink-0 items-center justify-center rounded-sm text-[9px] text-white leading-none'
865-
style={{ backgroundColor: activeWorkspaceFull.color ?? 'var(--brand-accent)' }}
866-
>
867-
{workspaceInitial}
868-
</div>
869-
)
859+
{activeWorkspaceFull?.logoUrl ? (
860+
<img
861+
src={activeWorkspaceFull.logoUrl}
862+
alt={activeWorkspaceFull.name || 'Workspace logo'}
863+
className='size-[16px] flex-shrink-0 rounded-sm object-cover'
864+
/>
865+
) : activeWorkspace ? (
866+
<div
867+
className='flex size-[16px] flex-shrink-0 items-center justify-center rounded-sm font-medium text-[9px] text-white leading-none'
868+
style={{ backgroundColor: activeWorkspaceFull?.color ?? 'var(--brand-accent)' }}
869+
>
870+
{workspaceInitial}
871+
</div>
870872
) : (
871873
<Skeleton className='size-[16px] flex-shrink-0 rounded-sm' />
872874
)}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { buildFolderTree, getFolderPathNames } from '@/lib/folders/tree'
4444
import { captureEvent } from '@/lib/posthog/client'
4545
import { CONNECT_MODE } from '@/app/workspace/[workspaceId]/integrations/connect-route'
4646
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
47+
import { useWorkspaceHostContext } from '@/app/workspace/[workspaceId]/providers/workspace-host-provider'
4748
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
4849
import type { SettingsSection } from '@/app/workspace/[workspaceId]/settings/navigation'
4950
import { createCommands } from '@/app/workspace/[workspaceId]/utils/commands-utils'
@@ -422,6 +423,7 @@ export const Sidebar = memo(function Sidebar({
422423

423424
const posthog = usePostHog()
424425
const { data: sessionData, isPending: sessionLoading } = useSession()
426+
const { workspace: routeWorkspace } = useWorkspaceHostContext()
425427
const { canEdit, isLoading: permissionsLoading } = useUserPermissionsContext()
426428
const {
427429
config: permissionConfig,
@@ -1354,7 +1356,7 @@ export const Sidebar = memo(function Sidebar({
13541356
)}
13551357
>
13561358
<WorkspaceHeader
1357-
activeWorkspace={activeWorkspace}
1359+
activeWorkspace={activeWorkspace ?? routeWorkspace}
13581360
workspaceId={workspaceId}
13591361
workspaces={workspaces}
13601362
pinnedWorkspaceIds={pinnedWorkspaceIds}

0 commit comments

Comments
 (0)