1
- import { FunctionComponent } from "react" ;
1
+ import { FunctionComponent , useEffect , useState } from "react" ;
2
2
import {
3
3
DialogBackdrop ,
4
4
DialogBody ,
@@ -10,23 +10,46 @@ import {
10
10
DialogTitle ,
11
11
DialogTrigger ,
12
12
} from "@/components/ui/dialog" ;
13
- import { Text } from "@chakra-ui/react" ;
13
+ import { Box , Button , Clipboard , Text } from "@chakra-ui/react" ;
14
14
import { ExternalLink } from "@/components/externalLink" ;
15
15
import { FallbackProps , useErrorBoundary } from "react-error-boundary" ;
16
16
import { MappedIcon } from "@/components/mappedIcon" ;
17
+ import SplunkOtelWeb from "@splunk/otel-web" ;
18
+ import { capitalize , isEmpty , words } from "lodash" ;
17
19
18
20
export interface ErrorMessageProps extends FallbackProps {
19
21
icon ?: string ;
20
22
title ?: string ;
21
23
message ?: string ;
22
24
}
23
25
26
+ type ErrorDetail = { label : string ; value : string } ;
27
+ const clipboardText = ( detail : Array < ErrorDetail > ) =>
28
+ detail . map ( ( { label, value } ) => `${ label } : ${ value } ` ) . join ( "\n" ) ;
29
+
24
30
const ErrorMessage : FunctionComponent < ErrorMessageProps & FallbackProps > = ( {
25
31
icon = "exclamation-circle" ,
26
32
title = "An unexpected error has occurred" ,
27
33
message,
34
+ error,
28
35
} ) => {
29
36
const { resetBoundary } = useErrorBoundary ( ) ;
37
+ const [ errorDetails , setErrorDetails ] = useState < Array < ErrorDetail > > ( [ ] ) ;
38
+
39
+ useEffect ( ( ) => {
40
+ setErrorDetails (
41
+ Object . entries ( {
42
+ splunkSessionId : SplunkOtelWeb . getSessionId ( ) ,
43
+ timestamp : new Date ( ) . toISOString ( ) ,
44
+ detail :
45
+ error ?. reason ?. toString ( ) ?? error ?. message ?? error ?. toString ( ) ,
46
+ } )
47
+ . filter ( ( [ _key , value ] ) => ! isEmpty ( value ) )
48
+ . map ( ( [ key , value ] ) => {
49
+ return { label : words ( key ) ?. map ( capitalize ) ?. join ( " " ) , value } ;
50
+ } ) ,
51
+ ) ;
52
+ } , [ error ] ) ;
30
53
31
54
return (
32
55
< DialogRoot
@@ -56,8 +79,30 @@ const ErrorMessage: FunctionComponent<ErrorMessageProps & FallbackProps> = ({
56
79
>
57
80
contact eResearch
58
81
</ ExternalLink > { " " }
59
- for assistance.
82
+ for assistance, providing the following information:
60
83
</ Text >
84
+ < Box
85
+ border = { "dashed" }
86
+ borderWidth = { 1 }
87
+ borderColor = { "gray.300" }
88
+ p = { 2 }
89
+ mt = { 4 }
90
+ mb = { 4 }
91
+ >
92
+ { errorDetails . map ( ( { label, value } ) => (
93
+ < Text key = { label } >
94
+ { label } : { value }
95
+ </ Text >
96
+ ) ) }
97
+ </ Box >
98
+ < Clipboard . Root value = { clipboardText ( errorDetails ) } >
99
+ < Clipboard . Trigger asChild >
100
+ < Button variant = "surface" size = "sm" >
101
+ < Clipboard . Indicator />
102
+ < Clipboard . CopyText />
103
+ </ Button >
104
+ </ Clipboard . Trigger >
105
+ </ Clipboard . Root >
61
106
</ DialogBody >
62
107
< DialogFooter />
63
108
</ DialogContent >
0 commit comments