import type { ComponentProps } from 'react' import { useMemo } from 'react' import { Button } from 'ui' import { Chart, ChartActions, ChartLoadingState, ChartMetric } from 'ui-patterns/Chart' import { PageContainer } from 'ui-patterns/PageContainer' import { PageSection, PageSectionAside, PageSectionContent, PageSectionMeta, PageSectionSummary, } from 'ui-patterns/PageSection' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import { EdgeFunctionChartEmptyState } from './EdgeFunctionChartEmptyState' import { EdgeFunctionInvocationsChart } from './EdgeFunctionInvocationsChart' import { EDGE_FUNCTION_CHART_INTERVALS, formatRate, getChartEmptyStateCopy, getSegmentedButtonClassName, } from './EdgeFunctionOverview.utils' import type { InvocationChartDatum, InvocationUpdateAnnotation } from './EdgeFunctionOverview.utils' import { toAlertError } from './EdgeFunctionRecentErrors.utils' import AlertError from '@/components/ui/AlertError' import type { ChartIntervals } from '@/types' interface EdgeFunctionInvocationsSectionProps { interval: string onIntervalChange: (interval: string) => void selectedInterval: ChartIntervals actions?: ComponentProps['actions'] totalInvocationCount: number totalErrorCount: number totalWarningCount: number isLoadingFunction: boolean isErrorFunction: boolean functionError?: unknown isLoadingChart: boolean isErrorChart: boolean chartErrorMessage?: string chartData: InvocationChartDatum[] onChartClick: () => void updateAnnotation?: InvocationUpdateAnnotation } export const EdgeFunctionInvocationsSection = ({ interval, onIntervalChange, selectedInterval, actions, totalInvocationCount, totalErrorCount, totalWarningCount, isLoadingFunction, isErrorFunction, functionError, isLoadingChart, isErrorChart, chartErrorMessage, chartData, onChartClick, updateAnnotation, }: EdgeFunctionInvocationsSectionProps) => { const dateTimeFormat = selectedInterval.format ?? 'MMM D, h:mma' const emptyStateCopy = useMemo( () => getChartEmptyStateCopy('invocations', isErrorChart, chartErrorMessage), [chartErrorMessage, isErrorChart] ) return (
{EDGE_FUNCTION_CHART_INTERVALS.map((item, index) => { return ( ) })}
{isLoadingFunction && } {isErrorFunction && ( )}
{isLoadingChart ? ( ) : isErrorChart || chartData.length === 0 ? ( ) : ( )}
) }