@@ -18,29 +18,68 @@ import type { AlertsPageItem } from './types';
1818
1919import styles from '../styles/AlertsPage.module.scss' ;
2020
21- function AlertHistoryCard ( { history } : { history : AlertHistory } ) {
21+ function AlertHistoryCard ( {
22+ history,
23+ alertUrl,
24+ } : {
25+ history : AlertHistory ;
26+ alertUrl : string ;
27+ } ) {
2228 const start = new Date ( history . createdAt . toString ( ) ) ;
2329 const today = React . useMemo ( ( ) => new Date ( ) , [ ] ) ;
2430
31+ const href = React . useMemo ( ( ) => {
32+ if ( ! alertUrl || ! history . lastValues ?. [ 0 ] ?. startTime ) return null ;
33+
34+ // Create time window from alert creation to last recorded value
35+ const to = new Date ( history . createdAt ) . getTime ( ) ;
36+ const from = new Date ( history . lastValues [ 0 ] . startTime ) . getTime ( ) ;
37+
38+ // Construct URL with time range parameters
39+ const url = new URL ( alertUrl , window . location . origin ) ;
40+ url . searchParams . set ( 'from' , from . toString ( ) ) ;
41+ url . searchParams . set ( 'to' , to . toString ( ) ) ;
42+ url . searchParams . set ( 'isLive' , 'false' ) ;
43+
44+ return url . pathname + url . search ;
45+ } , [ history , alertUrl ] ) ;
46+
47+ const content = (
48+ < div
49+ className = { cx (
50+ styles . historyCard ,
51+ history . state === AlertState . OK ? styles . ok : styles . alarm ,
52+ href && styles . clickable ,
53+ ) }
54+ />
55+ ) ;
56+
2557 return (
2658 < Tooltip
2759 label = { `${ history . counts ?? 0 } alerts ${ formatRelative ( start , today ) } ` }
2860 color = "dark"
2961 withArrow
3062 >
31- < div
32- className = { cx (
33- styles . historyCard ,
34- history . state === AlertState . OK ? styles . ok : styles . alarm ,
35- ) }
36- />
63+ { href ? (
64+ < a href = { href } className = { styles . historyCardLink } >
65+ { content }
66+ </ a >
67+ ) : (
68+ content
69+ ) }
3770 </ Tooltip >
3871 ) ;
3972}
4073
4174const HISTORY_ITEMS = 18 ;
4275
43- function AlertHistoryCardList ( { history } : { history : AlertHistory [ ] } ) {
76+ function AlertHistoryCardList ( {
77+ history,
78+ alertUrl,
79+ } : {
80+ history : AlertHistory [ ] ;
81+ alertUrl : string ;
82+ } ) {
4483 const items = React . useMemo ( ( ) => {
4584 if ( history . length < HISTORY_ITEMS ) {
4685 return history ;
@@ -66,7 +105,7 @@ function AlertHistoryCardList({ history }: { history: AlertHistory[] }) {
66105 . slice ( )
67106 . reverse ( )
68107 . map ( ( history , index ) => (
69- < AlertHistoryCard key = { index } history = { history } />
108+ < AlertHistoryCard key = { index } history = { history } alertUrl = { alertUrl } />
70109 ) ) }
71110 </ div >
72111 ) ;
@@ -192,7 +231,7 @@ function AlertDetails({ alert }: { alert: AlertsPageItem }) {
192231 </ Group >
193232
194233 < Group >
195- < AlertHistoryCardList history = { alert . history } />
234+ < AlertHistoryCardList history = { alert . history } alertUrl = { alertUrl } />
196235 </ Group >
197236 </ div >
198237 ) ;
0 commit comments