Intelligence
Artifacts
Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.
Repository
assignment-dispatch-button.tsxassignment-status-badge.tsxassignments-panel.tsxcreate-mission-form.tsxgovernance-panels.tsxmission-dispatch.tsxmission-edit.tsxmission-state-actions.tsxmission-status-badge.tsxobjective-edit.tsxobjective-status-badge.tsxobjective-status-select.tsxobjectives-panel.tsxreport-list.tsxwork-orders-panel.tsx
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/components/assets/asset-edit.tsx
4.7 KB
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { Pencil, X, Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Card } from "@/components/ui/card";
import type { Asset, AssetStatus, AssetType } from "@/lib/assets/types";
const TYPES: AssetType[] = [
"Code", "Document", "PDF", "Image", "Video", "Research",
"Prompt", "Template", "Architecture", "Configuration", "Policy", "Other",
];
const STATUSES: AssetStatus[] = ["Active", "Archived", "Deprecated"];
/** Edit an asset's mutable metadata — origin lineage is never editable. */
export function AssetEdit({ asset }: { asset: Asset }) {
const router = useRouter();
const [open, setOpen] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [form, setForm] = useState({
name: asset.name,
type: asset.type,
status: asset.status,
tags: asset.tags.join(", "),
description: asset.description,
});
async function save(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
const res = await fetch(`/api/assets/${asset.asset_id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: form.name,
type: form.type,
status: form.status,
description: form.description,
tags: form.tags.split(",").map((t) => t.trim()).filter(Boolean),
}),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error ?? "Update failed.");
setOpen(false);
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : "Update failed.");
} finally {
setBusy(false);
}
}
return (
<div className="flex flex-col items-end gap-2">
<Button type="button" variant="outline" size="sm" onClick={() => setOpen((v) => !v)}>
{open ? <X className="h-3.5 w-3.5" /> : <Pencil className="h-3.5 w-3.5" />}
{open ? "Close" : "Edit"}
</Button>
{error && <span className="text-[11px] text-destructive">{error}</span>}
{open && (
<Card className="w-full max-w-md p-5 text-left">
<form className="space-y-3" onSubmit={save}>
<Labeled label="Name">
<Input value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })} />
</Labeled>
<div className="grid grid-cols-2 gap-3">
<Labeled label="Type">
<select
value={form.type}
onChange={(e) => setForm({ ...form, type: e.target.value as AssetType })}
className="h-9 w-full rounded-md border border-input bg-background px-2 text-sm"
>
{TYPES.map((t) => (
<option key={t}>{t}</option>
))}
</select>
</Labeled>
<Labeled label="Status">
<select
value={form.status}
onChange={(e) => setForm({ ...form, status: e.target.value as AssetStatus })}
className="h-9 w-full rounded-md border border-input bg-background px-2 text-sm"
>
{STATUSES.map((s) => (
<option key={s}>{s}</option>
))}
</select>
</Labeled>
</div>
<Labeled label="Tags (comma-separated)">
<Input value={form.tags} onChange={(e) => setForm({ ...form, tags: e.target.value })} />
</Labeled>
<Labeled label="Description">
<textarea
value={form.description}
onChange={(e) => setForm({ ...form, description: e.target.value })}
rows={2}
className="flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
</Labeled>
<div className="flex justify-end">
<Button type="submit" size="sm" disabled={busy}>
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : "Save"}
</Button>
</div>
</form>
</Card>
)}
</div>
);
}
function Labeled({ label, children }: { label: string; children: React.ReactNode }) {
return (
<label className="block">
<span className="mb-1 block text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground">
{label}
</span>
{children}
</label>
);
}
root · /srv/aaf