import { useRef, useState } from 'react' import { ResizableHandle, ResizablePanel, Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger, } from 'ui' import { LogDetail } from './components/LogDetail' import { LogStepSummary } from './components/LogTimeline' import { LogUser } from './components/LogUser' import { LogTimestampHeader, RequestTimeline } from './components/RequestTimeline' import { useLogEnrichment } from './components/useLogEnrichment' import { LogSelectionActions } from './LogSelectionActions' import { LogPanelCloseButton, LogPanelNavigation, } from './ServiceFlow/components/ServiceFlowPanelControls' import { getLogDataForMetadataVisibility } from './ServiceFlowPanel.utils' import { ColumnSchema } from './UnifiedLogs.schema' import { QuerySearchParamsType } from './UnifiedLogs.types' import { getEventMessageDisplay, getRawLogData } from './UnifiedLogs.utils' import { JsonCodeBlock } from '@/components/ui/JsonCodeBlock' import { ShortcutBadge } from '@/components/ui/ShortcutBadge' import { useUnifiedLogsBackend } from '@/data/logs/unified-logs-infinite-query' import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { SHORTCUT_IDS } from '@/state/shortcuts/registry' const TAB_TRIGGER_CLASS_NAME = 'py-2.5 data-[state=active]:shadow-none' interface ServiceFlowPanelProps { dock: 'bottom' | 'right' setDock: (value: 'bottom' | 'right') => void selectedRows: ColumnSchema[] searchParameters: QuerySearchParamsType } export function ServiceFlowPanel({ dock, setDock, selectedRows, searchParameters, }: ServiceFlowPanelProps) { const [activeTab, setActiveTab] = useState('overview') const overviewTabRef = useRef(null) const [openedLog, setOpenedLog] = useState<{ fromId: string; log: ColumnSchema } | null>(null) const isRequestTimelineEnabled = useUnifiedLogsBackend(searchParameters) const hasMultiple = selectedRows.length > 1 const selectedRow = selectedRows[0] const activeLog = (openedLog && openedLog.fromId === selectedRow?.id ? openedLog.log : undefined) ?? selectedRow const isProcessLog = selectedRow?.log_type === 'compute' || selectedRow?.log_type === 'pipelines' const showTimeline = isRequestTimelineEnabled && !isProcessLog const showUser = !isProcessLog const tabs = [ 'overview', 'raw-json', ...(showTimeline ? ['timeline'] : []), ...(showUser ? ['user'] : []), ] const currentTab = tabs.includes(activeTab) ? activeTab : 'overview' const title = hasMultiple ? `${selectedRows.length} logs selected` : getEventMessageDisplay(activeLog?.log_type ?? '', activeLog?.event_message).message || activeLog?.id const handleSelectTimelineLog = (log: ColumnSchema) => { if (!selectedRow) return setOpenedLog(log.id === selectedRow.id ? null : { fromId: selectedRow.id, log }) setActiveTab('overview') overviewTabRef.current?.focus() } const { logsMetadata } = useIsFeatureEnabled(['logs:metadata']) const selectedJson = selectedRows.map((row) => getLogDataForMetadataVisibility(getRawLogData(row), logsMetadata) ) return ( <>
{/* Matches the table header height so the title lines up with the column labels */}
{!hasMultiple && activeLog ? ( ) : ( {title} )}
{hasMultiple ? (
{JSON.stringify(selectedJson, null, 2)}
) : ( Overview Raw JSON {showTimeline && ( Timeline )} {showUser && ( User )} {tabs.map((tab) => ( {tab === 'timeline' && selectedRow && activeLog && ( )} {tab === 'user' && activeLog && ( )} {(tab === 'overview' || tab === 'raw-json') && activeLog && ( } /> )} ))} )}
Extend selection
) } /** Shows a spinner in place of the log type icon while the open log's details load */ function OpenLogSummary({ log, searchParameters, }: { log: ColumnSchema searchParameters: QuerySearchParamsType }) { const { isLoading } = useLogEnrichment({ row: log, searchParameters, shouldFetch: false }) return }