mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 3 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 ← this PR** | **Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime** | | 4 | #54307 | 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/{Database,TableGridEditor,Storage,SQLEditor,BranchManagement,Branching,Functions,Realtime}/` off `next/link`. **Changed:** - Replaced `next/link` across all 60 importing files in Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, and Realtime interfaces - Updated legacy permanent-redirect hrefs (`/reports` → `/observability`, `/database/schema` → `/database/schemas`) to their canonical TanStack routes - Dropped legacy `passHref` in `GridHeaderActions.tsx`, removed duplicate `RouterLink` alias in `ChooseFunctionForm.tsx`, and removed `vi.mock('next/link', ...)` in `ReplicationPipelineLayout.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Check Table Editor, SQL Editor, Database (tables, policies, functions, triggers, replication, backups), Storage (files/analytics/vector buckets), Edge Functions, Branching, and Realtime links - [ ] Verify SQL Editor and Table Editor links with query parameters (`schema`, `content`, `search`) do not double-encode values --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
222 lines
7.7 KiB
TypeScript
222 lines
7.7 KiB
TypeScript
import { BookIcon, Loader2Icon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { extensions } from 'shared-data'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
GithubIcon,
|
|
Switch,
|
|
TableCell,
|
|
TableRow,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
import { EnableExtensionModal } from './EnableExtensionModal'
|
|
import { EXTENSION_DISABLE_WARNINGS } from './Extensions.constants'
|
|
import { DynamicLink } from '@/components/ui/DynamicLink'
|
|
import { useDatabaseExtensionDisableMutation } from '@/data/database-extensions/database-extension-disable-mutation'
|
|
import { DatabaseExtension } from '@/data/database-extensions/database-extensions-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useIsOrioleDb, useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
interface ExtensionRowProps {
|
|
extension: DatabaseExtension
|
|
}
|
|
|
|
export const ExtensionRow = ({ extension }: ExtensionRowProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isOn = extension.installed_version !== null
|
|
const isOrioleDb = useIsOrioleDb()
|
|
|
|
const [isDisableModalOpen, setIsDisableModalOpen] = useState(false)
|
|
const [showConfirmEnableModal, setShowConfirmEnableModal] = useState(false)
|
|
|
|
const { can: canUpdateExtensions } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.DATABASE_WRITE
|
|
)
|
|
const orioleDbCheck = isOrioleDb && extension.name === 'orioledb'
|
|
const disabled = !canUpdateExtensions || orioleDbCheck
|
|
|
|
const extensionMeta = extensions.find((item) => item.name === extension.name)
|
|
const docsUrl = extensionMeta?.link.startsWith('/guides')
|
|
? `${DOCS_URL}${extensionMeta?.link}`
|
|
: (extensionMeta?.link ?? undefined)
|
|
|
|
const { mutate: disableExtension, isPending: isDisabling } = useDatabaseExtensionDisableMutation({
|
|
onSuccess: () => {
|
|
toast.success(`${extension.name} is off.`)
|
|
setIsDisableModalOpen(false)
|
|
},
|
|
})
|
|
|
|
const onConfirmDisable = () => {
|
|
if (project === undefined) return console.error('Project is required')
|
|
|
|
disableExtension({
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
id: extension.name,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<TableRow>
|
|
<TableCell>
|
|
<div className="flex items-center gap-x-2">
|
|
<span title={extension.name} className="truncate inline-block max-w-48">
|
|
{extension.name}
|
|
</span>
|
|
{extensionMeta?.deprecated && extensionMeta?.deprecated.length > 0 && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Badge variant="warning" className="cursor-default" tabIndex={0}>
|
|
Deprecated
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">
|
|
The extension is deprecated and will be removed in{' '}
|
|
{extensionMeta.deprecated.join(', ')}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
|
|
<TableCell className="w-28 font-mono tracking-tighter">
|
|
{extension?.installed_version ?? extension.default_version}
|
|
</TableCell>
|
|
|
|
<TableCell className="truncate">{isOn ? extension.schema : '-'}</TableCell>
|
|
|
|
<TableCell className="text-foreground-light">
|
|
<p className="block" title={extension.comment ?? undefined}>
|
|
{extension.comment}
|
|
</p>
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{extensionMeta?.product ? (
|
|
<div className="flex flex-col gap-1">
|
|
{extensionMeta.product_url ? (
|
|
<DynamicLink
|
|
href={extensionMeta.product_url.replace('{ref}', project?.ref ?? '')}
|
|
className="transition hover:text-foreground"
|
|
>
|
|
{extensionMeta.product}
|
|
</DynamicLink>
|
|
) : (
|
|
<span>{extensionMeta.product}</span>
|
|
)}
|
|
{!isOn && (
|
|
<span className="text-foreground-lighter text-xs">
|
|
Install extension to use {extensionMeta.product}
|
|
</span>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<span className="text-foreground-lighter">-</span>
|
|
)}
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
<div className="flex gap-2 items-center">
|
|
{extensionMeta?.github_url && (
|
|
<Button asChild icon={<GithubIcon />} className="rounded-full">
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
href={extensionMeta.github_url}
|
|
className="font-mono tracking-tighter"
|
|
>
|
|
{extensionMeta.github_url.split('/').slice(-2).join('/')}
|
|
</a>
|
|
</Button>
|
|
)}
|
|
{docsUrl !== undefined && (
|
|
<Button asChild icon={<BookIcon />} className="rounded-full">
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="font-mono tracking-tighter"
|
|
href={docsUrl}
|
|
>
|
|
Docs
|
|
</a>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
|
|
{/*
|
|
Left border on the absolute child makes the sticky column more distinct.
|
|
Sticky positioning/background come from ShadowScrollArea's stickyLastColumn.
|
|
*/}
|
|
<TableCell className="w-20 relative">
|
|
<div className="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center border-l">
|
|
{isDisabling ? (
|
|
<Loader2Icon className="animate-spin" size={16} />
|
|
) : (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div>
|
|
<Switch
|
|
aria-label="Toggle extension"
|
|
disabled={disabled}
|
|
checked={isOn}
|
|
onCheckedChange={() =>
|
|
isOn ? setIsDisableModalOpen(true) : setShowConfirmEnableModal(true)
|
|
}
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
{disabled && (
|
|
<TooltipContent side="bottom">
|
|
{!canUpdateExtensions
|
|
? 'You need additional permissions to toggle extensions'
|
|
: orioleDbCheck
|
|
? 'Project is using OrioleDB and cannot be disabled'
|
|
: null}
|
|
</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
|
|
<EnableExtensionModal
|
|
visible={showConfirmEnableModal}
|
|
extension={extension}
|
|
onCancel={() => setShowConfirmEnableModal(false)}
|
|
/>
|
|
|
|
<ConfirmationModal
|
|
visible={isDisableModalOpen}
|
|
title="Confirm to disable extension"
|
|
confirmLabel="Disable"
|
|
variant="destructive"
|
|
confirmLabelLoading="Disabling"
|
|
loading={isDisabling}
|
|
onCancel={() => setIsDisableModalOpen(false)}
|
|
onConfirm={() => onConfirmDisable()}
|
|
>
|
|
<div className="flex flex-col gap-y-3">
|
|
<p className="text-sm text-foreground-light">
|
|
Are you sure you want to turn OFF the "{extension.name}" extension?
|
|
</p>
|
|
{EXTENSION_DISABLE_WARNINGS[extension.name] && (
|
|
<Admonition type="warning">{EXTENSION_DISABLE_WARNINGS[extension.name]}</Admonition>
|
|
)}
|
|
</div>
|
|
</ConfirmationModal>
|
|
</>
|
|
)
|
|
}
|