|
1 |
| -import { Menu, Settings } from "lucide-react"; |
| 1 | +import { useState } from "react"; |
| 2 | + |
| 3 | +import { Play, ChevronDown, ChevronRight, Settings } from "lucide-react"; |
2 | 4 | import { Button } from "@/components/ui/button";
|
| 5 | +import { Input } from "@/components/ui/input"; |
| 6 | +import { |
| 7 | + Select, |
| 8 | + SelectContent, |
| 9 | + SelectItem, |
| 10 | + SelectTrigger, |
| 11 | + SelectValue, |
| 12 | +} from "@/components/ui/select"; |
3 | 13 |
|
4 |
| -const Sidebar = ({ connectionStatus }: { connectionStatus: string }) => ( |
5 |
| - <div className="w-64 bg-card border-r border-border"> |
6 |
| - <div className="flex items-center p-4 border-b border-gray-200"> |
7 |
| - <Menu className="w-6 h-6 text-gray-500" /> |
8 |
| - <h1 className="ml-2 text-lg font-semibold">MCP Inspector</h1> |
9 |
| - </div> |
| 14 | +interface SidebarProps { |
| 15 | + connectionStatus: "disconnected" | "connected" | "error"; |
| 16 | + transportType: "stdio" | "sse"; |
| 17 | + setTransportType: (type: "stdio" | "sse") => void; |
| 18 | + command: string; |
| 19 | + setCommand: (command: string) => void; |
| 20 | + args: string; |
| 21 | + setArgs: (args: string) => void; |
| 22 | + url: string; |
| 23 | + setUrl: (url: string) => void; |
| 24 | + env: Record<string, string>; |
| 25 | + setEnv: (env: Record<string, string>) => void; |
| 26 | + onConnect: () => void; |
| 27 | +} |
| 28 | + |
| 29 | +const Sidebar = ({ |
| 30 | + connectionStatus, |
| 31 | + transportType, |
| 32 | + setTransportType, |
| 33 | + command, |
| 34 | + setCommand, |
| 35 | + args, |
| 36 | + setArgs, |
| 37 | + url, |
| 38 | + setUrl, |
| 39 | + env, |
| 40 | + setEnv, |
| 41 | + onConnect, |
| 42 | +}: SidebarProps) => { |
| 43 | + const [showEnvVars, setShowEnvVars] = useState(false); |
10 | 44 |
|
11 |
| - <div className="p-4"> |
12 |
| - <div className="flex items-center space-x-2 mb-4"> |
13 |
| - <div |
14 |
| - className={`w-2 h-2 rounded-full ${ |
15 |
| - connectionStatus === "connected" |
16 |
| - ? "bg-green-500" |
17 |
| - : connectionStatus === "error" |
18 |
| - ? "bg-red-500" |
19 |
| - : "bg-gray-500" |
20 |
| - }`} |
21 |
| - /> |
22 |
| - <span className="text-sm text-gray-600"> |
23 |
| - {connectionStatus === "connected" |
24 |
| - ? "Connected" |
25 |
| - : connectionStatus === "error" |
26 |
| - ? "Connection Error" |
27 |
| - : "Disconnected"} |
28 |
| - </span> |
| 45 | + return ( |
| 46 | + <div className="w-80 bg-card border-r border-border flex flex-col h-full"> |
| 47 | + <div className="flex items-center p-4 border-b border-gray-200"> |
| 48 | + <Settings className="w-6 h-6 text-gray-500" /> |
| 49 | + <h1 className="ml-2 text-lg font-semibold">MCP Inspector</h1> |
29 | 50 | </div>
|
30 | 51 |
|
31 |
| - <Button variant="outline" className="w-full justify-start"> |
32 |
| - <Settings className="w-4 h-4 mr-2" /> |
33 |
| - Connection Settings |
34 |
| - </Button> |
| 52 | + <div className="p-4 flex-1 overflow-auto"> |
| 53 | + <div className="space-y-4"> |
| 54 | + <div className="space-y-2"> |
| 55 | + <label className="text-sm font-medium">Transport Type</label> |
| 56 | + <Select |
| 57 | + value={transportType} |
| 58 | + onValueChange={(value: "stdio" | "sse") => |
| 59 | + setTransportType(value) |
| 60 | + } |
| 61 | + > |
| 62 | + <SelectTrigger> |
| 63 | + <SelectValue placeholder="Select transport type" /> |
| 64 | + </SelectTrigger> |
| 65 | + <SelectContent> |
| 66 | + <SelectItem value="stdio">STDIO</SelectItem> |
| 67 | + <SelectItem value="sse">SSE</SelectItem> |
| 68 | + </SelectContent> |
| 69 | + </Select> |
| 70 | + </div> |
| 71 | + {transportType === "stdio" ? ( |
| 72 | + <> |
| 73 | + <div className="space-y-2"> |
| 74 | + <label className="text-sm font-medium">Command</label> |
| 75 | + <Input |
| 76 | + placeholder="Command" |
| 77 | + value={command} |
| 78 | + onChange={(e) => setCommand(e.target.value)} |
| 79 | + /> |
| 80 | + </div> |
| 81 | + <div className="space-y-2"> |
| 82 | + <label className="text-sm font-medium">Arguments</label> |
| 83 | + <Input |
| 84 | + placeholder="Arguments (space-separated)" |
| 85 | + value={args} |
| 86 | + onChange={(e) => setArgs(e.target.value)} |
| 87 | + /> |
| 88 | + </div> |
| 89 | + </> |
| 90 | + ) : ( |
| 91 | + <div className="space-y-2"> |
| 92 | + <label className="text-sm font-medium">URL</label> |
| 93 | + <Input |
| 94 | + placeholder="URL" |
| 95 | + value={url} |
| 96 | + onChange={(e) => setUrl(e.target.value)} |
| 97 | + /> |
| 98 | + </div> |
| 99 | + )} |
| 100 | + {transportType === "stdio" && ( |
| 101 | + <div className="space-y-2"> |
| 102 | + <Button |
| 103 | + variant="outline" |
| 104 | + onClick={() => setShowEnvVars(!showEnvVars)} |
| 105 | + className="flex items-center w-full" |
| 106 | + > |
| 107 | + {showEnvVars ? ( |
| 108 | + <ChevronDown className="w-4 h-4 mr-2" /> |
| 109 | + ) : ( |
| 110 | + <ChevronRight className="w-4 h-4 mr-2" /> |
| 111 | + )} |
| 112 | + Environment Variables |
| 113 | + </Button> |
| 114 | + {showEnvVars && ( |
| 115 | + <div className="space-y-2"> |
| 116 | + {Object.entries(env).map(([key, value]) => ( |
| 117 | + <div key={key} className="grid grid-cols-[1fr,auto] gap-2"> |
| 118 | + <div className="space-y-1"> |
| 119 | + <Input |
| 120 | + placeholder="Key" |
| 121 | + value={key} |
| 122 | + onChange={(e) => { |
| 123 | + const newEnv = { ...env }; |
| 124 | + newEnv[e.target.value] = value; |
| 125 | + setEnv(newEnv); |
| 126 | + }} |
| 127 | + /> |
| 128 | + <Input |
| 129 | + placeholder="Value" |
| 130 | + value={value} |
| 131 | + onChange={(e) => { |
| 132 | + const newEnv = { ...env }; |
| 133 | + newEnv[key] = e.target.value; |
| 134 | + setEnv(newEnv); |
| 135 | + }} |
| 136 | + /> |
| 137 | + </div> |
| 138 | + <Button |
| 139 | + variant="destructive" |
| 140 | + onClick={() => { |
| 141 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 142 | + const { [key]: removed, ...rest } = env; |
| 143 | + setEnv(rest); |
| 144 | + }} |
| 145 | + > |
| 146 | + Remove |
| 147 | + </Button> |
| 148 | + </div> |
| 149 | + ))} |
| 150 | + <Button |
| 151 | + variant="outline" |
| 152 | + onClick={() => { |
| 153 | + const newEnv = { ...env }; |
| 154 | + newEnv[""] = ""; |
| 155 | + setEnv(newEnv); |
| 156 | + }} |
| 157 | + > |
| 158 | + Add Environment Variable |
| 159 | + </Button> |
| 160 | + </div> |
| 161 | + )} |
| 162 | + </div> |
| 163 | + )} |
| 164 | + |
| 165 | + <div className="space-y-2"> |
| 166 | + <Button className="w-full" onClick={onConnect}> |
| 167 | + <Play className="w-4 h-4 mr-2" /> |
| 168 | + Connect |
| 169 | + </Button> |
| 170 | + |
| 171 | + <div className="flex items-center justify-center space-x-2 mb-4"> |
| 172 | + <div |
| 173 | + className={`w-2 h-2 rounded-full ${ |
| 174 | + connectionStatus === "connected" |
| 175 | + ? "bg-green-500" |
| 176 | + : connectionStatus === "error" |
| 177 | + ? "bg-red-500" |
| 178 | + : "bg-gray-500" |
| 179 | + }`} |
| 180 | + /> |
| 181 | + <span className="text-sm text-gray-600"> |
| 182 | + {connectionStatus === "connected" |
| 183 | + ? "Connected" |
| 184 | + : connectionStatus === "error" |
| 185 | + ? "Connection Error" |
| 186 | + : "Disconnected"} |
| 187 | + </span> |
| 188 | + </div> |
| 189 | + </div> |
| 190 | + </div> |
| 191 | + </div> |
35 | 192 | </div>
|
36 |
| - </div> |
37 |
| -); |
| 193 | + ); |
| 194 | +}; |
38 | 195 |
|
39 | 196 | export default Sidebar;
|
0 commit comments