Skip to content

Commit 0409ef0

Browse files
author
Dylan Huang
committed
Refactor StatusIndicator component to accept status prop, enhancing flexibility for displaying connection and evaluation statuses. Update App and Row components to utilize the new StatusIndicator implementation.
1 parent ce3eead commit 0409ef0

3 files changed

Lines changed: 53 additions & 26 deletions

File tree

vite-app/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ const App = observer(() => {
123123
<img src={logoLight} alt="Eval Protocol" className="h-6 w-auto" />
124124
</div>
125125
<div className="flex items-center gap-2">
126-
<StatusIndicator isConnected={state.isConnected} />
126+
<StatusIndicator
127+
status={state.isConnected ? "connected" : "disconnected"}
128+
/>
127129
<Button onClick={handleManualRefresh} className="ml-2">
128130
Refresh
129131
</Button>

vite-app/src/components/Row.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useState } from "react";
33
import type { EvaluationRow } from "../types/eval-protocol";
44
import { ChatInterface } from "./ChatInterface";
55
import { MetadataSection } from "./MetadataSection";
6+
import StatusIndicator from "./StatusIndicator";
67

78
export const Row = observer(
89
({ row }: { row: EvaluationRow; index: number }) => {
@@ -59,19 +60,7 @@ export const Row = observer(
5960

6061
{/* Status */}
6162
<td className="px-3 py-3 text-xs">
62-
<span
63-
className={`px-2 py-1 rounded text-xs font-medium ${
64-
row.eval_metadata?.status === "finished"
65-
? "bg-green-100 text-green-800"
66-
: row.eval_metadata?.status === "running"
67-
? "bg-blue-100 text-blue-800"
68-
: row.eval_metadata?.status === "error"
69-
? "bg-red-100 text-red-800"
70-
: "bg-gray-100 text-gray-800"
71-
}`}
72-
>
73-
{row.eval_metadata?.status || "N/A"}
74-
</span>
63+
<StatusIndicator status={row.eval_metadata?.status || "N/A"} />
7564
</td>
7665

7766
{/* Row ID */}

vite-app/src/components/StatusIndicator.tsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
11
import React from "react";
22

33
interface StatusIndicatorProps {
4-
isConnected: boolean;
4+
status: string;
55
className?: string;
66
}
77

88
const StatusIndicator: React.FC<StatusIndicatorProps> = ({
9-
isConnected,
9+
status,
1010
className = "",
1111
}) => {
12+
const getStatusConfig = (status: string) => {
13+
switch (status.toLowerCase()) {
14+
case "connected":
15+
return {
16+
dotColor: "bg-green-500",
17+
textColor: "text-green-700",
18+
text: "Connected",
19+
};
20+
case "disconnected":
21+
return {
22+
dotColor: "bg-red-500",
23+
textColor: "text-red-700",
24+
text: "Disconnected",
25+
};
26+
case "finished":
27+
return {
28+
dotColor: "bg-green-500",
29+
textColor: "text-green-700",
30+
text: "finished",
31+
};
32+
case "running":
33+
return {
34+
dotColor: "bg-blue-500",
35+
textColor: "text-blue-700",
36+
text: "running",
37+
};
38+
case "error":
39+
return {
40+
dotColor: "bg-red-500",
41+
textColor: "text-red-700",
42+
text: "error",
43+
};
44+
default:
45+
return {
46+
dotColor: "bg-gray-500",
47+
textColor: "text-gray-700",
48+
text: status,
49+
};
50+
}
51+
};
52+
53+
const config = getStatusConfig(status);
54+
1255
return (
1356
<div
14-
className={`inline-flex items-center px-2 py-0.5 border text-xs font-medium ${className}`}
15-
style={{ boxShadow: "none" }}
57+
className={`inline-flex items-center gap-1.5 text-xs font-medium ${config.textColor} ${className}`}
1658
>
17-
<div
18-
className={`w-1 h-1 border mr-1 ${
19-
isConnected
20-
? "bg-green-500 border-green-500"
21-
: "bg-red-500 border-red-500"
22-
}`}
23-
/>
24-
{isConnected ? "Connected" : "Disconnected"}
59+
<div className={`w-1.5 h-1.5 rounded-full ${config.dotColor}`} />
60+
{config.text}
2561
</div>
2662
);
2763
};

0 commit comments

Comments
 (0)