mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Part 4 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 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | 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 `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
251 lines
8.4 KiB
TypeScript
251 lines
8.4 KiB
TypeScript
import { Link, useNavigate } from '@tanstack/react-router'
|
|
import { ChevronLeftIcon, ChevronRightIcon, RefreshCwIcon, TerminalIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
Card,
|
|
CardFooter,
|
|
Input,
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import { COMPUTE_REGION_SHORT } from './Compute.constants'
|
|
import type {
|
|
ComputeInstance,
|
|
ComputeInstanceAccess,
|
|
ComputeInstanceBuildState,
|
|
} from './Compute.types'
|
|
import { filterComputeInstances, formatResources, getPage } from './Compute.utils'
|
|
import { ComputeInstanceStatePill } from './ComputeInstanceStatePill'
|
|
import { RuntimeBadge } from './RuntimeBadge'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { navigateToUrl } from '@/lib/navigation'
|
|
|
|
interface ComputeListProps {
|
|
projectRef: string
|
|
instances: ComputeInstance[]
|
|
onDeploy: () => void
|
|
onRefresh: () => void
|
|
isRefreshing: boolean
|
|
}
|
|
|
|
const STATE_FILTERS: { value: ComputeInstanceBuildState | 'all'; label: string }[] = [
|
|
{ value: 'all', label: 'All states' },
|
|
{ value: 'active', label: 'Active' },
|
|
{ value: 'building', label: 'Building' },
|
|
{ value: 'failed', label: 'Failed' },
|
|
]
|
|
|
|
const ACCESS_FILTERS: { value: ComputeInstanceAccess | 'all'; label: string }[] = [
|
|
{ value: 'all', label: 'All access' },
|
|
{ value: 'public', label: 'Public' },
|
|
{ value: 'private', label: 'Private' },
|
|
]
|
|
|
|
const PAGE_SIZE = 10
|
|
|
|
const parseStateFilter = (value: string): ComputeInstanceBuildState | 'all' =>
|
|
STATE_FILTERS.find((option) => option.value === value)?.value ?? 'all'
|
|
|
|
const parseAccessFilter = (value: string): ComputeInstanceAccess | 'all' =>
|
|
ACCESS_FILTERS.find((option) => option.value === value)?.value ?? 'all'
|
|
|
|
export const ComputeList = ({
|
|
projectRef,
|
|
instances,
|
|
onDeploy,
|
|
onRefresh,
|
|
isRefreshing,
|
|
}: ComputeListProps) => {
|
|
const navigate = useNavigate()
|
|
const [search, setSearch] = useState('')
|
|
const [stateFilter, setStateFilter] = useState<ComputeInstanceBuildState | 'all'>('all')
|
|
const [accessFilter, setAccessFilter] = useState<ComputeInstanceAccess | 'all'>('all')
|
|
const [page, setPage] = useState(1)
|
|
|
|
const filtered = filterComputeInstances(instances, {
|
|
search,
|
|
state: stateFilter,
|
|
access: accessFilter,
|
|
})
|
|
const { items: paged, currentPage, totalPages, startIndex } = getPage(filtered, page, PAGE_SIZE)
|
|
|
|
const resetToFirstPage = () => setPage(1)
|
|
|
|
const computeInstancePagePath = (name: string) => `/project/${projectRef}/compute/${name}`
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<div className="flex flex-col gap-3 md:flex-row md:items-center">
|
|
<Input
|
|
size="small"
|
|
className="w-full md:w-64"
|
|
placeholder="Search by name"
|
|
value={search}
|
|
onChange={(e) => {
|
|
setSearch(e.target.value)
|
|
resetToFirstPage()
|
|
}}
|
|
/>
|
|
<Select
|
|
value={stateFilter}
|
|
onValueChange={(value) => {
|
|
setStateFilter(parseStateFilter(value))
|
|
resetToFirstPage()
|
|
}}
|
|
>
|
|
<SelectTrigger size="small" className="w-full md:w-40">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{STATE_FILTERS.map((option) => (
|
|
<SelectItem key={option.value} value={option.value}>
|
|
{option.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
<Select
|
|
value={accessFilter}
|
|
onValueChange={(value) => {
|
|
setAccessFilter(parseAccessFilter(value))
|
|
resetToFirstPage()
|
|
}}
|
|
>
|
|
<SelectTrigger size="small" className="w-full md:w-40">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{ACCESS_FILTERS.map((option) => (
|
|
<SelectItem key={option.value} value={option.value}>
|
|
{option.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
|
|
<div className="flex items-center gap-3 md:ml-auto">
|
|
<Button icon={<RefreshCwIcon />} loading={isRefreshing} onClick={onRefresh}>
|
|
Refresh
|
|
</Button>
|
|
<Button variant="primary" icon={<TerminalIcon />} onClick={onDeploy}>
|
|
Deploy
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<Card>
|
|
<Table className="table-fixed">
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Name</TableHead>
|
|
<TableHead className="w-36">State</TableHead>
|
|
<TableHead className="w-40">Runtime</TableHead>
|
|
<TableHead className="w-28">Access</TableHead>
|
|
<TableHead className="hidden w-20 xl:table-cell">Region</TableHead>
|
|
<TableHead className="hidden w-48 lg:table-cell">Resources</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{filtered.length === 0 && (
|
|
<TableRow>
|
|
<TableCell colSpan={6} className="text-center text-foreground-lighter">
|
|
No instances match your filters
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
{paged.map((instance) => (
|
|
<TableRow
|
|
key={instance.name}
|
|
className="cursor-pointer"
|
|
onClick={() => void navigateToUrl(navigate, computeInstancePagePath(instance.name))}
|
|
>
|
|
<TableCell className="max-w-0 font-medium text-foreground">
|
|
<Link
|
|
to="/project/$ref/compute/$name"
|
|
params={{ ref: projectRef, name: instance.name }}
|
|
className="block truncate"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
{instance.name}
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell className="w-36">
|
|
<ComputeInstanceStatePill instance={instance} />
|
|
</TableCell>
|
|
<TableCell className="w-40 truncate">
|
|
<RuntimeBadge runtime={instance.runtime} />
|
|
</TableCell>
|
|
<TableCell className="w-28">
|
|
{instance.access === 'public' ? (
|
|
<Badge variant="success">Public</Badge>
|
|
) : (
|
|
<Badge>Private</Badge>
|
|
)}
|
|
</TableCell>
|
|
<TableCell className="hidden w-20 truncate text-foreground-light xl:table-cell">
|
|
{COMPUTE_REGION_SHORT}
|
|
</TableCell>
|
|
<TableCell className="hidden w-48 truncate text-foreground-light lg:table-cell">
|
|
{formatResources(instance)}
|
|
</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
|
|
{filtered.length > 0 && (
|
|
<CardFooter className="flex items-center justify-between border-t p-4">
|
|
<p className="text-sm text-foreground-muted">
|
|
Showing {startIndex + 1} to {startIndex + paged.length} of {filtered.length} instance
|
|
{filtered.length === 1 ? '' : <span>s</span>}
|
|
</p>
|
|
<div className="flex items-center gap-x-2" aria-label="Pagination">
|
|
<ButtonTooltip
|
|
icon={<ChevronLeftIcon />}
|
|
aria-label="Previous page"
|
|
size="tiny"
|
|
disabled={currentPage === 1}
|
|
onClick={() => setPage(currentPage - 1)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'top',
|
|
text: currentPage === 1 ? 'Already on the first page' : undefined,
|
|
},
|
|
}}
|
|
/>
|
|
<span className="text-sm text-foreground-light tabular-nums">
|
|
Page {currentPage} of {totalPages}
|
|
</span>
|
|
<ButtonTooltip
|
|
icon={<ChevronRightIcon />}
|
|
aria-label="Next page"
|
|
size="tiny"
|
|
disabled={currentPage >= totalPages}
|
|
onClick={() => setPage(currentPage + 1)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'top',
|
|
text: currentPage >= totalPages ? 'Already on the last page' : undefined,
|
|
},
|
|
}}
|
|
/>
|
|
</div>
|
|
</CardFooter>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
)
|
|
}
|