Skip to content

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

fix(studio): use nuqs for database functions search to prevent caret jumping (#44909)

Ali Waseem0c931f8c58d1
diff --git a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
index 75a0ed06db9..440a5e2491d 100644
--- a/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
+++ b/apps/studio/components/interfaces/Database/Functions/FunctionsList/FunctionsList.tsx
@@ -1,7 +1,5 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useParams } from 'common'
import { Search } from 'lucide-react'
-import { useRouter } from 'next/router'
import { parseAsBoolean, parseAsJson, parseAsString, useQueryState } from 'nuqs'
import { useEffect } from 'react'
import { toast } from 'sonner'
@@ -45,8 +43,6 @@ end;
$$;`
export const FunctionsList = () => {
- const router = useRouter()
- const { search } = useParams()
const { data: project } = useSelectedProjectQuery()
const aiSnap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
@@ -96,7 +92,10 @@ export const FunctionsList = () => {
}
}
- const filterString = search ?? ''
+ const [filterString, setFilterString] = useQueryState(
+ 'search',
+ parseAsString.withDefault('').withOptions({ clearOnDefault: true })
+ )
// Filters
const [returnTypeFilter, setReturnTypeFilter] = useQueryState(
@@ -108,16 +107,6 @@ export const FunctionsList = () => {
parseAsJson(selectFilterSchema.parse)
)
- const setFilterString = (str: string) => {
- const url = new URL(document.URL)
- if (str === '') {
- url.searchParams.delete('search')
- } else {
- url.searchParams.set('search', str)
- }
- router.push(url)
- }
-
const { can: canCreateFunctions } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
'functions'
@@ -254,10 +243,7 @@ export const FunctionsList = () => {
selectedSchemaName={selectedSchema}
onSelectSchema={(schema) => {
setFilterString('')
- // Wait for the filter to be cleared from the URL
- setTimeout(() => {
- setSelectedSchema(schema)
- }, 50)
+ setSelectedSchema(schema)
}}
/>
<Input