1
1
import { AlertDto } from "./models" ; // Adjust the import path as needed
2
2
import Modal from "@/components/ui/Modal" ; // Ensure this path matches your project structure
3
- import { Button , Icon , Switch , Text } from "@tremor/react" ;
3
+ import { Button , Icon , Switch , Text } from "@tremor/react" ;
4
4
import { toast } from "react-toastify" ;
5
- import { getApiURL } from "../../ utils/apiUrl " ;
5
+ import { useApiUrl } from "utils/hooks/useConfig " ;
6
6
import { useSession } from "next-auth/react" ;
7
7
import { XMarkIcon } from "@heroicons/react/24/outline" ;
8
8
import "./ViewAlertModal.css" ;
9
- import React , { useState } from "react" ;
9
+ import React , { useState } from "react" ;
10
10
11
11
interface ViewAlertModalProps {
12
12
alert : AlertDto | null | undefined ;
13
13
handleClose : ( ) => void ;
14
14
mutate : ( ) => void ;
15
15
}
16
16
17
- const objectToJSONLine = ( obj : any ) => {
17
+ const objectToJSONLine = ( obj : any ) => {
18
18
return JSON . stringify ( obj , null , 2 ) . slice ( 2 , - 2 ) ;
19
- }
19
+ } ;
20
20
21
- export const ViewAlertModal : React . FC < ViewAlertModalProps > = ( { alert, handleClose, mutate} ) => {
21
+ export const ViewAlertModal : React . FC < ViewAlertModalProps > = ( {
22
+ alert,
23
+ handleClose,
24
+ mutate,
25
+ } ) => {
22
26
const isOpen = ! ! alert ;
23
27
const [ showHighlightedOnly , setShowHighlightedOnly ] = useState ( false ) ;
24
- const { data : session } = useSession ( ) ;
28
+ const { data : session } = useSession ( ) ;
29
+ const apiUrl = useApiUrl ( ) ;
25
30
26
31
const unEnrichAlert = async ( key : string ) => {
27
32
if ( confirm ( `Are you sure you want to un-enrich ${ key } ?` ) ) {
@@ -30,7 +35,7 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
30
35
enrichments : [ key ] ,
31
36
fingerprint : alert ! . fingerprint ,
32
37
} ;
33
- const response = await fetch ( `${ getApiURL ( ) } /alerts/unenrich` , {
38
+ const response = await fetch ( `${ apiUrl } /alerts/unenrich` , {
34
39
method : "POST" ,
35
40
headers : {
36
41
"Content-Type" : "application/json" ,
@@ -52,35 +57,46 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
52
57
toast . error ( "An unexpected error occurred" ) ;
53
58
}
54
59
}
55
- }
60
+ } ;
56
61
57
62
const highlightKeys = ( json : any , keys : string [ ] ) => {
58
-
59
63
const lines = Object . keys ( json ) . length ;
60
- const isLast = ( index : number ) => index == lines - 1
64
+ const isLast = ( index : number ) => index == lines - 1 ;
61
65
62
66
return Object . keys ( json ) . map ( ( key : string , index : number ) => {
63
67
if ( keys . includes ( key ) ) {
64
- return < p key = { key } className = "text-green-600 cursor-pointer line-container" onClick = { ( ) => unEnrichAlert ( key ) } >
65
- < span className = "un-enrich-icon" >
66
- < Icon
67
- icon = { XMarkIcon }
68
- tooltip = { `Click to un-enrich ${ key } ` }
69
- size = "xs"
70
- color = "red"
71
- className = "cursor-pointer px-0 py-0"
72
- variant = "outlined"
73
- />
74
- </ span >
75
- { objectToJSONLine ( { [ key ] : json [ key ] } ) } { isLast ( index ) ? null : "," }
76
- </ p >
68
+ return (
69
+ < p
70
+ key = { key }
71
+ className = "text-green-600 cursor-pointer line-container"
72
+ onClick = { ( ) => unEnrichAlert ( key ) }
73
+ >
74
+ < span className = "un-enrich-icon" >
75
+ < Icon
76
+ icon = { XMarkIcon }
77
+ tooltip = { `Click to un-enrich ${ key } ` }
78
+ size = "xs"
79
+ color = "red"
80
+ className = "cursor-pointer px-0 py-0"
81
+ variant = "outlined"
82
+ />
83
+ </ span >
84
+ { objectToJSONLine ( { [ key ] : json [ key ] } ) }
85
+ { isLast ( index ) ? null : "," }
86
+ </ p >
87
+ ) ;
77
88
} else {
78
89
if ( ! showHighlightedOnly || keys . length == 0 ) {
79
- return < p key = { key } > { objectToJSONLine ( { [ key ] : json [ key ] } ) } { isLast ( index ) ? null : "," } </ p >
90
+ return (
91
+ < p key = { key } >
92
+ { objectToJSONLine ( { [ key ] : json [ key ] } ) }
93
+ { isLast ( index ) ? null : "," }
94
+ </ p >
95
+ ) ;
80
96
}
81
97
}
82
- } )
83
- }
98
+ } ) ;
99
+ } ;
84
100
85
101
const handleCopy = async ( ) => {
86
102
if ( alert ) {
@@ -94,23 +110,31 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
94
110
} ;
95
111
96
112
return (
97
- < Modal onClose = { handleClose } isOpen = { isOpen } className = "overflow-visible max-w-fit" >
113
+ < Modal
114
+ onClose = { handleClose }
115
+ isOpen = { isOpen }
116
+ className = "overflow-visible max-w-fit"
117
+ >
98
118
< div className = "flex justify-between items-center mb-4 min-w-full" >
99
119
< h2 className = "text-lg font-semibold" > Alert Details</ h2 >
100
- < div className = "flex gap-x-2" > { /* Adjust gap as needed */ }
120
+ < div className = "flex gap-x-2" >
121
+ { " " }
122
+ { /* Adjust gap as needed */ }
101
123
< div className = "placeholder-resizing min-w-48" > </ div >
102
124
< div className = "flex items-center space-x-2" >
103
125
< Switch
104
- color = "orange"
105
- id = "showHighlightedOnly"
106
- checked = { showHighlightedOnly }
107
- onChange = { ( ) => setShowHighlightedOnly ( ! showHighlightedOnly ) }
108
- />
109
- < label htmlFor = "showHighlightedOnly" className = "text-sm text-gray-500" >
126
+ color = "orange"
127
+ id = "showHighlightedOnly"
128
+ checked = { showHighlightedOnly }
129
+ onChange = { ( ) => setShowHighlightedOnly ( ! showHighlightedOnly ) }
130
+ />
131
+ < label
132
+ htmlFor = "showHighlightedOnly"
133
+ className = "text-sm text-gray-500"
134
+ >
110
135
< Text > Enriched Fields Only</ Text >
111
136
</ label >
112
137
</ div >
113
-
114
138
< Button onClick = { handleCopy } color = "orange" >
115
139
Copy to Clipboard
116
140
</ Button >
0 commit comments