feature: navigation highlighting in tree

This commit is contained in:
2026-03-16 19:35:35 +01:00
parent 2495041a2b
commit 92ef00e78f
4 changed files with 257 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ export interface GraphHandle {
navigateTo: (nodeId: string, path: Array<{ id: string; name: string | undefined }>) => void;
}
const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetStateAction<BreadcrumbItemType[]>> }>(function Graph({ setGraphPath }, ref) {
const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetStateAction<BreadcrumbItemType[]>>, onNavigate?: (graphId: string) => void }>(function Graph({ setGraphPath, onNavigate }, ref) {
const containerRef = useRef(null);
const [graph, setGraph] = useState(defaultGraph());
const [contextMenuOpened, openContextMenu] = useState(false);
@@ -125,6 +125,7 @@ const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetSt
setGraphsPath([createPathSegment('main', 'Main')]);
openNodeContext(null);
openContextMenu(false);
onNavigate?.('main');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loadCount]);
@@ -139,6 +140,7 @@ const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetSt
if (graph) {
setGraph(graph);
}
onNavigate?.(graphId);
}, [graphId]);
async function renderGraph() {
@@ -249,6 +251,7 @@ const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetSt
useImperativeHandle(ref, () => ({
navigateTo(nodeId, path) {
const newPath = path.map(p => createPathSegment(p.id, p.name));
openNodeContext(null);
setGraphsPath(newPath);
selectGraphId(nodeId);
}

View File

@@ -41,6 +41,7 @@ export default function NodeContextMenu({
const graphContextValue = useContext(graphContext)!;
const graphsById = useGraphsStore((s) => (s as { graphsById: Map<string, GraphModel> }).graphsById);
const addTreeNode = useGraphLayersTreeStore(store => store.add);
const removeTreeNode = useGraphLayersTreeStore(store => store.remove);
function contextMenuOpenChange(open: boolean) {
if (!open) {
@@ -56,6 +57,7 @@ export default function NodeContextMenu({
}
case 'remove': {
removeNode(nodeContext.nodeId);
removeTreeNode(nodeContext.nodeId);
break;
}
case 'subgraph': {