mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Description Part of the work for OAuth apps with the scoped permissions. This PR wires the org and users authorized apps lists to backend.
144 lines
5.0 KiB
TypeScript
144 lines
5.0 KiB
TypeScript
import { BoxesIcon, MoreVerticalIcon, XIcon } from 'lucide-react'
|
|
import { useRef, useState } from 'react'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogTrigger,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
TableCell,
|
|
TableRow,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
|
|
|
|
import { GrantDisconnectDialogContent } from './GrantDisconnectDialogContent'
|
|
import { GrantProjectsDialogContent } from './GrantProjectsDialogContent'
|
|
import { OAuthGrant } from '@/data/oauth-apps/oauth-apps-grants-query'
|
|
|
|
export interface OAuthAppsAuthorizedRowProps {
|
|
className?: string
|
|
grant: OAuthGrant
|
|
}
|
|
|
|
export const GrantRow = ({ className, grant }: OAuthAppsAuthorizedRowProps) => {
|
|
const [isDialogOpen, setIsDialogOpen] = useState(false)
|
|
const [dialogContent, setDialogContent] = useState<'projects' | 'disconnect' | null>(null)
|
|
const menuTriggerRef = useRef<HTMLButtonElement | null>(null)
|
|
return (
|
|
<TableRow className={className}>
|
|
<TableCell>
|
|
<div className="flex items-center gap-x-3">
|
|
<div
|
|
className="flex h-[30px] w-[30px] shrink-0 items-center justify-center rounded-full border border-control bg-cover bg-center bg-no-repeat text-xs"
|
|
style={{
|
|
backgroundImage: grant.attributes.app.icon
|
|
? `url('${grant.attributes.app.icon}')`
|
|
: 'none',
|
|
}}
|
|
>
|
|
{!!grant.attributes.app.icon ? '' : grant.attributes.app.name[0]}
|
|
</div>
|
|
<div className="flex flex-col">
|
|
<p className="min-w-0 truncate" title={grant.attributes.app.name}>
|
|
{grant.attributes.app.name}
|
|
</p>
|
|
<p className="min-w-0 text-foreground-lighter">
|
|
{grant.attributes.projects?.length ?? <span>All</span>}{' '}
|
|
{grant.attributes.projects?.length === 1 ? (
|
|
<span>project</span>
|
|
) : (
|
|
<span>projects</span>
|
|
)}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</TableCell>
|
|
<TableCell>{grant.attributes.organization.name}</TableCell>
|
|
<TableCell>
|
|
<TimestampInfo
|
|
utcTimestamp={grant.attributes.approved_at ?? ''}
|
|
labelFormat="DD MMM YYYY"
|
|
className="text-sm"
|
|
/>
|
|
</TableCell>
|
|
<TableCell className="text-right">
|
|
<Dialog
|
|
open={isDialogOpen}
|
|
onOpenChange={(open) => {
|
|
setIsDialogOpen(open)
|
|
// When users close the dialogs, we need to restore the focus on the menu button
|
|
// Done in a setTimeout because the dialog tries to restore focus on the trigger despite onCloseAutoFocus being cancelled in the dialog contents
|
|
setTimeout(() => {
|
|
if (!open && menuTriggerRef.current) {
|
|
menuTriggerRef.current.focus()
|
|
}
|
|
})
|
|
}}
|
|
>
|
|
<DropdownMenu>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
ref={menuTriggerRef}
|
|
icon={<MoreVerticalIcon />}
|
|
className="px-1"
|
|
aria-label="Manage app"
|
|
aria-describedby={undefined}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Manage app</TooltipContent>
|
|
</Tooltip>
|
|
<DropdownMenuContent align="end" side="bottom" className="w-40">
|
|
{grant.attributes.projects != null && grant.attributes.projects.length > 0 && (
|
|
<>
|
|
<DialogTrigger asChild>
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={() => setDialogContent('projects')}
|
|
>
|
|
<BoxesIcon size={14} />
|
|
View projects
|
|
</DropdownMenuItem>
|
|
</DialogTrigger>
|
|
<DropdownMenuSeparator />
|
|
</>
|
|
)}
|
|
<DialogTrigger asChild>
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={() => setDialogContent('disconnect')}
|
|
>
|
|
<XIcon size={14} />
|
|
Revoke access
|
|
</DropdownMenuItem>
|
|
</DialogTrigger>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
{dialogContent === 'projects' && (
|
|
<GrantProjectsDialogContent grant={grant} onCloseAutoFocus={preventDefault} />
|
|
)}
|
|
{dialogContent === 'disconnect' && (
|
|
<GrantDisconnectDialogContent
|
|
grant={grant}
|
|
onClose={() => setIsDialogOpen(false)}
|
|
onCloseAutoFocus={preventDefault}
|
|
/>
|
|
)}
|
|
</Dialog>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
}
|
|
|
|
const preventDefault = (event: Event) => {
|
|
event.preventDefault()
|
|
}
|