Files
supabase/apps/studio/components/interfaces/Functions/EdgeFunctionOverview/EdgeFunctionPerformanceSection.tsx
Jordi Enric b84aafd1a6 fix(ui-patterns): fix chart y-axis label clipping (#47890)
## Summary
- Chart y-axis tick labels were clipped (e.g. edge function overview
execution time charts) because `chart-line.tsx`/`chart-bar.tsx`
hardcoded a `-40` left margin regardless of the actual
`YAxisProps.width` passed in.
- Margin now scales with the configured axis width.

## Test plan
- [ ] Visually check edge function overview performance/usage charts
render full tick labels (e.g. "195ms" instead of "ms")

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
  - Improved chart layout and alignment across line and bar charts.
- Adjusted Y-axis spacing so labels display more consistently when axes
are shown or hidden.
- Removed unnecessary fixed spacing from Edge Function performance, CPU,
and memory charts.
- Tightened spacing around chart timestamp rows for a more compact
presentation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-14 10:05:07 +02:00

104 lines
3.2 KiB
TypeScript

import { useMemo } from 'react'
import { ChartMetric } from 'ui-patterns/Chart'
import { PageContainer } from 'ui-patterns/PageContainer'
import {
PageSection,
PageSectionContent,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { getExecutionTooltipDetails } from './EdgeFunctionMetricTooltipDetails'
import {
EXECUTION_TIME_CHART_CONFIG,
formatMetric,
getChartEmptyStateCopy,
} from './EdgeFunctionOverview.utils'
import type { EdgeFunctionChartDatum } from './EdgeFunctionOverview.utils'
import { EdgeFunctionTimeSeriesChartCard } from './EdgeFunctionTimeSeriesChartCard'
interface EdgeFunctionPerformanceSectionProps {
data: EdgeFunctionChartDatum[]
dateTimeFormat: string
isLoading: boolean
isError: boolean
errorMessage?: string
averageExecutionTime: number
maxExecutionTime: number
}
export const EdgeFunctionPerformanceSection = ({
data,
dateTimeFormat,
isLoading,
isError,
errorMessage,
averageExecutionTime,
maxExecutionTime,
}: EdgeFunctionPerformanceSectionProps) => {
const emptyStateCopy = getChartEmptyStateCopy('execution time', isError, errorMessage)
const tooltipDetails = useMemo(
() => getExecutionTooltipDetails(averageExecutionTime),
[averageExecutionTime]
)
const metrics = (
<div className="flex flex-wrap gap-x-8 gap-y-4">
<ChartMetric
label="Average Execution Time"
value={formatMetric(averageExecutionTime, 'ms')}
tooltip="Average execution time of function invocations"
/>
<ChartMetric
label="Max Execution Time"
value={formatMetric(maxExecutionTime, 'ms')}
tooltip="Maximum execution time of function invocations"
/>
</div>
)
return (
<PageSection>
<PageSectionContent>
<PageContainer size="full">
<div className="flex flex-col gap-6">
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>Performance</PageSectionTitle>
</PageSectionSummary>
</PageSectionMeta>
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<EdgeFunctionTimeSeriesChartCard
className="lg:col-span-2"
data={data}
dateTimeFormat={dateTimeFormat}
isLoading={isLoading}
isError={isError}
emptyTitle={emptyStateCopy.title}
emptyDescription={emptyStateCopy.description}
metrics={metrics}
dataKey="max_execution_time"
dataKeys={['avg_execution_time', 'max_execution_time']}
config={EXECUTION_TIME_CHART_CONFIG}
tooltipDetails={tooltipDetails}
referenceLines={[
{
y: averageExecutionTime,
label: 'average',
stroke: 'var(--foreground-default)',
strokeWidth: 1.5,
},
]}
yAxisProps={{
tickFormatter: (value: number) => `${Math.round(value)}ms`,
}}
/>
</div>
</div>
</PageContainer>
</PageSectionContent>
</PageSection>
)
}