Files
supabase/apps/studio/components/interfaces/Issues/IssuesOverview.tsx
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

131 lines
4.8 KiB
TypeScript

import { useFlag, useParams } from 'common'
import { ChevronRightIcon } from 'lucide-react'
import Link from 'next/link'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import {
CATEGORY_ICONS,
CATEGORY_LABELS,
ISSUE_CATEGORIES,
ISSUE_SEVERITIES,
SEVERITY_LABELS,
} from './Issues.constants'
import { IssuesLegacyRedirect } from './IssuesLegacyRedirect'
import { SeverityIndicator } from './SeverityIndicator'
import { AlertError } from '@/components/ui/AlertError'
import { DocsButton } from '@/components/ui/DocsButton'
import type { IssueSeverity } from '@/data/issues/issue.types'
import { useProjectIssues } from '@/data/issues/useProjectIssues'
import { DOCS_URL } from '@/lib/constants'
const countBy = <T extends string>(values: T[]) =>
values.reduce<Record<string, number>>((counts, value) => {
counts[value] = (counts[value] ?? 0) + 1
return counts
}, {})
export const IssuesOverview = () => {
const { ref } = useParams()
const isHealthAdvisorEnabled = useFlag('healthAdvisor')
const { issues, error, isLoading, isError, isSuccess } = useProjectIssues({ projectRef: ref })
const severityCounts = countBy(issues.map((issue) => issue.severity))
const categoryCounts = countBy(issues.map((issue) => issue.category))
const categories = ISSUE_CATEGORIES.filter(
(category) => category !== 'health' || isHealthAdvisorEnabled
)
return (
<div className="h-full overflow-y-auto bg-card">
<IssuesLegacyRedirect />
<div className="mx-auto flex w-full max-w-3xl flex-col gap-10 px-6 pb-16 pt-10">
<header className="flex items-start justify-between gap-4">
<div className="flex flex-col gap-1">
<h1 className="text-2xl text-foreground">Issues</h1>
<p className="text-sm text-foreground-light">
Problems found in this project by Supabase checks
</p>
</div>
<DocsButton href={`${DOCS_URL}/guides/observability/advisors`} />
</header>
{isLoading && <GenericSkeletonLoader />}
{isError && <AlertError error={error} subject="Failed to retrieve issues" />}
{isSuccess && (
<>
<section
aria-label="Open issues by severity"
className="grid grid-cols-2 gap-3 sm:grid-cols-4"
>
<StatCard label="Open" value={issues.length} href={`/project/${ref}/issues`} />
{ISSUE_SEVERITIES.map((severity) => (
<StatCard
key={severity}
label={SEVERITY_LABELS[severity]}
value={severityCounts[severity] ?? 0}
severity={severity}
href={`/project/${ref}/issues?severity=${severity}`}
/>
))}
</section>
<section aria-labelledby="issues-by-category" className="flex flex-col gap-3">
<h2 id="issues-by-category" className="text-sm text-foreground">
Open by category
</h2>
<ul className="flex flex-col divide-y rounded-md border">
{categories.map((category) => {
const Icon = CATEGORY_ICONS[category]
const firstIssue = issues.find((issue) => issue.category === category)
const href = firstIssue
? `/project/${ref}/issues/${firstIssue.id}?category=${category}`
: `/project/${ref}/issues?category=${category}`
return (
<li key={category}>
<Link
href={href}
className="flex items-center gap-3 px-4 py-2.5 text-sm text-foreground-light hover:bg-muted hover:text-foreground"
>
<Icon size={14} className="shrink-0 text-foreground-lighter" />
<span className="flex-1">{CATEGORY_LABELS[category]}</span>
<span className="tabular-nums text-foreground-lighter">
{categoryCounts[category] ?? 0}
</span>
<ChevronRightIcon size={14} className="shrink-0 text-foreground-muted" />
</Link>
</li>
)
})}
</ul>
</section>
</>
)}
</div>
</div>
)
}
const StatCard = ({
label,
value,
href,
severity,
}: {
label: string
value: number
href: string
severity?: IssueSeverity
}) => (
<Link
href={href}
className="flex flex-col gap-1 rounded-md border bg-card px-4 py-3 hover:border-strong"
>
<span className="flex items-center gap-1.5 text-xs text-foreground-lighter">
{severity && <SeverityIndicator severity={severity} aria-hidden />}
{label}
</span>
<span className="text-2xl tabular-nums text-foreground">{value}</span>
</Link>
)