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

Commit 640fe4c

Browse files
committed
integrate BE
1 parent 9f2950a commit 640fe4c

File tree

11 files changed

+80
-1727
lines changed

11 files changed

+80
-1727
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VITE_BASE_API_URL=https://localhost:5001/api
1+
VITE_BASE_API_URL=http://localhost:8989

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
},
3737
"devDependencies": {
3838
"@eslint/js": "^9.15.0",
39-
"@faker-js/faker": "^9.2.0",
4039
"@types/node": "^22.10.1",
4140
"@types/react": "^18.3.12",
4241
"@types/react-dom": "^18.3.1",
@@ -52,4 +51,4 @@
5251
"typescript-eslint": "^8.15.0",
5352
"vite": "^6.0.1"
5453
}
55-
}
54+
}

src/components/Dashboard.tsx

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ import { useEffect, useState } from "react";
1515
import { BarChart } from "@/viz/BarChart";
1616
import { LineChart } from "@/viz/LineChart";
1717
import { useAlertsStore } from "@/hooks/useAlertsStore";
18+
import { Markdown } from "./Markdown";
19+
20+
const wrapObjectOutput = (input: string) => {
21+
const isObject = /\{"/.test(input);
22+
23+
if (isObject) {
24+
return (
25+
<pre className="w-full h-40 overflow-auto whitespace-pre-wrap bg-gray-100 p-2">
26+
<code>{input}</code>
27+
</pre>
28+
);
29+
}
30+
return <Markdown className="overflow-x-hidden">{input || "N/A"}</Markdown>;
31+
};
1832

1933
export function Dashboard() {
2034
const { alerts, loading, fetchAlerts } = useAlertsStore();
@@ -52,7 +66,7 @@ export function Dashboard() {
5266
/>
5367
</div>
5468
<div className="relative w-[350px] h-[240px]">
55-
<LineChart alerts={alerts} loading={loading}/>
69+
<LineChart alerts={alerts} loading={loading} />
5670
</div>
5771
</div>
5872

@@ -92,29 +106,39 @@ export function Dashboard() {
92106
<Table>
93107
<TableHeader>
94108
<TableRow>
95-
<TableHead>Trigger Type</TableHead>
96-
<TableHead>Trigger Token</TableHead>
97-
<TableHead>File</TableHead>
98-
<TableHead>Code</TableHead>
99-
<TableHead>Timestamp</TableHead>
109+
<TableHead className="max-w-[100px]">Trigger Type</TableHead>
110+
<TableHead className="w-[30%] max-w-[300px]">
111+
Trigger Token
112+
</TableHead>
113+
<TableHead className="max-w-[100px]">File</TableHead>
114+
<TableHead className="w-[30%] max-w-[300px]">Code</TableHead>
115+
<TableHead className="max-w-[100px]">Timestamp</TableHead>
100116
</TableRow>
101117
</TableHeader>
102118
<TableBody>
103119
{filteredAlerts.map((alert) => (
104120
<TableRow key={alert.alert_id}>
105-
<TableCell>{alert.trigger_type}</TableCell>
106-
<TableCell>{alert.trigger_string || "N/A"}</TableCell>
107-
<TableCell>{alert.code_snippet?.filepath || "N/A"}</TableCell>
108-
<TableCell>
121+
<TableCell className="max-w-[100px] truncate">
122+
{alert.trigger_type}
123+
</TableCell>
124+
<TableCell className="w-[30%] max-w-[300px]">
125+
<div className="max-h-40 p-4 rounded overflow-y-auto whitespace-pre-wrap">
126+
{wrapObjectOutput(alert.trigger_string ?? "")}
127+
</div>
128+
</TableCell>
129+
<TableCell className="max-w-[100px] truncate">
130+
{alert.code_snippet?.filepath || "N/A"}
131+
</TableCell>
132+
<TableCell className="w-[30%] max-w-[300px]">
109133
{alert.code_snippet?.code ? (
110-
<pre className="whitespace-pre-wrap bg-gray-100 p-2 h-20 overflow-auto text-sm">
111-
{alert.code_snippet?.code}
134+
<pre className="w-full h-40 overflow-auto whitespace-pre-wrap bg-gray-100 p-2">
135+
<code>{alert.code_snippet?.code}</code>
112136
</pre>
113137
) : (
114138
"N/A"
115139
)}
116140
</TableCell>
117-
<TableCell>
141+
<TableCell className="max-w-[100px] truncate">
118142
<div>{format(new Date(alert.timestamp), "y/MM/dd")}</div>
119143
<div>{format(new Date(alert.timestamp), "HH:mm a")}</div>
120144
</TableCell>

src/hooks/useAlertsStore.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { create } from "zustand";
22
import { AlertState } from "../types";
3-
import { MOCKED_ALERTS } from "@/mock/alerts";
3+
import { getAlerts } from "@/service";
44

55
export const useAlertsStore = create<AlertState>((set) => ({
66
alerts: [],
77
loading: false,
8-
fetchAlerts: () => {
8+
fetchAlerts: async () => {
99
set({ loading: true });
10-
setTimeout(() => {
11-
set({ alerts: MOCKED_ALERTS, loading: false });
12-
}, 2000);
10+
const alerts = await getAlerts();
11+
set({ alerts, loading: false });
1312
},
1413
}));

src/hooks/usePromptsStore.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { create } from "zustand";
22
import { PromptState } from "../types";
3-
import { MOCKED_PROMPTS } from "@/mock/prompts";
3+
import { getPrompts } from "@/service";
44

55
export const usePromptsStore = create<PromptState>((set) => ({
66
prompts: [],
77
loading: false,
8-
fetchPrompts: () => {
9-
set({ prompts: MOCKED_PROMPTS, loading: false });
8+
fetchPrompts: async () => {
9+
set({ loading: true });
10+
const prompts = await getPrompts();
11+
set({ prompts, loading: false });
1012
},
1113
}));

src/lib/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ export function groupPromptsByRelativeDate(prompts: Prompt[]) {
9696

9797
export function getAllIssues(alerts: Alert[]) {
9898
const groupedTriggerCounts = alerts
99-
.filter((alert) => alert.trigger_category === "critical")
99+
.filter(
100+
(alert) =>
101+
alert.trigger_category === "critical" ||
102+
alert.trigger_category === "info"
103+
)
100104
.reduce<Record<string, number>>((acc, alert) => {
101105
const triggerType = alert.trigger_type;
102106
if (triggerType) {

0 commit comments

Comments
 (0)