mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Enhanced type safety in internal function handling to improve code stability and maintainability. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45991) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
49 lines
1.3 KiB
TypeScript
49 lines
1.3 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
|
|
onCreateNew: () => void
|
|
onRefresh: () => void
|
|
}
|
|
|
|
export function useFunctionsListShortcuts({
|
|
searchInputRef,
|
|
setSearch,
|
|
sort,
|
|
setSort,
|
|
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, {
|
|
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,
|
|
})
|
|
}
|