fix(desktop): de-duplicate localhost url in output card (hide subtitle when == title)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-05-30 17:10:40 +08:00
parent 95d1ba997a
commit 78baace37e
2 changed files with 9 additions and 6 deletions

View File

@ -74,10 +74,10 @@ describe('AssistantOutputTargetCard', () => {
expect(screen.getByText('docs/readme.md')).toBeInTheDocument()
})
it('renders a localhost target title + Localhost badge', () => {
it('renders a localhost target title + Localhost badge (URL not duplicated)', () => {
render(<AssistantOutputTargetCard target={localhostTarget} sessionId="s1" />)
// Title + subtitle both fall back to href, so it appears twice.
expect(screen.getAllByText('http://localhost:5173/').length).toBeGreaterThan(0)
// subtitle equals the title for localhost, so the URL renders exactly once.
expect(screen.getAllByText('http://localhost:5173/')).toHaveLength(1)
expect(screen.getByText('assistantOutputs.kind.localhost')).toBeInTheDocument()
})

View File

@ -34,6 +34,7 @@ export function AssistantOutputTargetCard({ target, sessionId, workDir }: Props)
? t('assistantOutputs.kind.markdown')
: t('assistantOutputs.kind.image')
const subtitle = target.subtitle ?? target.normalizedPath ?? target.href
const showSubtitle = subtitle !== target.title
const handleOpen = useCallback((event: ReactMouseEvent<HTMLButtonElement>) => {
event.stopPropagation()
@ -99,9 +100,11 @@ export function AssistantOutputTargetCard({ target, sessionId, workDir }: Props)
{badge}
</span>
</div>
<div className="mt-1 truncate text-xs text-[var(--color-text-tertiary)]" title={subtitle}>
{subtitle}
</div>
{showSubtitle && (
<div className="mt-1 truncate text-xs text-[var(--color-text-tertiary)]" title={subtitle}>
{subtitle}
</div>
)}
</div>
<div className="flex shrink-0 items-center gap-1.5">