mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
fix(w3): say 'no ports' once in the Ports panel
Design-squad P3 from the #382 recheck: with no ports, the panel showed the empty line under Active Workspace and again as the centered empty state. Center it only when the panel has no group at all (no footer such as Orca Cloud's Shared links, no remote-only forwards); otherwise keep the inline line.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { WorkspacePort } from '../../../../shared/workspace-ports'
|
||||
import { getLocalWorkspacePortSections } from './local-workspace-port-sections'
|
||||
import {
|
||||
getLocalWorkspacePortSections,
|
||||
shouldShowCenteredPortsEmpty
|
||||
} from './local-workspace-port-sections'
|
||||
|
||||
const external = (
|
||||
port: number,
|
||||
@@ -36,3 +39,26 @@ describe('getLocalWorkspacePortSections', () => {
|
||||
expect(sections.externalPorts.map((port) => port.port)).toEqual([6768, 23456, 5432, 8123])
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldShowCenteredPortsEmpty', () => {
|
||||
const none = {
|
||||
activePorts: [],
|
||||
otherWorkspacePorts: [],
|
||||
externalPorts: [],
|
||||
remoteOnlyForwards: [],
|
||||
hasFooter: false
|
||||
}
|
||||
|
||||
it('centers the empty message only when the panel has no group at all', () => {
|
||||
expect(shouldShowCenteredPortsEmpty({}, none)).toBe(true)
|
||||
// Orca Cloud: Shared links is a group, so the inline line under Active Workspace stays.
|
||||
expect(shouldShowCenteredPortsEmpty({}, { ...none, hasFooter: true })).toBe(false)
|
||||
expect(shouldShowCenteredPortsEmpty({}, { ...none, remoteOnlyForwards: [1] })).toBe(false)
|
||||
expect(shouldShowCenteredPortsEmpty({}, { ...none, externalPorts: [1] })).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps the inline Scanning line before the first scan and hides on scan errors', () => {
|
||||
expect(shouldShowCenteredPortsEmpty(null, none)).toBe(false)
|
||||
expect(shouldShowCenteredPortsEmpty({ unavailableReason: 'x' }, none)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -50,6 +50,31 @@ export function shouldShowLocalWorkspacePortSections(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The panel says "no ports" once: centered when it would show no group at all, otherwise inline
|
||||
* under Active Workspace (e.g. above Orca Cloud's Shared links, or beside remote-only forwards).
|
||||
*/
|
||||
export function shouldShowCenteredPortsEmpty(
|
||||
scan: { unavailableReason?: string } | null | undefined,
|
||||
sections: {
|
||||
activePorts: unknown[]
|
||||
otherWorkspacePorts: unknown[]
|
||||
externalPorts: unknown[]
|
||||
remoteOnlyForwards: unknown[]
|
||||
hasFooter: boolean
|
||||
}
|
||||
): boolean {
|
||||
return (
|
||||
Boolean(scan) &&
|
||||
!scan?.unavailableReason &&
|
||||
sections.activePorts.length === 0 &&
|
||||
sections.otherWorkspacePorts.length === 0 &&
|
||||
sections.externalPorts.length === 0 &&
|
||||
sections.remoteOnlyForwards.length === 0 &&
|
||||
!sections.hasFooter
|
||||
)
|
||||
}
|
||||
|
||||
function workspacePortAsExternal(port: WorkspacePort & { kind: 'workspace' }): WorkspacePort {
|
||||
return {
|
||||
id: port.id,
|
||||
|
||||
@@ -22,6 +22,7 @@ import { translate } from '@/i18n/i18n'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import {
|
||||
getLocalWorkspacePortSections,
|
||||
shouldShowCenteredPortsEmpty,
|
||||
shouldShowLocalWorkspacePortSections
|
||||
} from './local-workspace-port-sections'
|
||||
import { LocalPortSection } from './local-port-section'
|
||||
@@ -222,6 +223,17 @@ export function LocalWorkspacePortsPanel({
|
||||
otherWorkspacePorts,
|
||||
externalPorts
|
||||
})
|
||||
const remoteOnlyForwards =
|
||||
runtimeForwarding?.forwards.filter(
|
||||
(forward) => !displayScan?.ports.some((port) => port.port === forward.remotePort)
|
||||
) ?? []
|
||||
const showCenteredEmpty = shouldShowCenteredPortsEmpty(displayScan, {
|
||||
activePorts,
|
||||
otherWorkspacePorts,
|
||||
externalPorts,
|
||||
remoteOnlyForwards,
|
||||
hasFooter: Boolean(footer)
|
||||
})
|
||||
|
||||
if (!activeRepoId) {
|
||||
return (
|
||||
@@ -280,7 +292,7 @@ export function LocalWorkspacePortsPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showPortSections && (
|
||||
{showPortSections && !showCenteredEmpty && (
|
||||
<>
|
||||
<LocalPortSection
|
||||
id="active"
|
||||
@@ -326,30 +338,20 @@ export function LocalWorkspacePortsPanel({
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{runtimeForwarding && (
|
||||
<RuntimeForwardedPortsSection
|
||||
forwards={runtimeForwarding.forwards.filter(
|
||||
(forward) => !displayScan?.ports.some((port) => port.port === forward.remotePort)
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{runtimeForwarding && <RuntimeForwardedPortsSection forwards={remoteOnlyForwards} />}
|
||||
|
||||
{!displayScan?.unavailableReason &&
|
||||
displayScan &&
|
||||
activePorts.length === 0 &&
|
||||
otherWorkspacePorts.length === 0 &&
|
||||
externalPorts.length === 0 && (
|
||||
<div className="flex flex-col items-center justify-center flex-1 px-4 text-center text-muted-foreground">
|
||||
<Server size={32} className="mb-3 opacity-50" />
|
||||
<p className="text-sm">
|
||||
{runtimeForwarding ? (
|
||||
<RuntimePortsEmptyText />
|
||||
) : (
|
||||
t('auto.components.right.sidebar.PortsPanel.a2a9fc6899', 'No local ports detected')
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{showCenteredEmpty && (
|
||||
<div className="flex flex-col items-center justify-center flex-1 px-4 text-center text-muted-foreground">
|
||||
<Server size={32} className="mb-3 opacity-50" />
|
||||
<p className="text-sm">
|
||||
{runtimeForwarding ? (
|
||||
<RuntimePortsEmptyText />
|
||||
) : (
|
||||
t('auto.components.right.sidebar.PortsPanel.a2a9fc6899', 'No local ports detected')
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{footer?.(activePorts)}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { WorkspacePort } from '../../../../shared/workspace-ports'
|
||||
import type { RuntimePortForward } from '../../../../shared/runtime-port-forwards'
|
||||
import { LocalPortSection } from './local-port-section'
|
||||
import { RuntimeForwardedPortsSection } from './runtime-forwarded-ports-section'
|
||||
import { SharedLinksList } from './cloud-share/shared-links-list'
|
||||
import {
|
||||
RuntimePortForwardStatus,
|
||||
type RuntimePortForwardRowState
|
||||
@@ -112,6 +113,25 @@ function Panel({ empty = false }: { empty?: boolean }): React.JSX.Element {
|
||||
|
||||
export const allStates = defineFixture({ width: 300, render: () => <Panel /> })
|
||||
export const noPorts = defineFixture({ width: 300, render: () => <Panel empty /> })
|
||||
/** Orca Cloud with no ports: one inline empty line under Active Workspace, then Shared links; no centered empty state. */
|
||||
export const cloudNoPorts = defineFixture({
|
||||
width: 300,
|
||||
render: () => (
|
||||
<div className="w-[280px] bg-background text-foreground">
|
||||
<Panel empty />
|
||||
<SharedLinksList
|
||||
status="ready"
|
||||
shares={[]}
|
||||
now={0}
|
||||
onShare={() => {}}
|
||||
onRetry={() => {}}
|
||||
onCopy={async () => true}
|
||||
onOpen={() => {}}
|
||||
onRevoke={async () => true}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
export const hostOffline = defineFixture({
|
||||
width: 300,
|
||||
render: () => (
|
||||
|
||||
Reference in New Issue
Block a user