Files
Saxon FletcherandClaude Opus 5.5 4b39a529f0 chore(studio): show issue severity as bars (#53582)
<img width="1305" height="861"
alt="file-4841beec98e7fc8c1c9774747afc79a8"
src="https://github.com/user-attachments/assets/5455f835-79d7-4e5f-9e12-b0203019084d"
/>

Replaces the colored severity dots on Issues with three ascending bars,
filled up to the severity in its color:

- Critical: three red bars
- Warning: two yellow bars
- Info: one gray bar

Empty bars are neutral gray. The new `SeverityIndicator` component is
used everywhere the dot was: the Issues sidebar list, the issue detail
header, the overview stat cards, and the Issues card on Project Home.

## How to test

1. Open a project with open issues and go to **Issues**.
2. Check the sidebar list: each row shows bars matching its severity,
and the second line stays aligned with the title.
3. Check the overview stat cards: Critical, Warning, and Info each show
their bars next to the label.
4. Open an issue and check the bars next to the severity in the header.
5. Go to **Project Home** and check the Issues card.
6. Repeat in light and dark themes.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 16:03:29 +10:00

185 lines
6.0 KiB
TypeScript

import { useFlag, useParams } from 'common'
import { CheckCircle2Icon } from 'lucide-react'
import Link from 'next/link'
import {
AiIconAnimation,
Badge,
Button,
Card,
CardContent,
Tooltip,
TooltipContent,
TooltipTrigger,
} from 'ui'
import { Row } from 'ui-patterns/Row'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { HomeCard } from './HomeCard'
import {
CATEGORY_ICONS,
CATEGORY_LABELS,
SEVERITY_LABELS,
} from '@/components/interfaces/Issues/Issues.constants'
import {
buildIssuePrompt,
getIssueTelemetryProperties,
summarizeAffected,
} from '@/components/interfaces/Issues/Issues.utils'
import { SeverityIndicator } from '@/components/interfaces/Issues/SeverityIndicator'
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { AlertError } from '@/components/ui/AlertError'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import CopyButton from '@/components/ui/CopyButton'
import type { Issue } from '@/data/issues/issue.types'
import { useProjectIssues } from '@/data/issues/useProjectIssues'
import { useTrack } from '@/lib/telemetry/track'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
const MAX_HOMEPAGE_ISSUES = 4
export const IssuesSection = ({ showEmptyState = false }: { showEmptyState?: boolean }) => {
const { ref: projectRef } = useParams()
const isHealthAdvisorInHomepageEnabled = useFlag('healthAdvisorInHomepage')
const { issues, error, isError, isSuccess, refetch } = useProjectIssues({
projectRef,
enabled: !showEmptyState,
includeHealth: isHealthAdvisorInHomepageEnabled,
})
return (
<section aria-labelledby="home-issues-heading">
<div className="mb-6 flex items-center justify-between gap-4">
<div className="flex items-center gap-2">
<h2 id="home-issues-heading">Issues</h2>
{!showEmptyState && isSuccess && <Badge>{issues.length.toLocaleString()} open</Badge>}
</div>
{!showEmptyState && (
<Button asChild variant="default">
<Link href={`/project/${projectRef}/issues`}>View all issues</Link>
</Button>
)}
</div>
{showEmptyState ? (
<EmptyState />
) : (
<>
{!isSuccess && !isError && <GenericSkeletonLoader />}
{isError && (
<AlertError
error={error}
subject="Failed to retrieve issues"
projectRef={projectRef}
additionalActions={
<Button variant="default" onClick={() => refetch()}>
Retry
</Button>
}
/>
)}
{isSuccess && issues.length === 0 && <EmptyState />}
{issues.length > 0 && (
<Row maxColumns={4} minWidth={280}>
{issues.slice(0, MAX_HOMEPAGE_ISSUES).map((issue) => (
<IssueCard
key={issue.id}
issue={issue}
issuesCount={issues.length}
projectRef={projectRef ?? ''}
/>
))}
</Row>
)}
</>
)}
</section>
)
}
const IssueCard = ({
issue,
issuesCount,
projectRef,
}: {
issue: Issue
issuesCount: number
projectRef: string
}) => {
const track = useTrack()
const snap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
const CategoryIcon = CATEGORY_ICONS[issue.category]
const affectedSummary = summarizeAffected(issue.affected)
const handleOpenIssue = () => {
track('advisor_detail_opened', {
origin: 'homepage',
advisorSource: issue.source,
...getIssueTelemetryProperties(issue),
})
}
const handleAskAssistant = () => {
track('advisor_assistant_button_clicked', {
origin: 'homepage',
issuesCount,
...getIssueTelemetryProperties(issue),
})
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
snap.newChat({ name: issue.title, initialMessage: buildIssuePrompt(issue) })
}
return (
<HomeCard
href={`/project/${projectRef}/issues/${issue.id}`}
onClick={handleOpenIssue}
icon={<CategoryIcon size={16} strokeWidth={1.5} className="text-foreground-light" />}
label={CATEGORY_LABELS[issue.category]}
title={issue.title}
meta={
<span className="flex flex-wrap items-center gap-x-2 gap-y-1">
<span className="inline-flex items-center gap-1.5">
<SeverityIndicator severity={issue.severity} aria-hidden />
{SEVERITY_LABELS[issue.severity]}
</span>
{affectedSummary && <span className="truncate">· {affectedSummary}</span>}
</span>
}
actions={
<>
<ButtonTooltip
variant="text"
className="size-7 px-0"
icon={<AiIconAnimation size={16} />}
aria-label={`Ask Assistant about ${issue.title}`}
tooltip={{ content: { text: 'Ask Assistant' } }}
onClick={handleAskAssistant}
/>
<Tooltip>
<TooltipTrigger asChild>
<CopyButton
iconOnly
variant="text"
className="size-7 px-0"
aria-label={`Copy ${issue.title} for your agent`}
asyncText={() => buildIssuePrompt(issue)}
onClick={() => track('ai_prompt_copied', { source: 'advisor_section' })}
/>
</TooltipTrigger>
<TooltipContent>Copy issue for your agent</TooltipContent>
</Tooltip>
</>
}
/>
)
}
const EmptyState = () => (
<Card className="h-64 bg-transparent">
<CardContent className="flex h-full flex-col items-center justify-center gap-2 p-8">
<CheckCircle2Icon size={20} strokeWidth={1.5} className="text-foreground-muted" />
<p className="text-center text-sm text-foreground-light">No open issues</p>
</CardContent>
</Card>
)