Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(explorer): address code review issues from PR #557

KaifAhmad1aab7e2312562
diff --git a/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx b/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx
index 3425a30f..9dd3949a 100644
--- a/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx
+++ b/explorer/src/workspaces/DecisionWorkspace/DecisionWorkspace.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect, useMemo } from "react";
+import { useState, useEffect, useMemo, useRef } from "react";
import { Scale, Search, ArrowRight, Info } from "lucide-react";
type OutcomeKind = "approved" | "rejected" | "deferred" | "pending" | string;
@@ -93,6 +93,9 @@ export function DecisionWorkspace() {
const [listLoading, setListLoading] = useState(true);
const [filter, setFilter] = useState("");
+ // Tracks the active chain request so stale responses from rapid selections are ignored.
+ const chainCtrlRef = useRef<AbortController | null>(null);
+
useEffect(() => {
const ctrl = new AbortController();
setListLoading(true);
@@ -108,17 +111,27 @@ export function DecisionWorkspace() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ // Cancel any in-flight chain request when the workspace unmounts.
+ useEffect(() => () => { chainCtrlRef.current?.abort(); }, []);
+
async function loadChain(d: { decision_id: string; category?: string; outcome?: string }) {
+ chainCtrlRef.current?.abort();
+ const ctrl = new AbortController();
+ chainCtrlRef.current = ctrl;
+
setSelected(d);
setChainLoading(true);
setChain([]);
try {
- const res = await fetch(`/api/decisions/${encodeURIComponent(d.decision_id)}/chain`);
+ const res = await fetch(`/api/decisions/${encodeURIComponent(d.decision_id)}/chain`, { signal: ctrl.signal });
if (!res.ok) throw new Error(`${res.status}`);
const data = await res.json();
- setChain(data.chain || []);
- } catch (e) { console.error(e); }
- finally { setChainLoading(false); }
+ if (!ctrl.signal.aborted) setChain(data.chain || []);
+ } catch (e) {
+ if (e instanceof Error && e.name !== "AbortError") console.error(e);
+ } finally {
+ if (!ctrl.signal.aborted) setChainLoading(false);
+ }
}
const filtered = useMemo(() => {
diff --git a/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx b/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx
index 4c69c2a1..9e8f867a 100644
--- a/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx
+++ b/explorer/src/workspaces/DiffMergeWorkspace/DiffMergeWorkspace.tsx
@@ -73,6 +73,10 @@ export function DiffMergeWorkspace() {
{/* Diff table */}
<div className="ws-card" style={{ padding: 0, overflow: "hidden" }}>
+ <div style={{ padding: "6px 16px", background: "rgba(242,182,109,0.06)", borderBottom: "1px solid rgba(242,182,109,0.15)", display: "flex", alignItems: "center", gap: 6 }}>
+ <span style={{ fontSize: 10, fontWeight: 700, color: "var(--ws-amber)", letterSpacing: "0.08em", textTransform: "uppercase" }}>Sample preview</span>
+ <span style={{ fontSize: 11, color: "var(--ws-text-dim)" }}>— field comparison will load from the graph once the backend is connected</span>
+ </div>
<div style={{ display: "grid", gridTemplateColumns: "140px 1fr 1fr", background: "rgba(0,0,0,0.28)", borderBottom: "1px solid var(--ws-border)" }}>
<div style={{ padding: "10px 16px", fontSize: 11, fontWeight: 700, color: "var(--ws-text-dim)", letterSpacing: "0.08em", textTransform: "uppercase" }}>Field</div>
<div style={{ padding: "10px 16px", fontSize: 11, fontWeight: 700, color: "var(--ws-accent)", letterSpacing: "0.08em", textTransform: "uppercase", borderLeft: "1px solid var(--ws-border)" }}>Primary (keep)</div>
diff --git a/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx b/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx
index f61cbe55..9a7bb915 100644
--- a/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx
+++ b/explorer/src/workspaces/ImportExportWorkspace/ImportExportWorkspace.tsx
@@ -57,7 +57,11 @@ export function ImportExportWorkspace() {
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
- a.href = url; a.download = `semantica_export.${exportFormat}`; a.click();
+ a.href = url;
+ a.download = `semantica_export.${exportFormat}`;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
URL.revokeObjectURL(url);
showToast("success", `Export ready — semantica_export.${exportFormat}`);
logEvent("export", `Exported graph as ${exportFormat.toUpperCase()}`, { format: exportFormat });
diff --git a/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx b/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx
index 455e1c59..bd53cc14 100644
--- a/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx
+++ b/explorer/src/workspaces/LineageWorkspace/LineageDiagram.tsx
@@ -2,6 +2,7 @@
* src/workspaces/LineageWorkspace/LineageDiagram.tsx
*/
import { useEffect, useState } from "react";
+import { Link2 } from "lucide-react";
import { ReactFlow, Background, Controls } from "@xyflow/react";
import "@xyflow/react/dist/style.css";
@@ -149,7 +150,7 @@ export function LineageDiagram() {
</ReactFlow>
) : (
<div className="ws-empty" style={{ height: "100%", paddingTop: 72 }}>
- <div className="ws-empty-icon" style={{ fontSize: 36 }}>🔗</div>
+ <div className="ws-empty-icon"><Link2 size={36} color="var(--ws-accent)" /></div>
<div className="ws-empty-title">PROV-O Lineage Viewer</div>
<div className="ws-empty-body">Enter a Node ID in the toolbar above and click Trace to view its W3C PROV-O lineage diagram.</div>
</div>
diff --git a/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx b/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx
index e28ad1d3..862153dc 100644
--- a/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx
+++ b/explorer/src/workspaces/OntologyWorkspace/AlignmentsTab.tsx
@@ -49,19 +49,24 @@ export function AlignmentsTab() {
const reload = useCallback(async () => {
setError("");
- // Load registry and alignments independently so a backend failure shows
- // empty state rather than an error banner.
- const [registryData, alignmentData] = await Promise.allSettled([
+ const [registryResult, alignmentResult] = await Promise.allSettled([
loadOntologyRegistry(),
loadAlignments(),
]);
- if (registryData.status === "fulfilled") {
- setRegistry(registryData.value);
- setSourceOntology((current) => current || registryData.value[0]?.uri || "");
- setTargetOntology((current) => current || registryData.value[1]?.uri || registryData.value[0]?.uri || "");
+
+ if (registryResult.status === "fulfilled") {
+ setRegistry(registryResult.value);
+ setSourceOntology((current) => current || registryResult.value[0]?.uri || "");
+ setTargetOntology((current) => current || registryResult.value[1]?.uri || registryResult.value[0]?.uri || "");
+ }
+ if (alignmentResult.status === "fulfilled") {
+ setAlignments(alignmentResult.value);
}
- if (alignmentData.status === "fulfilled") {
- setAlignments(alignmentData.value);
+
+ // If both failed the backend is unreachable — show a soft warning so the
+ // user knows data is missing (not just that the registry is empty).
+ if (registryResult.status === "rejected" && alignmentResult.status === "rejected") {
+ setError("Backend unavailable — connect the server to load ontologies and alignments.");
}
}, []);
diff --git a/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx b/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx
index 3efe4158..bb831025 100644
--- a/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx
+++ b/explorer/src/workspaces/OntologyWorkspace/OntologyManager.tsx
@@ -251,6 +251,7 @@ export function OntologyManager() {
const fetchRegistry = useCallback(async () => {
setLoading(true);
+ setActionMsg(null);
try {
const params = new URLSearchParams();
if (searchQ) params.set("q", searchQ);
@@ -258,11 +259,14 @@ export function OntologyManager() {
if (res.ok) {
setEntries(await res.json());
} else {
- // Server not ready or registry empty — treat as empty list, not an error
+ // Non-OK response — show empty state with a soft warning (not a blocking error)
setEntries([]);
+ if (res.status !== 404) {
+ flashMsg("err", `Registry unavailable (HTTP ${res.status}) — connect the backend to load ontologies`);
+ }
}
} catch {
- // Network error (backend not running) — show empty state, not error banner
+ // Network error — backend not running; show empty state silently
setEntries([]);
} finally {
setLoading(false);
diff --git a/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx b/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx
index dc383d56..82bf90dd 100644
--- a/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx
+++ b/explorer/src/workspaces/SparqlWorkspace/SparqlWorkspace.tsx
@@ -96,17 +96,24 @@ export function SparqlWorkspace() {
navigator.clipboard.writeText(query).then(() => {
setCopyState(true);
setTimeout(() => setCopyState(false), 1500);
+ }).catch(() => {
+ // Clipboard API unavailable (insecure context or denied) — no-op; query is visible in editor
});
}
function handleExportCSV() {
if (!result?.rows || !result?.columns) return;
- const header = result.columns.join(",");
- const rows = result.rows.map((r) => result.columns!.map((c) => JSON.stringify(r[c] ?? "")).join(",")).join("\n");
+ const cols = result.columns;
+ const header = cols.join(",");
+ const rows = result.rows.map((r) => cols.map((c) => JSON.stringify(r[c] ?? "")).join(",")).join("\n");
const blob = new Blob([`${header}\n${rows}`], { type: "text/csv" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
- a.href = url; a.download = "sparql_results.csv"; a.click();
+ a.href = url;
+ a.download = "sparql_results.csv";
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
URL.revokeObjectURL(url);
}
@@ -200,7 +207,7 @@ export function SparqlWorkspace() {
</div>
)}
- {result?.rows && !isLoading && (
+ {result?.rows && result?.columns && !isLoading && (
<div className="ws-animate-in" style={{ overflowX: "auto" }}>
{result.rows.length === 0 ? (
<div className="ws-empty">
@@ -212,7 +219,7 @@ export function SparqlWorkspace() {
<thead>
<tr style={{ borderBottom: "1px solid var(--ws-border)", background: "rgba(0,0,0,0.2)" }}>
<th style={{ padding: "8px 14px", textAlign: "left", color: "var(--ws-text-dim)", fontFamily: "monospace", fontSize: 11, fontWeight: 700, letterSpacing: "0.06em", width: 40 }}>#</th>
- {result.columns!.map((c) => (
+ {result.columns.map((c) => (
<th key={c} style={{ padding: "8px 14px", textAlign: "left", color: "var(--ws-text-muted)", fontFamily: "monospace", fontSize: 11, fontWeight: 700, letterSpacing: "0.06em" }}>?{c}</th>
))}
</tr>
@@ -221,7 +228,7 @@ export function SparqlWorkspace() {
{result.rows.map((r, i) => (
<tr key={i} style={{ borderBottom: "1px solid rgba(74,163,255,0.06)" }}>
<td style={{ padding: "7px 14px", color: "var(--ws-text-dim)", fontFamily: "monospace", fontSize: 11 }}>{i + 1}</td>
- {result.columns!.map((c) => (
+ {(result.columns ?? []).map((c) => (
<td key={c} style={{ padding: "7px 14px", maxWidth: 300, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontFamily: "monospace" }} title={String(r[c] ?? "")}>
{r[c] != null ? (
String(r[c]).startsWith("urn:") || String(r[c]).startsWith("http")