Skip to content

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

Chore/realtime inspector fixes 051223 (#19430)

Joshen Lim7473a6536188
diff --git a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyChat.tsx b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyChat.tsx
index 46a917878ca..ce46b475d7c 100644
--- a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyChat.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyChat.tsx
@@ -2,7 +2,7 @@ import { zodResolver } from '@hookform/resolvers/zod'
import { compact, last, sortBy } from 'lodash'
import { Loader2 } from 'lucide-react'
import OpenAI from 'openai'
-import { useEffect, useMemo, useRef, useState } from 'react'
+import { useEffect, useMemo, useRef } from 'react'
import { useForm } from 'react-hook-form'
import {
AiIcon,
@@ -17,8 +17,8 @@ import {
import * as z from 'zod'
import { useProfile } from 'lib/profile'
-import Message from './Message'
import { useAppStateSnapshot } from 'state/app-state'
+import Message from './Message'
interface AIPolicyChatProps {
messages: OpenAI.Beta.Threads.Messages.ThreadMessage[]
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover/index.tsx
index 353f7b1f161..e1d9be354c6 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover/index.tsx
@@ -1,18 +1,21 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import Link from 'next/link'
import { Dispatch, SetStateAction, useState } from 'react'
+import { useForm } from 'react-hook-form'
import {
Button,
- IconBroadcast,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ FormItem_Shadcn_,
+ Form_Shadcn_,
IconChevronDown,
- IconDatabaseChanges,
- IconPresence,
- Input,
+ Input_Shadcn_,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
- Toggle,
} from 'ui'
+import * as z from 'zod'
-import Link from 'next/link'
import { RealtimeConfig } from '../useRealtimeMessages'
interface ChooseChannelPopoverProps {
@@ -22,16 +25,28 @@ interface ChooseChannelPopoverProps {
export const ChooseChannelPopover = ({ config, onChangeConfig }: ChooseChannelPopoverProps) => {
const [open, setOpen] = useState(false)
- const [channelName, setChannelName] = useState(config.channelName)
+
+ const FormSchema = z.object({ channel: z.string() })
+ const form = useForm<z.infer<typeof FormSchema>>({
+ mode: 'onBlur',
+ reValidateMode: 'onBlur',
+ resolver: zodResolver(FormSchema),
+ defaultValues: { channel: '' },
+ })
const onOpen = (v: boolean) => {
// when opening, copy the outside config into the intermediate one
if (v === true) {
- setChannelName(config.channelName)
+ form.setValue('channel', config.channelName)
}
setOpen(v)
}
+ const onSubmit = () => {
+ setOpen(false)
+ onChangeConfig({ ...config, channelName: form.getValues('channel'), enabled: true })
+ }
+
return (
<Popover_Shadcn_ open={open} onOpenChange={onOpen}>
<PopoverTrigger_Shadcn_ asChild>
@@ -45,38 +60,45 @@ export const ChooseChannelPopover = ({ config, onChangeConfig }: ChooseChannelPo
className="max-w-[120px] truncate"
title={config.channelName.length > 0 ? config.channelName : ''}
>
- {config.channelName.length > 0 ? `Channel: ${config.channelName}` : 'Choose channel'}
+ {config.channelName.length > 0 ? `Channel: ${config.channelName}` : 'Join a channel'}
</p>
</Button>
</PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="p-0" align="start">
- <div className="border-b border-overlay p-4 flex flex-col text-sm">
+ <PopoverContent_Shadcn_ className="p-0 w-[320px]" align="start">
+ <div className="p-4 flex flex-col text-sm">
{config.channelName.length === 0 ? (
<>
- <label className="text-foreground text-xs mb-2">Name of channel</label>
- <div className="flex flex-row">
- <Input
- size="tiny"
- className="w-full"
- inputClassName="rounded-r-none"
- placeholder="Enter a channel name"
- value={channelName}
- onChange={(e) => {
- setChannelName(e.target.value)
- }}
- />
- <Button
- type="default"
- className="rounded-l-none"
- disabled={channelName.length === 0}
- onClick={() => {
- setOpen(false)
- onChangeConfig({ ...config, channelName })
- }}
- >
- Set channel
- </Button>
- </div>
+ <Form_Shadcn_ {...form}>
+ <form id="realtime-channel" onSubmit={form.handleSubmit(() => onSubmit())}>
+ <FormField_Shadcn_
+ name="channel"
+ control={form.control}
+ render={({ field }) => (
+ <FormItem_Shadcn_>
+ <label className="text-foreground text-xs mb-2">Name of channel</label>
+ <div className="flex">
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ autoComplete="off"
+ className="rounded-r-none text-xs px-2.5 py-1 h-auto"
+ placeholder="Enter a channel name"
+ />
+ </FormControl_Shadcn_>
+ <Button
+ type="primary"
+ className="rounded-l-none"
+ disabled={form.getValues().channel.length === 0}
+ onClick={() => onSubmit()}
+ >
+ Listen to channel
+ </Button>
+ </div>
+ </FormItem_Shadcn_>
+ )}
+ />
+ </form>
+ </Form_Shadcn_>
<p className="text-xs text-foreground-lighter mt-2">
The channel you initialize with the Supabase Realtime client. Learn more in{' '}
<Link
@@ -92,84 +114,23 @@ export const ChooseChannelPopover = ({ config, onChangeConfig }: ChooseChannelPo
) : (
<div className="space-y-2">
<div className="flex items-center gap-x-2">
- <p className="text-foreground text-xs">Currently using channel</p>
+ <p className="text-foreground text-xs">Currently joined channel:</p>
<p className="text-xs border border-scale-600 py-0.5 px-1 rounded-md bg-surface-200">
{config.channelName}
</p>
</div>
<p className="text-xs text-foreground-lighter mt-2">
- If you unset this channel, all of the messages populated on this page will disappear
+ If you leave this channel, all of the messages populated on this page will disappear
</p>
<Button
type="default"
onClick={() => onChangeConfig({ ...config, channelName: '', enabled: false })}
>
- Unset channel
+ Leave channel
</Button>
</div>
)}
</div>
- <div className="border-b border-overlay p-4">
- <div className="flex items-center justify-between gap-2">
- <div className="flex gap-2.5 items-center">
- <IconPresence size="xlarge" className="bg-brand-400 rounded text-brand-600" />
- <label htmlFor="toggle-presence" className="text-sm">
- Presence
- </label>
- </div>
- <Toggle
- id="toggle-presence"
- size="tiny"
- checked={config.enablePresence}
- onChange={() => onChangeConfig({ ...config, enablePresence: !config.enablePresence })}
- />
- </div>
- <p className="text-xs text-foreground-light pt-1">
- Store and synchronize user state consistently across clients
- </p>
- </div>
- <div className="border-b border-overlay p-4">
- <div className="flex items-center justify-between">
- <div className="flex gap-2.5 items-center">
- <IconBroadcast size="xlarge" className="bg-brand-400 rounded text-brand-600" />
- <label htmlFor="toggle-broadcast" className="text-sm">
- Broadcast
- </label>
- </div>
- <Toggle
- id="toggle-broadcast"
- size="tiny"
- checked={config.enableBroadcast}
- onChange={() =>
- onChangeConfig({ ...config, enableBroadcast: !config.enableBroadcast })
- }
- />
- </div>
- <p className="text-xs text-foreground-light pt-1">
- Send any data to any client subscribed to the same channel
- </p>
- </div>
- <div className="border-b border-overlay p-4">
- <div className="flex items-center justify-between">
- <div className="flex gap-2.5 items-center">
- <IconDatabaseChanges size="xlarge" className="bg-brand-400 rounded text-brand-600" />
- <label htmlFor="toggle-db-changes" className="text-sm">
- Database changes
- </label>
- </div>
- <Toggle
- id="toggle-db-changes"
- size="tiny"
- checked={config.enableDbChanges}
- onChange={() =>
- onChangeConfig({ ...config, enableDbChanges: !config.enableDbChanges })
- }
- />
- </div>
- <p className="text-xs text-foreground-light pt-1">
- Listen for Database inserts, updates, deletes and more
- </p>
- </div>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
)
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx b/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
index db806c9d303..11c7e1bdd55 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
@@ -1,3 +1,4 @@
+import * as Tooltip from '@radix-ui/react-tooltip'
import { PlayCircle, StopCircle } from 'lucide-react'
import { Dispatch, SetStateAction } from 'react'
import { Button } from 'ui'
@@ -18,16 +19,37 @@ export const Header = ({ config, onChangeConfig }: HeaderProps) => {
<div className="flex flex-row">
<ChooseChannelPopover config={config} onChangeConfig={onChangeConfig} />
<RealtimeTokensPopover config={config} onChangeConfig={onChangeConfig} />
- <Button
- size="tiny"
- type={config.enabled ? 'warning' : 'primary'}
- className="rounded-l-none border-l-0"
- disabled={config.channelName.length === 0}
- icon={config.enabled ? <StopCircle size="16" /> : <PlayCircle size="16" />}
- onClick={() => onChangeConfig({ ...config, enabled: !config.enabled })}
- >
- {config.enabled ? `Stop listening` : `Start listening`}
- </Button>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ size="tiny"
+ type={config.enabled ? 'warning' : 'primary'}
+ className="rounded-l-none border-l-0"
+ disabled={config.channelName.length === 0}
+ icon={config.enabled ? <StopCircle size="16" /> : <PlayCircle size="16" />}
+ onClick={() => onChangeConfig({ ...config, enabled: !config.enabled })}
+ >
+ {config.enabled ? `Stop listening` : `Start listening`}
+ </Button>
+ </Tooltip.Trigger>
+ {config.channelName.length === 0 && (
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ ].join(' ')}
+ >
+ <span className="text-xs text-foreground">
+ You'll need to join a channel first
+ </span>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ )}
+ </Tooltip.Root>
</div>
<RealtimeFilterPopover config={config} onChangeConfig={onChangeConfig} />
</div>
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessagesFormatters.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessagesFormatters.tsx
index da6d08f97a4..8f20acebf9a 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/MessagesFormatters.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessagesFormatters.tsx
@@ -7,17 +7,29 @@ export const RowLayout = ({ children }: PropsWithChildren<{}>) => (
<div className="flex h-full w-full items-center gap-4">{children}</div>
)
// renders a timestamp (either unix microsecond or iso timestamp)
-export const SelectionDetailedTimestampRow = ({ value }: { value: string | number }) => (
- <SelectionDetailedRow label="Timestamp" value={unixMicroToIsoTimestamp(value)} />
+export const SelectionDetailedTimestampRow = ({
+ value,
+ hideCopy = false,
+}: {
+ value: string | number
+ hideCopy?: boolean
+}) => (
+ <SelectionDetailedRow
+ label="Timestamp"
+ value={unixMicroToIsoTimestamp(value)}
+ hideCopy={hideCopy}
+ />
)
export const SelectionDetailedRow = ({
label,
value,
valueRender,
+ hideCopy = false,
}: {
label: string
value: string
valueRender?: React.ReactNode
+ hideCopy?: boolean
}) => {
return (
<div className="grid grid-cols-12 group">
@@ -25,13 +37,15 @@ export const SelectionDetailedRow = ({
<span className="text-scale-1200 text-sm col-span-6 whitespace-pre-wrap break-all">
{valueRender ?? value}
</span>
- <CopyButton
- bounceIconOnCopy
- text={value}
- className="group-hover:opacity-100 opacity-0 my-auto transition col-span-2 h-4 w-4 px-0 py-0"
- type="text"
- title="Copy to clipboard"
- />
+ {!hideCopy && (
+ <CopyButton
+ bounceIconOnCopy
+ text={value}
+ className="group-hover:opacity-100 opacity-0 my-auto transition col-span-2 h-4 w-4 px-0 py-0"
+ type="text"
+ title="Copy to clipboard"
+ />
+ )}
</div>
)
}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
index 7620eaf1001..98e6f72dd6a 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
@@ -11,86 +11,91 @@ import ShimmerLine from 'components/ui/ShimmerLine'
import MessageSelection from './MessageSelection'
import { LogData } from './Messages.types'
import { ColumnRenderer } from './RealtimeMessageColumnRenderer'
+import NoChannelEmptyState from './NoChannelEmptyState'
export const isErrorLog = (l: LogData) => {
return l.message === 'SYSTEM' && l.metadata?.status === 'error'
}
-interface MessagesTableProps {
- enabled: boolean
- data?: LogData[]
- showSendMessage: () => void
-}
-
const NoResultAlert = ({
enabled,
+ hasChannelSet,
showSendMessage,
}: {
enabled: boolean
+ hasChannelSet: boolean
showSendMessage: () => void
}) => {
- const router = useRouter()
const { ref } = useParams()
return (
<div className="w-full max-w-md flex items-center flex-col">
- {enabled ? <p>No Realtime messages found</p> : null}
- <p className="text-foreground-lighter">Realtime message logs will be shown here</p>
+ {!hasChannelSet ? (
+ <NoChannelEmptyState />
+ ) : (
+ <>
+ {enabled ? <p>No Realtime messages found</p> : null}
+ <p className="text-foreground-lighter">Realtime message logs will be shown here</p>
- <div className="mt-4 border bg-surface-100 border-border rounded-md justify-start items-center flex flex-col w-full">
- <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
- <IconBroadcast size="xlarge" className="bg-brand-400 rounded w-6 text-brand-600" />
- <div className="grow flex-col flex">
- <p className="text-foreground">Create a Broadcast message</p>
- <p className="text-foreground-lighter text-xs">Start developing in preview</p>
- </div>
- <Button type="default" onClick={showSendMessage}>
- Send a test message
- </Button>
- </div>
- <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
- <IconPresence size="xlarge" className="bg-brand-400 rounded w-6 text-brand-600" />
- <div className="grow flex-col flex">
- <p className="text-foreground">Join from another browser tab</p>
- <p className="text-foreground-lighter text-xs">
- Experiment with presence messages between multiple clients
- </p>
- </div>
- <Link href={`${router.basePath}${router.asPath}`} target="_blank">
- <Button type="default" iconRight={<IconExternalLink />}>
- Open inspector
- </Button>
- </Link>
- </div>
+ <div className="mt-4 border bg-surface-100 border-border rounded-md justify-start items-center flex flex-col w-full">
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
+ <IconBroadcast size="xlarge" className="bg-brand-400 rounded w-6 text-brand-600" />
+ <div className="grow flex-col flex">
+ <p className="text-foreground">Create a Broadcast message</p>
+ <p className="text-foreground-lighter text-xs">Send a message in the channel</p>
+ </div>
+ <Button type="default" onClick={showSendMessage}>
+ Broadcast a message
+ </Button>
+ </div>
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
+ <IconPresence size="xlarge" className="bg-brand-400 rounded w-6 text-brand-600" />
+ <div className="grow flex-col flex">
+ <p className="text-foreground">Join from another browser tab</p>
+ <p className="text-foreground-lighter text-xs">
+ Send messages between multiple clients
+ </p>
+ </div>
+ <Link href={`/project/${ref}/realtime/inspector`} target="_blank" rel="noreferrer">
+ <Button type="default" iconRight={<IconExternalLink />}>
+ Open inspector
+ </Button>
+ </Link>
+ </div>
- <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
- <IconDatabaseChanges size="xlarge" className="bg-brand-400 rounded w-6 text-brand-600" />
- <div className="grow flex-col flex">
- <p className="text-foreground">Listen to a table for changes</p>
- <p className="text-foreground-lighter text-xs">Start developing in preview</p>
- </div>
- <Link
- href={`${router.basePath}/project/${ref}/database/replication`}
- target="_blank"
- rel="noreferrer"
- >
- <Button type="default" iconRight={<IconExternalLink />}>
- Replication settings
- </Button>
- </Link>
- </div>
- <div className="w-full px-5 py-4 items-center gap-4 inline-flex rounded-b-md bg-background">
- <div className="grow flex-col flex">
- <p className="text-foreground">Not sure what to do?</p>
- <p className="text-foreground-lighter text-xs">Browse our documentation</p>
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
+ <IconDatabaseChanges
+ size="xlarge"
+ className="bg-brand-400 rounded w-6 text-brand-600"
+ />
+ <div className="grow flex-col flex">
+ <p className="text-foreground">Listen to a table for changes</p>
+ <p className="text-foreground-lighter text-xs">Tables must have realtime enabled</p>
+ </div>
+ <Link href={`/project/${ref}/database/replication`} target="_blank" rel="noreferrer">
+ <Button type="default" iconRight={<IconExternalLink />}>
+ Replication settings
+ </Button>
+ </Link>
+ </div>
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex rounded-b-md bg-background">
+ <div className="grow flex-col flex">
+ <p className="text-foreground">Not sure what to do?</p>
+ <p className="text-foreground-lighter text-xs">Browse our documentation</p>
+ </div>
+ <Button type="default" iconRight={<IconExternalLink />}>
+ <a
+ href="https://supabase.com/docs/guides/realtime"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Documentation
+ </a>
+ </Button>
+ </div>
</div>
- <Button type="default" iconRight={<IconExternalLink />}>
- <a href="https://supabase.com/docs/guides/realtime" target="_blank" rel="noreferrer">
- Documentation
- </a>
- </Button>
- </div>
- </div>
+ </>
+ )}
</div>
)
}
@@ -99,7 +104,19 @@ const RowRenderer = (key: Key, props: RenderRowProps<LogData, unknown>) => {
return <Row key={key} {...props} isRowSelected={false} selectedCellIdx={undefined} />
}
-const MessagesTable = ({ enabled, data = [], showSendMessage }: MessagesTableProps) => {
+interface MessagesTableProps {
+ enabled: boolean
+ data?: LogData[]
+ hasChannelSet: boolean
+ showSendMessage: () => void
+}
+
+const MessagesTable = ({
+ enabled,
+ hasChannelSet,
+ data = [],
+ showSendMessage,
+}: MessagesTableProps) => {
const [focusedLog, setFocusedLog] = useState<LogData | null>(null)
const stringData = JSON.stringify(data)
@@ -133,16 +150,16 @@ const MessagesTable = ({ enabled, data = [], showSendMessage }: MessagesTablePro
: `No message found yet...`}
</div>
</div>
- <Button type="link" onClick={showSendMessage}>
- <span className="underline text-foreground-light hover:text-brand-600">
- Send test message
+ <Button type="text" onClick={showSendMessage} className="group">
+ <span className="text-foreground-light group-hover:text-foreground transition">
+ Broadcast a message
</span>
</Button>
</div>
)}
<DataGrid
- className="data-grid--simple-logs h-full"
+ className="data-grid--simple-logs h-full border-b-0"
rowHeight={40}
headerRowHeight={0}
onSelectedCellChange={({ rowIdx }) => {
@@ -165,7 +182,11 @@ const MessagesTable = ({ enabled, data = [], showSendMessage }: MessagesTablePro
renderRow: RowRenderer,
noRowsFallback: (
<div className="mx-auto flex h-full w-full items-center justify-center space-y-12 py-4 transition-all delay-200 duration-500">
- <NoResultAlert enabled={enabled} showSendMessage={showSendMessage} />
+ <NoResultAlert
+ enabled={enabled}
+ hasChannelSet={hasChannelSet}
+ showSendMessage={showSendMessage}
+ />
</div>
),
}}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/NoChannelEmptyState.tsx b/apps/studio/components/interfaces/Realtime/Inspector/NoChannelEmptyState.tsx
new file mode 100644
index 00000000000..46937e4b2c3
--- /dev/null
+++ b/apps/studio/components/interfaces/Realtime/Inspector/NoChannelEmptyState.tsx
@@ -0,0 +1,31 @@
+import { PlayCircle } from 'lucide-react'
+import { Button, IconExternalLink } from 'ui'
+
+const NoChannelEmptyState = () => {
+ return (
+ <div className="border bg-background border-border rounded-md justify-start items-center flex flex-col w-10/12 relative">
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b rounded-t-md">
+ <div className="grow flex-col flex gap-y-1">
+ <p className="text-foreground">Join a channel to start listening to messages</p>
+ <p className="text-foreground-lighter text-xs">
+ Channels are the building blocks of realtime where clients can bi-directionally send and
+ receive messages in.
+ </p>
+ </div>
+ </div>
+ <div className="w-full px-5 py-4 items-center gap-4 inline-flex rounded-b-md">
+ <div className="grow flex-col flex">
+ <p className="text-foreground">Not sure what to do?</p>
+ <p className="text-foreground-lighter text-xs">Browse our documentation</p>
+ </div>
+ <Button type="default" iconRight={<IconExternalLink />}>
+ <a href="https://supabase.com/docs/guides/realtime" target="_blank" rel="noreferrer">
+ Documentation
+ </a>
+ </Button>
+ </div>
+ </div>
+ )
+}
+
+export default NoChannelEmptyState
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterSchema.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterSchema.tsx
index e17510760b4..a6e1f600409 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterSchema.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/FilterSchema.tsx
@@ -11,6 +11,7 @@ export const FilterSchema = ({
<div className="flex flex-row gap-4 items-center">
<p className="w-[60px] flex justify-end text-sm">WHERE</p>
<SchemaSelector
+ disabled
supportSelectAll
size="small"
selectedSchemaName={value}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
index c3946d529df..3fab3670448 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
@@ -3,10 +3,14 @@ import { Dispatch, SetStateAction, useState } from 'react'
import {
Badge,
Button,
+ IconBroadcast,
+ IconDatabaseChanges,
+ IconPresence,
Input,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
+ Toggle,
cn,
} from 'ui'
@@ -34,7 +38,9 @@ export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilter
setOpen(v)
}
- const isFiltered = config.schema !== '*'
+ // [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'
return (
<>
@@ -65,45 +71,119 @@ export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilter
) : null}
</Button>
</PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="p-0 w-full" align="start">
+ <PopoverContent_Shadcn_ className="p-0 w-[365px]" align="start">
<div className="border-b border-overlay text-xs px-4 py-3 text-foreground">
- Filter incoming messages
+ Listen to event types
</div>
- <div className="flex border-b border-overlay p-4 gap-y-2 flex-col">
- <FilterSchema
- value={tempConfig.schema}
- onChange={(v) => setTempConfig({ ...tempConfig, schema: v, table: '*' })}
- />
-
- <TableSchema
- value={tempConfig.table}
- schema={tempConfig.schema}
- onChange={(table) => setTempConfig({ ...tempConfig, table })}
- />
+ <div className="py-3 px-4 border-b border-overlay">
+ <div className="flex items-center justify-between gap-2">
+ <div className="flex gap-2.5 items-center">
+ <IconPresence size="xlarge" className="bg-brand-400 rounded text-brand-600" />
+ <label htmlFor="toggle-presence" className="text-sm">
+ Presence
+ </label>
+ </div>
+ <Toggle
+ id="toggle-presence"
+ size="tiny"
+ checked={tempConfig.enablePresence}
+ onChange={() =>
+ setTempConfig({ ...tempConfig, enablePresence: !tempConfig.enablePresence })
+ }
+ />
+ </div>
+ <p className="text-xs text-foreground-light pt-1">
+ Store and synchronize user state consistently across clients
+ </p>
+ </div>
+ <div className="py-3 px-4 border-b border-overlay">
+ <div className="flex items-center justify-between">
+ <div className="flex gap-2.5 items-center">
+ <IconBroadcast size="xlarge" className="bg-brand-400 rounded text-brand-600" />
+ <label htmlFor="toggle-broadcast" className="text-sm">
+ Broadcast
+ </label>
+ </div>
+ <Toggle
+ id="toggle-broadcast"
+ size="tiny"
+ checked={tempConfig.enableBroadcast}
+ onChange={() =>
+ setTempConfig({ ...tempConfig, enableBroadcast: !tempConfig.enableBroadcast })
+ }
+ />
+ </div>
+ <p className="text-xs text-foreground-light pt-1">
+ Send any data to any client subscribed to the same channel
+ </p>
</div>
- <div className="border-b border-overlay p-4 flex flex-col gap-2">
- <div className="flex flex-row gap-4 items-center">
- <p className="w-[60px] flex justify-end text-sm">AND</p>
- <Input
+ <div className="py-3 px-4 border-b border-overlay">
+ <div className="flex items-center justify-between">
+ <div className="flex gap-2.5 items-center">
+ <IconDatabaseChanges
+ size="xlarge"
+ className="bg-brand-400 rounded text-brand-600"
+ />
+ <label htmlFor="toggle-db-changes" className="text-sm">
+ Database changes
+ </label>
+ </div>
+ <Toggle
+ id="toggle-db-changes"
size="tiny"
- className="flex-grow"
- placeholder="body=eq.hey"
- value={tempConfig.filter}
- onChange={(v) => setTempConfig({ ...tempConfig, filter: v.target.value })}
+ checked={tempConfig.enableDbChanges}
+ onChange={() =>
+ setTempConfig({ ...tempConfig, enableDbChanges: !tempConfig.enableDbChanges })
+ }
/>
</div>
- <p className="text-xs text-foreground-light pl-[80px]">
- Learn more about realtime filtering in{' '}
- <Link
- className="underline"
- target="_blank"
- rel="noreferrer"
- href="https://supabase.com/docs/guides/realtime/postgres-changes#available-filters"
- >
- our docs
- </Link>
+ <p className="text-xs text-foreground-light pt-1">
+ Listen for Database inserts, updates, deletes and more
</p>
</div>
+
+ {tempConfig.enableDbChanges && (
+ <>
+ <div className="border-b border-overlay text-xs px-4 py-3 text-foreground">
+ Filter messages from database changes
+ </div>
+ <div className="flex border-b border-overlay p-4 gap-y-2 flex-col">
+ <FilterSchema
+ value={tempConfig.schema}
+ onChange={(v) => setTempConfig({ ...tempConfig, schema: v, table: '*' })}
+ />
+
+ <TableSchema
+ value={tempConfig.table}
+ schema={tempConfig.schema}
+ onChange={(table) => setTempConfig({ ...tempConfig, table })}
+ />
+ </div>
+ <div className="border-b border-overlay p-4 flex flex-col gap-2">
+ <div className="flex flex-row gap-4 items-center">
+ <p className="w-[60px] flex justify-end text-sm">AND</p>
+ <Input
+ size="tiny"
+ className="flex-grow"
+ placeholder="body=eq.hey"
+ value={tempConfig.filter}
+ onChange={(v) => setTempConfig({ ...tempConfig, filter: v.target.value })}
+ />
+ </div>
+ <p className="text-xs text-foreground-light pl-[80px]">
+ Learn more about realtime filtering in{' '}
+ <Link
+ className="underline"
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/docs/guides/realtime/postgres-changes#available-filters"
+ >
+ our docs
+ </Link>
+ </p>
+ </div>
+ </>
+ )}
<div className="px-4 py-2 gap-2 flex justify-end">
<Button type="default" onClick={() => setOpen(false)}>
Cancel
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
index 2cb05a85f17..348b234d828 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeTokensPopover/index.tsx
@@ -20,6 +20,10 @@ export const RealtimeTokensPopover = ({ config, onChangeConfig }: RealtimeTokens
? apiService.serviceApiKey
: undefined
+ const anonServiceRoleKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
+ ? apiService.serviceApiKey
+ : undefined
+
const { data: postgrestConfig } = useProjectPostgrestConfigQuery({
projectRef: config.projectRef,
})
@@ -29,6 +33,7 @@ export const RealtimeTokensPopover = ({ config, onChangeConfig }: RealtimeTokens
useEffect(() => {
let token: string | undefined
+ let bearer: string | null = null
if (
config.projectRef !== undefined &&
@@ -36,13 +41,14 @@ export const RealtimeTokensPopover = ({ config, onChangeConfig }: RealtimeTokens
snap.role !== undefined &&
snap.role.type === 'postgrest'
) {
- token = getRoleImpersonationJWT(config.projectRef, jwtSecret, snap.role)
+ token = anonServiceRoleKey
+ bearer = getRoleImpersonationJWT(config.projectRef, jwtSecret, snap.role)
} else {
token = serviceRoleKey
}
if (token) {
- onChangeConfig({ ...config, token })
+ onChangeConfig({ ...config, token, bearer })
}
}, [config.projectRef, jwtSecret, serviceRoleKey, snap.role])
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/SelectedRealtimeMessagePanel.tsx b/apps/studio/components/interfaces/Realtime/Inspector/SelectedRealtimeMessagePanel.tsx
index e553e863c6e..44f0a236042 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/SelectedRealtimeMessagePanel.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/SelectedRealtimeMessagePanel.tsx
@@ -19,11 +19,11 @@ export const SelectedRealtimeMessagePanel = ({ log }: { log: LogData }) => {
</div>
<LogsDivider />
<div className="px-8 space-y-2">
- <SelectionDetailedTimestampRow value={log.timestamp} />
+ <SelectionDetailedTimestampRow hideCopy value={log.timestamp} />
</div>
<LogsDivider />
<div className="px-8">
- <h3 className="mb-4 text-lg text-scale-1200">Metadata</h3>
+ <h3 className="mb-4 text-sm text-foreground-lighter">Metadata</h3>
<pre className="syntax-highlight overflow-x-auto text-sm">
<div
className="text-wrap"
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/SendMessageModal.tsx b/apps/studio/components/interfaces/Realtime/Inspector/SendMessageModal.tsx
index 8dce33c9b25..d2fcd857869 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/SendMessageModal.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/SendMessageModal.tsx
@@ -10,18 +10,23 @@ interface SendMessageModalProps {
onSelectConfirm: (v: { message: string; payload: string }) => void
}
+const defaultPayload = {
+ message: 'Test message',
+ payload: '{ "message": "Hello World" }',
+}
+
export const SendMessageModal = ({
visible,
onSelectCancel,
onSelectConfirm,
}: SendMessageModalProps) => {
const [error, setError] = useState<string>()
- const [values, setValues] = useState({ message: 'test', payload: '{}' })
+ const [values, setValues] = useState(defaultPayload)
useEffect(() => {
if (visible) {
setError(undefined)
- setValues({ message: 'test', payload: '{}' })
+ setValues(defaultPayload)
}
}, [visible])
@@ -38,7 +43,7 @@ export const SendMessageModal = ({
if (payload === undefined) {
setError('Please provide a valid JSON')
} else {
- onSelectConfirm(values)
+ onSelectConfirm({ ...values, payload })
}
}}
>
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
index a78b2aa819d..0dbed74dad5 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
@@ -19,7 +19,7 @@ export const RealtimeInspector = () => {
channelName: '',
logLevel: 'info',
token: '', // will be filled out by RealtimeTokensPopover
- schema: '*',
+ schema: 'public',
table: '*',
filter: undefined,
bearer: null,
@@ -31,11 +31,12 @@ export const RealtimeInspector = () => {
const { logData, sendMessage } = useRealtimeMessages(realtimeConfig)
return (
- <div className="flex flex-col flex-grow h-full">
+ <div className="flex flex-col grow h-full">
<Header config={realtimeConfig} onChangeConfig={setRealtimeConfig} />
- <div className="relative flex flex-col flex-grow h-full">
- <div className="flex h-full">
+ <div className="relative flex flex-col grow">
+ <div className="flex grow">
<MessagesTable
+ hasChannelSet={realtimeConfig.channelName.length > 0}
enabled={realtimeConfig.enabled}
data={logData}
showSendMessage={() => setSendMessageShown(true)}
diff --git a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
index 252767497bd..961839006c0 100644
--- a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
+++ b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
@@ -23,7 +23,7 @@ const RealtimeLayout = ({ children }: PropsWithChildren<RealtimeLayoutProps>) =>
product="Realtime"
productMenu={<ProductMenu page={page} menu={generateRealtimeMenu(project)} />}
>
- <main className="h-screen">{children}</main>
+ {children}
</ProjectLayout>
)
}
diff --git a/apps/studio/components/ui/SchemaSelector.tsx b/apps/studio/components/ui/SchemaSelector.tsx
index 5e84e4977bc..85e2dc697bf 100644
--- a/apps/studio/components/ui/SchemaSelector.tsx
+++ b/apps/studio/components/ui/SchemaSelector.tsx
@@ -25,6 +25,7 @@ import { useSchemasQuery } from 'data/database/schemas-query'
interface SchemaSelectorProps {
className?: string
+ disabled?: boolean
size?: 'tiny' | 'small'
showError?: boolean
selectedSchemaName: string
@@ -35,6 +36,7 @@ interface SchemaSelectorProps {
const SchemaSelector = ({
className,
+ disabled = false,
size = 'tiny',
showError = true,
selectedSchemaName,
@@ -92,6 +94,7 @@ const SchemaSelector = ({
<PopoverTrigger_Shadcn_ asChild>
<Button
size={size}
+ disabled={disabled}
type="outline"
className={`w-full [&>span]:w-full ${size === 'small' ? 'py-1.5' : ''}`}
iconRight={