mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
133 lines
4.3 KiB
TypeScript
133 lines
4.3 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useFlag } from 'common'
|
|
import { ArrowUpRightIcon, ExternalLinkIcon, MoreVerticalIcon } from 'lucide-react'
|
|
import {
|
|
Button,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import { OAuthAppAvatar } from '@/components/interfaces/Organization/OAuthApps/OAuthAppAvatar'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import type { OAuthProjectDatabaseAccessData } from '@/data/oauth-apps/oauth-apps-project-database-access-query'
|
|
|
|
export function JitDbAccessApps({
|
|
apps,
|
|
organizationSlug,
|
|
isPending,
|
|
error,
|
|
canRead,
|
|
}: {
|
|
apps: OAuthProjectDatabaseAccessData
|
|
organizationSlug?: string
|
|
isPending: boolean
|
|
error: Error | null
|
|
canRead: boolean
|
|
}) {
|
|
const isScopedOAuthManageEnabled = useFlag('enableScopedOAuthManage')
|
|
|
|
if (isPending || (canRead && !error && apps.length === 0)) return null
|
|
|
|
return (
|
|
<CardContent className="p-0">
|
|
<CardHeader
|
|
className={cn(
|
|
'bg flex flex-row items-center justify-between gap-2',
|
|
canRead && error && 'border-b-0'
|
|
)}
|
|
>
|
|
<div className="flex flex-col gap-y-0.5 mb-0">
|
|
<CardTitle id="token-access-apps">OAuth apps</CardTitle>
|
|
<CardDescription>
|
|
OAuth apps authorized to use token access to this database.
|
|
</CardDescription>
|
|
</div>
|
|
{organizationSlug && (
|
|
<Button asChild iconRight={<ArrowUpRightIcon size={14} aria-hidden="true" />}>
|
|
<Link to="/org/$slug/apps" params={{ slug: organizationSlug }} search={{}}>
|
|
OAuth Apps
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</CardHeader>
|
|
{!canRead && (
|
|
<div className="px-6 pb-4">
|
|
<NoPermission resourceText="view authorized apps" />
|
|
</div>
|
|
)}
|
|
{canRead && error && (
|
|
<AlertError
|
|
subject="Failed to load authorized apps"
|
|
error={error}
|
|
className="rounded-none border-x-0 border-b-0"
|
|
/>
|
|
)}
|
|
{canRead && !isPending && !error && (
|
|
<Table aria-labelledby="token-access-apps">
|
|
<TableHeader className="[&>tr]:bg-background">
|
|
<TableRow>
|
|
<TableHead>App</TableHead>
|
|
<TableHead>Access level</TableHead>
|
|
<TableHead className="w-1">
|
|
<span className="sr-only">Actions</span>
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{apps.map((app) => (
|
|
<TableRow key={app.id}>
|
|
<TableCell>
|
|
<div className="flex items-center gap-2">
|
|
<OAuthAppAvatar name={app.name} icon={app.icon} />
|
|
{app.name}
|
|
</div>
|
|
</TableCell>
|
|
<TableCell>{app.access === 'write' ? 'Read and write' : 'Read only'}</TableCell>
|
|
<TableCell className="text-right">
|
|
{organizationSlug && isScopedOAuthManageEnabled && (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
icon={<MoreVerticalIcon />}
|
|
className="px-1"
|
|
aria-label={`Manage ${app.name}`}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" side="bottom" className="w-40">
|
|
<DropdownMenuItem asChild className="gap-x-2">
|
|
<Link
|
|
to="/org/$slug/apps"
|
|
params={{ slug: organizationSlug }}
|
|
search={{ access_app: app.id }}
|
|
>
|
|
<ExternalLinkIcon size={14} />
|
|
View access
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)}
|
|
</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
)}
|
|
</CardContent>
|
|
)
|
|
}
|