Skip to content

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

feat(realtime): shortcuts for realtime (#46001)

Ali Waseem3d9fb2f98d75
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover.tsx b/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover.tsx
index 609514a2763..5171ac96264 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/ChooseChannelPopover.tsx
@@ -21,20 +21,41 @@ import * as z from 'zod'
import { RealtimeConfig } from './useRealtimeMessages'
import { DocsButton } from '@/components/ui/DocsButton'
+import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { getTemporaryAPIKey } from '@/data/api-keys/temp-api-keys-query'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { DOCS_URL } from '@/lib/constants'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
-interface ChooseChannelPopoverProps {
+type ControlledOpenProps =
+ | { open: boolean; onOpenChange: (open: boolean) => void }
+ | { open?: undefined; onOpenChange?: undefined }
+
+type ChooseChannelPopoverProps = {
config: RealtimeConfig
onChangeConfig: Dispatch<SetStateAction<RealtimeConfig>>
-}
+} & ControlledOpenProps
const FormSchema = z.object({ channel: z.string(), isPrivate: z.boolean() })
-export const ChooseChannelPopover = ({ config, onChangeConfig }: ChooseChannelPopoverProps) => {
- const [open, setOpen] = useState(false)
+export const ChooseChannelPopover = ({
+ config,
+ onChangeConfig,
+ open: controlledOpen,
+ onOpenChange,
+}: ChooseChannelPopoverProps) => {
+ const [internalOpen, setInternalOpen] = useState(false)
+ const isControlled = controlledOpen !== undefined
+ const open = isControlled ? controlledOpen : internalOpen
+
+ const setOpen = (v: boolean) => {
+ if (isControlled) {
+ onOpenChange?.(v)
+ } else {
+ setInternalOpen(v)
+ }
+ }
const { ref } = useParams()
const { data: org } = useSelectedOrganizationQuery()
const { mutate: sendEvent } = useSendEventMutation()
@@ -80,18 +101,28 @@ export const ChooseChannelPopover = ({ config, onChangeConfig }: ChooseChannelPo
})
}
+ const channelPopoverTrigger = (
+ <PopoverTrigger asChild>
+ <Button className="rounded-r-none" type="default" size="tiny" iconRight={<ChevronDown />}>
+ <p
+ className="max-w-[120px] truncate"
+ title={config.channelName.length > 0 ? config.channelName : ''}
+ >
+ {config.channelName.length > 0 ? `Channel: ${config.channelName}` : 'Join a channel'}
+ </p>
+ </Button>
+ </PopoverTrigger>
+ )
+
return (
<Popover open={open} onOpenChange={onOpen}>
- <PopoverTrigger asChild>
- <Button className="rounded-r-none" type="default" size="tiny" iconRight={<ChevronDown />}>
- <p
- className="max-w-[120px] truncate"
- title={config.channelName.length > 0 ? config.channelName : ''}
- >
- {config.channelName.length > 0 ? `Channel: ${config.channelName}` : 'Join a channel'}
- </p>
- </Button>
- </PopoverTrigger>
+ {!open && config.channelName.length === 0 ? (
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL} side="bottom">
+ {channelPopoverTrigger}
+ </ShortcutTooltip>
+ ) : (
+ channelPopoverTrigger
+ )}
<PopoverContent className="p-0 w-[320px]" align="start">
<div className="p-4 flex flex-col text-sm">
{config.channelName.length === 0 ? (
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx b/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
index 4a5a9b090a6..1a2c7dc759a 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/Header.tsx
@@ -1,24 +1,39 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { IS_PLATFORM, useParams } from 'common'
import { PlayCircle, StopCircle } from 'lucide-react'
-import { Dispatch, SetStateAction } from 'react'
+import { Dispatch, SetStateAction, useCallback } from 'react'
+import { Button } from 'ui'
import { ChooseChannelPopover } from './ChooseChannelPopover'
import { RealtimeFilterPopover } from './RealtimeFilterPopover'
import { RealtimeTokensPopover } from './RealtimeTokensPopover'
import { RealtimeConfig } from './useRealtimeMessages'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
+import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { getTemporaryAPIKey } from '@/data/api-keys/temp-api-keys-query'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
+import { useShortcut } from '@/state/shortcuts/useShortcut'
interface HeaderProps {
config: RealtimeConfig
onChangeConfig: Dispatch<SetStateAction<RealtimeConfig>>
+ channelPopoverOpen: boolean
+ onChannelPopoverChange: (open: boolean) => void
+ filterPopoverOpen: boolean
+ onFilterPopoverChange: (open: boolean) => void
}
-export const Header = ({ config, onChangeConfig }: HeaderProps) => {
+export const Header = ({
+ config,
+ onChangeConfig,
+ channelPopoverOpen,
+ onChannelPopoverChange,
+ filterPopoverOpen,
+ onFilterPopoverChange,
+}: HeaderProps) => {
const { mutate: sendEvent } = useSendEventMutation()
const { ref } = useParams()
const { data: org } = useSelectedOrganizationQuery()
@@ -28,53 +43,90 @@ export const Header = ({ config, onChangeConfig }: HeaderProps) => {
'service_api_keys'
)
+ const canToggleListening = canReadAPIKeys && config.channelName.length > 0
+
+ const handleToggleListening = useCallback(async () => {
+ const willStartListening = !config.enabled
+ // [Joshen] Refresh if starting to listen + using temp API key, since it has a low refresh rate
+ if (willStartListening && (config.token.startsWith('sb_temp') || !IS_PLATFORM)) {
+ const data = await getTemporaryAPIKey({ projectRef: config.projectRef, expiry: 3600 })
+ const token = data.api_key
+ onChangeConfig({ ...config, token, enabled: !config.enabled })
+ } else {
+ onChangeConfig({ ...config, enabled: !config.enabled })
+ }
+
+ if (willStartListening) {
+ sendEvent({
+ action: 'realtime_inspector_listen_channel_clicked',
+ groups: {
+ project: ref ?? 'Unknown',
+ organization: org?.slug ?? 'Unknown',
+ },
+ })
+ }
+ }, [config, onChangeConfig, sendEvent, ref, org])
+
+ useShortcut(SHORTCUT_IDS.INSPECTOR_TOGGLE_LISTENING, handleToggleListening, {
+ enabled: canToggleListening,
+ })
+
+ const listeningButton = (
+ <Button
+ size="tiny"
+ type={config.enabled ? 'warning' : 'primary'}
+ className="rounded-l-none border-l-0"
+ disabled={!canToggleListening}
+ icon={config.enabled ? <StopCircle size="16" /> : <PlayCircle size="16" />}
+ onClick={handleToggleListening}
+ >
+ {config.enabled ? `Stop listening` : `Start listening`}
+ </Button>
+ )
+
return (
<div className="flex flex-row min-h-14 md:min-h-(--header-height) gap-2.5 items-center px-4 border-b ">
<div className="flex flex-row">
- <ChooseChannelPopover config={config} onChangeConfig={onChangeConfig} />
+ <ChooseChannelPopover
+ config={config}
+ onChangeConfig={onChangeConfig}
+ open={channelPopoverOpen}
+ onOpenChange={onChannelPopoverChange}
+ />
<RealtimeTokensPopover config={config} onChangeConfig={onChangeConfig} />
- <ButtonTooltip
- size="tiny"
- type={config.enabled ? 'warning' : 'primary'}
- className="rounded-l-none border-l-0"
- disabled={!canReadAPIKeys || config.channelName.length === 0}
- icon={config.enabled ? <StopCircle size="16" /> : <PlayCircle size="16" />}
- onClick={async () => {
- // [Joshen] Refresh if starting to listen + using temp API key, since it has a low refresh rate
- if (!config.enabled && (config.token.startsWith('sb_temp') || !IS_PLATFORM)) {
- const data = await getTemporaryAPIKey({ projectRef: config.projectRef, expiry: 3600 })
- const token = data.api_key
- onChangeConfig({ ...config, token, enabled: !config.enabled })
- } else {
- onChangeConfig({ ...config, enabled: !config.enabled })
- }
-
- if (!config.enabled) {
- // the user has clicked to start listening
- sendEvent({
- action: 'realtime_inspector_listen_channel_clicked',
- groups: {
- project: ref ?? 'Unknown',
- organization: org?.slug ?? 'Unknown',
- },
- })
- }
- }}
- tooltip={{
- content: {
- side: 'bottom',
- text: !canReadAPIKeys
- ? 'You need additional permissions to use the realtime inspector'
- : config.channelName.length === 0
- ? 'You need to join a channel first'
- : undefined,
- },
- }}
- >
- {config.enabled ? `Stop listening` : `Start listening`}
- </ButtonTooltip>
+ {canToggleListening ? (
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_TOGGLE_LISTENING} side="bottom">
+ {listeningButton}
+ </ShortcutTooltip>
+ ) : (
+ <ButtonTooltip
+ size="tiny"
+ type={config.enabled ? 'warning' : 'primary'}
+ className="rounded-l-none border-l-0"
+ disabled
+ icon={config.enabled ? <StopCircle size="16" /> : <PlayCircle size="16" />}
+ onClick={handleToggleListening}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: !canReadAPIKeys
+ ? 'You need additional permissions to use the realtime inspector'
+ : config.channelName.length === 0
+ ? 'You need to join a channel first'
+ : undefined,
+ },
+ }}
+ >
+ {config.enabled ? `Stop listening` : `Start listening`}
+ </ButtonTooltip>
+ )}
</div>
- <RealtimeFilterPopover config={config} onChangeConfig={onChangeConfig} />
+ <RealtimeFilterPopover
+ config={config}
+ onChangeConfig={onChangeConfig}
+ open={filterPopoverOpen}
+ onOpenChange={onFilterPopoverChange}
+ />
</div>
)
}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessageSelection.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessageSelection.tsx
index 24802aff91d..2d8c6ae1fe3 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/MessageSelection.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessageSelection.tsx
@@ -1,13 +1,17 @@
import { useParams } from 'common'
import { X } from 'lucide-react'
import { useMemo } from 'react'
-import { Button, cn } from 'ui'
+import { toast } from 'sonner'
+import { Button, cn, copyToClipboard } from 'ui'
import type { LogData } from './Messages.types'
import { SelectedRealtimeMessagePanel } from './SelectedRealtimeMessagePanel'
import CopyButton from '@/components/ui/CopyButton'
+import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
+import { useShortcut } from '@/state/shortcuts/useShortcut'
export interface MessageSelectionProps {
log: LogData | null
@@ -23,6 +27,32 @@ const MessageSelection = ({ log, onClose }: MessageSelectionProps) => {
const { data: org } = useSelectedOrganizationQuery()
const { mutate: sendEvent } = useSendEventMutation()
+ const handleCopy = () => {
+ if (!log) return
+ copyToClipboard(selectionText)
+ toast.success('Message copied to clipboard')
+ }
+
+ useShortcut(SHORTCUT_IDS.INSPECTOR_COPY_MESSAGE, handleCopy, {
+ enabled: !!log,
+ ignoreInputs: true,
+ registerInCommandMenu: true,
+ })
+
+ const copyButton = (
+ <CopyButton
+ text={selectionText}
+ type="default"
+ title="Copy log to clipboard"
+ onClick={() => {
+ sendEvent({
+ action: 'realtime_inspector_copy_message_clicked',
+ groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
+ })
+ }}
+ />
+ )
+
return (
<div className={cn('relative flex h-full grow flex-col border-l overflow-y-scroll bg-200')}>
<div
@@ -68,17 +98,13 @@ const MessageSelection = ({ log, onClose }: MessageSelectionProps) => {
<div className="pt-4 flex flex-col gap-4">
<div className="px-4 flex flex-row justify-between items-center">
<div className="transition">
- <CopyButton
- text={selectionText}
- type="default"
- title="Copy log to clipboard"
- onClick={() => {
- sendEvent({
- action: 'realtime_inspector_copy_message_clicked',
- groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
- })
- }}
- />
+ {log ? (
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_COPY_MESSAGE} side="bottom">
+ {copyButton}
+ </ShortcutTooltip>
+ ) : (
+ copyButton
+ )}
</div>
<Button
type="text"
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
index 2ab63db7077..8a2e2240a48 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/MessagesTable.tsx
@@ -15,10 +15,12 @@ import { ColumnRenderer } from './RealtimeMessageColumnRenderer'
import { DocsButton } from '@/components/ui/DocsButton'
import NoPermission from '@/components/ui/NoPermission'
import ShimmerLine from '@/components/ui/ShimmerLine'
+import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { DOCS_URL } from '@/lib/constants'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
export const isErrorLog = (l: LogData) => {
return l.message === 'SYSTEM' && l.metadata?.status === 'error'
@@ -40,6 +42,12 @@ const NoResultAlert = ({
'service_api_keys'
)
+ const broadcastButton = (
+ <Button type="default" onClick={showSendMessage}>
+ Broadcast a message
+ </Button>
+ )
+
return (
<div className="w-full max-w-md flex items-center flex-col">
{isLoadingPermissions ? (
@@ -63,9 +71,13 @@ const NoResultAlert = ({
<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>
+ {enabled ? (
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_BROADCAST} side="bottom">
+ {broadcastButton}
+ </ShortcutTooltip>
+ ) : (
+ broadcastButton
+ )}
</div>
<div className="w-full px-5 py-4 items-center gap-4 inline-flex border-b">
<IconPresence
@@ -169,13 +181,15 @@ const MessagesTable = ({
: `No message found yet...`}
</div>
</div>
- <Button
- type="default"
- onClick={showSendMessage}
- icon={<Megaphone strokeWidth={1.5} />}
- >
- <span>Broadcast a message</span>
- </Button>
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_BROADCAST} side="bottom">
+ <Button
+ type="default"
+ onClick={showSendMessage}
+ icon={<Megaphone strokeWidth={1.5} />}
+ >
+ <span>Broadcast a message</span>
+ </Button>
+ </ShortcutTooltip>
</div>
)}
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
index f47d91b8a5d..53a44db2638 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/RealtimeFilterPopover/index.tsx
@@ -21,19 +21,40 @@ import { RealtimeConfig } from '../useRealtimeMessages'
import { FilterSchema } from './FilterSchema'
import { FilterTable } from './FilterTable'
import { InlineLink } from '@/components/ui/InlineLink'
+import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { useDatabasePublicationsQuery } from '@/data/database-publications/database-publications-query'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { DOCS_URL } from '@/lib/constants'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
-interface RealtimeFilterPopoverProps {
+type ControlledOpenProps =
+ | { open: boolean; onOpenChange: (open: boolean) => void }
+ | { open?: undefined; onOpenChange?: undefined }
+
+type RealtimeFilterPopoverProps = {
config: RealtimeConfig
onChangeConfig: Dispatch<SetStateAction<RealtimeConfig>>
-}
+} & ControlledOpenProps
+
+export const RealtimeFilterPopover = ({
+ config,
+ onChangeConfig,
+ open: controlledOpen,
+ onOpenChange,
+}: RealtimeFilterPopoverProps) => {
+ const [internalOpen, setInternalOpen] = useState(false)
+ const isControlled = controlledOpen !== undefined
+ const open = isControlled ? controlledOpen : internalOpen
-export const RealtimeFilterPopover = ({ config, onChangeConfig }: RealtimeFilterPopoverProps) => {
- const [open, setOpen] = useState(false)
+ const setOpen = (v: boolean) => {
+ if (isControlled) {
+ onOpenChange?.(v)
+ } else {
+ setInternalOpen(v)
+ }
+ }
const [applyConfigOpen, setApplyConfigOpen] = useState(false)
const [tempConfig, setTempConfig] = useState(config)
@@ -66,27 +87,36 @@ 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.table !== '*'
+ const filterPopoverTrigger = (
+ <PopoverTrigger asChild>
+ <Button
+ icon={<PlusCircle size="16" />}
+ type={isFiltered ? 'primary' : 'dashed'}
+ className={cn('rounded-full px-1 text-xs h-[26px]')}
+ size="small"
+ >
+ {isFiltered ? (
+ <>
+ <span className="mr-1">Filtered by </span>
+ <Badge variant="success">table: {config.table}</Badge>
+ </>
+ ) : (
+ <span className="mr-1">Filter messages</span>
+ )}
+ </Button>
+ </PopoverTrigger>
+ )
return (
<>
<Popover open={open} onOpenChange={onOpen}>
- <PopoverTrigger asChild>
- <Button
- icon={<PlusCircle size="16" />}
- type={isFiltered ? 'primary' : 'dashed'}
- className={cn('rounded-full px-1 text-xs h-[26px]')}
- size="small"
- >
- {isFiltered ? (
- <>
- <span className="mr-1">Filtered by </span>
- <Badge variant="success">table: {config.table}</Badge>
- </>
- ) : (
- <span className="mr-1">Filter messages</span>
- )}
- </Button>
- </PopoverTrigger>
+ {!open && config.channelName.length > 0 ? (
+ <ShortcutTooltip shortcutId={SHORTCUT_IDS.INSPECTOR_TOGGLE_FILTERS} side="bottom">
+ {filterPopoverTrigger}
+ </ShortcutTooltip>
+ ) : (
+ filterPopoverTrigger
+ )}
<PopoverContent className="p-0 w-[365px]" align="start">
<div className="border-b border-overlay text-xs px-4 py-3 text-foreground">
Listen to event types
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
index 64570e52d8c..85260981ac2 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
+++ b/apps/studio/components/interfaces/Realtime/Inspector/index.tsx
@@ -1,10 +1,11 @@
import { useParams } from 'common'
-import { useEffect, useState } from 'react'
+import { useCallback, useEffect, useState } from 'react'
import { EmptyRealtime } from './EmptyRealtime'
import { Header } from './Header'
import MessagesTable from './MessagesTable'
import { SendMessageModal } from './SendMessageModal'
+import { useRealtimeInspectorShortcuts } from './useRealtimeInspectorShortcuts'
import { RealtimeConfig, useRealtimeMessages } from './useRealtimeMessages'
import { useDatabasePublicationsQuery } from '@/data/database-publications/database-publications-query'
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
@@ -32,6 +33,8 @@ export const RealtimeInspector = () => {
((realtimePublication?.tables ?? []).length > 0 || realtimePublication?.tables === null)
const [sendMessageShown, setSendMessageShown] = useState(false)
+ const [channelPopoverOpen, setChannelPopoverOpen] = useState(false)
+ const [filterPopoverOpen, setFilterPopoverOpen] = useState(false)
const [realtimeConfig, setRealtimeConfig] = useState<RealtimeConfig>({
enabled: false,
projectRef: ref!,
@@ -51,6 +54,35 @@ export const RealtimeInspector = () => {
const { mutate: sendEvent } = useSendEventMutation()
const { logData, sendMessage } = useRealtimeMessages(realtimeConfig, setRealtimeConfig)
+ const hasChannel = realtimeConfig.channelName.length > 0
+ const isListening = realtimeConfig.enabled
+
+ const handleJoinChannel = useCallback(() => {
+ if (!hasChannel) {
+ setChannelPopoverOpen(true)
+ }
+ }, [hasChannel])
+
+ const handleToggleFilters = useCallback(() => {
+ if (hasChannel) {
+ setFilterPopoverOpen(true)
+ }
+ }, [hasChannel])
+
+ const handleBroadcast = useCallback(() => {
+ if (isListening) {
+ setSendMessageShown(true)
+ }
+ }, [isListening])
+
+ useRealtimeInspectorShortcuts({
+ hasChannel,
+ isListening,
+ onJoinChannel: handleJoinChannel,
+ onToggleFilters: handleToggleFilters,
+ onBroadcast: handleBroadcast,
+ })
+
// Update enableDbChanges when publications change
useEffect(() => {
setRealtimeConfig((prev) => ({ ...prev, enableDbChanges: isRealtimeAvailable }))
@@ -58,13 +90,20 @@ export const RealtimeInspector = () => {
return (
<div className="flex flex-col grow h-full">
- <Header config={realtimeConfig} onChangeConfig={setRealtimeConfig} />
+ <Header
+ config={realtimeConfig}
+ onChangeConfig={setRealtimeConfig}
+ channelPopoverOpen={channelPopoverOpen}
+ onChannelPopoverChange={setChannelPopoverOpen}
+ filterPopoverOpen={filterPopoverOpen}
+ onFilterPopoverChange={setFilterPopoverOpen}
+ />
<div className="relative flex flex-col grow">
<div className="flex grow">
{(logData ?? []).length > 0 ? (
<MessagesTable
- hasChannelSet={realtimeConfig.channelName.length > 0}
- enabled={realtimeConfig.enabled}
+ hasChannelSet={hasChannel}
+ enabled={isListening}
data={logData}
showSendMessage={() => setSendMessageShown(true)}
/>
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeInspectorShortcuts.ts b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeInspectorShortcuts.ts
new file mode 100644
index 00000000000..33cbf1baf66
--- /dev/null
+++ b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeInspectorShortcuts.ts
@@ -0,0 +1,42 @@
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
+import { useShortcut } from '@/state/shortcuts/useShortcut'
+
+interface UseRealtimeInspectorShortcutsParams {
+ hasChannel: boolean
+ isListening: boolean
+ onJoinChannel: () => void
+ onToggleFilters: () => void
+ onBroadcast: () => void
+}
+
+/**
+ * Registers shortcuts scoped to the Realtime Inspector page:
+ * - Shift+J: open the join-channel popover
+ * - Shift+F: open the filter popover
+ * - Shift+B: open the broadcast message modal
+ *
+ * The Shift+L (toggle listening) shortcut is registered inside the Header
+ * component so it shares the start/stop handler — including temp-API-key
+ * refresh, permission gating, and telemetry — with the button click.
+ *
+ * Should be mounted once at the RealtimeInspector component level.
+ */
+export function useRealtimeInspectorShortcuts({
+ hasChannel,
+ isListening,
+ onJoinChannel,
+ onToggleFilters,
+ onBroadcast,
+}: UseRealtimeInspectorShortcutsParams) {
+ useShortcut(SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL, onJoinChannel, {
+ enabled: !hasChannel,
+ })
+
+ useShortcut(SHORTCUT_IDS.INSPECTOR_TOGGLE_FILTERS, onToggleFilters, {
+ enabled: hasChannel,
+ })
+
+ useShortcut(SHORTCUT_IDS.INSPECTOR_BROADCAST, onBroadcast, {
+ enabled: isListening,
+ })
+}
diff --git a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
index 4e2cf485ea6..813605f2a7e 100644
--- a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
+++ b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
@@ -4,6 +4,7 @@ import type { PropsWithChildren } from 'react'
import { ProjectLayout } from '../ProjectLayout'
import { generateRealtimeMenu } from './RealtimeMenu.utils'
import { ProductMenu } from '@/components/ui/ProductMenu'
+import { ProductMenuShortcuts } from '@/components/ui/ProductMenu/ProductMenuShortcuts'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { withAuth } from '@/hooks/misc/withAuth'
@@ -28,13 +29,16 @@ export const RealtimeLayout = ({ title, children }: PropsWithChildren<RealtimeLa
const { data: project } = useSelectedProjectQuery()
const router = useRouter()
const page = router.pathname.split('/')[4]
+ const menu = generateRealtimeMenu(project)
return (
<ProjectLayout
product="Realtime"
browserTitle={{ section: title }}
- productMenu={<ProductMenu page={page} menu={generateRealtimeMenu(project)} />}
+ productMenu={<ProductMenu page={page} menu={menu} />}
+ isBlocking={false}
>
+ <ProductMenuShortcuts menu={menu} />
{children}
</ProjectLayout>
)
diff --git a/apps/studio/components/layouts/RealtimeLayout/RealtimeMenu.utils.ts b/apps/studio/components/layouts/RealtimeLayout/RealtimeMenu.utils.ts
index 3c2b36f093c..75d4c0bb29e 100644
--- a/apps/studio/components/layouts/RealtimeLayout/RealtimeMenu.utils.ts
+++ b/apps/studio/components/layouts/RealtimeLayout/RealtimeMenu.utils.ts
@@ -1,6 +1,7 @@
import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
import type { Project } from '@/data/projects/project-detail-query'
import { IS_PLATFORM } from '@/lib/constants'
+import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
export const generateRealtimeMenu = (project: Project | undefined): ProductMenuGroup[] => {
const ref = project?.ref ?? 'default'
@@ -15,6 +16,7 @@ export const generateRealtimeMenu = (project: Project | undefined): ProductMenuG
key: 'inspector',
url: `/project/${ref}/realtime/inspector`,
items: [],
+ shortcutId: SHORTCUT_IDS.NAV_REALTIME_INSPECTOR,
},
],
},
@@ -26,6 +28,7 @@ export const generateRealtimeMenu = (project: Project | undefined): ProductMenuG
key: 'policies',
url: `/project/${ref}/realtime/policies`,
items: [],
+ shortcutId: SHORTCUT_IDS.NAV_REALTIME_POLICIES,
},
...(showRealtimeSettings
? [
@@ -34,6 +37,7 @@ export const generateRealtimeMenu = (project: Project | undefined): ProductMenuG
key: 'settings',
url: `/project/${ref}/realtime/settings`,
items: [],
+ shortcutId: SHORTCUT_IDS.NAV_REALTIME_SETTINGS,
},
]
: []),
diff --git a/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.test.tsx b/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.test.tsx
index 2b42db09204..c44f85a3c50 100644
--- a/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.test.tsx
+++ b/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.test.tsx
@@ -42,6 +42,19 @@ const ACTIVE_FUNCTION_DETAIL_NAV_SHORTCUT_IDS = [
SHORTCUT_IDS.NAV_FUNCTION_DETAIL_OVERVIEW,
] satisfies ShortcutId[]
+const ACTIVE_REALTIME_NAV_SHORTCUT_IDS = [
+ ...ACTIVE_SHORTCUT_IDS,
+ SHORTCUT_IDS.NAV_REALTIME_INSPECTOR,
+] satisfies ShortcutId[]
+
+const ACTIVE_REALTIME_INSPECTOR_SHORTCUT_IDS = [
+ ...ACTIVE_SHORTCUT_IDS,
+ SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL,
+ SHORTCUT_IDS.INSPECTOR_TOGGLE_LISTENING,
+ SHORTCUT_IDS.INSPECTOR_BROADCAST,
+ SHORTCUT_IDS.INSPECTOR_COPY_MESSAGE,
+] satisfies ShortcutId[]
+
const ACTIVE_SURFACE_SHORTCUT_IDS = [
...ACTIVE_SHORTCUT_IDS,
SHORTCUT_IDS.AUTH_USERS_REFRESH,
@@ -168,6 +181,25 @@ describe('ShortcutsReferenceSheet', () => {
expect(screen.getByText('Go to Overview')).toBeInTheDocument()
})
+ it('shows the realtime navigation section when realtime shortcuts are active', async () => {
+ renderShortcutsReferenceSheet(ACTIVE_REALTIME_NAV_SHORTCUT_IDS)
+
+ expect(await screen.findByText('Global Navigation')).toBeInTheDocument()
+ expect(screen.getByText('Realtime Navigation')).toBeInTheDocument()
+ expect(screen.getByText('Go to Inspector')).toBeInTheDocument()
+ })
+
+ it('uses human labels for realtime inspector shortcut groups', async () => {
+ renderShortcutsReferenceSheet(ACTIVE_REALTIME_INSPECTOR_SHORTCUT_IDS)
+
+ expect(await screen.findByText('Realtime Inspector')).toBeInTheDocument()
+ expect(screen.getByText('Join a channel')).toBeInTheDocument()
+ expect(screen.getByText('Start/Stop listening')).toBeInTheDocument()
+ expect(screen.getByText('Broadcast a message')).toBeInTheDocument()
+ expect(screen.getByText('Copy selected message')).toBeInTheDocument()
+ expect(screen.queryByText('realtime-inspector')).not.toBeInTheDocument()
+ })
+
it('uses human labels for active surface shortcut groups', async () => {
renderShortcutsReferenceSheet(ACTIVE_SURFACE_SHORTCUT_IDS)
diff --git a/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.tsx b/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.tsx
index 76b7451a789..f12e5cf153e 100644
--- a/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.tsx
+++ b/apps/studio/components/ui/GlobalShortcuts/ShortcutsReferenceSheet.tsx
@@ -55,6 +55,7 @@ const GROUP_LABELS: Record<string, string> = {
nav: 'Navigation',
'operation-queue': 'Operation Queue',
results: 'Results',
+ 'realtime-inspector': 'Realtime Inspector',
'schema-visualizer': 'Schema Visualizer',
shortcuts: 'Shortcuts',
'sql-editor': 'SQL Editor',
diff --git a/apps/studio/state/shortcuts/referenceGroups.ts b/apps/studio/state/shortcuts/referenceGroups.ts
index 545cea9c947..a9bb1461b6f 100644
--- a/apps/studio/state/shortcuts/referenceGroups.ts
+++ b/apps/studio/state/shortcuts/referenceGroups.ts
@@ -5,6 +5,7 @@ export const SHORTCUT_REFERENCE_GROUPS = {
NAVIGATION_STORAGE: 'navigation.storage',
NAVIGATION_FUNCTIONS: 'navigation.functions',
NAVIGATION_FUNCTION_DETAIL: 'navigation.function-detail',
+ NAVIGATION_REALTIME: 'navigation.realtime',
} as const
export const SHORTCUT_REFERENCE_GROUP_LABELS: Record<string, string> = {
@@ -14,6 +15,7 @@ export const SHORTCUT_REFERENCE_GROUP_LABELS: Record<string, string> = {
[SHORTCUT_REFERENCE_GROUPS.NAVIGATION_STORAGE]: 'Storage Navigation',
[SHORTCUT_REFERENCE_GROUPS.NAVIGATION_FUNCTIONS]: 'Edge Functions Navigation',
[SHORTCUT_REFERENCE_GROUPS.NAVIGATION_FUNCTION_DETAIL]: 'Edge Function Tabs',
+ [SHORTCUT_REFERENCE_GROUPS.NAVIGATION_REALTIME]: 'Realtime Navigation',
}
export const SHORTCUT_REFERENCE_GROUP_ORDER = [
@@ -31,6 +33,8 @@ export const SHORTCUT_REFERENCE_GROUP_ORDER = [
SHORTCUT_REFERENCE_GROUPS.NAVIGATION_FUNCTION_DETAIL,
'functions-detail',
'functions-overview',
+ SHORTCUT_REFERENCE_GROUPS.NAVIGATION_REALTIME,
+ 'realtime-inspector',
'logs-preview',
'nav',
'ai-assistant',
diff --git a/apps/studio/state/shortcuts/registry.ts b/apps/studio/state/shortcuts/registry.ts
index 26366888cea..39e45ec9d21 100644
--- a/apps/studio/state/shortcuts/registry.ts
+++ b/apps/studio/state/shortcuts/registry.ts
@@ -15,6 +15,11 @@ import {
} from './registry/functions-overview'
import { LIST_PAGE_SHORTCUT_IDS, listPageRegistry } from './registry/list-page'
import { LOGS_PREVIEW_SHORTCUT_IDS, logsPreviewRegistry } from './registry/logs-preview'
+import {
+ REALTIME_INSPECTOR_SHORTCUT_IDS,
+ realtimeInspectorRegistry,
+} from './registry/realtime-inspector'
+import { REALTIME_NAV_SHORTCUT_IDS, realtimeNavRegistry } from './registry/realtime-nav'
import {
SCHEMA_VISUALIZER_SHORTCUT_IDS,
schemaVisualizerRegistry,
@@ -110,6 +115,11 @@ export const SHORTCUT_IDS = {
// Per-function Overview tab shortcuts (intervals, refresh, open logs)
...FUNCTIONS_OVERVIEW_SHORTCUT_IDS,
+ // Realtime sub-page navigation chords
+ ...REALTIME_NAV_SHORTCUT_IDS,
+ // Realtime Inspector page shortcuts
+ ...REALTIME_INSPECTOR_SHORTCUT_IDS,
+
// LogsPreviewer shortcuts (Function Logs, Function Invocations, Logs Explorer)
...LOGS_PREVIEW_SHORTCUT_IDS,
} as const
@@ -415,6 +425,11 @@ export const SHORTCUT_DEFINITIONS: Record<ShortcutId, ShortcutDefinition> = {
// Per-function Overview tab shortcut registration
...functionsOverviewRegistry,
+ // Realtime sub-page navigation chord registration
+ ...realtimeNavRegistry,
+ // Realtime Inspector page shortcut registration
+ ...realtimeInspectorRegistry,
+
// LogsPreviewer shortcut registration
...logsPreviewRegistry,
}
diff --git a/apps/studio/state/shortcuts/registry/realtime-inspector.ts b/apps/studio/state/shortcuts/registry/realtime-inspector.ts
new file mode 100644
index 00000000000..aad91901e10
--- /dev/null
+++ b/apps/studio/state/shortcuts/registry/realtime-inspector.ts
@@ -0,0 +1,57 @@
+import { RegistryDefinations } from '../types'
+
+/**
+ * Shortcuts scoped to the Realtime Inspector page.
+ *
+ * Active only while the inspector is mounted. All use `Shift+<letter>` to
+ * avoid conflicting with the global `Mod+` shortcuts and the multi-step nav
+ * chords.
+ */
+export const REALTIME_INSPECTOR_SHORTCUT_IDS = {
+ INSPECTOR_JOIN_CHANNEL: 'realtime-inspector.join-channel',
+ INSPECTOR_TOGGLE_LISTENING: 'realtime-inspector.toggle-listening',
+ INSPECTOR_TOGGLE_FILTERS: 'realtime-inspector.toggle-filters',
+ INSPECTOR_BROADCAST: 'realtime-inspector.broadcast',
+ INSPECTOR_COPY_MESSAGE: 'realtime-inspector.copy-message',
+}
+
+export type RealtimeInspectorShortcutId =
+ (typeof REALTIME_INSPECTOR_SHORTCUT_IDS)[keyof typeof REALTIME_INSPECTOR_SHORTCUT_IDS]
+
+export const realtimeInspectorRegistry: RegistryDefinations<RealtimeInspectorShortcutId> = {
+ [REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL]: {
+ id: REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_JOIN_CHANNEL,
+ label: 'Join a channel',
+ sequence: ['Shift+J'],
+ showInSettings: false,
+ options: { ignoreInputs: true, registerInCommandMenu: true },
+ },
+ [REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_TOGGLE_LISTENING]: {
+ id: REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_TOGGLE_LISTENING,
+ label: 'Start/Stop listening',
+ sequence: ['Shift+L'],
+ showInSettings: false,
+ options: { ignoreInputs: true, registerInCommandMenu: true },
+ },
+ [REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_TOGGLE_FILTERS]: {
+ id: REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_TOGGLE_FILTERS,
+ label: 'Toggle filters',
+ sequence: ['Shift+F'],
+ showInSettings: false,
+ options: { ignoreInputs: true, registerInCommandMenu: true },
+ },
+ [REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_BROADCAST]: {
+ id: REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_BROADCAST,
+ label: 'Broadcast a message',
+ sequence: ['Shift+B'],
+ showInSettings: false,
+ options: { ignoreInputs: true, registerInCommandMenu: true },
+ },
+ [REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_COPY_MESSAGE]: {
+ id: REALTIME_INSPECTOR_SHORTCUT_IDS.INSPECTOR_COPY_MESSAGE,
+ label: 'Copy selected message',
+ sequence: ['Mod+Shift+C'],
+ showInSettings: false,
+ options: { ignoreInputs: true, registerInCommandMenu: true },
+ },
+}
diff --git a/apps/studio/state/shortcuts/registry/realtime-nav.ts b/apps/studio/state/shortcuts/registry/realtime-nav.ts
new file mode 100644
index 00000000000..f19234aaa98
--- /dev/null
+++ b/apps/studio/state/shortcuts/registry/realtime-nav.ts
@@ -0,0 +1,43 @@
+import { SHORTCUT_REFERENCE_GROUPS } from '../referenceGroups'
+import { RegistryDefinations } from '../types'
+
+/**
+ * Contextual chords for jumping between Realtime sub-pages — `R + <letter>`.
+ *
+ * Active only while RealtimeLayout is mounted (i.e. the user is somewhere
+ * under `/project/<ref>/realtime/*`). Mirrors the database-nav / auth-nav /
+ * functions-nav pattern: the leading `R` is layout-scoped so it doesn't burn a
+ * global key.
+ */
+export const REALTIME_NAV_SHORTCUT_IDS = {
+ NAV_REALTIME_INSPECTOR: 'nav.realtime-inspector',
+ NAV_REALTIME_POLICIES: 'nav.realtime-policies',
+ NAV_REALTIME_SETTINGS: 'nav.realtime-settings',
+}
+
+export type RealtimeNavShortcutId =
+ (typeof REALTIME_NAV_SHORTCUT_IDS)[keyof typeof REALTIME_NAV_SHORTCUT_IDS]
+
+export const realtimeNavRegistry: RegistryDefinations<RealtimeNavShortcutId> = {
+ [REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_INSPECTOR]: {
+ id: REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_INSPECTOR,
+ label: 'Go to Inspector',
+ sequence: ['R', 'I'],
+ showInSettings: false,
+ referenceGroup: SHORTCUT_REFERENCE_GROUPS.NAVIGATION_REALTIME,
+ },
+ [REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_POLICIES]: {
+ id: REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_POLICIES,
+ label: 'Go to Policies',
+ sequence: ['R', 'P'],
+ showInSettings: false,
+ referenceGroup: SHORTCUT_REFERENCE_GROUPS.NAVIGATION_REALTIME,
+ },
+ [REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_SETTINGS]: {
+ id: REALTIME_NAV_SHORTCUT_IDS.NAV_REALTIME_SETTINGS,
+ label: 'Go to Settings',
+ sequence: ['R', 'S'],
+ showInSettings: false,
+ referenceGroup: SHORTCUT_REFERENCE_GROUPS.NAVIGATION_REALTIME,
+ },
+}