From d89e7f3e342b787de19b17b62f21a3338bd490a7 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 21 May 2026 16:24:14 -0700 Subject: [PATCH] Fix inline agent row hover dismissal (#2568) Co-authored-by: Orca --- .../dashboard/DashboardAgentRow.test.tsx | 144 ++++++++++++++++++ .../dashboard/DashboardAgentRow.tsx | 10 +- 2 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 src/renderer/src/components/dashboard/DashboardAgentRow.test.tsx diff --git a/src/renderer/src/components/dashboard/DashboardAgentRow.test.tsx b/src/renderer/src/components/dashboard/DashboardAgentRow.test.tsx new file mode 100644 index 000000000..33c55e96f --- /dev/null +++ b/src/renderer/src/components/dashboard/DashboardAgentRow.test.tsx @@ -0,0 +1,144 @@ +import { renderToStaticMarkup } from 'react-dom/server' +import { describe, expect, it, vi } from 'vitest' +import type { AgentStatusEntry } from '../../../../shared/agent-status-types' +import type { TerminalTab } from '../../../../shared/types' +import DashboardAgentRow from './DashboardAgentRow' +import type { DashboardAgentRow as DashboardAgentRowData } from './useDashboardData' + +const NOW = 120_000 + +function makeAgent( + overrides: Partial = {}, + entryOverrides: Partial = {} +): DashboardAgentRowData { + const paneKey = overrides.paneKey ?? 'tab-1:leaf-1' + const tab: TerminalTab = { + id: 'tab-1', + ptyId: null, + worktreeId: 'wt-1', + title: 'Terminal 1', + customTitle: null, + color: null, + sortOrder: 0, + createdAt: 1 + } + const entry: AgentStatusEntry = { + state: 'working', + prompt: 'Fix hover scope', + updatedAt: 60_000, + stateStartedAt: 60_000, + agentType: 'codex', + paneKey, + stateHistory: [], + ...entryOverrides + } + + return { + paneKey, + entry, + tab, + agentType: entry.agentType ?? 'codex', + state: entry.state, + startedAt: entry.stateStartedAt, + ...overrides + } +} + +function renderRow(agent: DashboardAgentRowData): string { + return renderToStaticMarkup( + + ) +} + +function classAttributes(markup: string): string[] { + return Array.from(markup.matchAll(/class="([^"]*)"/g), (match) => match[1]) +} + +function classTokens(markup: string): string[] { + return classAttributes(markup).flatMap((className) => className.split(/\s+/).filter(Boolean)) +} + +function hoverSwapClasses(markup: string): string[] { + return classAttributes(markup).filter( + (className) => + className.includes('group-hover') || className.includes('focus-visible:opacity-100') + ) +} + +function dismissButtonClass(markup: string): string { + const match = markup.match(/]*aria-label="Dismiss agent")[^>]*class="([^"]*)"/) + if (!match) { + throw new Error('Expected dismiss agent button in rendered markup') + } + return match[1] +} + +function dismissButtonClassTokens(markup: string): string[] { + return dismissButtonClass(markup).split(/\s+/).filter(Boolean) +} + +function tokenCount(markup: string, token: string): number { + return classTokens(markup).filter((classToken) => classToken === token).length +} + +describe('DashboardAgentRow', () => { + it('scopes the timestamp and dismiss hover swap to the row-owned group', () => { + const markup = renderRow(makeAgent()) + const classes = hoverSwapClasses(markup) + const tokens = classTokens(markup) + + expect(tokens).toContain('group/agent-row') + expect(tokens).toContain('group-hover/agent-row:opacity-0') + expect(dismissButtonClassTokens(markup)).toContain('group-hover/agent-row:opacity-100') + expect(dismissButtonClassTokens(markup)).toContain('focus-visible:opacity-100') + expect(classes.every((className) => !/\bgroup-hover:/.test(className))).toBe(true) + }) + + it('uses the row-owned group for the standalone dismiss control without timestamps', () => { + const markup = renderRow( + makeAgent({ startedAt: 0 }, { updatedAt: 0, stateStartedAt: 0, stateHistory: [] }) + ) + const classes = hoverSwapClasses(markup) + + expect(dismissButtonClassTokens(markup)).toContain('group-hover/agent-row:opacity-100') + expect(dismissButtonClassTokens(markup)).toContain('focus-visible:opacity-100') + expect(classes.every((className) => !/\bgroup-hover:/.test(className))).toBe(true) + }) + + it('keeps each row hover boundary inside an anonymous ancestor group', () => { + const markup = renderToStaticMarkup( +
+ + +
+ ) + const classes = hoverSwapClasses(markup) + + expect(markup).toContain('class="group"') + expect(tokenCount(markup, 'group/agent-row')).toBe(2) + expect(tokenCount(markup, 'group-hover/agent-row:opacity-100')).toBe(2) + expect(tokenCount(markup, 'group-hover/agent-row:opacity-0')).toBe(2) + expect(classes.every((className) => !/\bgroup-hover:/.test(className))).toBe(true) + }) +}) diff --git a/src/renderer/src/components/dashboard/DashboardAgentRow.tsx b/src/renderer/src/components/dashboard/DashboardAgentRow.tsx index 051a1c2c2..6b4573344 100644 --- a/src/renderer/src/components/dashboard/DashboardAgentRow.tsx +++ b/src/renderer/src/components/dashboard/DashboardAgentRow.tsx @@ -202,7 +202,9 @@ const DashboardAgentRow = React.memo(function DashboardAgentRow({
@@ -315,7 +317,7 @@ const DashboardAgentRow = React.memo(function DashboardAgentRow({ className={cn( '[grid-area:1/1] inline-flex items-center justify-center text-muted-foreground/70 hover:text-foreground', 'opacity-0 transition-opacity duration-150', - 'group-hover:opacity-100 focus-visible:opacity-100' + 'group-hover/agent-row:opacity-100 focus-visible:opacity-100' )} aria-label="Dismiss agent" title="Dismiss" @@ -338,7 +340,7 @@ const DashboardAgentRow = React.memo(function DashboardAgentRow({ className={cn( 'inline-flex shrink-0 items-center justify-center text-muted-foreground/70 hover:text-foreground', 'opacity-0 transition-opacity duration-150', - 'group-hover:opacity-100 focus-visible:opacity-100' + 'group-hover/agent-row:opacity-100 focus-visible:opacity-100' )} aria-label="Dismiss agent" title="Dismiss"