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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(ui): fit the scoped Galaxy toolbar by measuring instead of clipping
Bernhard Jackiewicze43a77724573
diff --git a/graph-ui/src/galaxy/GalaxyPanel.toolbar.test.tsx b/graph-ui/src/galaxy/GalaxyPanel.toolbar.test.tsxindex 41e8d7e35..114050971 100644--- a/graph-ui/src/galaxy/GalaxyPanel.toolbar.test.tsx+++ b/graph-ui/src/galaxy/GalaxyPanel.toolbar.test.tsx@@ -79,3 +79,28 @@ it('K2: the history group and the root button say what they are to assistive tecexpect(name.getAttribute('aria-label')).toBe('Open the source of n2');expect(name.textContent).toBe('n2');});++it('K3: the scoped toolbar measures its fit and carries a short label for each wide control', async () => {+ const nodes = [1, 2, 3].map(id => scopeNode(id));+ const edges = [{ id: 1, source: 1, target: 2, type: 'CALLS' }, { id: 2, source: 3, target: 1, type: 'CALLS' }];+ await act(async () => root.render(<GalaxyPanel project="sample" visible workspaceExpanded onOpenNode={vi.fn()} fetch={scopeFetch({ nodes, edges }).fetch} />));+ await settle(() => expect(seam().nodes).toBe(3));+ await act(async () => { seam().clickNode('sample.n1'); });+ await settle(() => expect(host.querySelector('.atlas-graph-scope-count')?.textContent).toBe('3 nodes · 2 edges'));+ const bar = host.querySelector<HTMLElement>('.atlas-graph-exploration')!;+ // jsdom lays nothing out, so everything fits.+ expect(bar.dataset.fit).toBe('full');+ const narrow = (element: Element | null | undefined) => element?.querySelector('.atlas-fit-narrow')?.getAttribute('data-label');+ const expand = [...bar.querySelectorAll('button')].find(entry => entry.textContent === 'Expand +1')!;+ expect(expand.getAttribute('aria-label')).toBe('Expand +1');+ expect(narrow(expand)).toBe('+1');+ expect(narrow(bar.querySelector('.atlas-graph-path-picker > summary'))).toBe('Path…');+ expect(narrow(bar.querySelector('.atlas-trace-edge-filter > summary'))).toBe('Types · All');+ expect(narrow([...bar.querySelectorAll('button')].find(entry => entry.textContent === 'Call order'))).toBe('Calls');+ // The short label is drawn by CSS only: the text of each control stays what it was.+ expect(bar.querySelector('.atlas-trace-edge-filter > summary')?.textContent).toBe('Edge types · All');+ // Out of the scope the toolbar wraps as before and is not measured.+ await act(async () => [...bar.querySelectorAll('button')].find(entry => entry.textContent === 'All graph')!.click());+ await settle(() => expect(host.querySelector('.atlas-graph-scope-name')).toBeNull());+ expect(host.querySelector<HTMLElement>('.atlas-graph-exploration')!.dataset.fit).toBeUndefined();+});diff --git a/graph-ui/src/galaxy/GalaxyPanel.tsx b/graph-ui/src/galaxy/GalaxyPanel.tsxindex 6038aa1be..154ea4691 100644--- a/graph-ui/src/galaxy/GalaxyPanel.tsx+++ b/graph-ui/src/galaxy/GalaxyPanel.tsx@@ -141,6 +141,7 @@ import { PathPicker, PathSteps } from './ScopePathControls';import { callOrder, pathNodes, shortestScopePath, type ScopePathStep } from './scope-path';import { galaxyHierarchyText, galaxyHistoryText, galaxyLayerText, galaxyPathText, galaxyToolbarText } from './galaxy-strings';import { HierarchyEdgeLabels } from './HierarchyEdgeLabels';+import { FitLabel, useToolbarFit } from './toolbar-fit';import { emptyNavigationHistory, moveNavigation, peekNavigation, pushNavigation } from '../graph/navigation-history';import { galaxyHistoryOptions, historyEntryDetail, historyEntryLabel, scopeIdentity, type GalaxyHistoryEntry, type ScopeTrail } from './scope-history';import { useOrganicLayout } from './use-organic-layout';@@ -2036,6 +2037,10 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {} : undefined, [props.workspaceExpanded, scope.scope, scope.result, scope.complete, scope.direction, traceTypes]);const selectionContent = typeof props.selectionPanel === 'function' ? props.selectionPanel(selectionScope) : props.selectionPanel;+ /* K3 und Review: die Leiste misst, ob sie voll, knapp oder umgebrochen passt (toolbar-fit.tsx). */+ const explorationBar = useRef<HTMLDivElement>(null);+ useToolbarFit(explorationBar, Boolean(props.workspaceExpanded && scope.scope));+/* Was die Leiste sonst noch braucht (K3): Quelle der Wurzel, Gruppen und was ausserhalb der Limits liegt. */const openRoot = props.workspaceExpanded && scopedRoot?.file_path? () => props.onOpenNode(layoutNodeForSelection(layout, scopedRoot) ?? scopedRoot) : undefined;@@ -2557,7 +2562,7 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {</span>)}</header>- {(props.workspaceExpanded || scope.scope) && <div className="atlas-graph-exploration" aria-label="Graph scope"+ {(props.workspaceExpanded || scope.scope) && <div className="atlas-graph-exploration" aria-label="Graph scope" ref={explorationBar}data-scoped={props.workspaceExpanded && scope.scope ? 'true' : undefined}>{historyControls}{props.workspaceExpanded && <GalaxyNavigator embedded nodes={layout?.nodes ?? []} project={project} fetch={fetchImpl} onSelect={handleNodeClick} onSelectScope={next => { props.onClearSelection?.(); setBackgroundCleared(false); clearTrail(); scope.select(next); }} />}@@ -2589,13 +2594,14 @@ export default function GalaxyPanel(props: GalaxyPanelProps): JSX.Element {<span>{scope.depth} {scope.depth === 1 ? 'layer' : 'layers'}</span><button type="button" disabled={scope.loading || scope.result?.exhausted || Boolean(scope.result?.partial)}data-warning={expandWarning || undefined} title={expandTitle}- onClick={() => scope.setDepth(scope.depth + 1)}>Expand +1</button>+ onClick={() => scope.setDepth(scope.depth + 1)} aria-label={galaxyToolbarText.expand}>+ <FitLabel wide={galaxyToolbarText.expand} narrow={galaxyToolbarText.expandNarrow} /></button>{props.workspaceExpanded && (mode === 'galaxy' || scopedProjection) && <><PathPicker nodes={pathCandidates} onPick={node => { setTrail({ key: organicKey, kind: 'path', target: node.id, name: node.name }); setTrailStep(0); }} /><button type="button" disabled={rootCalls.length === 0} aria-pressed={trail?.key === organicKey && trail.kind === 'calls'}title={rootCalls.length ? galaxyPathText.callOrderTitle : galaxyPathText.callOrderUnavailable}onClick={() => { if (trail?.key === organicKey && trail.kind === 'calls') clearTrail(); else { setTrail({ key: organicKey, kind: 'calls' }); setTrailStep(0); } }}>- {galaxyPathText.callOrder}</button>+ <FitLabel wide={galaxyPathText.callOrder} narrow={galaxyPathText.callOrderNarrow} /></button></>}<span className="atlas-graph-scope-count" role="status" data-state={scopeState}title={partial ? galaxyLayerText.partialTitle(partial.layer, partial.limit === 'nodes' ? nodeBudget : edgeBudget, partial.limit)diff --git a/graph-ui/src/galaxy/ScopePathControls.tsx b/graph-ui/src/galaxy/ScopePathControls.tsxindex 2cf4e251a..d902267eb 100644--- a/graph-ui/src/galaxy/ScopePathControls.tsx+++ b/graph-ui/src/galaxy/ScopePathControls.tsx@@ -3,6 +3,7 @@ import type { KeyboardEvent } from 'react';import { galaxyPathText as text } from './galaxy-strings';import type { ScopePathStep } from './scope-path';import type { GraphNode } from './types';+import { FitLabel } from './toolbar-fit';const PICKER_LIMIT = 40;@@ -28,7 +29,7 @@ export function PathPicker({ nodes, onPick }: { nodes: readonly GraphNode[]; onP.sort((a, b) => rank(a) - rank(b) || a.name.localeCompare(b.name) || a.id - b.id);}, [nodes, query]);return <details ref={details} className="atlas-graph-path-picker" onKeyDown={closeOnEscape}>- <summary title={text.pathToTitle}>{text.pathTo}</summary>+ <summary title={text.pathToTitle}><FitLabel wide={text.pathTo} narrow={text.pathToNarrow} /></summary><div className="atlas-graph-path-menu" role="group" aria-label={text.pathToTitle}><input type="search" aria-label={text.pathSearch} placeholder={text.pathSearchPlaceholder}value={query} onChange={event => setQuery(event.target.value)} />diff --git a/graph-ui/src/galaxy/TraceEdgeFilter.tsx b/graph-ui/src/galaxy/TraceEdgeFilter.tsxindex d60de5460..f67034bb1 100644--- a/graph-ui/src/galaxy/TraceEdgeFilter.tsx+++ b/graph-ui/src/galaxy/TraceEdgeFilter.tsx@@ -1,4 +1,5 @@import type { EdgeKind } from './galaxy-legend';+import { FitLabel } from './toolbar-fit';/** This changes which relationships traversal follows, not just their paint. */export function TraceEdgeFilter({ kinds, availableTypes, selected, onChange }: {@@ -10,13 +11,15 @@ export function TraceEdgeFilter({ kinds, availableTypes, selected, onChange }: {}) {const included = new Set(selected ?? availableTypes ?? kinds.map(kind => kind.type));const includedCount = kinds.filter(kind => included.has(kind.type)).length;+ const shown = selected === undefined ? 'All' : includedCount === 0 ? 'None' : String(includedCount);return <details className="atlas-trace-edge-filter" onKeyDown={event => {if (event.key === 'Escape') {event.stopPropagation(); event.currentTarget.open = false;event.currentTarget.querySelector('summary')?.focus();}}}>- <summary>Edge types · {selected === undefined ? 'All' : includedCount === 0 ? 'None' : includedCount}</summary>+ {/* Review of K3: a narrow scoped toolbar shows "Types · All" (src/galaxy/toolbar-fit.tsx). */}+ <summary><FitLabel wide={`Edge types · ${shown}`} narrow={`Types · ${shown}`} /></summary><div className="atlas-trace-edge-menu" role="group" aria-label="Trace edge types"><div className="atlas-trace-edge-actions"><button type="button" onClick={() => onChange(undefined)}>All types</button>diff --git a/graph-ui/src/galaxy/galaxy-strings.ts b/graph-ui/src/galaxy/galaxy-strings.tsindex 7e5ace725..124f7500f 100644--- a/graph-ui/src/galaxy/galaxy-strings.ts+++ b/graph-ui/src/galaxy/galaxy-strings.ts@@ -14,6 +14,9 @@ export const galaxyPathText = {pathNoMatch: 'No matching node in the loaded scope.',pathMore: (count: number) => `${count.toLocaleString()} more, type to narrow`,callOrder: 'Call order',+ /** The short labels of a narrow toolbar (review of K3). */+ pathToNarrow: 'Path…',+ callOrderNarrow: 'Calls',callOrderTitle: 'Step through the outgoing calls of the root in source line order',callOrderUnavailable: 'The root has no outgoing calls in the loaded scope',panel: 'Path steps',@@ -117,5 +120,7 @@ export const galaxyToolbarText = {/** The root button's accessible name: its action, with the visible name in it. */openRootLabel: (name: string) => `Open the source of ${name}`,traceTitle: 'Trace direction: incoming, outgoing or both',+ expand: 'Expand +1',+ expandNarrow: '+1',outsideLimits: (nodes: number, edges: number) => `${nodes.toLocaleString()} nodes · ${edges.toLocaleString()} edges outside render limits`,};diff --git a/graph-ui/src/galaxy/graph-exploration.css b/graph-ui/src/galaxy/graph-exploration.cssindex 90dd7ddac..c74ede1be 100644--- a/graph-ui/src/galaxy/graph-exploration.css+++ b/graph-ui/src/galaxy/graph-exploration.css@@ -25,9 +25,27 @@.atlas-graph-exploration[data-scoped=true] .atlas-galaxy-search-container { flex:0 1 9rem; min-width:5rem; transition:flex-basis .15s ease; }.atlas-graph-exploration[data-scoped=true] .atlas-galaxy-search-container:focus-within { flex-basis:18rem; }.atlas-graph-exploration[data-scoped=true] .atlas-graph-scope-name { flex:0 1 auto; min-width:3.5rem; max-width:11rem; }-/* Der Zaehler gibt zuletzt nach: der Name steht auch am Ring in der Szene, die Zahl nur hier. */-.atlas-graph-exploration[data-scoped=true] .atlas-graph-scope-count { flex:none; max-width:12rem; overflow:hidden; text-overflow:ellipsis; }+/* Der Zaehler gibt zuletzt nach: der Name steht auch am Ring in der Szene, die Zahl nur hier. Voll steht er ganz da. */+.atlas-graph-exploration[data-scoped=true] .atlas-graph-scope-count { flex:none; overflow:hidden; text-overflow:ellipsis; }.atlas-graph-exploration[data-scoped=true] .atlas-graph-scope-warning { flex:0 1 auto; width:auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }+/*+ * Review zu K3: die Leiste misst ihre Stufe (toolbar-fit.tsx). Ab "compact"+ * stehen die knappen Beschriftungen, in "tight" wird dazu der Zaehler kuerzer,+ * "wrap" bricht die knappe Leiste um. Nichts ragt mehr ueber den Rand.+ */+.atlas-fit-narrow { display:none; }+.atlas-fit-narrow::before { content:attr(data-label); }+.atlas-graph-exploration:is([data-fit=compact], [data-fit=tight], [data-fit=wrap]) .atlas-fit-wide { display:none; }+.atlas-graph-exploration:is([data-fit=compact], [data-fit=tight], [data-fit=wrap]) .atlas-fit-narrow { display:inline; }+/*+ * Suchfeld und Wurzelname geben zuerst nach, der Zaehler zuletzt und nie unter+ * 8,5rem. Die Rangfolge steckt im Verhaeltnis der Faktoren und nicht in einem+ * Faktor unter 1: ein solcher nimmt nur seinen Bruchteil des Fehlbetrags auf,+ * und der Rest ragte wieder hinaus.+ */+.atlas-graph-exploration[data-scoped=true][data-fit=tight] :is(.atlas-galaxy-search-container, .atlas-graph-scope-name) { flex-shrink:8; }+.atlas-graph-exploration[data-scoped=true][data-fit=tight] .atlas-graph-scope-count { flex:0 1 auto; min-width:8.5rem; }+.atlas-graph-exploration[data-scoped=true][data-fit=wrap] { flex-wrap:wrap; row-gap:.35rem; }.atlas-graph-exploration button.atlas-graph-scope-name { position:relative; padding-right:1.2rem; font-weight:600; border-color:transparent; background:transparent; text-align:left; }.atlas-graph-exploration button.atlas-graph-scope-name::after { content:'↗'; position:absolute; right:.35rem; color:#7fa592; font-weight:400; }.atlas-graph-exploration button.atlas-graph-scope-name:hover { text-decoration:underline; }diff --git a/graph-ui/src/galaxy/toolbar-fit.test.ts b/graph-ui/src/galaxy/toolbar-fit.test.tsnew file mode 100644index 000000000..8b481537d--- /dev/null+++ b/graph-ui/src/galaxy/toolbar-fit.test.ts@@ -0,0 +1,61 @@+// @vitest-environment jsdom+/*+ * Review zu K3: die Leiste eines Ausschnitts blieb einzeilig, indem sie+ * abschnitt. Bei offenem Chat und 1.494 px Fensterbreite (der des Handtests)+ * lagen Zaehler und Menue "⋯" mit den Limits jenseits des Randes. Jetzt+ * wird gemessen: erst die volle Leiste, dann die knappe Beschriftung, und erst+ * wenn auch die nicht passt, bricht die Zeile um. Nichts ragt mehr hinaus.+ */+import { afterEach, describe, expect, it } from 'vitest';+import { chooseToolbarFit, fitToolbar, type ToolbarFit } from './toolbar-fit';++describe('chooseToolbarFit', () => {+ it('takes the first level at which nothing sticks out, and wraps as the last resort', () => {+ const tried: ToolbarFit[] = [];+ expect(chooseToolbarFit(fit => { tried.push(fit); return false; })).toBe('full');+ expect(tried).toEqual(['full']);+ expect(chooseToolbarFit(fit => fit === 'full')).toBe('compact');+ expect(chooseToolbarFit(fit => fit !== 'tight')).toBe('tight');+ expect(chooseToolbarFit(() => true)).toBe('wrap');+ });+});++describe('fitToolbar', () => {+ afterEach(() => { document.body.innerHTML = ''; });+ /** A bar 1,000 px wide whose last item ends where `rightAt` says for the level the bar is set to. */+ const bar = (rightAt: Record<ToolbarFit, number>) => {+ const element = document.createElement('div');+ element.style.paddingRight = '10px';+ const rect = (left: number, right: number) => ({ left, right, width: right - left, top: 0, bottom: 40, height: 40, x: left, y: 0, toJSON: () => ({}) }) as DOMRect;+ element.getBoundingClientRect = () => rect(0, 1000);+ for (const at of [0, 1]) {+ const child = document.createElement('button');+ child.getBoundingClientRect = () => at === 0 ? rect(10, 200) : rect(210, rightAt[(element.dataset.fit ?? 'full') as ToolbarFit]);+ element.append(child);+ }+ document.body.append(element);+ return element;+ };++ it('keeps the full bar while it fits inside the padding', () => {+ const element = bar({ full: 990, compact: 900, tight: 900, wrap: 900 });+ expect(fitToolbar(element)).toBe('full');+ expect(element.dataset.fit).toBe('full');+ });++ it('turns to the short labels when the full bar sticks out, before it wraps', () => {+ const element = bar({ full: 1072, compact: 960, tight: 940, wrap: 600 });+ expect(fitToolbar(element)).toBe('compact');+ expect(element.dataset.fit).toBe('compact');+ });++ it('shortens the count next, and wraps when even that sticks out, so every control stays reachable', () => {+ expect(fitToolbar(bar({ full: 1134, compact: 1003, tight: 985, wrap: 600 }))).toBe('tight');+ const element = bar({ full: 1134, compact: 1003, tight: 995, wrap: 600 });+ expect(fitToolbar(element)).toBe('wrap');+ expect(element.dataset.fit).toBe('wrap');+ // A wider bar later goes back to the full labels.+ element.getBoundingClientRect = () => ({ left: 0, right: 1200, width: 1200, top: 0, bottom: 40, height: 40, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect;+ expect(fitToolbar(element)).toBe('full');+ });+});diff --git a/graph-ui/src/galaxy/toolbar-fit.tsx b/graph-ui/src/galaxy/toolbar-fit.tsxnew file mode 100644index 000000000..99dc1b8c0--- /dev/null+++ b/graph-ui/src/galaxy/toolbar-fit.tsx@@ -0,0 +1,89 @@+/*+ * Die Leiste eines Ausschnitts passt sich ihrer Breite an (Handtest K3 und+ * das Review dazu).+ *+ * Zuerst hielt sie die eine Zeile, indem sie nicht mehr umbrach, und schnitt+ * dabei ab: bei offenem Chat und 1.494 px Fensterbreite, der Breite des+ * Handtests, lagen Zaehler und Menue "⋯" mit den Limits jenseits des Randes,+ * also genau das Menue, auf das der Hinweis einer abgeschnittenen Ebene+ * verweist. Jetzt wird gemessen, in drei Stufen:+ *+ * - `full`: alle Beschriftungen ausgeschrieben.+ * - `compact`: knappe Beschriftungen ("+1" statt "Expand +1", "Path…",+ * "Types · All", "Calls"); so passt sie bei offenem Chat und 1.494 px.+ * - `tight`: dazu wird der Zaehler kuerzer, nie unter 8,5rem und mit vollem+ * Text im Tooltip; "Partial:" steht vorn und bleibt. So passt sie bis rund+ * 1.440 px.+ * - `wrap`: die knappe Leiste bricht um. Zwei Zeilen sind besser als ein+ * Knopf, den niemand mehr sieht.+ *+ * Die Stufe steht als `data-fit` direkt am Element und nicht im Zustand von+ * React: das Probieren der Stufen ist dann ein paar Layout-Abfragen in einem+ * Durchgang und kein Rendern je Stufe. Die knappen Worte zeichnet CSS+ * (`attr(data-label)`), so bleiben Text und zugaenglicher Name jedes Knopfes,+ * wie sie waren.+ */+import { useLayoutEffect, type RefObject } from 'react';++export type ToolbarFit = 'full' | 'compact' | 'tight' | 'wrap';+const FITS: readonly ToolbarFit[] = ['full', 'compact', 'tight', 'wrap'];++/** Die erste Stufe, bei der nichts hinausragt; die letzte passt immer, denn sie bricht um. */+export function chooseToolbarFit(overflowsAt: (fit: ToolbarFit) => boolean): ToolbarFit {+ for (const fit of FITS.slice(0, -1)) {+ if (!overflowsAt(fit)) return fit;+ }+ return 'wrap';+}++/** Ob ein Kind der Leiste ueber ihren Inhaltsrand ragt. Aufgeklappte Menues liegen absolut in ihren Kindern und zaehlen nicht. */+export function toolbarOverflows(bar: HTMLElement): boolean {+ const style = getComputedStyle(bar);+ const edge = bar.getBoundingClientRect().right - (parseFloat(style.paddingRight) || 0) - (parseFloat(style.borderRightWidth) || 0);+ for (const child of bar.children) {+ const box = child.getBoundingClientRect();+ if (box.width > 0 && box.right > edge + 0.5) return true;+ }+ return false;+}++/** Setzt die Leiste auf die erste Stufe, die passt, und gibt sie zurueck. */+export function fitToolbar(bar: HTMLElement): ToolbarFit {+ const fit = chooseToolbarFit(level => { bar.dataset.fit = level; return toolbarOverflows(bar); });+ bar.dataset.fit = fit;+ return fit;+}++/*+ * Neu gemessen wird, wenn die Leiste ihre Breite aendert (Chat auf oder zu,+ * Fenster) und wenn sich ihr Inhalt aendert (Zaehler, Wurzelname, Knoepfe).+ * Beides erst im naechsten Bild: die Messung aendert die Hoehe der Leiste, und+ * im Rueckruf des ResizeObservers waere das eine Schleife.+ */+export function useToolbarFit(ref: RefObject<HTMLElement | null>, active: boolean): void {+ useLayoutEffect(() => {+ const bar = ref.current;+ if (!bar) return;+ if (!active) { delete bar.dataset.fit; return; }+ fitToolbar(bar);+ let frame = 0;+ const schedule = () => {+ if (frame) return;+ frame = requestAnimationFrame(() => { frame = 0; fitToolbar(bar); });+ };+ const resize = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);+ resize?.observe(bar);+ const content = typeof MutationObserver === 'undefined' ? undefined : new MutationObserver(schedule);+ content?.observe(bar, { childList: true, subtree: true, characterData: true });+ return () => {+ resize?.disconnect(); content?.disconnect();+ if (frame) cancelAnimationFrame(frame);+ delete bar.dataset.fit;+ };+ }, [ref, active]);+}++/** Eine Beschriftung mit knapper Form ab `data-fit=compact`; im DOM steht nur die volle. */+export function FitLabel({ wide, narrow }: { wide: string; narrow: string }) {+ return <><span className="atlas-fit-wide">{wide}</span><span className="atlas-fit-narrow" data-label={narrow} aria-hidden="true" /></>;+}