Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(ui): keep the Galaxy selection on Back and cancel to the same root

Bernhard Jackiewiczd173178f08a7
diff --git a/docs/development/pr-2068-galaxy-history.md b/docs/development/pr-2068-galaxy-history.md
index af318c5a8..448757a04 100644
--- a/docs/development/pr-2068-galaxy-history.md
+++ b/docs/development/pr-2068-galaxy-history.md
@@ -56,6 +56,11 @@ the scope that was open before.
10. **Empty canvas.** A click on empty canvas inside a scope clears only the
path highlight (K9). That is a step of its own, so Back brings the path
back.
+11. **Selection follows the root.** Back or Forward to "All graph" clears the
+ selection. An entry with another root selects that root once it is loaded.
+ An entry with the same root (another depth, direction or path, and a
+ cancelled layer) keeps the selection, so Selection details and the chat
+ context stay.
## Where it lives
diff --git a/graph-ui/src/galaxy/GalaxyPanel.history.test.tsx b/graph-ui/src/galaxy/GalaxyPanel.history.test.tsx
index 62aa0773d..e705d193d 100644
--- a/graph-ui/src/galaxy/GalaxyPanel.history.test.tsx
+++ b/graph-ui/src/galaxy/GalaxyPanel.history.test.tsx
@@ -5,7 +5,7 @@
* Attrappe mit einem Knopf fuer die leere Flaeche; die Beziehungen kommen ueber
* dieselbe RPC-Strecke wie im Betrieb (test-scope-fetch.ts).
*/
-import { act } from 'react';
+import { act, useState } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import GalaxyPanel from './GalaxyPanel';
@@ -206,3 +206,56 @@ it('K2: the recent list jumps straight to an earlier root with its last depth',
expect(named('Forward')?.disabled).toBe(true);
expect(named('Back')?.title).toBe('Back to n5 · 1 layer (Alt+Left)');
});
+
+/*
+ * Wie App.tsx: die Auswahl lebt ausserhalb des Panels, "Selection details"
+ * steht nur, solange sie besteht, und `onClearSelection` loescht sie.
+ */
+function SelectionHarness({ fetch }: { fetch: typeof globalThis.fetch }) {
+ const [selected, setSelected] = useState<string | undefined>();
+ return <GalaxyPanel project="sample" visible workspaceExpanded onOpenNode={vi.fn()} fetch={fetch}
+ onSelectNode={node => setSelected(node.name)} onClearSelection={() => setSelected(undefined)}
+ selectionPanel={selected ? <p data-testid="selected-node">{selected}</p> : undefined} />;
+}
+const selectedNode = () => host.querySelector('[data-testid="selected-node"]')?.textContent;
+
+it('K2/K8: Back to the same root at another depth, and a cancelled layer, keep the selection and its details', async () => {
+ let block = false, release: () => void = () => {};
+ const { fetch } = scopeFetch({ nodes, edges, gate: async () => {
+ if (block) await new Promise<void>(resolve => { release = resolve; });
+ } });
+ await act(async () => root.render(<SelectionHarness fetch={fetch} />));
+ await settle(() => expect(seam().nodes).toBe(5));
+ await act(async () => { seam().clickNode('sample.n1'); });
+ await settle(() => expect(host.querySelector('.atlas-graph-scope-count')?.textContent).toBe('4 nodes · 3 edges'));
+ expect(selectedNode()).toBe('n1');
+ await act(async () => button('Expand +1')!.click());
+ await settle(() => expect(layers()).toBe('2 layers'));
+ expect(selectedNode()).toBe('n1');
+
+ // Back to the same root one layer less: the root stays selected, Selection details stays open to read.
+ await act(async () => named('Back')!.click());
+ await settle(() => expect(layers()).toBe('1 layer'));
+ expect(scopeName()).toBe('n1');
+ expect(selectedNode()).toBe('n1');
+ expect(host.querySelector('.atlas-galaxy-selection-details')).not.toBeNull();
+ await act(async () => named('Forward')!.click());
+ await settle(() => expect(layers()).toBe('2 layers'));
+ expect(selectedNode()).toBe('n1');
+
+ // "−" while a layer loads cancels back one step; the selection is the same root and stays.
+ block = true;
+ await act(async () => button('Expand +1')!.click());
+ await settle(() => expect(host.querySelector('.atlas-graph-scope-count')?.getAttribute('data-state')).toBe('loading'));
+ await act(async () => host.querySelector<HTMLButtonElement>('button[aria-label="Remove graph layer"]')!.click());
+ await settle(() => expect(layers()).toBe('2 layers'));
+ expect(selectedNode()).toBe('n1');
+ expect(host.querySelector('.atlas-galaxy-selection-details')).not.toBeNull();
+ block = false;
+ await act(async () => { release(); });
+
+ // Back to All graph still clears it: the whole graph has no selected root.
+ await act(async () => button('All graph')!.click());
+ await settle(() => expect(host.querySelector('.atlas-graph-scope-name')).toBeNull());
+ expect(selectedNode()).toBeUndefined();
+});
diff --git a/graph-ui/src/galaxy/GalaxyPanel.tsx b/graph-ui/src/galaxy/GalaxyPanel.tsx
index a6ceeada8..2b05a2250 100644
--- a/graph-ui/src/galaxy/GalaxyPanel.tsx
+++ b/graph-ui/src/galaxy/GalaxyPanel.tsx
@@ -1954,10 +1954,16 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {
setTrailStep(0);
setBackgroundCleared(false);
setNote('');
- // A symbol scope reports its root itself once it is complete (see `notifiedScopedSymbol`); the same root stays selected.
- const sameRoot = entry.scope && scope.scope && scopeIdentity(entry.scope) === scopeIdentity(scope.scope);
- if (entry.scope && !sameRoot) selectOnComplete.current = entry.scope.kind === 'symbol' ? undefined : scopeIdentity(entry.scope);
- else { setHighlighted(null); props.onClearSelection?.(); }
+ /*
+ * Die Auswahl folgt der Wurzel: der ganze Graph hat keine, eine andere
+ * Wurzel waehlt sich, sobald sie geladen ist (ein Symbol meldet sich
+ * selbst, siehe `notifiedScopedSymbol`), und dieselbe Wurzel auf einer
+ * anderen Tiefe oder nach einem Abbruch bleibt ausgewaehlt, mit ihren
+ * "Selection details" und dem Kontext des Chats.
+ */
+ if (!entry.scope) { setHighlighted(null); props.onClearSelection?.(); }
+ else if (!scope.scope || scopeIdentity(entry.scope) !== scopeIdentity(scope.scope))
+ selectOnComplete.current = entry.scope.kind === 'symbol' ? undefined : scopeIdentity(entry.scope);
}, [scope.restore, scope.scope, changeTraceTypes, project, props.onClearSelection]);
const historyBack = peekNavigation(history, -1);
const historyForward = peekNavigation(history, 1);