Files
supabase/apps/studio/components/interfaces/Functions/useFunctionsListShortcuts.ts
T
Gildas Garcia 8d647f3d05 fix: incorrect react 19 type change (#45991)
<!-- 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 -->

[![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/45991)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-15 14:27:35 +00:00

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,
})
}