// @ts-nocheck import { PermissionAction } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import { isEqual } from 'lodash' import { ExternalLink, Loader2, Megaphone } from 'lucide-react' import Link from 'next/link' 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' 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 { 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' } const NoResultAlert = ({ enabled, hasChannelSet, showSendMessage, }: { enabled: boolean hasChannelSet: boolean showSendMessage: () => void }) => { const { ref } = useParams() const { can: canReadAPIKeys, isLoading: isLoadingPermissions } = useAsyncCheckPermissions( PermissionAction.READ, 'service_api_keys' ) 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 { ref } = useParams() const { data: org } = useSelectedOrganizationQuery() const { mutate: sendEvent } = useSendEventMutation() useEffect(() => { if (!data) return const found = data.find((datum) => datum.id === focusedLog?.id) if (!found) { setFocusedLog(null) } }, [stringData]) if (!data) return null return ( <>
{enabled && (
Listening
{data.length > 0 ? data.length >= 100 ? `Found a large number of messages, showing only the latest 100...` : `Found ${data.length} messages...` : `No message found yet...`}
)} { 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 ( { sendEvent({ action: 'realtime_inspector_message_clicked', groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown', }, }) setFocusedLog(row) }} /> ) }, noRowsFallback: (
), }} />
setFocusedLog(null)} log={focusedLog} />
) } export default MessagesTable