import { useEffect, useState } from "react"; import type { EnvVar } from "../../lib/types"; import Button from "../ui/Button"; import { monoInputClass } from "../ui/Field"; interface Props { envVars: EnvVar[]; disabled: boolean; disabledReason?: string; onSave: (vars: EnvVar[]) => Promise; } /** Env-var table. Used inline in Project Home → Config and in global Settings. */ export default function EnvVarsEditor({ envVars: initial, disabled, disabledReason, onSave, }: Props) { const [vars, setVars] = useState(initial); useEffect(() => { setVars(initial); }, [initial]); const updateVar = (index: number, field: keyof EnvVar, value: string) => { const updated = [...vars]; updated[index] = { ...updated[index], [field]: value }; setVars(updated); }; return (
{disabled && disabledReason && (

{disabledReason}

)} {vars.length === 0 && (

No environment variables configured.

)} {/* The row's widths live on wrapper divs, not on the inputs. `inputClass` carries `w-full`, and a width utility on the input itself does not beat it — class-attribute order is not what resolves the conflict, stylesheet order is. Sizing the key input directly left it asking for the whole row and collapsed the value input, whose `flex-1` basis of 0 gave it only the leftover space, to an unusable sliver. */} {vars.map((ev, i) => (
updateVar(i, "key", e.target.value)} onBlur={() => onSave(vars)} placeholder="KEY" aria-label={`Environment variable ${i + 1} name`} disabled={disabled} className={monoInputClass} />
updateVar(i, "value", e.target.value)} onBlur={() => onSave(vars)} placeholder="value" aria-label={`Environment variable ${i + 1} value`} disabled={disabled} className={monoInputClass} />
))}
); }