Files
supabase/apps/studio/components/interfaces/Functions/useFunctionsDetailShortcuts.ts
Vaibhav d0edaefc1a fix: edgefn shotcuts (#46057)
## TL;DR

fixes few edge cases in edgefn shrortcuts

## ref:
- closes https://github.com/supabase/supabase/issues/46056

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Improvements**
* Edge function shortcuts now enforce permission requirements. Shortcuts
for viewing function details are only available to users with read
access, and shortcuts for creating new functions require create
permissions.
* Creating new edge functions is now restricted to active projects.
Users must have the appropriate permissions and an active project to use
the creation shortcut.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46057?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-19 17:41:21 -06:00

74 lines
2.1 KiB
TypeScript

import { useRouter } from 'next/router'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
interface UseFunctionsDetailShortcutsParams {
projectRef: string | undefined
functionSlug: string | undefined
canReadFunctions: boolean
isPlatform: boolean
onOpenTest: () => void
onOpenDownload: () => void
onCopyUrl: () => void
}
/**
* Registers shortcuts that apply across every tab of a single edge function:
* - 1..5: jump between Overview / Invocations / Logs / Code / Settings
* - Shift+T: open the test sheet
* - Shift+D: open the download popover
* - Shift+C: copy the function URL
*
* Should be mounted once at the EdgeFunctionDetailsLayout level.
*/
export function useFunctionsDetailShortcuts({
projectRef,
functionSlug,
canReadFunctions,
isPlatform,
onOpenTest,
onOpenDownload,
onCopyUrl,
}: UseFunctionsDetailShortcutsParams) {
const router = useRouter()
const ready = Boolean(projectRef && functionSlug)
const shortcutsEnabled = ready && canReadFunctions
const base = `/project/${projectRef}/functions/${functionSlug}`
useShortcut(SHORTCUT_IDS.NAV_FUNCTION_DETAIL_OVERVIEW, () => router.push(base), {
enabled: shortcutsEnabled && isPlatform,
})
useShortcut(
SHORTCUT_IDS.NAV_FUNCTION_DETAIL_INVOCATIONS,
() => router.push(`${base}/invocations`),
{ enabled: shortcutsEnabled && isPlatform }
)
useShortcut(SHORTCUT_IDS.NAV_FUNCTION_DETAIL_LOGS, () => router.push(`${base}/logs`), {
enabled: shortcutsEnabled && isPlatform,
})
useShortcut(SHORTCUT_IDS.NAV_FUNCTION_DETAIL_CODE, () => router.push(`${base}/code`), {
enabled: shortcutsEnabled,
})
useShortcut(SHORTCUT_IDS.NAV_FUNCTION_DETAIL_SETTINGS, () => router.push(`${base}/details`), {
enabled: shortcutsEnabled,
})
useShortcut(SHORTCUT_IDS.FUNCTION_DETAIL_OPEN_TEST, onOpenTest, {
enabled: shortcutsEnabled,
})
useShortcut(SHORTCUT_IDS.FUNCTION_DETAIL_OPEN_DOWNLOAD, onOpenDownload, {
enabled: shortcutsEnabled,
})
useShortcut(SHORTCUT_IDS.FUNCTION_DETAIL_COPY_URL, onCopyUrl, {
enabled: shortcutsEnabled,
})
}