mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## 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 --> [](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 -->
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { Dispatch, RefObject, SetStateAction } from 'react'
|
|
|
|
import type { EdgeFunctionsSort } from '@/components/interfaces/EdgeFunctions/EdgeFunctionsSortDropdown'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
|
|
const DEFAULT_SORT: EdgeFunctionsSort = 'name:asc'
|
|
|
|
interface UseFunctionsListShortcutsParams {
|
|
searchInputRef: RefObject<HTMLInputElement | null>
|
|
setSearch: Dispatch<SetStateAction<string>> | ((value: string) => void)
|
|
sort: EdgeFunctionsSort
|
|
setSort: (value: EdgeFunctionsSort) => void
|
|
canCreateNew: boolean
|
|
onCreateNew: () => void
|
|
onRefresh: () => void
|
|
}
|
|
|
|
export function useFunctionsListShortcuts({
|
|
searchInputRef,
|
|
setSearch,
|
|
sort,
|
|
setSort,
|
|
canCreateNew,
|
|
onCreateNew,
|
|
onRefresh,
|
|
}: UseFunctionsListShortcutsParams) {
|
|
useShortcut(
|
|
SHORTCUT_IDS.LIST_PAGE_FOCUS_SEARCH,
|
|
() => {
|
|
searchInputRef.current?.focus()
|
|
searchInputRef.current?.select()
|
|
},
|
|
{ label: 'Search functions' }
|
|
)
|
|
|
|
useShortcut(SHORTCUT_IDS.LIST_PAGE_NEW_ITEM, onCreateNew, {
|
|
enabled: canCreateNew,
|
|
label: 'Deploy a new function',
|
|
})
|
|
|
|
useShortcut(SHORTCUT_IDS.LIST_PAGE_RESET_FILTERS, () => {
|
|
setSearch('')
|
|
})
|
|
|
|
useShortcut(SHORTCUT_IDS.FUNCTIONS_LIST_REFRESH, onRefresh)
|
|
|
|
useShortcut(SHORTCUT_IDS.FUNCTIONS_LIST_CLEAR_SORT, () => setSort(DEFAULT_SORT), {
|
|
enabled: sort !== DEFAULT_SORT,
|
|
})
|
|
}
|