From e64b3cd33471023475bf29f59407c660f2fa2741 Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Fri, 7 Feb 2025 13:46:03 +0100 Subject: [PATCH 1/2] fix: show alert details on conversation page --- src/components/AlertDetail.tsx | 55 ++++++++++++++++++++++++++++++++++ src/routes/route-chat.tsx | 20 ++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/components/AlertDetail.tsx diff --git a/src/components/AlertDetail.tsx b/src/components/AlertDetail.tsx new file mode 100644 index 00000000..c3ccb7d8 --- /dev/null +++ b/src/components/AlertDetail.tsx @@ -0,0 +1,55 @@ +import { AlertConversation } from "@/api/generated"; +import { isAlertMalicious } from "@/features/alerts/lib/is-alert-malicious"; +import { isAlertSecret } from "@/features/alerts/lib/is-alert-secret"; +import { Markdown } from "./Markdown"; + +type MaliciousPkgType = { + name: string; + type: string; + status: string; + description: string; +}; + +export function AlertDetail({ alert }: { alert: AlertConversation }) { + if (alert.trigger_string === null) return "N/A"; + if (isAlertSecret(alert) && typeof alert.trigger_string === "string") { + return ( +
+ {alert.trigger_string} +
+ ); + } + + if (isAlertMalicious(alert) && typeof alert.trigger_string === "object") { + const maliciousPkg = alert.trigger_string as MaliciousPkgType; + + return ( +
+ +   + + {maliciousPkg.type}/{maliciousPkg.name} + + {maliciousPkg.status && ( + <> +
+ {maliciousPkg.status} + + )} + {maliciousPkg.description && ( + <> +
+ {" "} + {maliciousPkg.description} + + )} +
+ ); + } + return null; +} diff --git a/src/routes/route-chat.tsx b/src/routes/route-chat.tsx index 30f1b5f3..6cda4069 100644 --- a/src/routes/route-chat.tsx +++ b/src/routes/route-chat.tsx @@ -8,11 +8,14 @@ import { ChatBubbleMessage, } from "@/components/ui/chat/chat-bubble"; import { Markdown } from "@/components/Markdown"; -import { Breadcrumb, Breadcrumbs } from "@stacklok/ui-kit"; +import { Breadcrumb, Breadcrumbs, Card, CardBody } from "@stacklok/ui-kit"; import { BreadcrumbHome } from "@/components/BreadcrumbHome"; +import { useQueryGetWorkspaceAlertTable } from "@/features/alerts/hooks/use-query-get-workspace-alerts-table"; +import { AlertDetail } from "@/components/AlertDetail"; export function RouteChat() { const { id } = useParams(); + const { data = [] } = useQueryGetWorkspaceAlertTable(); const { data: prompts } = useQueryGetWorkspaceMessages(); const chat = prompts?.find((prompt) => prompt.chat_id === id); @@ -28,6 +31,13 @@ export function RouteChat() { chat.conversation_timestamp, ); + // we have an issue on BE, we received duplicated alerts + const alertDetail = data.filter((alert) => + alert.conversation.question_answers.some( + (item) => item.question.message_id === id, + ), + )[0]; + return ( <> @@ -36,6 +46,14 @@ export function RouteChat() {
+ {alertDetail && ( + + + + + + )} + {(chat?.question_answers ?? []).map(({ question, answer }, index) => (
From e1aa5f4df2e056a900e7f1fb500ebd946fd317cf Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Fri, 7 Feb 2025 15:28:24 +0100 Subject: [PATCH 2/2] feat: add utm_source to insight link --- src/components/AlertDetail.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AlertDetail.tsx b/src/components/AlertDetail.tsx index c3ccb7d8..10de3054 100644 --- a/src/components/AlertDetail.tsx +++ b/src/components/AlertDetail.tsx @@ -28,7 +28,7 @@ export function AlertDetail({ alert }: { alert: AlertConversation }) {