Restore SSH port forwarding UI (#2544)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -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<CheckStatus, string> = {
|
||||
|
||||
@@ -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' && <SearchPanel />}
|
||||
{effectiveTab === 'source-control' && <SourceControl />}
|
||||
{effectiveTab === 'checks' && <ChecksPanel />}
|
||||
{/* 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' && (
|
||||
<PortsPanel isVisible={rightSidebarOpen && effectiveTab === 'ports'} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -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'])
|
||||
})
|
||||
})
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user