import { Link } from '@tanstack/react-router' import { useParams } from 'common' import { isEqual } from 'lodash' import { ExternalLinkIcon, Loader2Icon, MegaphoneIcon } from 'lucide-react' import { useEffect, useState } from 'react' import DataGrid, { Row } from 'react-data-grid' import { Button, cn, IconBroadcast, IconDatabaseChanges, IconPresence } from 'ui' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import type { LogData } from './Messages.types' import MessageSelection from './MessageSelection' import NoChannelEmptyState from './NoChannelEmptyState' 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 { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { DOCS_URL } from '@/lib/constants' import { useTrack } from '@/lib/telemetry/track' import { SHORTCUT_IDS } from '@/state/shortcuts/registry' export const isErrorLog = (l: LogData) => { return l.message === 'SYSTEM' && l.metadata?.status === 'error' } const NoResultAlert = ({ enabled, hasChannelSet, showSendMessage, }: { enabled: boolean hasChannelSet: boolean showSendMessage: () => void }) => { const { ref } = useParams() const { can: canReadAPIKeys, isLoading: isLoadingPermissions } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.PROJECT.API_GATEWAY_KEYS_READ ) const broadcastButton = return (
{isLoadingPermissions ? ( ) : !canReadAPIKeys ? ( ) : !hasChannelSet ? ( ) : ( <> {enabled &&

No Realtime messages found

}

Realtime message logs will be shown here

Create a Broadcast message

Send a message in the channel

{enabled ? ( {broadcastButton} ) : ( broadcastButton )}

Join from another browser tab

Send messages between multiple clients

Listen to a table for changes

Tables must have realtime enabled

Not sure what to do?

Browse our documentation

)}
) } interface MessagesTableProps { enabled: boolean data?: LogData[] hasChannelSet: boolean showSendMessage: () => void } const MessagesTable = ({ enabled, hasChannelSet, data = [], showSendMessage, }: MessagesTableProps) => { const [focusedLog, setFocusedLog] = useState(null) const stringData = JSON.stringify(data) const track = useTrack() useEffect(() => { if (!data) return const found = data.find((datum) => datum.id === focusedLog?.id) if (!found) { setFocusedLog(null) } }, [stringData]) if (!data) return null return ( <>
{/* Persistent role="status" live region so screen readers announce when listening starts — a live region only announces updates to content it already contains. */}
{enabled && (
)}
{ return cn([ 'font-mono tracking-tight', isEqual(row, focusedLog) ? 'bg-scale-800 rdg-row--focused' : 'bg-200 hover:bg-scale-300 cursor-pointer', isErrorLog(row) && 'bg-warning-300!', ]) }} rows={data} rowKeyGetter={(row) => row.id} renderers={{ renderRow(idx, props) { const { row } = props return ( { track('realtime_inspector_message_clicked') setFocusedLog(row) }} /> ) }, noRowsFallback: (
), }} />
setFocusedLog(null)} log={focusedLog} />
) } export default MessagesTable