Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 04860b3

Browse files
committed
implement event column content correctly
1 parent bc6542f commit 04860b3

File tree

2 files changed

+20
-63
lines changed

2 files changed

+20
-63
lines changed

src/components/AlertsTable.tsx

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,25 @@ import {
1616
import { Switch } from "@stacklok/ui-kit";
1717
import { AlertConversation } from "@/api/generated";
1818
import { Tooltip, TooltipTrigger } from "@stacklok/ui-kit";
19-
import { getMaliciousPackage } from "@/lib/utils";
19+
import { sanitizeQuestionPrompt, parsingPromptText } from "@/lib/utils";
2020
import { Search } from "lucide-react";
2121
import { useAlertSearch } from "@/hooks/useAlertSearch";
2222
import { useCallback } from "react";
2323
import { useSearchParams } from "react-router-dom";
2424
import { useFilteredAlerts } from "@/hooks/useAlertsData";
2525
import { useClientSidePagination } from "@/hooks/useClientSidePagination";
2626

27-
const wrapObjectOutput = (input: AlertConversation["trigger_string"]) => {
28-
const data = getMaliciousPackage(input);
29-
if (data === null) return "N/A";
30-
if (typeof data === "string") {
31-
return (
32-
<div className="p-4 line-clamp-1 text-clip">
33-
{data.split("\n")[0] ?? ""}
34-
</div>
35-
);
36-
}
37-
if (!data.type || !data.name) return "N/A";
38-
39-
return (
40-
<div className="max-h-40 w-fit overflow-y-auto whitespace-pre-wrap p-2">
41-
<label className="font-medium">Package:</label>
42-
&nbsp;
43-
<a
44-
href={`https://www.insight.stacklok.com/report/${data.type}/${data.name}`}
45-
target="_blank"
46-
rel="noopener noreferrer"
47-
className="text-brand-500 hover:underline"
48-
>
49-
{data.type}/{data.name}
50-
</a>
51-
{data.status && (
52-
<>
53-
<br />
54-
<label className="font-medium">Status:</label> {data.status}
55-
</>
56-
)}
57-
{data.description && (
58-
<>
59-
<br />
60-
<label className="font-medium">Description:</label> {data.description}
61-
</>
62-
)}
63-
</div>
27+
const getTitle = (alert: AlertConversation) => {
28+
const prompt = alert.conversation;
29+
const title = parsingPromptText(
30+
sanitizeQuestionPrompt({
31+
question: prompt.question_answers?.[0]?.question.message ?? "",
32+
answer: prompt.question_answers?.[0]?.answer?.message ?? "",
33+
}),
34+
prompt.conversation_timestamp,
6435
);
36+
37+
return title;
6538
};
6639

6740
export function AlertsTable() {
@@ -179,9 +152,7 @@ export function AlertsTable() {
179152
})}
180153
</Cell>
181154
<Cell className="truncate">{alert.trigger_type}</Cell>
182-
<Cell className="overflow-auto whitespace-nowrap max-w-80">
183-
{wrapObjectOutput(alert.trigger_string)}
184-
</Cell>
155+
<Cell className="truncate">{getTitle(alert)}</Cell>
185156
</Row>
186157
))}
187158
</TableBody>

src/routes/__tests__/route-dashboard.test.tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,15 @@ describe("Dashboard", () => {
188188
/codegate-context-retriever/i,
189189
),
190190
).toBeVisible();
191+
});
191192

192-
expect(screen.getByText(/package:/i)).toBeVisible();
193-
expect(
194-
screen.getByRole("link", {
195-
name: /pypi\/invokehttp/i,
196-
}),
197-
).toHaveAttribute(
198-
"href",
199-
"https://www.insight.stacklok.com/report/pypi/invokehttp",
200-
);
201-
expect(
202-
screen.getByText(/malicious python http for humans\./i),
203-
).toBeVisible();
193+
it("renders event column", async () => {
194+
mockAlertsWithMaliciousPkg();
195+
render(<RouteDashboard />);
196+
197+
await waitFor(() => {
198+
expect(screen.getByText(/are there malicious/i)).toBeVisible();
199+
});
204200
});
205201

206202
it("should filter by malicious pkg", async () => {
@@ -228,16 +224,6 @@ describe("Dashboard", () => {
228224
expect(screen.getByTestId(/alerts-count/i)).toHaveTextContent("1"),
229225
);
230226

231-
expect(screen.getByText(/package:/i)).toBeVisible();
232-
expect(
233-
screen.getByRole("link", {
234-
name: /pypi\/invokehttp/i,
235-
}),
236-
).toBeVisible();
237-
expect(
238-
screen.getByText(/malicious python http for humans\./i),
239-
).toBeVisible();
240-
241227
userEvent.click(
242228
screen.getByRole("switch", {
243229
name: /malicious packages/i,

0 commit comments

Comments
 (0)