Skip to content

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

feat(studio): update query pattern section in query details (#38876)

kemal.earth4978d24adc9e
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
index b792220b714..78f7b829128 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryDetail.tsx
@@ -1,10 +1,11 @@
-import { Lightbulb } from 'lucide-react'
+import { Lightbulb, ChevronsUpDown, Expand } from 'lucide-react'
import { useEffect, useState } from 'react'
import dynamic from 'next/dynamic'
import dayjs from 'dayjs'
import { formatSql } from 'lib/formatSql'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, cn } from 'ui'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { QueryPanelContainer, QueryPanelSection } from './QueryPanel'
import {
QUERY_PERFORMANCE_COLUMNS,
@@ -38,6 +39,8 @@ export const QueryDetail = ({ selectedRow, onClickViewSuggestion }: QueryDetailP
}
}, [selectedRow])
+ const [isExpanded, setIsExpanded] = useState(false)
+
const formatDuration = (seconds: number) => {
const dur = dayjs.duration(seconds, 'seconds')
@@ -56,29 +59,56 @@ export const QueryDetail = ({ selectedRow, onClickViewSuggestion }: QueryDetailP
return (
<QueryPanelContainer>
- <QueryPanelSection>
- <h4 className="mb-2">Query pattern</h4>
- <SqlMonacoBlock value={query} height={310} lineNumbers="off" wrapperClassName="pl-3" />
- {isLinterWarning && (
- <Alert_Shadcn_
- variant="default"
- className="mt-2 border-brand-400 bg-alternative [&>svg]:p-0.5 [&>svg]:bg-transparent [&>svg]:text-brand"
+ <QueryPanelSection className="pt-2 border-b relative">
+ <h4 className="mb-4">Query pattern</h4>
+ <div
+ className={cn(
+ 'overflow-hidden pb-0 z-0 relative transition-all duration-300',
+ isExpanded ? 'h-[348px]' : 'h-[120px]'
+ )}
+ >
+ <SqlMonacoBlock
+ value={query}
+ height={322}
+ lineNumbers="off"
+ wrapperClassName={cn('pl-3 bg-surface-100', !isExpanded && 'pointer-events-none')}
+ />
+ {isLinterWarning && (
+ <Alert_Shadcn_
+ variant="default"
+ className="mt-2 border-brand-400 bg-alternative [&>svg]:p-0.5 [&>svg]:bg-transparent [&>svg]:text-brand"
+ >
+ <Lightbulb />
+ <AlertTitle_Shadcn_>Suggested optimization: Add an index</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Adding an index will help this query execute faster
+ </AlertDescription_Shadcn_>
+ <AlertDescription_Shadcn_>
+ <Button className="mt-3" onClick={() => onClickViewSuggestion()}>
+ View suggestion
+ </Button>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ </div>
+ <div
+ className={cn(
+ 'absolute left-0 bottom-0 w-full bg-gradient-to-t from-black/30 to-transparent h-24 transition-opacity duration-300',
+ isExpanded && 'opacity-0 pointer-events-none'
+ )}
+ />
+ <div className="absolute -bottom-[13px] left-0 right-0 w-full flex items-center justify-center z-10">
+ <Button
+ type="default"
+ className="rounded-full"
+ icon={<ChevronsUpDown />}
+ onClick={() => setIsExpanded(!isExpanded)}
>
- <Lightbulb />
- <AlertTitle_Shadcn_>Suggested optimization: Add an index</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Adding an index will help this query execute faster
- </AlertDescription_Shadcn_>
- <AlertDescription_Shadcn_>
- <Button className="mt-3" onClick={() => onClickViewSuggestion()}>
- View suggestion
- </Button>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
+ {isExpanded ? 'Collapse' : 'Expand'}
+ </Button>
+ </div>
</QueryPanelSection>
- <div className="border-t" />
- <QueryPanelSection className="pb-3">
+ <QueryPanelSection className="pb-3 pt-6">
<h4 className="mb-2">Metadata</h4>
<ul className="flex flex-col gap-y-3 divide-y divide-dashed">
{report
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
index c4748326ad4..57c33a87f59 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPanel.tsx
@@ -7,7 +7,7 @@ export const QueryPanelContainer = ({
children,
className,
}: PropsWithChildren<{ className?: string }>) => (
- <div className={cn('flex flex-col gap-y-6 py-4', className)}>{children}</div>
+ <div className={cn('flex flex-col gap-y-0 py-4', className)}>{children}</div>
)
export const QueryPanelSection = ({