Make env vars UI toggleable

This commit is contained in:
Justin Spahr-Summers
2024-11-07 15:28:10 +00:00
parent 76e2cf6fdc
commit afefcb3fa5

View File

@@ -43,6 +43,8 @@ import {
Send, Send,
Terminal, Terminal,
FolderTree, FolderTree,
ChevronDown,
ChevronRight,
} from "lucide-react"; } from "lucide-react";
import { ZodType } from "zod"; import { ZodType } from "zod";
@@ -94,6 +96,7 @@ const App = () => {
const [notifications, setNotifications] = useState<ServerNotification[]>([]); const [notifications, setNotifications] = useState<ServerNotification[]>([]);
const [roots, setRoots] = useState<Root[]>([]); const [roots, setRoots] = useState<Root[]>([]);
const [env, setEnv] = useState<Record<string, string>>({}); const [env, setEnv] = useState<Record<string, string>>({});
const [showEnvVars, setShowEnvVars] = useState(false);
const [pendingSampleRequests, setPendingSampleRequests] = useState< const [pendingSampleRequests, setPendingSampleRequests] = useState<
Array< Array<
@@ -384,46 +387,62 @@ const App = () => {
</div> </div>
{transportType === "stdio" && ( {transportType === "stdio" && (
<div className="mt-4"> <div className="mt-4">
<h3 className="text-md font-semibold mb-2"> <Button
variant="outline"
onClick={() => setShowEnvVars(!showEnvVars)}
className="flex items-center"
>
{showEnvVars ? (
<ChevronDown className="w-4 h-4 mr-2" />
) : (
<ChevronRight className="w-4 h-4 mr-2" />
)}
Environment Variables Environment Variables
</h3> </Button>
{Object.entries(env).map(([key, value]) => ( {showEnvVars && (
<div key={key} className="flex space-x-2 mb-2"> <div className="mt-2">
<Input {Object.entries(env).map(([key, value]) => (
placeholder="Key" <div key={key} className="flex space-x-2 mb-2">
value={key} <Input
onChange={(e) => placeholder="Key"
setEnv((prev) => ({ value={key}
...prev, onChange={(e) =>
[e.target.value]: value, setEnv((prev) => ({
})) ...prev,
} [e.target.value]: value,
/> }))
<Input }
placeholder="Value" />
value={value} <Input
onChange={(e) => placeholder="Value"
setEnv((prev) => ({ ...prev, [key]: e.target.value })) value={value}
} onChange={(e) =>
/> setEnv((prev) => ({
...prev,
[key]: e.target.value,
}))
}
/>
<Button
onClick={() =>
setEnv((prev) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [key]: _, ...rest } = prev;
return rest;
})
}
>
Remove
</Button>
</div>
))}
<Button <Button
onClick={() => onClick={() => setEnv((prev) => ({ ...prev, "": "" }))}
setEnv((prev) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [key]: _, ...rest } = prev;
return rest;
})
}
> >
Remove Add Environment Variable
</Button> </Button>
</div> </div>
))} )}
<Button
onClick={() => setEnv((prev) => ({ ...prev, "": "" }))}
>
Add Environment Variable
</Button>
</div> </div>
)} )}
</div> </div>