import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, CodeBlock, cn, } from 'ui' import { QUERY_PERFORMANCE_REPORTS, QUERY_PERFORMANCE_REPORT_TYPES, } from './QueryPerformance.constants' import { format } from 'sql-formatter' import { useEffect, useState } from 'react' import { QueryPanelContainer, QueryPanelSection } from './QueryPanel' import { Lightbulb } from 'lucide-react' interface QueryDetailProps { reportType: QUERY_PERFORMANCE_REPORT_TYPES selectedRow: any onClickViewSuggestion: () => void } export const QueryDetail = ({ reportType, selectedRow, onClickViewSuggestion, }: QueryDetailProps) => { // [Joshen] TODO implement this logic once the linter rules are in const isLinterWarning = false const report = QUERY_PERFORMANCE_REPORTS[reportType] const [query, setQuery] = useState(selectedRow?.['query']) useEffect(() => { if (selectedRow !== undefined) { try { const formattedQuery = format(selectedRow['query'], { language: 'postgresql', keywordCase: 'lower', }) setQuery(formattedQuery) } catch (err) { setQuery(selectedRow['query']) } } }, [selectedRow]) return (

Query pattern

code]:m-0 [&>code>span]:flex [&>code>span]:flex-wrap' )} /> {isLinterWarning && ( Suggested optimization: Add an index Adding an index will help this query execute faster )}
{report .filter((x) => x.id !== 'query') .map((x) => { const isTime = x.name.includes('time') const formattedValue = isTime ? `${selectedRow?.[x.id].toFixed(2)}ms` : String(selectedRow?.[x.id]) return (

{x.name}

{formattedValue}

) })}
) }