Files
supabase/apps/studio/components/interfaces/ProjectHome/IssuesSection.tsx
Alaister YoungandAlaister Young 680633ee4f [FE-5108] (part 5) refactor(studio): migrate remaining interfaces off next/link (#54308)
Part 5 of a 6-PR stack migrating all `next/link` imports in
`apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known
external URLs) and removing `compat/next/link.tsx`.

| Part | PR | Scope |
| --- | --- | --- |
| 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and
`components/ui/**` |
| 2 | #54305 | `components/layouts/**` and top-level shell components |
| 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor,
BranchManagement, Branching, Functions, Realtime |
| 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues,
Linter, Reports, QueryPerformance, QuerySources, ConfigDrift,
DiskManagement, Compute |
| **5** | **#54308 ← this PR** | **Remaining `components/interfaces/**`
(Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.)** |
| 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and
update basePath tests/docs |

Migrates the remaining `components/interfaces/**` directories off
`next/link`, leaving zero `next/link` component imports in
`apps/studio`.

**Changed:**

- Replaced `next/link` across all 73 remaining interface files
(`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`,
`ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`,
`ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`,
`Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`)
- Converted the sole remaining `UrlObject` link (`<Link href={{
pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link
to="/sign-in-sso" search={query}>`
- Migrated `SupportLink.tsx` onto `DynamicLink`
(`createSupportFormUrl(...)`)
- Standardized external `target="_blank"` anchors with `rel="noreferrer
noopener"`, switched `OverviewMetrics.tsx` observability link to typed
`<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink`
/ `InlineLinkClassName` on inline paragraph links per review feedback

Addresses
[FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link)

## To test

- [ ] Check Organization (billing, usage, team, documents, AWS
Marketplace), Auth (providers, templates, rate limits, users, OAuth
apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO
links
- [ ] Verify `SignInWithSSOButton` preserves query params when
navigating to `/sign-in-sso`
- [ ] Verify `SupportLink` pre-populates support form query parameters
cleanly

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 17:33:03 +08:00

187 lines
6.0 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useFlag, useParams } from 'common'
import { CheckCircle2Icon } from 'lucide-react'
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 to="/project/$ref/issues" params={{ ref: projectRef ?? '_' }}>
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>
)