import { PermissionAction } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import { includes } from 'lodash' import { Edit3, MoreVertical, Trash } from 'lucide-react' import Image from 'next/legacy/image' import { parseAsString, useQueryState } from 'nuqs' import { Badge, Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from 'ui' import Table from '@/components/to-be-cleaned/Table' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { useDatabaseHooksQuery } from '@/data/database-triggers/database-triggers-query' import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { BASE_PATH } from '@/lib/constants' export interface HookListProps { schema: string filterString: string } export const HookList = ({ schema, filterString }: HookListProps) => { const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const { data: hooks } = useDatabaseHooksQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const [, setSelectedHookIdToEdit] = useQueryState('edit', parseAsString.withDefault('')) const [, setSelectedHookIdToDelete] = useQueryState('delete', parseAsString.withDefault('')) const restUrl = project?.restUrl const restUrlTld = restUrl ? new URL(restUrl).hostname.split('.').pop() : 'co' const filteredHooks = (hooks ?? []).filter( (x) => includes(x.name.toLowerCase(), filterString.toLowerCase()) && x.schema === schema && x.function_args.length >= 2 ) const { can: canUpdateWebhook } = useAsyncCheckPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, 'triggers' ) return ( <> {filteredHooks.map((x) => { const isEdgeFunction = (url: string) => url.includes(`https://${ref}.functions.briven.${restUrlTld}/`) || url.includes(`https://${ref}.briven.${restUrlTld}/functions/`) const [url, method] = x.function_args return (
{x.name}
{x.table}
{method}: {url}
Edit hook
Delete hook