Files
supabase/apps/studio/data/database-publications/database-publications-query.ts
Joshen Lim f7ea722b35 Consolidate grid header actions in table editor into a single row (#45504)
## Consolidate Table Editor grid header actions into a single row


https://github.com/user-attachments/assets/1020c385-8fa9-4ef1-b5e7-03983111508b

## Changes involved
- Index advisor, Realtime, and API docs are now behind a dropdown menu
button (Treated as secondary actions)
- Grid header actions shifted into the same row as filter bar (more
space for data grid)
- Header actions will hide while filter bar is in focus (remove
distractions, more space for filter bar)

## Changes to filter bar
- Filter bar will refocus when deleting a filter
- Clicking on the search icon will focus on the free form input of the
filter bar

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

* **New Features**
* Added a “More” dropdown in grid actions to access Realtime, API docs,
and Index Advisor.
* New dialogs for enabling Index Advisor and toggling Realtime are now
consistently managed.

* **Improvements**
* Improved filter focus handling with auto-refocus when conditions
change and responsive header behavior.
* Adjusted popover alignment, separator visuals,
header/footer/pagination layout and sizing.
* Filter bar now supports programmatic focus; Connect button supports
icon-only mode.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
2026-05-06 10:53:49 +08:00

71 lines
2.4 KiB
TypeScript

import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
import { useQuery } from '@tanstack/react-query'
import { databasePublicationsKeys } from './keys'
import { get, handleError } from '@/data/fetchers'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type DatabasePublicationsVariables = {
projectRef?: string
connectionString?: string | null
}
export async function getDatabasePublications(
{ projectRef, connectionString }: DatabasePublicationsVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
let headers = new Headers()
if (connectionString) headers.set('x-connection-encrypted', connectionString)
const { data, error } = await get('/platform/pg-meta/{ref}/publications', {
params: {
header: {
'x-connection-encrypted': connectionString!,
'x-pg-application-name': DEFAULT_PLATFORM_APPLICATION_NAME,
},
path: {
ref: projectRef,
},
},
headers,
signal,
})
if (error) handleError(error)
return data
}
export type DatabasePublicationsData = Awaited<ReturnType<typeof getDatabasePublications>>
export type DatabasePublicationsError = ResponseError
export const useDatabasePublicationsQuery = <TData = DatabasePublicationsData>(
{ projectRef, connectionString }: DatabasePublicationsVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<DatabasePublicationsData, DatabasePublicationsError, TData> = {}
) =>
useQuery<DatabasePublicationsData, DatabasePublicationsError, TData>({
queryKey: databasePublicationsKeys.list(projectRef),
queryFn: ({ signal }) => getDatabasePublications({ projectRef, connectionString }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})
export const useIsTableRealtimeEnabled = ({ id }: { id: number }) => {
const { data: project } = useSelectedProjectQuery()
const { data: publications } = useDatabasePublicationsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const realtimePublication = (publications ?? []).find(
(publication) => publication.name === 'supabase_realtime'
)
const realtimeEnabledTables = realtimePublication?.tables ?? []
const isRealtimeEnabled = realtimeEnabledTables.some((t) => t.id === id)
return isRealtimeEnabled
}