The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update webhooks list UI
Joshen Lim2984279307fa
diff --git a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsxindex c8a0fe78e38..0f01072083c 100644--- a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx+++ b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx@@ -316,11 +316,11 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =className="lg:!col-span-4"description={<p className="text-sm text-scale-1000">- Select which table and events will trigger your function hook+ Select which table and events will trigger your webhook</p>}>- Conditions to fire hook+ Conditions to fire webhook</FormSectionLabel>}>@@ -378,7 +378,7 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =<FormSectionheader={<FormSectionLabel className="lg:!col-span-4">- Hook configuration+ Webhook configuration</FormSectionLabel>}>@@ -386,7 +386,7 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =<Radio.Groupid="function_type"name="function_type"- label="Type of hook"+ label="Type of webhook"type="cards">{AVAILABLE_WEBHOOK_TYPES.map((webhook) => (diff --git a/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx b/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsxindex 62b75c07cf0..46bed2316b5 100644--- a/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx+++ b/studio/components/interfaces/Database/Hooks/HooksList/HookList.tsx@@ -1,3 +1,4 @@+import Image from 'next/image'import { FC } from 'react'import { includes } from 'lodash'import { observer } from 'mobx-react-lite'@@ -5,7 +6,8 @@ import * as Tooltip from '@radix-ui/react-tooltip'import { PermissionAction } from '@supabase/shared-types/out/constants'import { Badge, Button, Dropdown, IconMoreVertical, IconTrash, IconEdit3 } from 'ui'-import { checkPermissions } from 'hooks'+import { checkPermissions, useParams, useStore } from 'hooks'+import { BASE_PATH } from 'lib/constants'import Table from 'components/to-be-cleaned/Table'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { useDatabaseHooks } from 'data/database-triggers/database-triggers-query'@@ -23,92 +25,106 @@ const HookList: FC<Props> = ({editHook = () => {},deleteHook = () => {},}) => {+ const { ui } = useStore()+ const { ref } = useParams()const { project } = useProjectContext()const { data: hooks } = useDatabaseHooks({projectRef: project?.ref,connectionString: project?.connectionString,})+ const restUrl = ui.selectedProject?.restUrl+ const restUrlTld = new URL(restUrl as string).hostname.split('.').pop()+const filteredHooks = (hooks ?? []).filter((x: any) => includes(x.name.toLowerCase(), filterString.toLowerCase()) && x.schema === schema)const canUpdateWebhook = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'triggers')- function onEdit(trigger: any) {- editHook(trigger)- }-- function onDelete(trigger: any) {- deleteHook(trigger)- }-return (<>- {filteredHooks.map((x: any) => (- <Table.tr key={x.id}>- <Table.td className="space-x-2">- <p>{x.name}</p>- </Table.td>- <Table.td className="hidden space-x-2 lg:table-cell">- <p>{x.table}</p>- </Table.td>- <Table.td className="hidden xl:table-cell">- <p>+ {filteredHooks.map((x: any) => {+ const isEdgeFunction = (url: string) =>+ url.includes(`https://${ref}.functions.supabase.${restUrlTld}/`)+ const [url, method] = x.function_args++ return (+ <Table.tr key={x.id}>+ <Table.td>+ <div className="flex items-center space-x-4">+ <Image+ src={+ isEdgeFunction(url)+ ? `${BASE_PATH}/img/function-providers/supabase-severless-function.png`+ : `${BASE_PATH}/img/function-providers/http-request.png`+ }+ layout="fixed"+ width="20"+ height="20"+ title={isEdgeFunction(url) ? 'Supabase Edge Function' : 'HTTP Request'}+ />+ <p title={x.name}>{x.name}</p>+ </div>+ </Table.td>+ <Table.td className="hidden space-x-2 lg:table-cell">+ <p title={x.table}>{x.table}</p>+ </Table.td>+ <Table.td className="hidden space-x-1 xl:table-cell">{x.events.map((event: string) => (<Badge key={event}>{event}</Badge>))}- </p>- </Table.td>- <Table.td className="hidden xl:table-cell">- <p>- <Badge>{x.function_args[0]}</Badge>- </p>- </Table.td>- <Table.td className="text-right">- <div className="flex justify-end gap-4">- {canUpdateWebhook ? (- <Dropdown- side="left"- overlay={- <>- <Dropdown.Item icon={<IconEdit3 size="tiny" />} onClick={() => onEdit(x)}>- Edit hook- </Dropdown.Item>- <Dropdown.Item- icon={<IconTrash stroke="red" size="tiny" />}- onClick={() => onDelete(x)}+ </Table.td>+ <Table.td className="hidden xl:table-cell">+ <p className="truncate" title={url}>+ <code className="font-mono text-xs">{method}</code>: {url}+ </p>+ </Table.td>+ <Table.td className="text-right">+ <div className="flex justify-end gap-4">+ {canUpdateWebhook ? (+ <Dropdown+ side="left"+ overlay={+ <>+ <Dropdown.Item icon={<IconEdit3 size="tiny" />} onClick={() => editHook(x)}>+ Edit hook+ </Dropdown.Item>+ <Dropdown.Item+ icon={<IconTrash stroke="red" size="tiny" />}+ onClick={() => deleteHook(x)}+ >+ Delete hook+ </Dropdown.Item>+ </>+ }+ >+ <Button as="span" type="default" icon={<IconMoreVertical />} className="px-1" />+ </Dropdown>+ ) : (+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <Button as="span" disabled type="default" icon={<IconMoreVertical />} />+ </Tooltip.Trigger>+ <Tooltip.Content side="left">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}>- Delete hook- </Dropdown.Item>- </>- }- >- <Button as="span" type="default" icon={<IconMoreVertical />} />- </Dropdown>- ) : (- <Tooltip.Root delayDuration={0}>- <Tooltip.Trigger>- <Button as="span" disabled type="default" icon={<IconMoreVertical />} />- </Tooltip.Trigger>- <Tooltip.Content side="left">- <Tooltip.Arrow className="radix-tooltip-arrow" />- <div- className={[- 'rounded bg-scale-100 py-1 px-2 leading-none shadow',- 'border border-scale-200',- ].join(' ')}- >- <span className="text-xs text-scale-1200">- You need additional permissions to update webhooks- </span>- </div>- </Tooltip.Content>- </Tooltip.Root>- )}- </div>- </Table.td>- </Table.tr>- ))}+ <span className="text-xs text-scale-1200">+ You need additional permissions to update webhooks+ </span>+ </div>+ </Tooltip.Content>+ </Tooltip.Root>+ )}+ </div>+ </Table.td>+ </Table.tr>+ )+ })}</>)}diff --git a/studio/components/interfaces/Database/Hooks/HooksList/SchemaTable.tsx b/studio/components/interfaces/Database/Hooks/HooksList/SchemaTable.tsxindex ff2b229556d..7175735cc79 100644--- a/studio/components/interfaces/Database/Hooks/HooksList/SchemaTable.tsx+++ b/studio/components/interfaces/Database/Hooks/HooksList/SchemaTable.tsx@@ -29,19 +29,19 @@ const SchemaTable: FC<Props> = ({className="table-fixed"head={<>- <Table.th key="name" className="space-x-4">- Name+ <Table.th key="name" className="w-[20%]">+ <p className="translate-x-[36px]">Name</p></Table.th>- <Table.th key="table" className="hidden lg:table-cell">+ <Table.th key="table" className="w-[15%] hidden lg:table-cell">Table</Table.th>- <Table.th key="events" className="hidden xl:table-cell">+ <Table.th key="events" className="w-[24%] hidden xl:table-cell">Events</Table.th><Table.th key="webhook" className="hidden xl:table-cell">Webhook</Table.th>- <Table.th key="buttons" className="w-1/6"></Table.th>+ <Table.th key="buttons" className="w-[5%]"></Table.th></>}body={