1
- import { memo , useMemo , useState } from 'react' ;
1
+ import { memo , useEffect , useMemo , useState } from 'react' ;
2
2
import Link from 'next/link' ;
3
3
import cx from 'classnames' ;
4
4
import { add } from 'date-fns' ;
@@ -8,9 +8,10 @@ import {
8
8
ChartConfigWithDateRange ,
9
9
DisplayType ,
10
10
} 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' ;
12
12
import { useDisclosure } from '@mantine/hooks' ;
13
13
import { notifications } from '@mantine/notifications' ;
14
+ import { IconArrowsDiagonal } from '@tabler/icons-react' ;
14
15
15
16
import { formatResponseForTimeChart , useTimeChartSettings } from '@/ChartUtils' ;
16
17
import { convertGranularityToSeconds } from '@/ChartUtils' ;
@@ -26,7 +27,6 @@ function DBTimeChartComponent({
26
27
config,
27
28
enabled = true ,
28
29
logReferenceTimestamp,
29
- onError,
30
30
onSettled,
31
31
onTimeRangeSelect,
32
32
queryKeyPrefix,
@@ -39,7 +39,6 @@ function DBTimeChartComponent({
39
39
config : ChartConfigWithDateRange ;
40
40
enabled ?: boolean ;
41
41
logReferenceTimestamp ?: number ;
42
- onError ?: ( error : Error | ClickHouseQueryError ) => void ;
43
42
onSettled ?: ( ) => void ;
44
43
onTimeRangeSelect ?: ( start : Date , end : Date ) => void ;
45
44
queryKeyPrefix ?: string ;
@@ -49,6 +48,7 @@ function DBTimeChartComponent({
49
48
showLegend ?: boolean ;
50
49
sourceId ?: string ;
51
50
} ) {
51
+ const [ isErrorExpanded , errorExpansion ] = useDisclosure ( false ) ;
52
52
const {
53
53
displayType : displayTypeProp ,
54
54
dateRange,
@@ -67,9 +67,14 @@ function DBTimeChartComponent({
67
67
placeholderData : ( prev : any ) => prev ,
68
68
queryKey : [ queryKeyPrefix , queriedConfig ] ,
69
69
enabled,
70
- onError,
71
70
} ) ;
72
71
72
+ useEffect ( ( ) => {
73
+ if ( ! isError && isErrorExpanded ) {
74
+ errorExpansion . close ( ) ;
75
+ }
76
+ } , [ isError , isErrorExpanded , errorExpansion ] ) ;
77
+
73
78
const isLoadingOrPlaceholder = isLoading || isPlaceholderData ;
74
79
const { data : source } = useSource ( { id : sourceId } ) ;
75
80
@@ -178,31 +183,48 @@ function DBTimeChartComponent({
178
183
Loading Chart Data...
179
184
</ div >
180
185
) : 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" >
182
187
< Text ta = "center" size = "sm" mt = "sm" >
183
188
Error loading chart, please check your query or try again later.
184
189
</ 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 >
206
228
</ div >
207
229
) : graphResults . length === 0 ? (
208
230
< div className = "d-flex h-100 w-100 align-items-center justify-content-center text-muted" >
0 commit comments