feat: implement snapshot restore functionality and enhance graph state management
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user