mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
refactor: Run button view + headless fixtures for review
This commit is contained in:
@@ -1,17 +1,5 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { ChevronDown, Play, Plug, RotateCw, Square, SquareTerminal } from 'lucide-react'
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { useShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useWorktreeRuntimeTarget } from '@/runtime/rpc/targets/use-worktree-runtime-target'
|
||||
import { workspacePortScanKeyForTarget } from '@/lib/workspace-ports/workspace-port-actions'
|
||||
@@ -22,29 +10,18 @@ import {
|
||||
type WorktreeRunActions
|
||||
} from '@/lib/run-actions/run-action-config'
|
||||
import { startRunAction, stopRunAction } from '@/lib/run-actions/run-action-controller'
|
||||
import {
|
||||
useWorktreeRunActionRuns,
|
||||
type RunActionRun,
|
||||
type RunActionStatus
|
||||
} from '@/lib/run-actions/run-actions-store'
|
||||
import type { OrcaRunAction } from '../../../../shared/orca-yaml-hook-types'
|
||||
import { useWorktreeRunActionRuns, type RunActionRun } from '@/lib/run-actions/run-actions-store'
|
||||
import type { WorkspacePort } from '../../../../shared/workspace-ports'
|
||||
import { RunActionButtonView } from './RunActionButtonView'
|
||||
|
||||
const EMPTY_PORTS: WorkspacePort[] = []
|
||||
|
||||
function isLive(status: RunActionStatus | undefined): boolean {
|
||||
return status === 'running' || status === 'stopping'
|
||||
}
|
||||
|
||||
/** Reloads on workspace switch and window focus, so an orca.yaml edit shows up without a restart. */
|
||||
function useWorktreeRunActions(worktreeId: string | null): WorktreeRunActions | null {
|
||||
function useWorktreeRunActions(worktreeId: string): WorktreeRunActions | null {
|
||||
const [config, setConfig] = useState<{ worktreeId: string; value: WorktreeRunActions } | null>(
|
||||
null
|
||||
)
|
||||
useEffect(() => {
|
||||
if (!worktreeId) {
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
const load = (): void => {
|
||||
void loadWorktreeRunActions(worktreeId, { background: true }).then((value) => {
|
||||
@@ -74,50 +51,10 @@ function useWorktreePorts(worktreeId: string): WorkspacePort[] {
|
||||
)
|
||||
}
|
||||
|
||||
function StatusDot({ status }: { status: RunActionStatus | undefined }): React.JSX.Element | null {
|
||||
if (!status) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
className={cn(
|
||||
'inline-block size-1.5 shrink-0 rounded-full',
|
||||
status === 'running' && 'bg-emerald-500',
|
||||
status === 'stopping' && 'bg-amber-500 motion-safe:animate-pulse',
|
||||
status === 'failed' && 'bg-destructive',
|
||||
(status === 'exited' || status === 'stopped') && 'bg-muted-foreground/50'
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function useStatusLabel(): (run: RunActionRun | undefined) => string {
|
||||
const t = useTranslate()
|
||||
return (run) => {
|
||||
switch (run?.status) {
|
||||
case 'running':
|
||||
return t('runActions.status.running', 'Running')
|
||||
case 'stopping':
|
||||
return t('runActions.status.stopping', 'Stopping…')
|
||||
case 'stopped':
|
||||
return t('runActions.status.stopped', 'Stopped')
|
||||
case 'exited':
|
||||
return t('runActions.status.exited', 'Exited')
|
||||
case 'failed':
|
||||
return run.exitCode === null
|
||||
? t('runActions.status.failed', 'Failed')
|
||||
: t('runActions.status.failedWithCode', 'Failed (exit {{code}})', { code: run.exitCode })
|
||||
default:
|
||||
return t('runActions.status.notRunning', 'Not running')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function focusRunTab(worktreeId: string, tabId: string): void {
|
||||
function focusRunTab(run: RunActionRun): void {
|
||||
const state = useAppStore.getState()
|
||||
state.setActiveTabType('terminal', worktreeId)
|
||||
state.setActiveTab(tabId)
|
||||
state.setActiveTabType('terminal', run.worktreeId)
|
||||
state.setActiveTab(run.tabId)
|
||||
}
|
||||
|
||||
function openPortsPanel(): void {
|
||||
@@ -126,69 +63,8 @@ function openPortsPanel(): void {
|
||||
state.setRightSidebarTab('ports')
|
||||
}
|
||||
|
||||
function ActionRow({
|
||||
worktreeId,
|
||||
action,
|
||||
run,
|
||||
config
|
||||
}: {
|
||||
worktreeId: string
|
||||
action: OrcaRunAction
|
||||
run: RunActionRun | undefined
|
||||
config: WorktreeRunActions
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const statusLabel = useStatusLabel()
|
||||
const live = isLive(run?.status)
|
||||
return (
|
||||
<>
|
||||
<DropdownMenuLabel className="flex items-center gap-2 pt-2 text-xs font-medium">
|
||||
<StatusDot status={run?.status} />
|
||||
<span className="min-w-0 flex-1 truncate">{action.name}</span>
|
||||
<span className="shrink-0 font-normal text-muted-foreground">{statusLabel(run)}</span>
|
||||
</DropdownMenuLabel>
|
||||
<div
|
||||
className="truncate px-2 pb-1 font-mono text-[11px] text-muted-foreground"
|
||||
title={action.command}
|
||||
>
|
||||
{action.command}
|
||||
</div>
|
||||
{live ? (
|
||||
<>
|
||||
<DropdownMenuItem onSelect={() => void startRunAction(worktreeId, action, config)}>
|
||||
<RotateCw className="size-3.5" />
|
||||
{t('runActions.restart', 'Restart')}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
disabled={run?.status === 'stopping'}
|
||||
onSelect={() => void stopRunAction(worktreeId, action.id)}
|
||||
>
|
||||
<Square className="size-3.5" />
|
||||
{t('runActions.stop', 'Stop')}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
) : (
|
||||
<DropdownMenuItem onSelect={() => void startRunAction(worktreeId, action, config)}>
|
||||
<Play className="size-3.5" />
|
||||
{run ? t('runActions.runAgain', 'Run again') : t('runActions.run', 'Run')}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{run ? (
|
||||
<DropdownMenuItem onSelect={() => focusRunTab(worktreeId, run.tabId)}>
|
||||
<SquareTerminal className="size-3.5" />
|
||||
{t('runActions.showOutput', 'Show output')}
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Titlebar control for orca.yaml run actions. The main button starts the primary action (or shows
|
||||
* its terminal while it runs); the menu holds every action, Stop/Restart, and the ports it opened.
|
||||
*/
|
||||
/** The workspace's Run button; renders nothing when the project defines no run actions. */
|
||||
export function RunActionButton({ worktreeId }: { worktreeId: string }): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const config = useWorktreeRunActions(worktreeId)
|
||||
const runs = useWorktreeRunActionRuns(worktreeId)
|
||||
const ports = useWorktreePorts(worktreeId)
|
||||
@@ -199,94 +75,20 @@ export function RunActionButton({ worktreeId }: { worktreeId: string }): React.J
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[config, worktreeId, runs]
|
||||
)
|
||||
const primaryRun = primary ? runs[primary.id] : undefined
|
||||
const anyLive = Object.values(runs).some((run) => isLive(run.status))
|
||||
|
||||
const onPrimaryClick = useCallback(() => {
|
||||
if (!config || !primary) {
|
||||
return
|
||||
}
|
||||
if (primaryRun && isLive(primaryRun.status)) {
|
||||
focusRunTab(worktreeId, primaryRun.tabId)
|
||||
return
|
||||
}
|
||||
void startRunAction(worktreeId, primary, config)
|
||||
}, [config, primary, primaryRun, worktreeId])
|
||||
|
||||
if (!config || !primary) {
|
||||
return null
|
||||
}
|
||||
|
||||
const primaryLive = isLive(primaryRun?.status)
|
||||
const primaryLabel = primaryLive
|
||||
? t('runActions.showRunning', 'Show {{name}}', { name: primary.name })
|
||||
: t('runActions.runNamed', 'Run {{name}}', { name: primary.name })
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mr-2 flex h-6 items-center rounded-md border border-border/60 text-xs text-muted-foreground [-webkit-app-region:no-drag]"
|
||||
data-testid="run-action-button"
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex h-full items-center gap-1.5 rounded-l-md px-2 hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
onClick={onPrimaryClick}
|
||||
aria-label={primaryLabel}
|
||||
>
|
||||
{primaryLive ? <StatusDot status={primaryRun?.status} /> : <Play className="size-3" />}
|
||||
<span className="max-w-32 truncate">{primary.name}</span>
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{shortcut ? `${primaryLabel} (${shortcut})` : primaryLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex h-full items-center rounded-r-md border-l border-border/60 px-1 hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
aria-label={t('runActions.menu', 'Run actions')}
|
||||
>
|
||||
{anyLive && !primaryLive ? <StatusDot status="running" /> : null}
|
||||
<ChevronDown className="size-3" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-72">
|
||||
{config.actions.map((action, index) => (
|
||||
<React.Fragment key={action.id}>
|
||||
{index > 0 ? <DropdownMenuSeparator /> : null}
|
||||
<ActionRow
|
||||
worktreeId={worktreeId}
|
||||
action={action}
|
||||
run={runs[action.id]}
|
||||
config={config}
|
||||
/>
|
||||
</React.Fragment>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuLabel className="text-xs font-medium">
|
||||
{t('runActions.ports', 'Ports')}
|
||||
</DropdownMenuLabel>
|
||||
{ports.length === 0 ? (
|
||||
<div className="px-2 pb-2 text-xs text-muted-foreground">
|
||||
{t('runActions.noPorts', 'No servers listening in this workspace yet.')}
|
||||
</div>
|
||||
) : (
|
||||
ports.slice(0, 6).map((port) => (
|
||||
<DropdownMenuItem key={port.id} onSelect={openPortsPanel}>
|
||||
<Plug className="size-3.5" />
|
||||
<span className="font-mono">:{port.port}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground">
|
||||
{port.processName ?? ''}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
<RunActionButtonView
|
||||
actions={config.actions}
|
||||
primary={primary}
|
||||
runs={runs}
|
||||
ports={ports}
|
||||
shortcut={shortcut || null}
|
||||
onRun={(action) => void startRunAction(worktreeId, action, config)}
|
||||
onStop={(action) => void stopRunAction(worktreeId, action.id)}
|
||||
onShowOutput={focusRunTab}
|
||||
onOpenPorts={openPortsPanel}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { defineFixture } from '../../component-fixtures/component-fixture'
|
||||
import type { RunActionRun } from '@/lib/run-actions/run-actions-store'
|
||||
import type { OrcaRunAction } from '../../../../shared/orca-yaml-hook-types'
|
||||
import type { WorkspacePort } from '../../../../shared/workspace-ports'
|
||||
import { RunActionButtonView, type RunActionButtonViewProps } from './RunActionButtonView'
|
||||
|
||||
const noop = (): void => {}
|
||||
|
||||
const web: OrcaRunAction = {
|
||||
id: 'web',
|
||||
name: 'Web',
|
||||
command: 'pnpm dev --port $ORCA_PORT',
|
||||
default: true
|
||||
}
|
||||
const worker: OrcaRunAction = { id: 'worker', name: 'Worker', command: 'pnpm worker:dev' }
|
||||
const tests: OrcaRunAction = { id: 'test', name: 'Test', command: 'pnpm test:watch' }
|
||||
|
||||
function run(action: OrcaRunAction, patch: Partial<RunActionRun>): RunActionRun {
|
||||
return {
|
||||
worktreeId: 'repo::/w',
|
||||
repoId: 'repo',
|
||||
actionId: action.id,
|
||||
actionName: action.name,
|
||||
tabId: `tab-${action.id}`,
|
||||
status: 'running',
|
||||
exitCode: null,
|
||||
startedAt: 0,
|
||||
...patch
|
||||
}
|
||||
}
|
||||
|
||||
const port = (value: number, processName: string): WorkspacePort => ({
|
||||
kind: 'workspace',
|
||||
id: `p-${value}`,
|
||||
bindHost: '127.0.0.1',
|
||||
connectHost: 'localhost',
|
||||
port: value,
|
||||
processName,
|
||||
protocol: 'http',
|
||||
owner: { worktreeId: 'repo::/w', confidence: 'cwd' }
|
||||
})
|
||||
|
||||
const base: RunActionButtonViewProps = {
|
||||
actions: [web, worker, tests],
|
||||
primary: web,
|
||||
runs: {},
|
||||
ports: [],
|
||||
shortcut: '⌥⌘↩',
|
||||
onRun: noop,
|
||||
onStop: noop,
|
||||
onShowOutput: noop,
|
||||
onOpenPorts: noop
|
||||
}
|
||||
|
||||
function Bar({ children }: { children: React.ReactNode }): React.JSX.Element {
|
||||
return (
|
||||
<div className="flex h-9 items-center justify-end border-b border-border bg-background pr-2">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function openMenu(frame: HTMLElement): void {
|
||||
const trigger = frame.querySelector<HTMLButtonElement>('button[aria-label="Run actions"]')
|
||||
trigger?.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
|
||||
}
|
||||
|
||||
export const idle = defineFixture({
|
||||
width: 420,
|
||||
render: () => (
|
||||
<Bar>
|
||||
<RunActionButtonView {...base} />
|
||||
</Bar>
|
||||
)
|
||||
})
|
||||
|
||||
export const idleMenu = defineFixture({ ...idle, width: 420, interact: openMenu })
|
||||
|
||||
const runningProps: RunActionButtonViewProps = {
|
||||
...base,
|
||||
runs: { web: run(web, {}), test: run(tests, { status: 'failed', exitCode: 1 }) },
|
||||
ports: [port(21230, 'node'), port(21231, 'node')]
|
||||
}
|
||||
|
||||
export const running = defineFixture({
|
||||
width: 420,
|
||||
render: () => (
|
||||
<Bar>
|
||||
<RunActionButtonView {...runningProps} />
|
||||
</Bar>
|
||||
)
|
||||
})
|
||||
|
||||
export const runningMenu = defineFixture({ ...running, interact: openMenu })
|
||||
|
||||
export const stoppingMenu = defineFixture({
|
||||
width: 420,
|
||||
render: () => (
|
||||
<Bar>
|
||||
<RunActionButtonView {...base} runs={{ web: run(web, { status: 'stopping' }) }} />
|
||||
</Bar>
|
||||
),
|
||||
interact: openMenu
|
||||
})
|
||||
|
||||
export const singleLegacyAction = defineFixture({
|
||||
width: 420,
|
||||
render: () => (
|
||||
<Bar>
|
||||
<RunActionButtonView
|
||||
{...base}
|
||||
actions={[{ id: 'run', name: 'Run', command: 'npm run dev -- --port $CONDUCTOR_PORT' }]}
|
||||
primary={{ id: 'run', name: 'Run', command: 'npm run dev -- --port $CONDUCTOR_PORT' }}
|
||||
/>
|
||||
</Bar>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,225 @@
|
||||
import React from 'react'
|
||||
import { ChevronDown, Play, Plug, RotateCw, Square, SquareTerminal } from 'lucide-react'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import type { RunActionRun, RunActionStatus } from '@/lib/run-actions/run-actions-store'
|
||||
import type { OrcaRunAction } from '../../../../shared/orca-yaml-hook-types'
|
||||
import type { WorkspacePort } from '../../../../shared/workspace-ports'
|
||||
|
||||
export function isRunLive(status: RunActionStatus | undefined): boolean {
|
||||
return status === 'running' || status === 'stopping'
|
||||
}
|
||||
|
||||
function StatusDot({ status }: { status: RunActionStatus | undefined }): React.JSX.Element | null {
|
||||
if (!status) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
className={cn(
|
||||
'inline-block size-1.5 shrink-0 rounded-full',
|
||||
status === 'running' && 'bg-emerald-500',
|
||||
status === 'stopping' && 'bg-amber-500 motion-safe:animate-pulse',
|
||||
status === 'failed' && 'bg-destructive',
|
||||
(status === 'exited' || status === 'stopped') && 'bg-muted-foreground/50'
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function useStatusLabel(): (run: RunActionRun | undefined) => string {
|
||||
const t = useTranslate()
|
||||
return (run) => {
|
||||
switch (run?.status) {
|
||||
case 'running':
|
||||
return t('runActions.status.running', 'Running')
|
||||
case 'stopping':
|
||||
return t('runActions.status.stopping', 'Stopping…')
|
||||
case 'stopped':
|
||||
return t('runActions.status.stopped', 'Stopped')
|
||||
case 'exited':
|
||||
return t('runActions.status.exited', 'Exited')
|
||||
case 'failed':
|
||||
return run.exitCode === null
|
||||
? t('runActions.status.failed', 'Failed')
|
||||
: t('runActions.status.failedWithCode', 'Failed (exit {{code}})', { code: run.exitCode })
|
||||
default:
|
||||
return t('runActions.status.notRunning', 'Not running')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type RunActionButtonViewProps = {
|
||||
actions: readonly OrcaRunAction[]
|
||||
primary: OrcaRunAction
|
||||
runs: Readonly<Record<string, RunActionRun>>
|
||||
ports: readonly WorkspacePort[]
|
||||
shortcut: string | null
|
||||
onRun: (action: OrcaRunAction) => void
|
||||
onStop: (action: OrcaRunAction) => void
|
||||
onShowOutput: (run: RunActionRun) => void
|
||||
onOpenPorts: () => void
|
||||
}
|
||||
|
||||
function ActionRow({
|
||||
action,
|
||||
run,
|
||||
onRun,
|
||||
onStop,
|
||||
onShowOutput
|
||||
}: {
|
||||
action: OrcaRunAction
|
||||
run: RunActionRun | undefined
|
||||
} & Pick<RunActionButtonViewProps, 'onRun' | 'onStop' | 'onShowOutput'>): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const statusLabel = useStatusLabel()
|
||||
const live = isRunLive(run?.status)
|
||||
return (
|
||||
<>
|
||||
<DropdownMenuLabel className="flex items-center gap-2 pt-2 text-xs font-medium">
|
||||
<StatusDot status={run?.status} />
|
||||
<span className="min-w-0 flex-1 truncate">{action.name}</span>
|
||||
<span className="shrink-0 font-normal text-muted-foreground">{statusLabel(run)}</span>
|
||||
</DropdownMenuLabel>
|
||||
<div
|
||||
className="truncate px-2 pb-1 font-mono text-[11px] text-muted-foreground"
|
||||
title={action.command}
|
||||
>
|
||||
{action.command}
|
||||
</div>
|
||||
{live ? (
|
||||
<>
|
||||
<DropdownMenuItem onSelect={() => onRun(action)}>
|
||||
<RotateCw className="size-3.5" />
|
||||
{t('runActions.restart', 'Restart')}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem disabled={run?.status === 'stopping'} onSelect={() => onStop(action)}>
|
||||
<Square className="size-3.5" />
|
||||
{t('runActions.stop', 'Stop')}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
) : (
|
||||
<DropdownMenuItem onSelect={() => onRun(action)}>
|
||||
<Play className="size-3.5" />
|
||||
{run ? t('runActions.runAgain', 'Run again') : t('runActions.run', 'Run')}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{run ? (
|
||||
<DropdownMenuItem onSelect={() => onShowOutput(run)}>
|
||||
<SquareTerminal className="size-3.5" />
|
||||
{t('runActions.showOutput', 'Show output')}
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Titlebar control for run actions. The main button starts the primary action (or shows its
|
||||
* terminal while it runs); the menu holds every action, Stop/Restart, and the ports it opened.
|
||||
*/
|
||||
export function RunActionButtonView({
|
||||
actions,
|
||||
primary,
|
||||
runs,
|
||||
ports,
|
||||
shortcut,
|
||||
onRun,
|
||||
onStop,
|
||||
onShowOutput,
|
||||
onOpenPorts
|
||||
}: RunActionButtonViewProps): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const primaryRun = runs[primary.id]
|
||||
const primaryLive = isRunLive(primaryRun?.status)
|
||||
const anyLive = Object.values(runs).some((run) => isRunLive(run.status))
|
||||
const primaryLabel = primaryLive
|
||||
? t('runActions.showRunning', 'Show {{name}}', { name: primary.name })
|
||||
: t('runActions.runNamed', 'Run {{name}}', { name: primary.name })
|
||||
const onPrimaryClick = (): void => {
|
||||
if (primaryRun && primaryLive) {
|
||||
onShowOutput(primaryRun)
|
||||
} else {
|
||||
onRun(primary)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mr-2 flex h-6 items-center rounded-md border border-border/60 text-xs text-muted-foreground [-webkit-app-region:no-drag]"
|
||||
data-testid="run-action-button"
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex h-full items-center gap-1.5 rounded-l-md px-2 hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
onClick={onPrimaryClick}
|
||||
aria-label={primaryLabel}
|
||||
>
|
||||
{primaryLive ? <StatusDot status={primaryRun?.status} /> : <Play className="size-3" />}
|
||||
<span className="max-w-32 truncate">{primary.name}</span>
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{shortcut ? `${primaryLabel} (${shortcut})` : primaryLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex h-full items-center gap-1 rounded-r-md border-l border-border/60 px-1 hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||
aria-label={t('runActions.menu', 'Run actions')}
|
||||
>
|
||||
{anyLive && !primaryLive ? <StatusDot status="running" /> : null}
|
||||
<ChevronDown className="size-3" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-72">
|
||||
{actions.map((action, index) => (
|
||||
<React.Fragment key={action.id}>
|
||||
{index > 0 ? <DropdownMenuSeparator /> : null}
|
||||
<ActionRow
|
||||
action={action}
|
||||
run={runs[action.id]}
|
||||
onRun={onRun}
|
||||
onStop={onStop}
|
||||
onShowOutput={onShowOutput}
|
||||
/>
|
||||
</React.Fragment>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuLabel className="text-xs font-medium">
|
||||
{t('runActions.ports', 'Ports')}
|
||||
</DropdownMenuLabel>
|
||||
{ports.length === 0 ? (
|
||||
<div className="px-2 pb-2 text-xs text-muted-foreground">
|
||||
{t('runActions.noPorts', 'No servers listening in this workspace yet.')}
|
||||
</div>
|
||||
) : (
|
||||
ports.slice(0, 6).map((port) => (
|
||||
<DropdownMenuItem key={port.id} onSelect={onOpenPorts}>
|
||||
<Plug className="size-3.5" />
|
||||
<span className="font-mono">:{port.port}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-muted-foreground">
|
||||
{port.processName ?? ''}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user