Skip to content

Commit 70fe682

Browse files
1 parent 07392d2 commit 70fe682

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

.changeset/proud-jobs-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
Add clickable alert timeline chips

packages/app/src/AlertsPage.tsx

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,68 @@ import type { AlertsPageItem } from './types';
1818

1919
import 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

4174
const 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
);

packages/app/styles/AlertsPage.module.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
background-color: var(--color-bg-muted);
2424
border-radius: 2px;
2525
margin: 0 1px;
26-
cursor: pointer;
26+
cursor: default;
2727
transition: opacity 0.1s ease-in;
2828

2929
&:hover {
@@ -38,6 +38,10 @@
3838
&.alarm {
3939
background-color: var(--color-bg-danger);
4040
}
41+
42+
&.clickable {
43+
cursor: pointer;
44+
}
4145
}
4246

4347
.alertRow {

0 commit comments

Comments
 (0)