Scope git history to current diagram by default

- History panel defaults to "This diagram" / "All" toggle
- "This diagram" filters git log to commits that touched only that
  diagram's JSON file (git log -- diagrams/0001_*.json)
- Automatically switches to "All" when no diagram is open
- Restore flow still works per-commit, per-file

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 20:07:05 -04:00
parent 072e620d56
commit 0bbcaa8ee5
5 changed files with 46 additions and 6 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ const api = {
},
git: {
status: () => apiFetch("/git/status"),
log: () => apiFetch("/git/log"),
log: (diagram_id) => apiFetch(diagram_id != null ? `/git/log?diagram_id=${diagram_id}` : "/git/log"),
commit: (message, diagram_id) => apiFetch("/git/commit", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message, diagram_id: diagram_id ?? null }) }),
push: () => apiFetch("/git/push", { method: "POST" }),
history: (hash) => apiFetch(`/git/history/${hash}`),
+23 -1
View File
@@ -2024,8 +2024,26 @@ class WiringApp {
commitBtn._gitBound = true;
commitBtn.addEventListener("click", () => this._gitCommit());
document.getElementById("btn-git-push").addEventListener("click", () => this._gitPush());
// History scope toggle
const btnDiagram = document.getElementById("btn-git-log-diagram");
const btnAll = document.getElementById("btn-git-log-all");
btnDiagram.addEventListener("click", () => {
btnDiagram.classList.add("active"); btnAll.classList.remove("active");
this._gitLoadLog();
});
btnAll.addEventListener("click", () => {
btnAll.classList.add("active"); btnDiagram.classList.remove("active");
this._gitLoadLog();
});
}
// Default scope: "this diagram" if one is open, else "all"
const hasDiagram = !!this.diagramId;
document.getElementById("btn-git-log-diagram").classList.toggle("active", hasDiagram);
document.getElementById("btn-git-log-all").classList.toggle("active", !hasDiagram);
document.getElementById("btn-git-log-diagram").disabled = !hasDiagram;
await this._gitRefresh();
}
@@ -2051,9 +2069,13 @@ class WiringApp {
async _gitLoadLog() {
const list = document.getElementById("git-log-list");
if (!list) return;
const diagramScope = document.getElementById("btn-git-log-diagram")?.classList.contains("active");
const diagramId = diagramScope && this.diagramId ? this.diagramId : null;
const title = document.getElementById("git-log-title");
if (title) title.textContent = diagramId ? "History — this diagram" : "History — all commits";
list.innerHTML = '<div style="color:#556;padding:4px">Loading…</div>';
try {
const entries = await api.git.log();
const entries = await api.git.log(diagramId);
if (!entries.length) {
list.innerHTML = '<div style="color:#556;padding:4px">No commits yet</div>';
return;