import React, { useState } from "react"; import { createPortal } from "react-dom"; /** * EnvironmentEditor — Claude-Code-on-Web parity environment config modal. * * Allows setting name, network access level, and environment variables. */ export default function EnvironmentEditor({ environment, onSave, onDelete, onClose }) { const [name, setName] = useState(environment?.name || ""); const [networkAccess, setNetworkAccess] = useState(environment?.network_access || "limited"); const [envVarsText, setEnvVarsText] = useState( environment?.env_vars ? Object.entries(environment.env_vars) .map(([k, v]) => `${k}=${v}`) .join("\n") : "" ); const handleSave = () => { const envVars = {}; envVarsText .split("\n") .map((line) => line.trim()) .filter((line) => line && line.includes("=")) .forEach((line) => { const idx = line.indexOf("="); const key = line.slice(0, idx).trim(); const val = line.slice(idx + 1).trim(); if (key) envVars[key] = val; }); onSave({ id: environment?.id || null, name: name.trim() || "Default", network_access: networkAccess, env_vars: envVars, }); }; return createPortal(
{ if (e.target === e.currentTarget) onClose(); }}>
e.stopPropagation()}>
{environment?.id ? "Edit Environment" : "New Environment"}
{/* Name */} setName(e.target.value)} placeholder="e.g. Development, Staging, Production" style={styles.input} /> {/* Network Access */}
{[ { value: "limited", label: "Limited", desc: "Allowlisted domains only (package managers, APIs)" }, { value: "full", label: "Full", desc: "Unrestricted internet access" }, { value: "none", label: "None", desc: "Air-gapped — no external network" }, ].map((opt) => ( ))}
{/* Environment Variables */}