feat: implement snapshot restore functionality and enhance graph state management
All checks were successful
On Push to Main / test (push) Successful in 40s
On Push to Main / publish (push) Successful in 1m10s
On Push to Main / deploy-dev (push) Successful in 1m35s

This commit is contained in:
RaymondVerhoef
2026-05-27 17:43:18 +02:00
parent 6ea8860b96
commit 6309ae716b
4 changed files with 164 additions and 11 deletions

View File

@@ -25,9 +25,12 @@ const KnowledgeGraph = () => {
const [showExcludeNodes, setShowExcludeNodes] = useState(false);
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [analyzeError, setAnalyzeError] = useState(null);
const [isRestoring, setIsRestoring] = useState(false);
const { topics, relations, reload, updateTopic, deleteTopic, addRelation, removeRelation, bulkSave } =
useGraphData();
const {
topics, relations, snapshotMeta,
reload, updateTopic, deleteTopic, addRelation, removeRelation, bulkSave, restoreSnapshot,
} = useGraphData();
// ── Canvas sizing ────────────────────────────────────────────────────────────
@@ -177,6 +180,24 @@ const KnowledgeGraph = () => {
}
}, [selectedNode, deleteTopic]);
// ── Snapshot restore ─────────────────────────────────────────────────────────
const handleRestore = useCallback(async () => {
if (
!confirm(
`Restore the graph to the snapshot from ${new Date(snapshotMeta?.ts).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}?\n\nThis will undo the last Analyze & Optimize run. The snapshot will be cleared after restoring.`,
)
)
return;
setIsRestoring(true);
try {
await restoreSnapshot();
setSelectedNode(null);
} finally {
setIsRestoring(false);
}
}, [restoreSnapshot, snapshotMeta]);
// ── AI graph analysis ────────────────────────────────────────────────────────
const analyzeGraph = useCallback(async () => {
@@ -309,6 +330,9 @@ Do not return the entire graph — only the actions to take.`;
analyzeError={analyzeError}
disabled={topics.length === 0}
onApplied={reload}
snapshotMeta={snapshotMeta}
onRestore={handleRestore}
isRestoring={isRestoring}
/>
<NodeDetailPanel
selectedNode={selectedNode}