refactor(agent-form): add tab navigation inside Edit modal; pair short fields in 2 columns; delete dead hidden input

The Edit modal was still a vertical scroll of 5 stacked sections (12+
form fields + an embedded Heartbeat card + action bar) even after C5
named the sections. A modal is a transient affordance — making the
user scroll inside it was the wrong design. Same IA move we made for
the Settings page one round ago: add tabs.

Tabs inside the modal:

  Identity | Runtime | Budget & scope | Behavior

Each tab swaps the pane. Tab label carries the section context, so
every section body lost its SectionHeader wrapper — the nested
"card-in-a-card" look around HeartbeatSection is gone; Behavior tab
just renders the heartbeat controls directly.

Field-level polish bundled in the same pass because it hit the same
render paths:

- Identity tab: Name + Role paired in a 2-column grid; Department +
  Reports To paired. Title spans full width because its values are
  often longer. The modal no longer grows tall just to fit two short
  inputs side by side.
- Runtime tab: Status stands alone at the top (high-frequency
  control — pause/resume). Connector + Model paired; Thinking Effort
  + Workspace paired. Each paired row keeps its inline hint (connector
  issue / effort-not-supported) tied to the field it belongs to,
  instead of appearing as loose paragraphs between fields.
- Budget tab: Budget input + BudgetBar + burn line cluster into one
  grouped column so typing a new cap updates the visual context in
  place.
- Behavior tab: HeartbeatSection rendered at the tab root — no
  SectionHeader wrapper around it. The card's "Continuous Execution"
  title + Wake-now button now read as the primary content of the
  tab, not as something buried beneath a header.

Also removed:
- `<input type="hidden" data-agent-id={agent.id} />` in RuntimeSection
  — dead code, zero semantic purpose, leftover from an earlier
  experiment. Caught during the audit.
- `SectionHeader.tsx` — no more callers after sections stopped
  wrapping themselves in it. File deleted.

Added i18n keys (zh + en):
  agent.form.tabsAria.

Tab-label copy reuses the existing `agent.form.sectionIdentity`,
`sectionRuntime`, `sectionConstraints`, `sectionBehavior` keys —
same strings that the removed SectionHeader rendered, now carried
by the tab labels.

Covers EJ1 / EJ2 / EJ3 / EJ4 / EJ5 / ES1 / ES3 / ES4 from the
second-round Edit-modal audit.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 21:14:00 -04:00
1 parent 1933fd6192
commit 50685b952c
7 files changed
+213 -177

No files matched your search

@@ -13,7 +13,8 @@ import { IdentitySection } from "./edit-sections/IdentitySection";
import { RuntimeSection } from "./edit-sections/RuntimeSection"; import { RuntimeSection } from "./edit-sections/RuntimeSection";
import { ConstraintsSection } from "./edit-sections/ConstraintsSection"; import { ConstraintsSection } from "./edit-sections/ConstraintsSection";
import { EditActionBar } from "./edit-sections/EditActionBar"; import { EditActionBar } from "./edit-sections/EditActionBar";
import { SectionHeader } from "./edit-sections/SectionHeader";
type EditTab = "identity" | "runtime" | "constraints" | "behavior";
interface EditFormBodyProps { interface EditFormBodyProps {
agent: AgentRecord; agent: AgentRecord;
@@ -31,16 +32,17 @@ interface EditFormBodyProps {
} }
/** /**
* Orchestrator for the agent Edit modal. Owns the save / wake / delete * Agent Edit modal body. Tabs replace the previous single-scroll stack
* side effects, the save-error latch, and the dirty-state derivation; * so a 12-field edit surface no longer forces the modal to grow tall
* renders through five section components so each concern (identity, * and scroll internally. Same IA pattern as the Settings page.
* runtime, constraints, behavior, skills) lives in a ≤200 LOC file.
* *
* "Dirty" is computed from the form state vs. the persisted agent record * Tab state is local — the modal is transient. Default is "identity"
* plus the persisted budget policy. We intentionally compare trimmed * because that is where users land for name/role/department edits,
* strings and numeric budget so that whitespace-only edits do not falsely * which are the most common touches after the runtime cluster.
* enable Save. Root-agent guards against Delete / terminate live here *
* and are threaded into the relevant sections. * Dirty-state and save/wake/delete handlers stay in this orchestrator;
* each tab renders a pure-body section component that receives form
* state + computed flags via props.
*/ */
export function EditFormBody({ export function EditFormBody({
agent, agent,
@@ -57,6 +59,7 @@ export function EditFormBody({
}: EditFormBodyProps) { }: EditFormBodyProps) {
const t = useT(); const t = useT();
const [saveError, setSaveError] = useState<string | null>(null); const [saveError, setSaveError] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState<EditTab>("identity");
const pendingApproval = agent.status === "pending_approval"; const pendingApproval = agent.status === "pending_approval";
const isRootAgent = !agent.reportsTo; const isRootAgent = !agent.reportsTo;
@@ -83,6 +86,13 @@ export function EditFormBody({
); );
}, [form, agent, pendingApproval]); }, [form, agent, pendingApproval]);
const tabs: Array<{ id: EditTab; label: string }> = [
{ id: "identity", label: t("agent.form.sectionIdentity") },
{ id: "runtime", label: t("agent.form.sectionRuntime") },
{ id: "constraints", label: t("agent.form.sectionConstraints") },
{ id: "behavior", label: t("agent.form.sectionBehavior") },
];
async function persistAgentDraft() { async function persistAgentDraft() {
const meta = { ...form.existingMeta }; const meta = { ...form.existingMeta };
if (form.thinkingEffort) meta.thinkingEffort = form.thinkingEffort; if (form.thinkingEffort) meta.thinkingEffort = form.thinkingEffort;
@@ -159,28 +169,65 @@ export function EditFormBody({
} }
return ( return (
<div className="grid min-w-0 gap-6"> <div className="grid min-w-0 gap-5">
<IdentitySection form={form} agent={agent} agents={agents} pendingApproval={pendingApproval} /> <nav
<RuntimeSection role="tablist"
form={form} aria-label={t("agent.form.tabsAria")}
agent={agent} className="flex flex-wrap gap-1 border-b border-border"
workspaces={workspaces} >
connectorOptions={connectorOptions} {tabs.map((tab) => {
selectedConnectorIssue={selectedConnectorIssue} const active = activeTab === tab.id;
pendingApproval={pendingApproval} return (
isRootAgent={isRootAgent} <button
/> key={tab.id}
<ConstraintsSection form={form} agent={agent} pendingApproval={pendingApproval} /> type="button"
<SectionHeader title={t("agent.form.sectionBehavior")}> role="tab"
<HeartbeatSection aria-selected={active}
agent={agent} onClick={() => setActiveTab(tab.id)}
companyId={companyId} className={`relative px-4 py-2 text-[13px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${
pendingApproval={pendingApproval} active
persistedConnectorIssue={selectedConnectorIssue ?? persistedConnectorIssue} ? "text-foreground"
onSaved={onSaved} : "text-muted-foreground hover:text-foreground"
onWakeNow={() => void handleWakeNow()} }`}
/> >
</SectionHeader> {tab.label}
{active ? (
<span aria-hidden="true" className="absolute inset-x-2 bottom-[-1px] h-[2px] bg-primary" />
) : null}
</button>
);
})}
</nav>
<div>
{activeTab === "identity" ? (
<IdentitySection form={form} agent={agent} agents={agents} pendingApproval={pendingApproval} />
) : null}
{activeTab === "runtime" ? (
<RuntimeSection
form={form}
workspaces={workspaces}
connectorOptions={connectorOptions}
selectedConnectorIssue={selectedConnectorIssue}
pendingApproval={pendingApproval}
isRootAgent={isRootAgent}
/>
) : null}
{activeTab === "constraints" ? (
<ConstraintsSection form={form} agent={agent} pendingApproval={pendingApproval} />
) : null}
{activeTab === "behavior" ? (
<HeartbeatSection
agent={agent}
companyId={companyId}
pendingApproval={pendingApproval}
persistedConnectorIssue={selectedConnectorIssue ?? persistedConnectorIssue}
onSaved={onSaved}
onWakeNow={() => void handleWakeNow()}
/>
) : null}
</div>
<EditActionBar <EditActionBar
agent={agent} agent={agent}
pendingApproval={pendingApproval} pendingApproval={pendingApproval}
@@ -4,7 +4,6 @@ import { BudgetBar } from "../../../helpers";
import { formatMoney } from "../../../../../lib/formatters"; import { formatMoney } from "../../../../../lib/formatters";
import { useT } from "../../../../../i18n"; import { useT } from "../../../../../i18n";
import type { AgentFormState } from "../../useAgentForm"; import type { AgentFormState } from "../../useAgentForm";
import { SectionHeader } from "./SectionHeader";
interface ConstraintsSectionProps { interface ConstraintsSectionProps {
form: AgentFormState; form: AgentFormState;
@@ -13,11 +12,10 @@ interface ConstraintsSectionProps {
} }
/** /**
* Budget + scope of work. Budget surfaces the live burn via BudgetBar so * Budget + scope of work. Live burn bar + spent/budget line appear
* the board can see whether a proposed change (typing a new budget in the * together under the input so typing a new cap updates the visual
* input) tracks reality. Capabilities gets a concrete placeholder so * context immediately. Capabilities gets a concrete placeholder so
* agents ship with useful, specific scope statements instead of the * agents ship with specific scope statements.
* previous "What this agent does" circular prompt.
*/ */
export function ConstraintsSection({ form, agent, pendingApproval }: ConstraintsSectionProps) { export function ConstraintsSection({ form, agent, pendingApproval }: ConstraintsSectionProps) {
const t = useT(); const t = useT();
@@ -25,26 +23,28 @@ export function ConstraintsSection({ form, agent, pendingApproval }: Constraints
const showBurn = budgetValue > 0 || agent.spentMonthlyUsd > 0; const showBurn = budgetValue > 0 || agent.spentMonthlyUsd > 0;
return ( return (
<SectionHeader title={t("agent.form.sectionConstraints")}> <div className="grid gap-4">
<Input <div className="grid gap-1.5">
label={t("agent.budget")} <Input
value={form.budget} label={t("agent.budget")}
onChange={form.setBudget} value={form.budget}
placeholder={t("agent.form.budgetPlaceholder")} onChange={form.setBudget}
type="number" placeholder={t("agent.form.budgetPlaceholder")}
readOnly={pendingApproval} type="number"
disabled={pendingApproval} readOnly={pendingApproval}
/> disabled={pendingApproval}
{showBurn ? ( />
<div className="grid gap-1.5"> {showBurn ? (
<BudgetBar spent={agent.spentMonthlyUsd} budget={budgetValue} /> <>
<p className="text-[11px] text-muted-foreground"> <BudgetBar spent={agent.spentMonthlyUsd} budget={budgetValue} />
{t("agent.form.budgetBurn") <p className="text-[11px] text-muted-foreground">
.replace("{spent}", formatMoney(agent.spentMonthlyUsd)) {t("agent.form.budgetBurn")
.replace("{budget}", formatMoney(budgetValue))} .replace("{spent}", formatMoney(agent.spentMonthlyUsd))
</p> .replace("{budget}", formatMoney(budgetValue))}
</div> </p>
) : null} </>
) : null}
</div>
<TextArea <TextArea
label={t("agent.capabilities")} label={t("agent.capabilities")}
value={form.capabilities} value={form.capabilities}
@@ -53,6 +53,6 @@ export function ConstraintsSection({ form, agent, pendingApproval }: Constraints
readOnly={pendingApproval} readOnly={pendingApproval}
disabled={pendingApproval} disabled={pendingApproval}
/> />
</SectionHeader> </div>
); );
} }
@@ -3,7 +3,6 @@ import type { AgentRecord, DepartmentId } from "@shared/types";
import { Input, Select } from "../../../../ui"; import { Input, Select } from "../../../../ui";
import { useT } from "../../../../../i18n"; import { useT } from "../../../../../i18n";
import type { AgentFormState } from "../../useAgentForm"; import type { AgentFormState } from "../../useAgentForm";
import { SectionHeader } from "./SectionHeader";
interface IdentitySectionProps { interface IdentitySectionProps {
form: AgentFormState; form: AgentFormState;
@@ -13,34 +12,36 @@ interface IdentitySectionProps {
} }
/** /**
* Who this agent is and where they sit in the org: Name / Role / Title / * Who this agent is and where they sit in the org. Rendered as the body
* Department / Reports To. "Assignments" (Reports To) lives here because it * of the Identity tab inside the Edit modal — no section header, the tab
* answers the same question identity fields do — who is this person — and * label carries that context. Short identity fields are paired on wider
* keeping it with Name/Role lets the user fill the whole identity picture * viewports via the 2-column grid so the modal does not grow tall just
* in one pass before moving to runtime config. * to fit Name + Role side by side.
*/ */
export function IdentitySection({ form, agent, agents, pendingApproval }: IdentitySectionProps) { export function IdentitySection({ form, agent, agents, pendingApproval }: IdentitySectionProps) {
const t = useT(); const t = useT();
const managerCandidates = agents.filter((a) => a.id !== agent.id); const managerCandidates = agents.filter((a) => a.id !== agent.id);
return ( return (
<SectionHeader title={t("agent.form.sectionIdentity")}> <div className="grid gap-4">
<Input <div className="grid gap-4 sm:grid-cols-2">
label={t("agent.name")} <Input
value={form.name} label={t("agent.name")}
onChange={form.setName} value={form.name}
placeholder={t("agent.name")} onChange={form.setName}
readOnly={pendingApproval} placeholder={t("agent.name")}
disabled={pendingApproval} readOnly={pendingApproval}
/> disabled={pendingApproval}
<Input />
label={t("agent.role")} <Input
value={form.role} label={t("agent.role")}
onChange={form.setRole} value={form.role}
placeholder={t("agent.role")} onChange={form.setRole}
readOnly={pendingApproval} placeholder={t("agent.role")}
disabled={pendingApproval} readOnly={pendingApproval}
/> disabled={pendingApproval}
/>
</div>
<Input <Input
label={t("agent.title")} label={t("agent.title")}
value={form.title} value={form.title}
@@ -49,26 +50,28 @@ export function IdentitySection({ form, agent, agents, pendingApproval }: Identi
readOnly={pendingApproval} readOnly={pendingApproval}
disabled={pendingApproval} disabled={pendingApproval}
/> />
<Select <div className="grid gap-4 sm:grid-cols-2">
label={t("comm.department")} <Select
value={form.department} label={t("comm.department")}
onChange={(value) => form.setDepartment(value as DepartmentId | "")} value={form.department}
disabled={pendingApproval} onChange={(value) => form.setDepartment(value as DepartmentId | "")}
options={DEPARTMENT_OPTIONS.map((option) => ({ disabled={pendingApproval}
value: option.value, options={DEPARTMENT_OPTIONS.map((option) => ({
label: option.value === "" ? t("comm.selectDepartment") : option.label, value: option.value,
}))} label: option.value === "" ? t("comm.selectDepartment") : option.label,
/> }))}
<Select />
label={t("agent.reportsTo")} <Select
value={form.reportsTo} label={t("agent.reportsTo")}
onChange={form.setReportsTo} value={form.reportsTo}
disabled={pendingApproval} onChange={form.setReportsTo}
options={[ disabled={pendingApproval}
{ value: "", label: t("agent.noManager") }, options={[
...managerCandidates.map((a) => ({ value: a.id, label: a.name })), { value: "", label: t("agent.noManager") },
]} ...managerCandidates.map((a) => ({ value: a.id, label: a.name })),
/> ]}
</SectionHeader> />
</div>
</div>
); );
} }
@@ -2,11 +2,9 @@ import type { AgentRecord, ConnectorRecord, WorkspaceRecord } from "@shared/type
import { Select } from "../../../../ui"; import { Select } from "../../../../ui";
import { useT } from "../../../../../i18n"; import { useT } from "../../../../../i18n";
import type { AgentFormState } from "../../useAgentForm"; import type { AgentFormState } from "../../useAgentForm";
import { SectionHeader } from "./SectionHeader";
interface RuntimeSectionProps { interface RuntimeSectionProps {
form: AgentFormState; form: AgentFormState;
agent: AgentRecord;
workspaces: WorkspaceRecord[]; workspaces: WorkspaceRecord[];
connectorOptions: Array<{ value: string; label: string }>; connectorOptions: Array<{ value: string; label: string }>;
selectedConnectorIssue: string | null; selectedConnectorIssue: string | null;
@@ -15,19 +13,15 @@ interface RuntimeSectionProps {
} }
/** /**
* How this agent runs: which connector, which model, thinking effort, * How this agent runs: status + which connector/model/effort it uses +
* which workspace, and what the current runtime status is. Status + * which workspace. Status leads because it is the high-frequency control
* connector + model cluster together because that is what the orchestrator * (pause / resume / mark error); the connector/model cluster follows
* reads when dispatching a run. * because those change rarely. Thinking Effort stays always-visible
* * with a disabled state when the current connector's models don't
* Thinking Effort is always shown (instead of disappearing when the model * accept the hint — users can see the option exists.
* does not support it) so users can see the option exists — it is
* disabled with an inline note when the selected connector's provider
* does not accept the hint.
*/ */
export function RuntimeSection({ export function RuntimeSection({
form, form,
agent,
workspaces, workspaces,
connectorOptions, connectorOptions,
selectedConnectorIssue, selectedConnectorIssue,
@@ -35,9 +29,10 @@ export function RuntimeSection({
isRootAgent, isRootAgent,
}: RuntimeSectionProps) { }: RuntimeSectionProps) {
const t = useT(); const t = useT();
const showInlineEffortHint = !form.supportsEffort && !pendingApproval;
return ( return (
<SectionHeader title={t("agent.form.sectionRuntime")}> <div className="grid gap-4">
<Select <Select
label={t("agent.status")} label={t("agent.status")}
value={form.status} value={form.status}
@@ -64,51 +59,58 @@ export function RuntimeSection({
{isRootAgent && !pendingApproval ? ( {isRootAgent && !pendingApproval ? (
<p className="text-[12px] text-muted-foreground">{t("agent.form.rootTerminateBlocked")}</p> <p className="text-[12px] text-muted-foreground">{t("agent.form.rootTerminateBlocked")}</p>
) : null} ) : null}
<Select <div className="grid gap-4 sm:grid-cols-2">
label={t("agent.connector")} <div className="grid gap-1.5">
value={form.connectorId} <Select
onChange={(v) => form.setConnectorId(v as ConnectorRecord["id"])} label={t("agent.connector")}
disabled={pendingApproval} value={form.connectorId}
options={connectorOptions} onChange={(v) => form.setConnectorId(v as ConnectorRecord["id"])}
/> disabled={pendingApproval}
{selectedConnectorIssue ? ( options={connectorOptions}
<p className="text-[12px] text-warning">{selectedConnectorIssue}</p> />
) : null} {selectedConnectorIssue ? (
{form.availableModels.length > 0 ? ( <p className="text-[12px] text-warning">{selectedConnectorIssue}</p>
) : null}
</div>
{form.availableModels.length > 0 ? (
<Select
label={t("agent.model")}
value={form.model}
onChange={form.setModel}
disabled={pendingApproval}
options={form.availableModels.map((m) => ({ value: m.id, label: m.label }))}
/>
) : <div />}
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="grid gap-1.5">
<Select
label={t("agent.thinkingEffort")}
value={form.thinkingEffort}
onChange={form.setThinkingEffort}
disabled={pendingApproval || !form.supportsEffort}
options={[
{ value: "", label: t("agent.form.effortDefault") },
{ value: "low", label: t("agent.form.effortLow") },
{ value: "medium", label: t("agent.form.effortMedium") },
{ value: "high", label: t("agent.form.effortHigh") },
]}
/>
{showInlineEffortHint ? (
<p className="text-[11px] text-muted-foreground">{t("agent.form.effortNotSupported")}</p>
) : null}
</div>
<Select <Select
label={t("agent.model")} label={t("agent.workspace")}
value={form.model} value={form.workspaceId}
onChange={form.setModel} onChange={form.setWorkspaceId}
disabled={pendingApproval} disabled={pendingApproval}
options={form.availableModels.map((m) => ({ value: m.id, label: m.label }))} options={[
{ value: "", label: t("agent.noWorkspace") },
...workspaces.map((w) => ({ value: w.id, label: w.name })),
]}
/> />
) : null} </div>
<Select </div>
label={t("agent.thinkingEffort")}
value={form.thinkingEffort}
onChange={form.setThinkingEffort}
disabled={pendingApproval || !form.supportsEffort}
options={[
{ value: "", label: t("agent.form.effortDefault") },
{ value: "low", label: t("agent.form.effortLow") },
{ value: "medium", label: t("agent.form.effortMedium") },
{ value: "high", label: t("agent.form.effortHigh") },
]}
/>
{!form.supportsEffort && !pendingApproval ? (
<p className="text-[11px] text-muted-foreground">{t("agent.form.effortNotSupported")}</p>
) : null}
<Select
label={t("agent.workspace")}
value={form.workspaceId}
onChange={form.setWorkspaceId}
disabled={pendingApproval}
options={[
{ value: "", label: t("agent.noWorkspace") },
...workspaces.map((w) => ({ value: w.id, label: w.name })),
]}
/>
<input type="hidden" data-agent-id={agent.id} />
</SectionHeader>
); );
} }
@@ -1,18 +0,0 @@
import type { ReactNode } from "react";
/**
* Consistent header for Edit-form sections. Single style (11px uppercase
* muted) used across Identity / Runtime / Constraints / Skills / Behavior
* so the form reads as one rhythm instead of a mix of bold banners + bare
* labels.
*/
export function SectionHeader({ title, children }: { title: string; children?: ReactNode }) {
return (
<section className="border-t border-border pt-4 first:border-t-0 first:pt-0">
<h3 className="mb-3 text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground">
{title}
</h3>
<div className="grid gap-4">{children}</div>
</section>
);
}
+1
View File
@@ -1390,6 +1390,7 @@ export const en: Record<string, string> = {
"agent.form.sectionRuntime": "Runtime", "agent.form.sectionRuntime": "Runtime",
"agent.form.sectionConstraints": "Budget & scope", "agent.form.sectionConstraints": "Budget & scope",
"agent.form.sectionBehavior": "Behavior", "agent.form.sectionBehavior": "Behavior",
"agent.form.tabsAria": "Agent edit categories",
"agent.form.statusIdle": "Idle", "agent.form.statusIdle": "Idle",
"agent.form.statusActive": "Active", "agent.form.statusActive": "Active",
"agent.form.statusRunning": "Running", "agent.form.statusRunning": "Running",
+1
View File
@@ -1390,6 +1390,7 @@ export const zh: Record<string, string> = {
"agent.form.sectionRuntime": "运行时", "agent.form.sectionRuntime": "运行时",
"agent.form.sectionConstraints": "预算与范围", "agent.form.sectionConstraints": "预算与范围",
"agent.form.sectionBehavior": "行为", "agent.form.sectionBehavior": "行为",
"agent.form.tabsAria": "成员编辑分类",
"agent.form.statusIdle": "空闲", "agent.form.statusIdle": "空闲",
"agent.form.statusActive": "活跃", "agent.form.statusActive": "活跃",
"agent.form.statusRunning": "运行中", "agent.form.statusRunning": "运行中",