Files
supabase/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceMetrics.tsx
kemal.earth 604be766a8 feat(studio): query performance metric cards (#38634)
* feat: remove tabs and unify columns

This removes the tabs from Query Performance with unified columns in the table.

* chore: remove unused imports

* chore: small adjustment to min max and mean time col size

* feat: original experiment with metric cards

* fix: height of table container on load

* feat: add percentage background for time consumed col

Adds a percentage based background colour for time consumed column and reshuffles some columns.

* feat: working metrics above rows

* feat: simplify stats + go back full width

* style: bring up percentage bar opacity

* chore: remove reportType again

* feat: add metric queries to reset function

* fix: type error for passing query metrics

* fix: query queries plural thing

* chore: remove next-env weirdness
2025-09-15 12:45:23 +01:00

51 lines
1.4 KiB
TypeScript

import { useMemo } from 'react'
import { Skeleton } from 'ui'
import { useQueryPerformanceQuery } from '../Reports/Reports.queries'
export const QueryPerformanceMetrics = () => {
const { data: queryMetrics, isLoading } = useQueryPerformanceQuery({
preset: 'queryMetrics',
})
const stats = useMemo(() => {
return [
{
title: queryMetrics?.[0]?.slow_queries === '1' ? 'Slow Query' : 'Slow Queries',
value: queryMetrics?.[0]?.slow_queries || '0',
},
{
title: 'Cache Hit Rate',
value: queryMetrics?.[0]?.cache_hit_rate || '0%',
},
{
title: 'Avg. Rows Per Call',
value: queryMetrics?.[0]?.avg_rows_per_call || '0',
},
]
}, [queryMetrics])
return (
<section className="px-6 pt-2 pb-4 flex flex-wrap gap-x-6 gap-y-2 w-full">
{stats.map((card, i) => (
<>
<div
key={i}
className="flex items-baseline gap-2 heading-subSection text-foreground-light"
>
{isLoading ? (
<Skeleton className="h-5 w-24" />
) : (
<>
<span className="text-foreground">{card.value}</span>
<span>{card.title}</span>
</>
)}
</div>
{i < stats.length - 1 && <span className="text-foreground-muted">/</span>}
</>
))}
</section>
)
}