Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/desktop/e2e/features/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ test('a serial group across projects waits for each step, then stops everything'
await expect(bar).toContainText(/front1启动中 \d\/2/)
await expect(titleBar).toHaveCount(0)
await page.getByRole('button', { name: '批量', exact: true }).click()
await expect(item).toContainText('已完成', { timeout: 30_000 })
await expect(item).toContainText('运行中 2/2', { timeout: 30_000 })
// The navigation badge and bar remain while the servers keep running after the execution ended.
await expect(running).toHaveText(/\d+/)
await page.getByRole('button', { name: '运行中', exact: true }).click()
await expect(bar).toContainText('front1运行中 2/2')
await expect(titleBar).toHaveCount(0)
await page.getByRole('button', { name: '批量', exact: true }).click()
await expect(detail).toContainText('2/2 个步骤完成')
await expect(detail).toContainText('服务进程可能仍在运行')
await expect(detail).toContainText('服务进程正在运行中')
await expect(detail.getByRole('button', { name: '停止全部' })).toBeEnabled()
await expect(detail.getByRole('listitem', { name: '运行步骤 1' })).toContainText('本次启动')
await detail
Expand Down Expand Up @@ -194,7 +194,7 @@ test('waits for a regex in the output and remembers the result after a restart',

const item = () => page.getByRole('listitem', { name: '批量任务 backend' })
await item().getByRole('button', { name: '执行 backend' }).click()
await expect(item()).toContainText(/已完成 · \d{2}:\d{2}/)
await expect(item()).toContainText('运行中 1/1', { timeout: 30_000 })
await item().getByRole('button', { name: '查看 backend' }).click()
const detail = () => page.getByRole('region', { name: '任务运行 backend' })
await expect(detail()).toContainText('本次启动')
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/e2e/process/ports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ for (const mode of ['serial', 'parallel'] as const) {
await item.getByRole('button', { name: '执行 replace listeners' }).click()

// Windows performs verified CIM snapshots for each sequential port takeover.
await expect(item).toContainText('已完成', { timeout: 35_000 })
await expect(item).toContainText('运行中 2/2', { timeout: 35_000 })
await expect.poll(() => httpBody(first.port)).toBe('group-first')
await expect.poll(() => httpBody(second.port)).toBe('group-second')
await expect.poll(() => [hasExited(first), hasExited(second)]).toEqual([true, true])
Expand Down
71 changes: 29 additions & 42 deletions apps/desktop/src/renderer/src/features/groups/batch-task-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@renderer/components/ui/dropdown-menu'
import { useRuns } from '@renderer/features/runs/use-runs'
import { cn } from '@renderer/lib/utils'
import { resolveGroupStatus } from './group-status'
import { GROUP_SORT_STORAGE_KEY, getStoredGroupSortOrder } from './group-sort'
import { GroupSortMenu } from './group-sort-menu'
import {
Expand Down Expand Up @@ -67,7 +68,8 @@ export function BatchTaskList({
}
}

const activeIds = new Set(activeGroups(states.data ?? [], runs).map((group) => group.groupId))
const activeList = activeGroups(states.data ?? [], runs)
const activeIds = new Set(activeList.map((group) => group.groupId))
const sortedGroups = sortGroups(groups.data ?? [], activeIds, {
order: sortOrder,
states: states.data
Expand Down Expand Up @@ -114,10 +116,9 @@ export function BatchTaskList({
<ul className="flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto">
{sortedGroups.map((group) => {
const state = states.data?.find((s) => s.groupId === group.id)
const active = activeList.find((a) => a.groupId === group.id)
const presentation = resolveGroupStatus({ group, state, active })
const isSelected = group.id === selectedGroupId
const running = state?.status === 'running'
const failed = state?.status === 'failed'
const done = state?.status === 'done'
const busy =
(start.isPending && start.variables === group.id) ||
(stop.isPending && stop.variables === group.id)
Expand All @@ -140,10 +141,11 @@ export function BatchTaskList({
<span
className={cn(
'size-1.5 shrink-0 rounded-full',
running && 'animate-pulse bg-primary',
failed && 'bg-destructive',
done && 'bg-muted-foreground/60',
!state && 'bg-muted-foreground/30'
presentation.dotState === 'starting' && 'animate-pulse bg-primary',
presentation.dotState === 'running' && 'bg-primary',
presentation.dotState === 'failed' && 'bg-destructive',
presentation.dotState === 'done' && 'bg-muted-foreground/60',
presentation.dotState === 'idle' && 'bg-muted-foreground/30'
)}
/>

Expand All @@ -168,21 +170,15 @@ export function BatchTaskList({
variant="secondary"
className={cn(
'h-4 shrink-0 px-1 font-mono text-[9px] font-normal border-0',
running && 'bg-primary/15 text-primary font-medium',
failed && 'bg-destructive/15 text-destructive font-medium',
done && 'bg-secondary text-muted-foreground',
!state && 'bg-secondary/60 text-muted-foreground/60'
presentation.isActive && 'bg-primary/15 text-primary font-medium',
presentation.phase === 'failed' &&
'bg-destructive/15 text-destructive font-medium',
(presentation.phase === 'done' || presentation.phase === 'stopped') &&
'bg-secondary text-muted-foreground',
presentation.phase === 'idle' && 'bg-secondary/60 text-muted-foreground/60'
)}
>
{running
? '运行中'
: failed
? '失败'
: done
? '已完成'
: group.mode === 'parallel'
? '并行'
: '串行'}
{presentation.badgeText}
</Badge>
</div>

Expand All @@ -191,14 +187,8 @@ export function BatchTaskList({
<span>
{group.steps.length} 步 · {group.mode === 'parallel' ? '并行' : '串行'}
</span>
<span>
{running
? '运行中'
: failed
? (state?.steps?.find((s) => s.state === 'failed')?.message ?? '失败')
: state?.finishedAt
? `已完成 · ${formatFinished(state.finishedAt)}`
: '未运行'}
<span className={cn(presentation.phase === 'failed' && 'text-destructive')}>
{presentation.summaryText}
</span>
</div>

Expand All @@ -208,12 +198,12 @@ export function BatchTaskList({
variant="ghost"
size="icon-xs"
onClick={() => start.mutate(group.id, { onError: (e) => setError(e.message) })}
disabled={busy || running}
disabled={busy || presentation.phase === 'starting'}
aria-label={`执行 ${group.name}`}
title="执行任务"
title={presentation.isActive ? '重新执行任务' : '执行任务'}
className="size-6 text-muted-foreground hover:text-foreground"
>
{busy && !running ? (
{busy && presentation.phase === 'starting' ? (
<Loader2 className="size-3 animate-spin" />
) : (
<Play className="size-3" />
Expand All @@ -224,10 +214,15 @@ export function BatchTaskList({
variant="ghost"
size="icon-xs"
onClick={() => stop.mutate(group.id, { onError: (e) => setError(e.message) })}
disabled={busy}
disabled={busy || !presentation.isActive}
aria-label={`停止 ${group.name}`}
title="停止全部"
className="size-6 text-muted-foreground hover:text-foreground"
className={cn(
'size-6 transition-colors',
presentation.isActive
? 'text-destructive hover:bg-destructive/15 hover:text-destructive'
: 'text-muted-foreground/40 hover:text-muted-foreground'
)}
>
<Square className="size-3" />
</Button>
Expand Down Expand Up @@ -309,11 +304,3 @@ export function BatchTaskList({
</section>
)
}

function formatFinished(iso: string): string {
const date = new Date(iso)
const time = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
return date.toDateString() === new Date().toDateString()
? time
: `${date.getMonth() + 1}月${date.getDate()}日 ${time}`
}
57 changes: 24 additions & 33 deletions apps/desktop/src/renderer/src/features/groups/group-detail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { Pencil, Play, RotateCcw, Square } from 'lucide-react'
import { formatDuration, type Group, type GroupRunState, type Run } from '@devhub/shared'
import { activeGroups, formatDuration, type Group, type Run } from '@devhub/shared'
import { access } from '@renderer/api'
import { Badge } from '@renderer/components/ui/badge'
import { Button } from '@renderer/components/ui/button'
Expand All @@ -12,28 +12,25 @@ import { cn } from '@renderer/lib/utils'
import { GroupEditor } from './group-editor'
import { GroupOutputPanel } from './group-output-panel'
import { GroupProgressBar } from './group-progress-bar'
import { resolveGroupStatus } from './group-status'
import { GroupStepCard } from './group-step-card'
import { useGroupStates, useStartGroup, useStopGroup } from './use-groups'

const statusLabels: Record<GroupRunState['status'], string> = {
running: '执行中',
done: '已完成',
failed: '失败',
stopped: '已停止'
}

export function GroupDetail({
group,
onOpenRun
}: {
group: Group
onOpenRun: (run: Run) => void
}): React.JSX.Element {
const state = useGroupStates().data?.find((candidate) => candidate.groupId === group.id)
const allStates = useGroupStates().data ?? []
const state = allStates.find((candidate) => candidate.groupId === group.id)
const execution = state?.group ?? group
const projects = useProjects().data ?? []
const runs = useRuns().data ?? []
const health = useRunHealth().data ?? []
const active = activeGroups(allStates, runs).find((candidate) => candidate.groupId === group.id)
const presentation = resolveGroupStatus({ group, state, active })
const start = useStartGroup()
const stop = useStopGroup()
const [editing, setEditing] = useState(false)
Expand Down Expand Up @@ -74,7 +71,6 @@ export function GroupDetail({
)

const isParallel = execution.mode === 'parallel'
const currentStepNum = Math.min(completed + 1, execution.steps.length)

return (
<section
Expand All @@ -92,32 +88,29 @@ export function GroupDetail({
{/* Run status badge */}
<Badge
variant={
state?.status === 'failed'
presentation.phase === 'failed'
? 'destructive'
: state?.status === 'done' || running
: presentation.isActive
? 'default'
: 'secondary'
}
className={cn(
'h-5 gap-1.5 px-2 text-[10px]',
(state?.status === 'done' || running) &&
presentation.isActive &&
'border-transparent bg-accent/15 text-accent hover:bg-accent/20'
)}
>
<span
className={cn(
'size-1.5 rounded-full',
running && 'animate-pulse bg-accent',
state?.status === 'done' && 'bg-accent',
state?.status === 'failed' && 'bg-destructive',
!state && 'bg-muted-foreground'
presentation.dotState === 'starting' && 'animate-pulse bg-accent',
presentation.dotState === 'running' && 'bg-accent',
presentation.dotState === 'failed' && 'bg-destructive',
(presentation.dotState === 'done' || presentation.dotState === 'idle') &&
'bg-muted-foreground'
)}
/>
{running
? `第 ${currentStepNum} / ${execution.steps.length} 步 · 运行中`
: state
? statusLabels[state.status]
: '尚未执行'}
{presentation.detailBadgeText}
</Badge>
</div>

Expand Down Expand Up @@ -205,15 +198,7 @@ export function GroupDetail({
totalCount={execution.steps.length}
stepStates={stepStates}
durationText={groupDurationMs !== null ? formatDuration(groupDurationMs) : null}
statusHint={
running
? `正在执行第 ${currentStepNum} 步`
: state?.status === 'done'
? '全部步骤就绪'
: state?.status === 'failed'
? '执行中断'
: '待执行'
}
statusHint={presentation.progressHint}
/>

{/* Main body scrollable area */}
Expand All @@ -237,9 +222,15 @@ export function GroupDetail({
</p>
)}

{state?.status === 'done' && (
{presentation.phase === 'running' && (
<p className="rounded-md border border-accent/20 bg-accent/5 p-3 text-sm text-foreground">
步骤已完成,服务进程可能仍在运行。当前有 {activeRuns.length} 个活动脚本。
步骤已就绪,服务进程正在运行中。当前有 {activeRuns.length} 个活动脚本。
</p>
)}

{presentation.phase === 'done' && (
<p className="rounded-md border border-border/80 bg-muted/40 p-3 text-sm text-muted-foreground">
上次执行步骤已完成,相关服务均已停止。
</p>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function GroupEditor({
<DialogDescription>把多个项目的脚本组合在一起,一键启动或停止。</DialogDescription>
</DialogHeader>

<div className="flex min-h-0 flex-col gap-4 overflow-y-auto pr-1">
<div className="flex min-h-0 flex-col gap-4 overflow-y-auto px-1">
<div className="flex flex-col gap-1.5">
<Label htmlFor="group-name">名称</Label>
<Input
Expand Down
Loading