-
Notifications
You must be signed in to change notification settings - Fork 805
/
Copy pathalert-timeline.tsx
135 lines (129 loc) · 4 KB
/
alert-timeline.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from "react";
import { Subtitle, Button, Card, Title } from "@tremor/react";
import { Chrono } from "react-chrono";
import { ArrowPathIcon } from "@heroicons/react/24/outline";
import { AlertDto } from "@/entities/alerts/model";
import { AuditEvent } from "utils/hooks/useAlerts";
import { getInitials } from "@/components/navbar/UserAvatar";
import { DynamicImageProviderIcon } from "@/components/ui";
const formatTimestamp = (timestamp: Date | string) => {
const date = new Date(timestamp);
return date.toLocaleString();
};
type AlertTimelineProps = {
alert: AlertDto | null;
auditData: AuditEvent[];
isLoading: boolean;
onRefresh: () => void;
};
const AlertTimeline: React.FC<AlertTimelineProps> = ({
alert,
auditData,
isLoading,
onRefresh,
}) => {
// Default audit event if no audit data is available
const defaultAuditEvent = alert
? [
{
user_id: "system",
action: "Alert is triggered",
description: "alert received from provider with status firing",
timestamp: alert.lastReceived,
},
]
: [];
const auditContent = auditData?.length ? auditData : defaultAuditEvent;
const content = auditContent.map((entry, index) => (
<div
key={index}
className="flex items-start space-x-4 ml-6"
style={{ width: "400px" }}
>
{entry.user_id.toLowerCase() === "system" ? (
<DynamicImageProviderIcon
src="/icons/keep-icon.png"
alt="Keep Logo"
width={40}
height={40}
className="rounded-full flex-shrink-0"
/>
) : (
<span className="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-orange-400 rounded-full flex-shrink-0">
<span className="font-medium text-white text-xs">
{getInitials(entry.user_id)}
</span>
</span>
)}
<div className="flex flex-col justify-center flex-grow overflow-hidden">
<Subtitle className="text-sm text-orange-500 font-semibold whitespace-normal overflow-wrap-break-word">
{entry.action.toLowerCase()}
</Subtitle>
<Subtitle className="text-xs whitespace-normal overflow-wrap-break-word">
{entry.description.toLowerCase()}
</Subtitle>
</div>
</div>
));
return (
<div className="flex flex-col gap-4">
<div className="flex justify-between items-center">
<Title>Timeline</Title>
<Button
icon={ArrowPathIcon}
color="orange"
size="xs"
disabled={isLoading}
loading={isLoading}
onClick={onRefresh}
title="Refresh"
/>
</div>
<Card className="max-h-[500px] overflow-y-auto p-0">
{isLoading ? (
<div className="flex justify-center items-center h-full">
<p>Loading...</p>
</div>
) : (
<div className="flex-grow">
<Chrono
items={
auditContent.map((entry) => ({
title: formatTimestamp(entry.timestamp),
})) || []
}
hideControls
disableToolbar
borderLessCards
slideShow={false}
mode="VERTICAL"
theme={{
primary: "orange",
secondary: "rgb(255 247 237)",
titleColor: "orange",
titleColorActive: "orange",
}}
fontSizes={{
title: ".75rem",
}}
cardWidth={400}
cardHeight="auto"
classNames={{
card: "hidden",
cardMedia: "hidden",
cardSubTitle: "hidden",
cardText: "hidden",
cardTitle: "hidden",
title: "mb-3",
contentDetails: "w-full !m-0",
}}
>
{content}
</Chrono>
</div>
)}
</Card>
</div>
);
};
export default AlertTimeline;