Skip to content

The agent that grows with you

refactor(desktop): profile switchers share one gateway section and the session dot colors

Brooklyn Nicholson10dc619adcd5
diff --git a/apps/desktop/src/app/chat/sidebar/fleet-gateway-menu-group.tsx b/apps/desktop/src/app/chat/sidebar/fleet-gateway-menu-group.tsx
new file mode 100644
index 00000000000..9e47b617b1f
--- /dev/null
+++ b/apps/desktop/src/app/chat/sidebar/fleet-gateway-menu-group.tsx
@@ -0,0 +1,71 @@
+import { useStore } from '@nanostores/react'
+import type { ReactNode } from 'react'
+
+import { Codicon } from '@/components/ui/codicon'
+import {
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ dropdownMenuSectionLabel,
+ DropdownMenuSeparator
+} from '@/components/ui/dropdown-menu'
+import { ProfileGlyph } from '@/components/ui/profile-glyph'
+import { useI18n } from '@/i18n'
+import { resolveProfileColor } from '@/lib/profile-color'
+import { cn } from '@/lib/utils'
+import { $profileColors } from '@/store/profile'
+
+import { ConnectionGlyph } from './connection-glyph'
+import type { FleetAgent, FleetGroup } from './fleet-rail'
+
+interface FleetGatewayMenuGroupProps {
+ group: FleetGroup
+ onSelect: (agent: FleetAgent) => void
+ /** `data-slot` on the group wrapper; each menu keeps its own for tests. */
+ slot: string
+ /** Optional wrapper around each row (the rail menu adds a launch context menu). */
+ wrapRow?: (row: ReactNode, agent: FleetAgent, label: string) => ReactNode
+}
+
+/** One remote gateway's section in a profile menu: separator, gateway label
+ * (amber dot when unreachable), then a row per profile on that gateway.
+ * Shared by the rail's overflow dropdown and the compact profile dropdown. */
+export function FleetGatewayMenuGroup({ group, onSelect, slot, wrapRow }: FleetGatewayMenuGroupProps) {
+ const { t } = useI18n()
+ const p = t.profiles
+ const colors = useStore($profileColors)
+
+ return (
+ <div data-connection-id={group.connectionId} data-slot={slot}>
+ <DropdownMenuSeparator />
+ <DropdownMenuLabel className={cn(dropdownMenuSectionLabel, 'flex items-center gap-1.5')}>
+ <ConnectionGlyph connection={group} />
+ <span className="truncate">{group.label}</span>
+ {!group.reachable && <span aria-hidden="true" className="size-1.5 shrink-0 rounded-full bg-amber-500" />}
+ </DropdownMenuLabel>
+ {[group.defaultAgent, ...group.named].map(agent => {
+ const localDefault = agent.connectionKind === 'local' && agent.isDefault
+ const label = localDefault ? p.fleet.localDevice : p.fleet.onGateway(agent.profile, group.label)
+
+ const row = (
+ <DropdownMenuItem aria-label={label} className="min-w-0" key={agent.profile} onSelect={() => onSelect(agent)}>
+ <span className="flex min-w-0 items-center gap-1.5">
+ {localDefault ? (
+ <Codicon aria-hidden="true" name="device-desktop" size="0.875rem" />
+ ) : (
+ <ProfileGlyph
+ aria-hidden="true"
+ color={resolveProfileColor(agent.profile, colors)}
+ isDefault={agent.isDefault}
+ name={agent.profile}
+ />
+ )}
+ <span className="truncate">{agent.profile}</span>
+ </span>
+ </DropdownMenuItem>
+ )
+
+ return wrapRow ? wrapRow(row, agent, label) : row
+ })}
+ </div>
+ )
+}
diff --git a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
index baf373bd49f..87d7285d261 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
@@ -8,10 +8,8 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
- dropdownMenuSectionLabel,
DropdownMenuSeparator,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
@@ -49,7 +47,7 @@ import { runImportProfileFlow } from '@/store/profile-share'
import { CreateProfileDialog } from '../../profiles/create-profile-dialog'
import { PROFILES_ROUTE } from '../../routes'
-import { ConnectionGlyph } from './connection-glyph'
+import { FleetGatewayMenuGroup } from './fleet-gateway-menu-group'
import { buildRestGroups, type FleetAgent, fleetRouteKey } from './fleet-rail'
import { useLocalDeviceSwitch } from './local-device-switch'
import { useFleetRoster } from './use-fleet-roster'
@@ -226,43 +224,12 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
)}
</DropdownMenuRadioGroup>
{restGroups.map(group => (
- <div data-connection-id={group.connectionId} data-slot="profile-switcher-gateway" key={group.connectionId}>
- <DropdownMenuSeparator />
- <DropdownMenuLabel className={cn(dropdownMenuSectionLabel, 'flex items-center gap-1.5')}>
- <ConnectionGlyph connection={group} />
- <span className="truncate">{group.label}</span>
- {!group.reachable && (
- <span aria-hidden="true" className="size-1.5 shrink-0 rounded-full bg-amber-500" />
- )}
- </DropdownMenuLabel>
- {[group.defaultAgent, ...group.named].map(agent => {
- const localDefault = agent.connectionKind === 'local' && agent.isDefault
- const label = localDefault ? p.fleet.localDevice : p.fleet.onGateway(agent.profile, group.label)
-
- return (
- <DropdownMenuItem
- aria-label={label}
- className="min-w-0"
- key={agent.profile}
- onSelect={() => switchToRest(agent)}
- >
- <span className="flex min-w-0 items-center gap-1.5">
- {localDefault ? (
- <Codicon aria-hidden="true" name="device-desktop" size="0.875rem" />
- ) : (
- <ProfileGlyph
- aria-hidden="true"
- color={resolveProfileColor(agent.profile, colors)}
- isDefault={agent.isDefault}
- name={agent.profile}
- />
- )}
- <span className="truncate">{agent.profile}</span>
- </span>
- </DropdownMenuItem>
- )
- })}
- </div>
+ <FleetGatewayMenuGroup
+ group={group}
+ key={group.connectionId}
+ onSelect={switchToRest}
+ slot="profile-switcher-gateway"
+ />
))}
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={() => setCreateOpen(true)}>
diff --git a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
index 50bded8ec5b..fcba8056790 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
@@ -34,10 +34,8 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
- dropdownMenuSectionLabel,
DropdownMenuSeparator,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
@@ -87,12 +85,7 @@ import {
setShowAllProfiles,
sortByProfileOrder
} from '@/store/profile'
-import {
- $profileDotStateByScope,
- type ProfileDotState,
- type ProfileDotSummary,
- profileDotSummaryFor
-} from '@/store/profile-dot-state'
+import { $profileDotStateByScope, type ProfileDotSummary, profileDotSummaryFor } from '@/store/profile-dot-state'
import {
$profileRemoteOverrides,
openRemoteOverrideDialog,
@@ -105,8 +98,10 @@ import { CreateProfileDialog } from '../../profiles/create-profile-dialog'
import { DeleteProfileDialog } from '../../profiles/delete-profile-dialog'
import { RenameProfileDialog } from '../../profiles/rename-profile-dialog'
import { PROFILES_ROUTE, SETTINGS_ROUTE } from '../../routes'
+import { sessionDotClassName } from '../session-status-dot'
import { ConnectionGlyph } from './connection-glyph'
+import { FleetGatewayMenuGroup } from './fleet-gateway-menu-group'
import { buildRestGroups, countRestAgents, type FleetAgent, type FleetGroup, fleetRouteKey } from './fleet-rail'
import { useLocalDeviceSwitch } from './local-device-switch'
import { ProfileLaunchContextMenu, ProfileLaunchMenuSection } from './profile-launch-menu'
@@ -124,13 +119,11 @@ const PROFILE_DROPDOWN_THRESHOLD = 13
// #91710: a profile that finished (or blocked, or is still working) while
// another was selected carries an indicator on its rail square and dropdown
-// row. The colors mirror the session status dot's palette — amber for "needs
-// your answer", accent for running, success green for unread — so a profile's
-// loudest state reads the same as its sessions' dots in the sidebar below.
-const PROFILE_STATUS_DOT_CLASS: Record<ProfileDotState, string> = {
- 'needs-input': 'bg-amber-500',
- working: 'bg-(--ui-accent)',
- unread: 'bg-(--ui-success)'
+// row. It paints the session status dot's own class for the same state, so a
+// profile's loudest state reads the same as its sessions' dots below. The
+// `profile-status-dot` slot lets tests (and tours) find it.
+function ProfileStatusDot({ summary }: { summary: ProfileDotSummary }) {
+ return <span aria-hidden="true" className={sessionDotClassName(summary.state)} data-slot="profile-status-dot" />
}
/** The a11y/tooltip text for one square's summary — every non-zero count,
@@ -164,18 +157,6 @@ function useProfileStatus(profile: null | string, connectionId: null | string |
)
}
-/** The dot a square/dropdown row paints for a summary. `status-dot` slot so
- * tests (and tours) can find it without duplicating the class string. */
-function ProfileStatusDot({ summary }: { summary: ProfileDotSummary }) {
- return (
- <span
- aria-hidden="true"
- className={cn('size-1.5 rounded-full', PROFILE_STATUS_DOT_CLASS[summary.state])}
- data-slot="profile-status-dot"
- />
- )
-}
-
// Neighbors reflow on RAIL_TRANSITION; the dragged square glides between
// snapped cells on the snappier DRAG_TRANSITION. Both come from the SHARED
// reorder primitive (lib/reorder.ts) so every reorder strip feels identical.
@@ -962,43 +943,22 @@ function ProfileDropdown({
))}
</DropdownMenuRadioGroup>
{restGroups.map(group => (
- <div data-connection-id={group.connectionId} data-slot="profile-dropdown-gateway" key={group.connectionId}>
- <DropdownMenuSeparator />
- <DropdownMenuLabel className={cn(dropdownMenuSectionLabel, 'flex items-center gap-1.5')}>
- <ConnectionGlyph connection={group} />
- <span className="truncate">{group.label}</span>
- {!group.reachable && <span aria-hidden="true" className="size-1.5 shrink-0 rounded-full bg-amber-500" />}
- </DropdownMenuLabel>
- {[group.defaultAgent, ...group.named].map(agent => {
- const localDefault = agent.connectionKind === 'local' && agent.isDefault
- const label = localDefault ? p.fleet.localDevice : p.fleet.onGateway(agent.profile, group.label)
-
- return (
- <ProfileLaunchContextMenu
- connectionId={agent.connectionId}
- key={agent.profile}
- label={label}
- profile={agent.profile}
- >
- <DropdownMenuItem aria-label={label} className="min-w-0" onSelect={() => onSelectRest(agent)}>
- <span className="flex min-w-0 items-center gap-1.5">
- {localDefault ? (
- <Codicon aria-hidden="true" name="device-desktop" size="0.875rem" />
- ) : (
- <ProfileGlyph
- aria-hidden="true"
- color={resolveProfileColor(agent.profile, colors)}
- isDefault={agent.isDefault}
- name={agent.profile}
- />
- )}
- <span className="truncate">{agent.profile}</span>
- </span>
- </DropdownMenuItem>
- </ProfileLaunchContextMenu>
- )
- })}
- </div>
+ <FleetGatewayMenuGroup
+ group={group}
+ key={group.connectionId}
+ onSelect={onSelectRest}
+ slot="profile-dropdown-gateway"
+ wrapRow={(row, agent, label) => (
+ <ProfileLaunchContextMenu
+ connectionId={agent.connectionId}
+ key={agent.profile}
+ label={label}
+ profile={agent.profile}
+ >
+ {row}
+ </ProfileLaunchContextMenu>
+ )}
+ />
))}
</DropdownMenuContent>
</DropdownMenu>
@@ -1142,11 +1102,7 @@ function ProfilePill({
type="button"
variant="ghost"
>
- {pending ? (
- <Loader2 aria-hidden="true" className="size-3 animate-spin" />
- ) : (
- <Codicon name={glyph} size="0.875rem" />
- )}
+ {pending ? <Loader2 className="animate-spin" /> : <Codicon name={glyph} size="0.875rem" />}
{summary && !active && (
<span className="absolute -right-0.5 -top-0.5">
<ProfileStatusDot summary={summary} />