import { useState } from "react"; import { Button } from "~/ui/Button"; import { TextAreaField, TextField } from "~/ui/Field"; import { ErrorBanner } from "~/ui/Callout"; import { EmptyState } from "~/ui/EmptyState"; import { Panel } from "~/ui/Panel"; import { RelativeTime } from "~/ui/RelativeTime"; type Item = { name: string; value?: string; updatedAt: number; detail?: string; /** Extra form fields resubmitted unchanged when only the value is edited (e.g. an owner value's access policy). */ keep?: Record; }; type Props = { title: string; kind: "secret" | "variable"; items: Item[]; pending: boolean; error: string | null; onSave: (name: string, value: string, form: FormData) => Promise; onDelete: (name: string) => void; extraFields?: React.ReactNode; description?: React.ReactNode; }; function ValueField({ kind, editing, defaultValue, }: { kind: Props["kind"]; editing?: boolean; defaultValue?: string; }) { return kind === "secret" ? ( ) : ( ); } /** Edits one value in place; the name is fixed, so renaming means removing it and adding a new one. */ function EditRow({ item, kind, pending, onSave, onDone, }: { item: Item; kind: Props["kind"]; pending: boolean; onSave: Props["onSave"]; onDone: () => void; }) { return (
  • { event.preventDefault(); const form = new FormData(event.currentTarget); if (await onSave(item.name, String(form.get("value") ?? ""), form)) onDone(); }} > {item.name} {Object.entries(item.keep ?? {}).map(([name, value]) => ( ))}
  • ); } /** Add/list/edit/remove panel shared by repository, environment and owner secrets and variables. */ export function ConfigValueList({ title, kind, items, pending, error, onSave, onDelete, extraFields, description, }: Props) { const [editing, setEditing] = useState(null); return (
    { event.preventDefault(); const element = event.currentTarget; const form = new FormData(element); const ok = await onSave(String(form.get("name") ?? ""), String(form.get("value") ?? ""), form); if (ok) element.reset(); }} >
    {extraFields} {description ?

    {description}

    : null} {items.length === 0 ? ( ) : (
      {items.map((item) => editing === item.name ? ( setEditing(null)} /> ) : (
    • {item.name} {item.value !== undefined && ( {item.value} )} {item.detail && {item.detail}} Updated
    • ), )}
    )}
    ); }