Skip to content

Commit 8154d3e

Browse files
authored
feat: show alert detail in the conversation page (#277)
* fix: show alert details on conversation page * feat: add utm_source to insight link
1 parent dbbc853 commit 8154d3e

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/components/AlertDetail.tsx

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { AlertConversation } from "@/api/generated";
2+
import { isAlertMalicious } from "@/features/alerts/lib/is-alert-malicious";
3+
import { isAlertSecret } from "@/features/alerts/lib/is-alert-secret";
4+
import { Markdown } from "./Markdown";
5+
6+
type MaliciousPkgType = {
7+
name: string;
8+
type: string;
9+
status: string;
10+
description: string;
11+
};
12+
13+
export function AlertDetail({ alert }: { alert: AlertConversation }) {
14+
if (alert.trigger_string === null) return "N/A";
15+
if (isAlertSecret(alert) && typeof alert.trigger_string === "string") {
16+
return (
17+
<div className="bg-gray-25 rounded-lg overflow-auto p-4">
18+
<Markdown>{alert.trigger_string}</Markdown>
19+
</div>
20+
);
21+
}
22+
23+
if (isAlertMalicious(alert) && typeof alert.trigger_string === "object") {
24+
const maliciousPkg = alert.trigger_string as MaliciousPkgType;
25+
26+
return (
27+
<div className="max-h-40 w-fit overflow-y-auto whitespace-pre-wrap p-2">
28+
<label className="font-medium">Package:</label>
29+
&nbsp;
30+
<a
31+
href={`https://www.insight.stacklok.com/report/${maliciousPkg.type}/${maliciousPkg.name}?utm_source=codegate-ui`}
32+
target="_blank"
33+
rel="noopener noreferrer"
34+
className="text-brand-500 hover:underline"
35+
>
36+
{maliciousPkg.type}/{maliciousPkg.name}
37+
</a>
38+
{maliciousPkg.status && (
39+
<>
40+
<br />
41+
<label className="font-medium">Status:</label> {maliciousPkg.status}
42+
</>
43+
)}
44+
{maliciousPkg.description && (
45+
<>
46+
<br />
47+
<label className="font-medium">Description:</label>{" "}
48+
{maliciousPkg.description}
49+
</>
50+
)}
51+
</div>
52+
);
53+
}
54+
return null;
55+
}

src/routes/route-chat.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {
88
ChatBubbleMessage,
99
} from "@/components/ui/chat/chat-bubble";
1010
import { Markdown } from "@/components/Markdown";
11-
import { Breadcrumb, Breadcrumbs } from "@stacklok/ui-kit";
11+
import { Breadcrumb, Breadcrumbs, Card, CardBody } from "@stacklok/ui-kit";
1212
import { BreadcrumbHome } from "@/components/BreadcrumbHome";
13+
import { useQueryGetWorkspaceAlertTable } from "@/features/alerts/hooks/use-query-get-workspace-alerts-table";
14+
import { AlertDetail } from "@/components/AlertDetail";
1315

1416
export function RouteChat() {
1517
const { id } = useParams();
18+
const { data = [] } = useQueryGetWorkspaceAlertTable();
1619
const { data: prompts } = useQueryGetWorkspaceMessages();
1720
const chat = prompts?.find((prompt) => prompt.chat_id === id);
1821

@@ -28,6 +31,13 @@ export function RouteChat() {
2831
chat.conversation_timestamp,
2932
);
3033

34+
// we have an issue on BE, we received duplicated alerts
35+
const alertDetail = data.filter((alert) =>
36+
alert.conversation.question_answers.some(
37+
(item) => item.question.message_id === id,
38+
),
39+
)[0];
40+
3141
return (
3242
<>
3343
<Breadcrumbs>
@@ -36,6 +46,14 @@ export function RouteChat() {
3646
</Breadcrumbs>
3747

3848
<div className="w-[calc(100vw-18rem)]">
49+
{alertDetail && (
50+
<Card className="w-full mb-2">
51+
<CardBody className="w-full h-fit overflow-auto max-h-[500px]">
52+
<AlertDetail alert={alertDetail} />
53+
</CardBody>
54+
</Card>
55+
)}
56+
3957
<ChatMessageList>
4058
{(chat?.question_answers ?? []).map(({ question, answer }, index) => (
4159
<div key={index} className="flex flex-col size-full gap-6">

0 commit comments

Comments
 (0)