Graph: highlight a selected node's links; nav: Connect only when signed out

Selecting a node highlights every edge into and out of it, with their
labels and the boxes at the far ends, and dims the rest. The Connect
menu item is shown only while signed out; when signed in, the name in
the menu links to the connection page so Disconnect stays reachable.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 14:09:42 +00:00
1 parent 11c9483a88
commit 44e4eb75c9
6 files changed
+133 -16

No files matched your search

+6 -2
View File
@@ -4,6 +4,10 @@ export interface GrantEdgeData {
label: string
/** Vertical nudge so labels on edges into the same node don't sit on top of each other. */
offset: number
/** Touches the selected node. */
linked?: boolean
/** Another node is selected and this edge isn't one of its links. */
dim?: boolean
onSelect: () => void
}
@@ -12,7 +16,7 @@ export interface GrantEdgeData {
* fanned out to different rows, instead of at the midpoint where edges from one policy bunch up.
*/
export function GrantEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, markerEnd, selected, data }: EdgeProps) {
const { label, offset, onSelect } = data as unknown as GrantEdgeData
const { label, offset, linked, dim, onSelect } = data as unknown as GrantEdgeData
const [path] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition })
return (
<>
@@ -20,7 +24,7 @@ export function GrantEdge({ id, sourceX, sourceY, targetX, targetY, sourcePositi
<EdgeLabelRenderer>
<button
type="button"
className={`nodrag nopan edge-label${selected ? ' edge-label-selected' : ''}`}
className={`nodrag nopan edge-label${selected ? ' edge-label-selected' : ''}${linked ? ' edge-label-linked' : ''}${dim ? ' edge-label-dim' : ''}`}
style={{ transform: `translate(-100%, -50%) translate(${targetX - 18}px, ${targetY + offset}px)` }}
onClick={onSelect}
>
+35 -4
View File
@@ -16,19 +16,19 @@ import { GraphPage } from './GraphPage'
// jsdom can't lay out React Flow, so render nodes/edges as plain buttons that fire the same callbacks.
vi.mock('@xyflow/react', () => ({
ReactFlow: (p: {
nodes: { id: string; data: { label: string } }[]
edges: { id: string; label?: string }[]
nodes: { id: string; className?: string; data: { label: string } }[]
edges: { id: string; className?: string; label?: string }[]
onNodeClick: (e: unknown, n: { id: string }) => void
onEdgeClick: (e: unknown, ed: { id: string }) => void
}) => (
<div>
{p.nodes.map((n) => (
<button key={n.id} type="button" onClick={(e) => p.onNodeClick(e, n)}>
<button key={n.id} type="button" data-class={n.className} onClick={(e) => p.onNodeClick(e, n)}>
node {n.data.label}
</button>
))}
{p.edges.map((ed) => (
<button key={ed.id} type="button" onClick={(e) => p.onEdgeClick(e, ed)}>
<button key={ed.id} type="button" data-class={ed.className} onClick={(e) => p.onEdgeClick(e, ed)}>
edge {ed.id}
</button>
))}
@@ -140,3 +140,34 @@ test('grants in unmanaged policies cannot be revoked', async () => {
expect(screen.queryByRole('button', { name: 'Revoke' })).not.toBeInTheDocument()
expect(screen.getByText(/does not manage/)).toBeInTheDocument()
})
const cls = (name: string) => screen.getByRole('button', { name }).getAttribute('data-class') ?? ''
test('selecting a node highlights its links and dims the rest', async () => {
const user = await open()
// nothing is dimmed until something is selected
expect(cls('node bob')).not.toContain('gnode-dim')
expect(cls('edge policy:legacy->path:secret/data/other')).not.toContain('edge-')
await user.click(screen.getByRole('button', { name: 'node envbao-user-alice' }))
// its links, in and out, are highlighted, with the boxes at their far ends
expect(cls('edge policy:envbao-user-alice->path:secret/data/app/*')).toContain('edge-linked')
expect(cls('edge identity:user:alice->policy:envbao-user-alice')).toContain('edge-linked')
expect(cls('node alice')).toContain('gnode-linked')
expect(cls('node secret/data/app/*')).toContain('gnode-linked')
expect(cls('node envbao-user-alice')).toContain('gnode-selected')
// an unrelated chain steps back
expect(cls('edge policy:legacy->path:secret/data/other')).toContain('edge-dim')
expect(cls('node bob')).toContain('gnode-dim')
expect(cls('node legacy')).toContain('gnode-dim')
})
test('clearing the selection, or selecting an edge, removes the highlight', async () => {
const user = await open()
await user.click(screen.getByRole('button', { name: 'node alice' }))
expect(cls('node bob')).toContain('gnode-dim')
await user.click(screen.getByRole('button', { name: 'edge policy:legacy->path:secret/data/other' }))
expect(cls('node bob')).not.toContain('gnode-dim')
expect(cls('edge policy:envbao-user-alice->path:secret/data/app/*')).not.toContain('edge-dim')
})
+11
View File
@@ -34,6 +34,11 @@ function capabilityLabel(caps: string[] | undefined): string | undefined {
function toFlow(graph: AccessGraph, selected: Selection | null, onEdgeSelect: (id: string) => void): { nodes: Node[]; edges: Edge[] } {
const pos = layoutColumns(graph)
// Selecting a node highlights every edge into or out of it, and the boxes at their far ends.
const focus = selected?.kind === 'node' ? selected.id : null
const linkedEdges = new Set(graph.edges.filter((e) => e.source === focus || e.target === focus).map((e) => e.id))
const linkedNodes = new Set<string>(focus ? [focus] : [])
for (const e of graph.edges) if (linkedEdges.has(e.id)) linkedNodes.add(e.source).add(e.target)
const nodes: Node[] = graph.nodes.map((n) => ({
id: n.id,
position: pos.get(n.id)!,
@@ -45,6 +50,8 @@ function toFlow(graph: AccessGraph, selected: Selection | null, onEdgeSelect: (i
n.type === 'policy' && n.missing ? 'gnode-missing' : '',
n.type === 'policy' && n.managed ? 'gnode-managed' : '',
selected?.kind === 'node' && selected.id === n.id ? 'gnode-selected' : '',
focus && n.id !== focus && linkedNodes.has(n.id) ? 'gnode-linked' : '',
focus && !linkedNodes.has(n.id) ? 'gnode-dim' : '',
].join(' '),
sourcePosition: Position.Right,
targetPosition: Position.Left,
@@ -59,6 +66,8 @@ function toFlow(graph: AccessGraph, selected: Selection | null, onEdgeSelect: (i
target: e.target,
markerEnd: { type: MarkerType.ArrowClosed },
selected: selected?.kind === 'edge' && selected.id === e.id,
className: focus ? (linkedEdges.has(e.id) ? 'edge-linked' : 'edge-dim') : undefined,
zIndex: linkedEdges.has(e.id) ? 1 : 0,
}
const label = capabilityLabel(e.capabilities)
if (!label) return base
@@ -66,6 +75,8 @@ function toFlow(graph: AccessGraph, selected: Selection | null, onEdgeSelect: (i
const data: GrantEdgeData = {
label,
offset: (siblings.indexOf(e.id) - (siblings.length - 1) / 2) * 24,
linked: linkedEdges.has(e.id),
dim: focus !== null && !linkedEdges.has(e.id),
onSelect: () => onEdgeSelect(e.id),
}
return { ...base, type: 'grant', data: data as unknown as Record<string, unknown> }