@@ -4,6 +4,7 @@ import { ArrowCounterClockwiseIcon, BugIcon } from '@phosphor-icons/react';
44import dynamic from 'next/dynamic' ;
55import { useCallback , useState } from 'react' ;
66import { Area , CartesianGrid , Legend , Tooltip , XAxis , YAxis } from 'recharts' ;
7+ import { METRIC_COLORS , METRICS } from '@/components/charts/metrics-constants' ;
78import { Button } from '@/components/ui/button' ;
89import { ErrorChartTooltip } from './error-chart-tooltip' ;
910
@@ -40,40 +41,53 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
4041 setIsZoomed ( false ) ;
4142 } , [ ] ) ;
4243
43- const handleBrushChange = useCallback ( ( brushData : any ) => {
44- if (
45- brushData &&
46- brushData . startIndex !== undefined &&
47- brushData . endIndex !== undefined
48- ) {
49- setZoomDomain ( {
50- startIndex : brushData . startIndex ,
51- endIndex : brushData . endIndex ,
52- } ) ;
53- setIsZoomed ( true ) ;
54- }
55- } , [ ] ) ;
44+ const handleBrushChange = useCallback (
45+ ( brushData : { startIndex ?: number ; endIndex ?: number } ) => {
46+ if (
47+ brushData &&
48+ brushData . startIndex !== undefined &&
49+ brushData . endIndex !== undefined
50+ ) {
51+ setZoomDomain ( {
52+ startIndex : brushData . startIndex ,
53+ endIndex : brushData . endIndex ,
54+ } ) ;
55+ setIsZoomed ( true ) ;
56+ }
57+ } ,
58+ [ ]
59+ ) ;
5660
5761 if ( ! errorChartData . length ) {
5862 return (
5963 < div className = "flex h-full items-center justify-center rounded-lg border border-sidebar-border bg-sidebar/20 p-8 shadow-sm" >
60- < div className = "text-center max-w-md" >
64+ < div className = "max-w-md text-center " >
6165 < BugIcon
62- className = "mx-auto h-8 w-8 text-muted-foreground mb-4 "
66+ className = "mx-auto mb-4 h-8 w-8 text-muted-foreground"
6367 weight = "duotone"
6468 />
6569 < h3 className = "mb-2 font-semibold text-sm" > No error trend data</ h3 >
6670 < p className = "text-muted-foreground text-xs leading-relaxed" >
67- Not enough data to display a trend chart. Error trends will appear here when your website encounters errors.
71+ Not enough data to display a trend chart. Error trends will appear
72+ here when your website encounters errors.
6873 </ p >
6974 </ div >
7075 </ div >
7176 ) ;
7277 }
7378
79+ // Get the error metrics with proper colors from the constants
80+ const totalErrorsMetric = METRICS . find ( ( m ) => m . key === 'total_errors' ) ;
81+ const affectedUsersMetric = METRICS . find ( ( m ) => m . key === 'affected_users' ) ;
82+
83+ const totalErrorsColor =
84+ totalErrorsMetric ?. color || METRIC_COLORS . bounce_rate . primary ;
85+ const affectedUsersColor =
86+ affectedUsersMetric ?. color || METRIC_COLORS . session_duration . primary ;
87+
7488 return (
7589 < div className = "flex h-full flex-col rounded-lg border border-sidebar-border bg-sidebar/10 shadow-sm" >
76- < div className = "flex items-center justify-between border-b border- sidebar-border p-4" >
90+ < div className = "flex items-center justify-between border-sidebar-border border-b p-4" >
7791 < div >
7892 < h3 className = "font-semibold text-base" > Error Trends</ h3 >
7993 < p className = "text-muted-foreground text-xs" >
@@ -121,8 +135,16 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
121135 y1 = "0"
122136 y2 = "1"
123137 >
124- < stop offset = "5%" stopColor = "hsl(var(--primary))" stopOpacity = { 0.25 } />
125- < stop offset = "95%" stopColor = "hsl(var(--primary))" stopOpacity = { 0.05 } />
138+ < stop
139+ offset = "5%"
140+ stopColor = { totalErrorsColor }
141+ stopOpacity = { 0.25 }
142+ />
143+ < stop
144+ offset = "95%"
145+ stopColor = { totalErrorsColor }
146+ stopOpacity = { 0.05 }
147+ />
126148 </ linearGradient >
127149 < linearGradient
128150 id = "colorAffectedUsers"
@@ -131,8 +153,16 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
131153 y1 = "0"
132154 y2 = "1"
133155 >
134- < stop offset = "5%" stopColor = "hsl(var(--chart-2))" stopOpacity = { 0.25 } />
135- < stop offset = "95%" stopColor = "hsl(var(--chart-2))" stopOpacity = { 0.05 } />
156+ < stop
157+ offset = "5%"
158+ stopColor = { affectedUsersColor }
159+ stopOpacity = { 0.25 }
160+ />
161+ < stop
162+ offset = "95%"
163+ stopColor = { affectedUsersColor }
164+ stopOpacity = { 0.05 }
165+ />
136166 </ linearGradient >
137167 </ defs >
138168 < CartesianGrid
@@ -181,7 +211,7 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
181211 fill = "url(#colorTotalErrors)"
182212 fillOpacity = { 1 }
183213 name = "Total Errors"
184- stroke = "hsl(var(--primary))"
214+ stroke = { totalErrorsColor }
185215 strokeWidth = { 2 }
186216 type = "monotone"
187217 />
@@ -190,7 +220,7 @@ export const ErrorTrendsChart = ({ errorChartData }: ErrorTrendsChartProps) => {
190220 fill = "url(#colorAffectedUsers)"
191221 fillOpacity = { 1 }
192222 name = "Affected Users"
193- stroke = "hsl(var(--chart-2))"
223+ stroke = { affectedUsersColor }
194224 strokeWidth = { 2 }
195225 type = "monotone"
196226 />
0 commit comments