Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
console: make the dashboard usable from a keyboard
Antonio Ojea228431882ce2
diff --git a/cmd/sam-console/public/app.js b/cmd/sam-console/public/app.jsindex 95f9a592..f086170a 100644--- a/cmd/sam-console/public/app.js+++ b/cmd/sam-console/public/app.js@@ -8,17 +8,11 @@ let refreshInFlight = false;let policyBaseline = '';document.addEventListener('DOMContentLoaded', () => {- // Navigation handling- const navItems = document.querySelectorAll('.nav-item');-- navItems.forEach(item => {- item.addEventListener('click', (e) => {- e.preventDefault();- switchTab(e.currentTarget.getAttribute('data-target'));-- // On mobile the sidebar is an overlay drawer; close it after navigating.- closeSidebar();- });+ // Each nav item is a real link to its view's hash, so the browser handles the+ // routing and hashchange drives switchTab. This only dismisses the drawer,+ // which is an overlay on mobile.+ document.querySelectorAll('.nav-item').forEach(item => {+ item.addEventListener('click', () => closeSidebar());});window.addEventListener('hashchange', () => switchTab(tabFromHash()));@@ -256,6 +250,7 @@ async function loadData() {}applySearchFilter();+ announce(`${nodesCount} nodes, ${routersCount} routers, ${reqsCount} enrollment requests.`);} catch (error) {console.error('Failed to load dashboard data:', error);@@ -265,10 +260,20 @@ async function loadData() {setTableMessage('table-enrollments', 4, errMsg, true);setTableMessage('table-routers', 3, errMsg, true);setTableMessage('table-bootstrap', 5, errMsg, true);+ announce(errMsg);throw error;}}+// Table renders replace rows wholesale, which a screen reader would otherwise+// never hear about.+function announce(message) {+ const region = document.getElementById('live-status');+ if (region) {+ region.textContent = message;+ }+}+function setTableMessage(tbodyID, colspan, message, isError = false) {const tbody = document.getElementById(tbodyID);if (!tbody) return;diff --git a/cmd/sam-console/public/index.html b/cmd/sam-console/public/index.htmlindex c21e0858..8df90f4b 100644--- a/cmd/sam-console/public/index.html+++ b/cmd/sam-console/public/index.html@@ -58,33 +58,33 @@<div class="logo"></div><h2>SAM Console</h2></div>- <nav class="sidebar-nav">- <a href="#" class="nav-item active" data-target="overview">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>+ <nav class="sidebar-nav" aria-label="Sections">+ <a href="#overview" class="nav-item active" data-target="overview">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>Overview</a>- <a href="#" class="nav-item" data-target="users">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>+ <a href="#users" class="nav-item" data-target="users">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>Users</a>- <a href="#" class="nav-item" data-target="nodes">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>+ <a href="#nodes" class="nav-item" data-target="nodes">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>Nodes</a>- <a href="#" class="nav-item" data-target="enrollments">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>+ <a href="#enrollments" class="nav-item" data-target="enrollments">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>Enrollments</a>- <a href="#" class="nav-item" data-target="routers">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M2 12h20"></path><path d="M12 2v20"></path><rect x="2" y="2" width="20" height="20" rx="2" ry="2"></rect></svg>+ <a href="#routers" class="nav-item" data-target="routers">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M2 12h20"></path><path d="M12 2v20"></path><rect x="2" y="2" width="20" height="20" rx="2" ry="2"></rect></svg>Routers</a>- <a href="#" class="nav-item" data-target="bootstrap">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>+ <a href="#bootstrap" class="nav-item" data-target="bootstrap">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>Bootstrap Tokens</a>- <a href="#" class="nav-item" data-target="policy">- <svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>+ <a href="#policy" class="nav-item" data-target="policy">+ <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>Mesh Policy</a></nav>@@ -97,27 +97,28 @@<main class="main-content"><header class="topbar"><button class="sidebar-toggle" id="sidebar-toggle" onclick="toggleSidebar()" aria-label="Toggle navigation">- <svg viewBox="0 0 24 24" width="22" height="22" stroke="currentColor" stroke-width="2" fill="none"><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>+ <svg aria-hidden="true" viewBox="0 0 24 24" width="22" height="22" stroke="currentColor" stroke-width="2" fill="none"><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></button><div class="search-bar">- <svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>+ <svg aria-hidden="true" viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg><input type="search" id="resource-search" placeholder="Search resources..." aria-label="Search resources"></div><div class="user-profile">- <div class="avatar">A</div>+ <div class="avatar" aria-hidden="true">A</div><span>Admin</span><button class="btn btn-sm btn-secondary" onclick="logout()" style="margin-left: 12px; padding: 4px 8px; font-size: 0.8rem; background: var(--border-color); border: 1px solid var(--border-color);">Logout</button></div></header><div class="content-scroll">+ <p id="live-status" class="visually-hidden" role="status" aria-live="polite"></p><!-- Overview View --><section id="view-overview" class="view-section active"><div class="header-banner"><h1>Network Overview</h1><p>Real-time statistics for your zero-trust mesh.</p><button class="btn btn-primary" onclick="loadData()">- <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><polyline points="23 4 23 10 17 10"></polyline><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path></svg>+ <svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none"><polyline points="23 4 23 10 17 10"></polyline><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path></svg>Refresh</button></div>diff --git a/cmd/sam-console/public/style.css b/cmd/sam-console/public/style.cssindex 602ea91a..c7fb0dab 100644--- a/cmd/sam-console/public/style.css+++ b/cmd/sam-console/public/style.css@@ -26,6 +26,27 @@ body {overflow: hidden;}+/* Every interactive control is custom-styled, so without this the browser's+ default focus ring is the only keyboard affordance and it is invisible on+ this palette. */+:focus-visible {+ outline: 2px solid var(--accent);+ outline-offset: 2px;+ border-radius: 4px;+}++.visually-hidden {+ position: absolute;+ width: 1px;+ height: 1px;+ margin: -1px;+ padding: 0;+ overflow: hidden;+ clip: rect(0, 0, 0, 0);+ white-space: nowrap;+ border: 0;+}+/* Layout */.app-container {display: flex;@@ -195,6 +216,15 @@ body {to { opacity: 1; transform: translateY(0); }}+@media (prefers-reduced-motion: reduce) {+ *, *::before, *::after {+ animation-duration: 0.01ms !important;+ animation-iteration-count: 1 !important;+ transition-duration: 0.01ms !important;+ scroll-behavior: auto !important;+ }+}+.header-banner {margin-bottom: 32px;display: flex;diff --git a/tests/ui/console.spec.js b/tests/ui/console.spec.jsindex 1ef8d52f..f352086f 100644--- a/tests/ui/console.spec.js+++ b/tests/ui/console.spec.js@@ -172,13 +172,17 @@ test('leaving the policy view warns about unsaved edits', async ({ page }) => {await page.fill('#policy-yaml', '# unsaved edit\n');let message = '';- page.once('dialog', async (d) => {- message = d.message();- await d.dismiss();+ const dismissed = new Promise((resolve) => {+ page.once('dialog', async (d) => {+ message = d.message();+ await d.dismiss();+ resolve();+ });});await page.click('.nav-item[data-target="overview"]');- await expect(page.locator('#view-policy')).toBeVisible();+ await dismissed;expect(message).toContain('unsaved policy changes');+ await expect(page.locator('#view-policy')).toBeVisible();page.once('dialog', (d) => d.accept());await page.click('.nav-item[data-target="overview"]');@@ -198,3 +202,16 @@ test('an unedited policy view navigates away without prompting', async ({ page }await expect(page.locator('#view-overview')).toBeVisible();expect(prompted).toBe(false);});++test('navigation is keyboard operable and refreshes are announced', async ({ page }) => {+ await login(page);++ // Real hrefs, so keyboard activation and open-in-new-tab work without JS.+ await expect(page.locator('.nav-item[data-target="nodes"]')).toHaveAttribute('href', '#nodes');++ await page.locator('.nav-item[data-target="routers"]').press('Enter');+ await expect(page.locator('#view-routers')).toBeVisible();+ await expect(page).toHaveURL(/#routers$/);++ await expect(page.locator('#live-status')).toHaveText(/nodes, .* routers/);+});