1- import { memo , useMemo , useState } from 'react' ;
1+ import { memo , useEffect , useMemo , useState } from 'react' ;
22import Link from 'next/link' ;
33import cx from 'classnames' ;
44import { add } from 'date-fns' ;
@@ -8,9 +8,10 @@ import {
88 ChartConfigWithDateRange ,
99 DisplayType ,
1010} from '@hyperdx/common-utils/dist/types' ;
11- import { Box , Button , Code , Collapse , Text } from '@mantine/core' ;
11+ import { Button , Code , Group , Modal , Text } from '@mantine/core' ;
1212import { useDisclosure } from '@mantine/hooks' ;
1313import { notifications } from '@mantine/notifications' ;
14+ import { IconArrowsDiagonal } from '@tabler/icons-react' ;
1415
1516import { formatResponseForTimeChart , useTimeChartSettings } from '@/ChartUtils' ;
1617import { convertGranularityToSeconds } from '@/ChartUtils' ;
@@ -26,7 +27,6 @@ function DBTimeChartComponent({
2627 config,
2728 enabled = true ,
2829 logReferenceTimestamp,
29- onError,
3030 onSettled,
3131 onTimeRangeSelect,
3232 queryKeyPrefix,
@@ -39,7 +39,6 @@ function DBTimeChartComponent({
3939 config : ChartConfigWithDateRange ;
4040 enabled ?: boolean ;
4141 logReferenceTimestamp ?: number ;
42- onError ?: ( error : Error | ClickHouseQueryError ) => void ;
4342 onSettled ?: ( ) => void ;
4443 onTimeRangeSelect ?: ( start : Date , end : Date ) => void ;
4544 queryKeyPrefix ?: string ;
@@ -49,6 +48,7 @@ function DBTimeChartComponent({
4948 showLegend ?: boolean ;
5049 sourceId ?: string ;
5150} ) {
51+ const [ isErrorExpanded , errorExpansion ] = useDisclosure ( false ) ;
5252 const {
5353 displayType : displayTypeProp ,
5454 dateRange,
@@ -67,9 +67,14 @@ function DBTimeChartComponent({
6767 placeholderData : ( prev : any ) => prev ,
6868 queryKey : [ queryKeyPrefix , queriedConfig ] ,
6969 enabled,
70- onError,
7170 } ) ;
7271
72+ useEffect ( ( ) => {
73+ if ( ! isError && isErrorExpanded ) {
74+ errorExpansion . close ( ) ;
75+ }
76+ } , [ isError , isErrorExpanded , errorExpansion ] ) ;
77+
7378 const isLoadingOrPlaceholder = isLoading || isPlaceholderData ;
7479 const { data : source } = useSource ( { id : sourceId } ) ;
7580
@@ -178,31 +183,48 @@ function DBTimeChartComponent({
178183 Loading Chart Data...
179184 </ div >
180185 ) : isError ? (
181- < div className = "h-100 w-100 align-items-center justify-content-center text-muted overflow-auto" >
186+ < div className = "h-100 w-100 d-flex g-1 flex-column align-items-center justify-content-center text-muted overflow-auto" >
182187 < Text ta = "center" size = "sm" mt = "sm" >
183188 Error loading chart, please check your query or try again later.
184189 </ Text >
185- < Box mt = "sm" >
186- < Text my = "sm" size = "sm" ta = "center" >
187- Error Message:
188- </ Text >
189- < Code
190- block
191- style = { {
192- whiteSpace : 'pre-wrap' ,
193- } }
194- >
195- { error . message }
196- </ Code >
197- { error instanceof ClickHouseQueryError && (
198- < >
199- < Text my = "sm" size = "sm" ta = "center" >
200- Sent Query:
201- </ Text >
202- < SQLPreview data = { error ?. query } />
203- </ >
204- ) }
205- </ Box >
190+ < Button
191+ className = "mx-auto"
192+ variant = "subtle"
193+ color = "red"
194+ onClick = { ( ) => errorExpansion . open ( ) }
195+ >
196+ < Group gap = "xxs" >
197+ < IconArrowsDiagonal size = { 16 } />
198+ See Error Details
199+ </ Group >
200+ </ Button >
201+ < Modal
202+ opened = { isErrorExpanded }
203+ onClose = { ( ) => errorExpansion . close ( ) }
204+ title = "Error Details"
205+ >
206+ < Group align = "start" >
207+ < Text size = "sm" ta = "center" >
208+ Error Message:
209+ </ Text >
210+ < Code
211+ block
212+ style = { {
213+ whiteSpace : 'pre-wrap' ,
214+ } }
215+ >
216+ { error . message }
217+ </ Code >
218+ { error instanceof ClickHouseQueryError && (
219+ < >
220+ < Text my = "sm" size = "sm" ta = "center" >
221+ Sent Query:
222+ </ Text >
223+ < SQLPreview data = { error ?. query } />
224+ </ >
225+ ) }
226+ </ Group >
227+ </ Modal >
206228 </ div >
207229 ) : graphResults . length === 0 ? (
208230 < div className = "d-flex h-100 w-100 align-items-center justify-content-center text-muted" >
0 commit comments