Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Allow users to set timeout value for webhooks when edge function selected

Joshen Lim918618737ad6
diff --git a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
index bae48fe938a..830bd41c110 100644
--- a/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
+++ b/studio/components/interfaces/Database/Hooks/EditHookPanel.tsx
@@ -96,6 +96,7 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =
function_type: isEdgeFunction(selectedHook?.function_args?.[0] ?? '')
? 'supabase_function'
: 'http_request',
+ timeout_ms: Number(selectedHook?.function_args?.[4] ?? 1000),
}
useEffect(() => {
@@ -168,6 +169,10 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =
}
}
+ if (values.timeout_ms < 1000 || values.timeout_ms > 5000) {
+ errors['timeout_ms'] = 'Timeout should be between 1000ms and 5000ms'
+ }
+
if (JSON.stringify(values) !== JSON.stringify(initialValues)) setIsEdited(true)
return errors
}
@@ -185,7 +190,6 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =
return ui.setNotification({ category: 'error', message: 'Unable to find selected table' })
}
- const serviceTimeoutMs = '1000'
const headers = httpHeaders
.filter((header) => header.name && header.value)
.reduce((a: any, b: any) => {
@@ -215,7 +219,7 @@ const EditHookPanel = ({ visible, selectedHook, onClose }: EditHookPanelProps) =
values.http_method,
JSON.stringify(headers),
JSON.stringify(parameters),
- serviceTimeoutMs,
+ values.timeout_ms.toString(),
],
}
diff --git a/studio/components/interfaces/Database/Hooks/HTTPRequestFields.tsx b/studio/components/interfaces/Database/Hooks/HTTPRequestFields.tsx
index cc4cf1919cc..b1c2e16ba4d 100644
--- a/studio/components/interfaces/Database/Hooks/HTTPRequestFields.tsx
+++ b/studio/components/interfaces/Database/Hooks/HTTPRequestFields.tsx
@@ -99,19 +99,34 @@ const HTTPRequestFields = ({
{errors.http_url && <p className="text-sm text-red-900">{errors.http_url}</p>}
</div>
) : type === 'supabase_function' && edgeFunctions.length > 0 ? (
- <Listbox id="http_url" name="http_url" label="Select which edge function to trigger">
- {edgeFunctions.map((fn) => {
- const restUrl = selectedProject?.restUrl
- const restUrlTld = new URL(restUrl as string).hostname.split('.').pop()
- const functionUrl = `https://${ref}.functions.supabase.${restUrlTld}/${fn.slug}`
+ <>
+ <Listbox id="http_url" name="http_url" label="Select which edge function to trigger">
+ {edgeFunctions.map((fn) => {
+ const restUrl = selectedProject?.restUrl
+ const restUrlTld = new URL(restUrl as string).hostname.split('.').pop()
+ const functionUrl = `https://${ref}.functions.supabase.${restUrlTld}/${fn.slug}`
- return (
- <Listbox.Option key={fn.id} id={functionUrl} value={functionUrl} label={fn.name}>
- {fn.name}
- </Listbox.Option>
- )
- })}
- </Listbox>
+ return (
+ <Listbox.Option
+ key={fn.id}
+ id={functionUrl}
+ value={functionUrl}
+ label={fn.name}
+ >
+ {fn.name}
+ </Listbox.Option>
+ )
+ })}
+ </Listbox>
+ <Input
+ id="timeout_ms"
+ name="timeout_ms"
+ label="Timeout"
+ labelOptional="Between 1000ms to 5000ms"
+ type="number"
+ actions={<p className="text-light pr-2">ms</p>}
+ />
+ </>
) : null}
</FormSectionContent>
</FormSection>
diff --git a/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx b/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
index ec66dbfa62c..7c408e29d19 100644
--- a/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
+++ b/studio/components/interfaces/Database/Hooks/HooksList/HooksList.tsx
@@ -8,7 +8,6 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useCheckPermissions } from 'hooks'
import SchemaTable from './SchemaTable'
-import AlphaPreview from 'components/to-be-cleaned/AlphaPreview'
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'