The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: Add server-side fetching and filtering to the Table Selector in the realtime inspector (#21256)
Ivan Vasilovb025cc3810b2
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSchema.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterTable.tsxsimilarity index 94%rename from apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSchema.tsxrename to apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterTable.tsxindex 2603b647ebc..0e2a5aa85f2 100644--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSchema.tsx+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterTable.tsx@@ -1,6 +1,6 @@import TableSelector from './TableSelector'-export const TableSchema = ({+export const FilterTable = ({value,schema,onChange,diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSelector.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSelector.tsxindex 2d5eba68ac3..02e8c6d347c 100644--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSelector.tsx+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/TableSelector.tsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { useEffect, useState } from 'react'import {AlertDescription_Shadcn_,AlertTitle_Shadcn_,@@ -21,6 +21,7 @@ import {import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'+import { debounce } from 'lodash'interface TableSelectorProps {className?: string@@ -40,13 +41,29 @@ const TableSelector = ({onSelectTable,}: TableSelectorProps) => {const [open, setOpen] = useState(false)+ const [initiallyLoaded, setInitiallyLoaded] = useState(false)const { project } = useProjectContext()+ const [searchInput, setSearchInput] = useState('')const { data, isLoading, isSuccess, isError, error, refetch } = useEntityTypesQuery({projectRef: project?.ref,+ search: searchInput,connectionString: project?.connectionString,schema: selectedSchemaName,})+ useEffect(() => {+ if (!initiallyLoaded && isSuccess) {+ setInitiallyLoaded(true)+ }+ }, [initiallyLoaded, isSuccess])++ useEffect(() => {+ if (!open && searchInput !== '') {+ setSearchInput('')+ }+ }, [open, searchInput])++ const searchTables = debounce(setSearchInput)const entities = (data?.pages[0].data.entities ? [...data?.pages[0].data.entities] : []).sort((a, b) => (a.name > b.name ? 0 : -1)@@ -54,100 +71,109 @@ const TableSelector = ({return (<div className={className}>- {isLoading && (- <Button- type="outline"- size={size}- className={`w-full [&>span]:w-full ${size === 'small' ? 'py-1.5' : ''}`}- icon={<IconLoader className="animate-spin" size={12} />}- >- <p className="flex text-xs text-light">Loading tables...</p>- </Button>- )}-- {showError && isError && (- <Alert_Shadcn_ variant="warning" className="!px-3 !py-3">- <AlertTitle_Shadcn_ className="text-xs text-amber-900">- Failed to load tables- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="text-xs mb-2">- Error: {(error as any)?.message}- </AlertDescription_Shadcn_>- <Button type="default" size="tiny" onClick={() => refetch()}>- Reload tables- </Button>- </Alert_Shadcn_>- )}-- {isSuccess && (- <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>- <PopoverTrigger_Shadcn_ asChild>- <Button- size={size}- type="outline"- className={`w-full [&>span]:w-full ${size === 'small' ? 'py-1.5' : ''}`}- iconRight={- <IconCode className="text-foreground-light rotate-90" strokeWidth={2} size={12} />- }- >+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>+ <PopoverTrigger_Shadcn_ asChild>+ <Button+ size={size}+ type="outline"+ disabled={isLoading}+ className={`w-full [&>span]:w-full ${size === 'small' ? 'py-1.5' : ''}`}+ icon={isLoading ? <IconLoader className="animate-spin" size={12} /> : null}+ iconRight={+ <IconCode className="text-foreground-light rotate-90" strokeWidth={2} size={12} />+ }+ >+ {initiallyLoaded ? (<div className="w-full flex space-x-3"><p className="text-xs text-light">table</p><p className="text-xs">{selectedTableName === '*' ? 'All tables' : selectedTableName}</p></div>- </Button>- </PopoverTrigger_Shadcn_>- <PopoverContent_Shadcn_ className="p-0 w-64" side="bottom" align="start">- <Command_Shadcn_>- <CommandInput_Shadcn_ placeholder="Find table..." />- <CommandList_Shadcn_>- <CommandEmpty_Shadcn_>No tables found</CommandEmpty_Shadcn_>- <CommandGroup_Shadcn_>- <ScrollArea className={(entities || []).length > 7 ? 'h-[210px]' : ''}>- <CommandItem_Shadcn_- key="all-tables"- className="cursor-pointer flex items-center justify-between space-x-2 w-full"- onSelect={() => {- onSelectTable('*', undefined)- setOpen(false)- }}- onClick={() => {- onSelectTable('*', undefined)- setOpen(false)- }}- >- <span>All tables</span>- {selectedSchemaName === '*' && (- <IconCheck className="text-brand" strokeWidth={2} />+ ) : (+ <p className="flex text-xs text-light">Loading tables...</p>+ )}+ </Button>+ </PopoverTrigger_Shadcn_>+ <PopoverContent_Shadcn_ className="p-0 w-64" side="bottom" align="start">+ <Command_Shadcn_>+ <CommandInput_Shadcn_+ placeholder="Find table..."+ onValueChange={(str) => searchTables(str)}+ />+ <CommandList_Shadcn_>+ {isLoading && (+ <div className="flex items-center justify-center space-x-2 px-3 py-2">+ <IconLoader className="animate-spin" size={12} />+ <p className="flex text-xs text-light">Loading tables...</p>+ </div>+ )}++ {showError && isError && (+ <Alert_Shadcn_ variant="warning" className="!px-3 !py-3 !border-0 rounded-none">+ <AlertTitle_Shadcn_ className="text-xs text-amber-900">+ Failed to load tables+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_ className="text-xs mb-2">+ Error: {(error as any)?.message}+ </AlertDescription_Shadcn_>+ <Button type="default" size="tiny" onClick={() => refetch()}>+ Reload tables+ </Button>+ </Alert_Shadcn_>+ )}++ {isSuccess && (+ <>+ <CommandGroup_Shadcn_ forceMount>+ <ScrollArea className={(entities || []).length > 7 ? 'h-[210px]' : ''}>+ <CommandEmpty_Shadcn_>No tables found</CommandEmpty_Shadcn_>+ {!searchInput && (+ <CommandItem_Shadcn_+ key="all-tables"+ className="cursor-pointer flex items-center justify-between space-x-2 w-full"+ onSelect={() => {+ onSelectTable('*', undefined)+ setOpen(false)+ }}+ onClick={() => {+ onSelectTable('*', undefined)+ setOpen(false)+ }}+ >+ <span>All tables</span>+ {selectedSchemaName === '*' && (+ <IconCheck className="text-brand" strokeWidth={2} />+ )}+ </CommandItem_Shadcn_>)}- </CommandItem_Shadcn_>- {entities?.map((table) => (- <CommandItem_Shadcn_- key={table.id}- className="cursor-pointer flex items-center justify-between space-x-2 w-full"- onSelect={() => {- onSelectTable(table.name, table.id)- setOpen(false)- }}- onClick={() => {- onSelectTable(table.name, table.id)- setOpen(false)- }}- >- <span>{table.name}</span>- {selectedSchemaName === table.name && (- <IconCheck className="text-brand" strokeWidth={2} />- )}- </CommandItem_Shadcn_>- ))}- </ScrollArea>- </CommandGroup_Shadcn_>- </CommandList_Shadcn_>- </Command_Shadcn_>- </PopoverContent_Shadcn_>- </Popover_Shadcn_>- )}+ {entities?.map((table) => (+ <CommandItem_Shadcn_+ key={table.id}+ className="cursor-pointer flex items-center justify-between space-x-2 w-full"+ onSelect={() => {+ onSelectTable(table.name, table.id)+ setOpen(false)+ }}+ onClick={() => {+ onSelectTable(table.name, table.id)+ setOpen(false)+ }}+ >+ <span>{table.name}</span>+ {selectedSchemaName === table.name && (+ <IconCheck className="text-brand" strokeWidth={2} />+ )}+ </CommandItem_Shadcn_>+ ))}+ </ScrollArea>+ </CommandGroup_Shadcn_>+ </>+ )}+ </CommandList_Shadcn_>+ </Command_Shadcn_>+ </PopoverContent_Shadcn_>+ </Popover_Shadcn_></div>)}diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsxindex 1bd776fb26a..9471b788361 100644--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx@@ -18,7 +18,7 @@ import Link from 'next/link'import { ApplyConfigModal } from '../ApplyConfigModal'import { RealtimeConfig } from '../useRealtimeMessages'import { FilterSchema } from './FilterSchema'-import { TableSchema } from './TableSchema'+import { FilterTable } from './FilterTable'interface RealtimeFilterPopoverProps {config: RealtimeConfig@@ -40,7 +40,7 @@ export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilter// [Joshen] Restricting the schemas to only public as any other schema won’t work out of the box due to missing permissions// Consequently, SchemaSelector here will also be disabled- const isFiltered = config.schema !== 'public'+ const isFiltered = config.table !== '*'return (<>@@ -55,20 +55,11 @@ export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilter{isFiltered ? (<><span className="mr-1">Filtered by </span>- <Badge className="!bg-brand-400 !text-brand-600">- schema: {config.schema === '*' ? 'All schemas' : config.schema}- </Badge>+ <Badge className="!bg-brand-400 !text-brand-600">table: {config.table}</Badge></>) : (<span className="mr-1">Filter messages</span>)}-- {config.table !== '*' ? (- <>- <span> and </span>- <Badge className="!bg-brand-400 !text-brand-600">table: {config.table}</Badge>- </>- ) : null}</Button></PopoverTrigger_Shadcn_><PopoverContent_Shadcn_ className="p-0 w-[365px]" align="start">@@ -159,7 +150,7 @@ export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilteronChange={(v) => setTempConfig({ ...tempConfig, schema: v, table: '*' })}/>- <TableSchema+ <FilterTablevalue={tempConfig.table}schema={tempConfig.schema}onChange={(table) => setTempConfig({ ...tempConfig, table })}