Skip to content

Commit d4b0eeb

Browse files
committed
fix(graph-ui): clear ADR content on delete
Signed-off-by: ShiroKSH <kushidashiro@gmail.com>
1 parent 8d00f4b commit d4b0eeb

2 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎graph-ui/src/components/StatsTab.test.tsx‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,53 @@ describe("StatsTab index modal", () => {
207207
await new Promise((r) => setTimeout(r, 400));
208208
expect(browseCalls()).toBe(before);
209209
});
210+
211+
it("posts empty ADR content when deleting an existing ADR", async () => {
212+
let saved: unknown = null;
213+
mockProjectsFetch((url, init) => {
214+
if (url === "/rpc") {
215+
const body = JSON.parse(String(init?.body));
216+
const tool = body.params?.name;
217+
const result = tool === "list_projects"
218+
? {
219+
projects: [{
220+
name: "demo",
221+
root_path: "/repo",
222+
indexed_at: "2026-01-01T00:00:00Z",
223+
}],
224+
}
225+
: { node_labels: [], edge_types: [], total_nodes: 0, total_edges: 0 };
226+
return new Response(JSON.stringify({
227+
result: { content: [{ text: JSON.stringify(result) }] },
228+
}), { status: 200, headers: { "Content-Type": "application/json" } });
229+
}
230+
if (url.startsWith("/api/adr")) {
231+
if (init?.method === "POST") {
232+
saved = JSON.parse(String(init.body));
233+
return new Response(JSON.stringify({ ok: true }), {
234+
status: 200,
235+
headers: { "Content-Type": "application/json" },
236+
});
237+
}
238+
return new Response(JSON.stringify({
239+
has_adr: true,
240+
content: "old decision text",
241+
updated_at: "2026-01-01",
242+
}), { status: 200, headers: { "Content-Type": "application/json" } });
243+
}
244+
return undefined;
245+
});
246+
247+
render(<StatsTab onSelectProject={() => {}} />);
248+
fireEvent.click(await screen.findByRole("button", { name: "ADR" }));
249+
expect(await screen.findByDisplayValue("old decision text")).toBeInTheDocument();
250+
251+
fireEvent.click(screen.getByRole("button", { name: "Delete" }));
252+
253+
await waitFor(() => {
254+
expect(saved).toEqual({ project: "demo", content: "" });
255+
});
256+
});
210257
});
211258

212259
describe("IndexProgress", () => {

‎graph-ui/src/components/StatsTab.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ function AdrButton({ project }: { project: string }) {
8585

8686
useEffect(() => { fetchAdr(); }, [fetchAdr]);
8787

88-
const save = async () => {
88+
const save = async (nextContent = content) => {
8989
setSaving(true);
9090
try {
9191
await fetch("/api/adr", {
9292
method: "POST",
9393
headers: { "Content-Type": "application/json" },
94-
body: JSON.stringify({ project, content }),
94+
body: JSON.stringify({ project, content: nextContent }),
9595
});
9696
await fetchAdr();
9797
setOpen(false);
@@ -138,15 +138,15 @@ function AdrButton({ project }: { project: string }) {
138138
{hasAdr && (
139139
<button
140140
onClick={async () => {
141-
setContent(""); await save();
141+
setContent(""); await save("");
142142
}}
143143
className="px-3 py-2 rounded-lg text-[12px] text-destructive/60 hover:text-destructive hover:bg-destructive/10 font-medium transition-all"
144144
>
145145
{t.common.delete}
146146
</button>
147147
)}
148148
<button onClick={() => setOpen(false)} className="px-4 py-2 rounded-lg text-[12px] text-foreground/40 hover:bg-white/[0.04] font-medium transition-all">{t.common.cancel}</button>
149-
<button onClick={save} disabled={saving} className="px-4 py-2 rounded-lg bg-primary/20 hover:bg-primary/30 text-primary text-[12px] font-medium transition-all disabled:opacity-30">
149+
<button onClick={() => save()} disabled={saving} className="px-4 py-2 rounded-lg bg-primary/20 hover:bg-primary/30 text-primary text-[12px] font-medium transition-all disabled:opacity-30">
150150
{saving ? t.common.saving : t.common.save}
151151
</button>
152152
</div>

0 commit comments

Comments
 (0)