diff --git a/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx b/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx index d9d283746..69d04ce2e 100644 --- a/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx +++ b/src/renderer/src/components/right-sidebar/activity-bar-buttons.tsx @@ -19,6 +19,8 @@ export type ActivityBarItem = { shortcut: string /** When true, hidden for non-git (folder-mode) repos. */ gitOnly?: boolean + /** When true, shown only for worktrees that belong to an SSH repo. */ + sshOnly?: boolean } const STATUS_DOT_COLOR: Record = { diff --git a/src/renderer/src/components/right-sidebar/index.tsx b/src/renderer/src/components/right-sidebar/index.tsx index 4aa16813a..a26f5c5a2 100644 --- a/src/renderer/src/components/right-sidebar/index.tsx +++ b/src/renderer/src/components/right-sidebar/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useMemo, useState } from 'react' -import { Files, Search, GitBranch, ListChecks, PanelRight } from 'lucide-react' +import { Plug, Files, Search, GitBranch, ListChecks, PanelRight } from 'lucide-react' import { useAppStore } from '@/store' import { useActiveWorktree, useRepoById } from '@/store/selectors' import { cn } from '@/lib/utils' @@ -19,6 +19,7 @@ import FileExplorer from './FileExplorer' import SourceControl from './SourceControl' import SearchPanel from './Search' import ChecksPanel from './ChecksPanel' +import PortsPanel from './PortsPanel' import { getTopActivityBarLayout } from './activity-bar-overflow' import { ActivityBarButton, @@ -26,6 +27,7 @@ import { type ActivityBarItem } from './activity-bar-buttons' import { getActiveChecksStatus } from './active-checks-status' +import { getVisibleRightSidebarActivityItems } from './right-sidebar-activity-visibility' const MIN_WIDTH = 220 // Why: long file names (e.g. construction drawing sheets, multi-part document @@ -69,6 +71,13 @@ const ACTIVITY_ITEMS: ActivityBarItem[] = [ title: 'Checks', shortcut: `${isMac ? '\u21E7' : 'Shift+'}${mod}K`, gitOnly: true + }, + { + id: 'ports', + icon: Plug, + title: 'Ports', + shortcut: '', + sshOnly: true } ] @@ -88,16 +97,11 @@ function RightSidebarInner(): React.JSX.Element { // Hide those tabs so the activity bar only shows relevant actions. const activeRepo = useRepoById(activeWorktree?.repoId ?? null) const isFolder = activeRepo ? isFolderRepo(activeRepo) : false + const isSshRepo = Boolean(activeRepo?.connectionId) const visibleItems = useMemo( - () => - ACTIVITY_ITEMS.filter((item) => { - if (item.gitOnly && isFolder) { - return false - } - return true - }), - [isFolder] + () => getVisibleRightSidebarActivityItems(ACTIVITY_ITEMS, { isFolder, isSshRepo }), + [isFolder, isSshRepo] ) // If the active tab is hidden (e.g. switched from a git repo to a folder), @@ -137,6 +141,12 @@ function RightSidebarInner(): React.JSX.Element { {effectiveTab === 'search' && } {effectiveTab === 'source-control' && } {effectiveTab === 'checks' && } + {/* Why: SSH port forwarding still depends on the raw ports.detect data, + which the workspace-scoped status bar popover intentionally does not + expose. Keep this panel reachable only for SSH worktrees. */} + {effectiveTab === 'ports' && ( + + )} ) diff --git a/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.test.ts b/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.test.ts new file mode 100644 index 000000000..69889e593 --- /dev/null +++ b/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from 'vitest' +import { Files } from 'lucide-react' +import type { ActivityBarItem } from './activity-bar-buttons' +import { getVisibleRightSidebarActivityItems } from './right-sidebar-activity-visibility' + +const items: ActivityBarItem[] = [ + { id: 'explorer', icon: Files, title: 'Explorer', shortcut: '' }, + { id: 'source-control', icon: Files, title: 'Source Control', shortcut: '', gitOnly: true }, + { id: 'ports', icon: Files, title: 'Ports', shortcut: '', sshOnly: true } +] + +describe('getVisibleRightSidebarActivityItems', () => { + it('shows ports only for SSH repos', () => { + expect( + getVisibleRightSidebarActivityItems(items, { isFolder: false, isSshRepo: false }).map( + (item) => item.id + ) + ).toEqual(['explorer', 'source-control']) + + expect( + getVisibleRightSidebarActivityItems(items, { isFolder: false, isSshRepo: true }).map( + (item) => item.id + ) + ).toEqual(['explorer', 'source-control', 'ports']) + }) + + it('still hides git-only tabs for folder repos', () => { + expect( + getVisibleRightSidebarActivityItems(items, { isFolder: true, isSshRepo: true }).map( + (item) => item.id + ) + ).toEqual(['explorer', 'ports']) + }) +}) diff --git a/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.ts b/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.ts new file mode 100644 index 000000000..ec55b86fe --- /dev/null +++ b/src/renderer/src/components/right-sidebar/right-sidebar-activity-visibility.ts @@ -0,0 +1,22 @@ +import type { ActivityBarItem } from './activity-bar-buttons' + +export function getVisibleRightSidebarActivityItems( + items: ActivityBarItem[], + { + isFolder, + isSshRepo + }: { + isFolder: boolean + isSshRepo: boolean + } +): ActivityBarItem[] { + return items.filter((item) => { + if (item.gitOnly && isFolder) { + return false + } + if (item.sshOnly && !isSshRepo) { + return false + } + return true + }) +}