UI: signed-out menu and landing, form checkbox layout, Secrets header

The menu shows only Connect while signed out and the section links
once signed in; / goes to Connect or Identities accordingly. Yes/no
settings in the engine forms put the box beside its text. The Secrets
page now has New secrets engine on its own line, then a labelled engine
picker with Settings and Delete beside it, then the breadcrumbs, and
dynamic engines use the full width.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 14:47:31 +00:00
1 parent 58b6230f9b
commit d488bb42cc
11 files changed
+235 -88

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
import { render, screen } from '@testing-library/react'
import { useEffect, useRef, type ReactNode } from 'react'
import { createMemoryRouter, RouterProvider } from 'react-router'
import { expect, test } from 'vitest'
import { BaoClient } from './api/bao'
import { SessionProvider } from './api/session'
import { useSession } from './api/useSession'
import { Home } from './Home'
import { Providers } from './test/providers'
/** Signs in first, and only renders its children once the session exists. */
function SignedIn({ children }: { children: ReactNode }) {
const { client, connect } = useSession()
// connect() isn't a stable function, so guard instead of listing it as a dependency (that would sign in forever).
const done = useRef(false)
useEffect(() => {
if (done.current) return
done.current = true
connect(new BaoClient('http://b', 't'), { accessor: 'a', display_name: 'alice', policies: [], ttl: 0, renewable: false })
})
return client ? children : null
}
function setup(landing: ReactNode) {
const router = createMemoryRouter(
[
{ path: '/', element: landing },
{ path: '/connect', element: <p>connect page</p> },
{ path: '/identities', element: <p>identities page</p> },
],
{ initialEntries: ['/'] },
)
render(
<Providers>
<SessionProvider>
<RouterProvider router={router} />
</SessionProvider>
</Providers>,
)
return router
}
test('sends a signed-out visitor to the connect page', async () => {
const router = setup(<Home />)
expect(await screen.findByText('connect page')).toBeInTheDocument()
expect(router.state.location.pathname).toBe('/connect')
})
test('sends a signed-in visitor to identities', async () => {
const router = setup(
<SignedIn>
<Home />
</SignedIn>,
)
expect(await screen.findByText('identities page')).toBeInTheDocument()
expect(router.state.location.pathname).toBe('/identities')
})
+8
View File
@@ -0,0 +1,8 @@
import { Navigate } from 'react-router'
import { useSession } from './api/useSession'
/** The landing route: straight to the work when signed in, otherwise to the only page that can be used. */
export function Home() {
const { client } = useSession()
return <Navigate to={client ? '/identities' : '/connect'} replace />
}
+10
View File
@@ -40,6 +40,16 @@ test('offers Connect only while signed out', async () => {
expect(screen.queryByRole('link', { name: 'Connection' })).not.toBeInTheDocument()
})
test('shows the section links only while signed in', async () => {
const user = setup()
const names = ['Identities', 'Secrets', 'Graph']
for (const n of names) expect(screen.queryByRole('link', { name: n })).not.toBeInTheDocument()
expect(screen.getByRole('link', { name: 'Connect' })).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'sign in' }))
for (const n of names) expect(screen.getByRole('link', { name: n })).toBeInTheDocument()
})
test('while signed in, the signed-in name links to the connection details', async () => {
const user = setup()
await user.click(screen.getByRole('button', { name: 'sign in' }))
+7 -5
View File
@@ -21,11 +21,13 @@ export function Layout() {
</a>
<nav aria-label="Main">
<strong>EnvBao</strong>
{links.map((l) => (
<NavLink key={l.to} to={l.to}>
{l.label}
</NavLink>
))}
{/* Every page needs a connection, so signed out there is nothing to navigate to but Connect. */}
{client &&
links.map((l) => (
<NavLink key={l.to} to={l.to}>
{l.label}
</NavLink>
))}
{client ? (
// Signed in: the name is the way back to the connection details and Disconnect.
<NavLink to="/connect" className="whoami" title="Connection details and sign out">
+2 -1
View File
@@ -13,7 +13,8 @@ function Field({ field, value, onChange }: { field: FieldDef; value: string | bo
if (field.type === 'bool') {
return (
<label>
// "check" lays the box beside its text; a plain label in a form stacks them.
<label className="check">
<input type="checkbox" checked={value === true} onChange={(e) => onChange(e.target.checked)} aria-describedby={describedBy} />{' '}
{field.label}
</label>
+8
View File
@@ -121,3 +121,11 @@ test('shows an empty state and the load error', async () => {
renderPanel('ssh')
expect(await screen.findByText('No roles yet.')).toBeInTheDocument()
})
test('yes/no settings lay the box beside its text (the "check" label), not stacked above it', async () => {
renderPanel('ssh')
const user = userEvent.setup()
await user.click(await screen.findByRole('button', { name: 'New role' }))
const box = screen.getByLabelText('Allow user certificates')
expect(box.closest('label')).toHaveClass('check')
})
+36 -4
View File
@@ -148,7 +148,7 @@ test('groups mounts by engine and shows the engine view for a dynamic mount', as
)
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'go' }))
const select = await screen.findByLabelText('Mount')
const select = await screen.findByLabelText('Secrets engine')
expect(within(select).getByRole('group', { name: 'KV' })).toBeInTheDocument()
expect(within(select).getByRole('group', { name: 'Database' })).toBeInTheDocument()
expect(within(select).queryByText('cubbyhole/')).not.toBeInTheDocument()
@@ -202,7 +202,7 @@ test('creating an engine selects it', async () => {
vi.spyOn(BaoClient.prototype, 'list').mockResolvedValue([])
await user.click(screen.getByRole('button', { name: 'Create' }))
expect(await screen.findByRole('heading', { name: /SSH · hosts\// })).toBeInTheDocument()
expect(screen.getByLabelText('Mount')).toHaveValue('hosts/')
expect(screen.getByLabelText('Secrets engine')).toHaveValue('hosts/')
})
test('Settings opens the selected mount\'s settings, and toggles closed', async () => {
@@ -223,7 +223,7 @@ test('deleting the selected engine falls back to another', async () => {
vi.mocked(mountsApi.deleteMount).mockResolvedValue()
vi.spyOn(BaoClient.prototype, 'list').mockResolvedValue([])
const user = await openPage()
await user.selectOptions(await screen.findByLabelText('Mount'), 'hosts/')
await user.selectOptions(await screen.findByLabelText('Secrets engine'), 'hosts/')
await user.click(screen.getByRole('button', { name: 'Delete' }))
expect(await screen.findByRole('alertdialog', { name: 'Delete hosts/' })).toBeInTheDocument()
vi.mocked(api.listMounts).mockResolvedValue([{ path: 'secret/', type: 'kv', version: '2' }])
@@ -244,10 +244,42 @@ test('switching mounts closes an open delete panel', async () => {
const user = await openPage()
await user.click(await screen.findByRole('button', { name: 'Delete' }))
expect(await screen.findByRole('alertdialog', { name: 'Delete secret/' })).toBeInTheDocument()
await user.selectOptions(screen.getByLabelText('Mount'), 'hosts/')
await user.selectOptions(screen.getByLabelText('Secrets engine'), 'hosts/')
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()
})
test('lays out New, then the labelled engine picker with Settings and Delete, then the breadcrumbs', async () => {
await openPage()
const newButton = await screen.findByRole('button', { name: 'New secrets engine' })
const select = screen.getByLabelText('Secrets engine') // a single engine still gets its picker, so the bar looks the same
const settings = screen.getByRole('button', { name: 'Settings' })
const del = screen.getByRole('button', { name: 'Delete' })
const crumbs = screen.getByRole('navigation', { name: 'Path' })
// Settings and Delete share the picker's line
const bar = select.closest('.mount-bar')!
expect(bar).toContainElement(settings)
expect(bar).toContainElement(del)
expect(bar).not.toContainElement(newButton)
expect(bar).not.toContainElement(crumbs)
// top to bottom: New, the bar, then the breadcrumbs
const before = (a: Element, b: Element) => Boolean(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
expect(before(newButton, select)).toBe(true)
expect(before(bar, crumbs)).toBe(true)
expect(screen.getByRole('button', { name: 'secret/' }).closest('nav')).toBe(crumbs)
})
test('a dynamic engine uses the full width, with the same header', async () => {
vi.mocked(api.listMounts).mockResolvedValue([{ path: 'hosts/', type: 'ssh' }])
vi.spyOn(BaoClient.prototype, 'list').mockResolvedValue([])
await openPage()
expect(await screen.findByLabelText('Secrets engine')).toHaveValue('hosts/')
expect(screen.getByRole('button', { name: 'Settings' })).toBeInTheDocument()
expect(screen.queryByRole('navigation', { name: 'Path' })).not.toBeInTheDocument()
expect(document.querySelector('.secrets-layout')).toBeNull()
})
test('asks to connect first', () => {
render(
<QueryClientProvider client={new QueryClient()}>
+66 -64
View File
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'
import { useId, useState } from 'react'
import type { BaoClient } from '../../api/bao'
import { engineFor, mountKind, mountTypeFor } from '../../api/engines/registry'
import { listSecrets } from '../../api/secrets'
@@ -12,6 +12,7 @@ import { MountDialog } from './MountDialog'
function Browser({ client }: { client: BaoClient }) {
const mounts = useMounts(client)
const selectId = useId()
const [mountChoice, setMount] = useState<string | null>(null)
const [prefix, setPrefix] = useState('')
const [selected, setSelected] = useState<string | null>(null)
@@ -37,21 +38,11 @@ function Browser({ client }: { client: BaoClient }) {
const existing = mounts.data.map((m) => m.path)
const closeDialog = () => setDialog(null)
const manage = (
<div className="mount-actions">
const newButton = (
<div className="mount-new">
<button type="button" onClick={() => setDialog(dialog === 'create' ? null : 'create')} aria-expanded={dialog === 'create'}>
New secrets engine
</button>
{current && mountTypeFor(current) && (
<button type="button" onClick={() => setDialog(dialog === 'edit' ? null : 'edit')} aria-expanded={dialog === 'edit'}>
Settings
</button>
)}
{current && (
<button type="button" onClick={() => setDialog(dialog === 'delete' ? null : 'delete')} aria-expanded={dialog === 'delete'}>
Delete
</button>
)}
</div>
)
const dialogs = dialog === 'delete' && current ? (
@@ -90,7 +81,7 @@ function Browser({ client }: { client: BaoClient }) {
return (
<>
<p>No secrets engines are mounted.</p>
{manage}
{newButton}
{dialogs}
</>
)
@@ -99,70 +90,81 @@ function Browser({ client }: { client: BaoClient }) {
const where = prefix ? `${mount}${prefix}` : mount
const kv = mounts.data.filter((m) => mountKind(m) === 'kv')
const dynamic = mounts.data.filter((m) => mountKind(m) === 'dynamic')
const mountSelect = mounts.data.length > 1 && (
<select
aria-label="Mount"
value={mount}
onChange={(e) => {
setMount(e.target.value)
go('')
// A settings or delete panel belongs to the mount it was opened for.
setDialog(null)
}}
>
{kv.length > 0 && (
<optgroup label="KV">
{kv.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</optgroup>
)}
{[...new Set(dynamic.map((m) => m.type))].map((type) => (
<optgroup key={type} label={engineFor(type).label}>
{dynamic
.filter((m) => m.type === type)
.map((m) => (
<option key={m.path}>{m.path}</option>
// New engine on its own line; then the engine picker with what you can do to it; then (for KV) where you are in it.
const header = (
<>
{newButton}
<div className="mount-bar">
<div className="mount-pick">
<label htmlFor={selectId}>Secrets engine</label>
<select
id={selectId}
value={mount}
onChange={(e) => {
setMount(e.target.value)
go('')
// A settings or delete panel belongs to the mount it was opened for.
setDialog(null)
}}
>
{kv.length > 0 && (
<optgroup label="KV">
{kv.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</optgroup>
)}
{[...new Set(dynamic.map((m) => m.type))].map((type) => (
<optgroup key={type} label={engineFor(type).label}>
{dynamic
.filter((m) => m.type === type)
.map((m) => (
<option key={m.path}>{m.path}</option>
))}
</optgroup>
))}
</optgroup>
))}
</select>
</select>
</div>
<div className="mount-actions">
{mountTypeFor(current) && (
<button type="button" onClick={() => setDialog(dialog === 'edit' ? null : 'edit')} aria-expanded={dialog === 'edit'}>
Settings
</button>
)}
<button type="button" onClick={() => setDialog(dialog === 'delete' ? null : 'delete')} aria-expanded={dialog === 'delete'}>
Delete
</button>
</div>
</div>
{dialogs}
</>
)
if (!isKv) {
return (
<>
{manage}
{dialogs}
<div className="secrets-layout">
<div className="secrets-browser">
<nav aria-label="Path" className="crumbs">
{mountSelect}
</nav>
</div>
<EngineView client={client} mount={current} />
</div>
{header}
<EngineView client={client} mount={current} />
</>
)
}
return (
<>
{manage}
{dialogs}
{header}
<nav aria-label="Path" className="crumbs">
<button type="button" onClick={() => go('')}>
{mount}
</button>
{crumbs.map((c, i) => (
<button key={i} type="button" onClick={() => go(crumbs.slice(0, i + 1).join('/') + '/')}>
{c}/
</button>
))}
</nav>
<div className="secrets-layout">
<div className="secrets-browser">
<nav aria-label="Path" className="crumbs">
{mountSelect}
<button type="button" onClick={() => go('')}>
{mount}
</button>
{crumbs.map((c, i) => (
<button key={i} type="button" onClick={() => go(crumbs.slice(0, i + 1).join('/') + '/')}>
{c}/
</button>
))}
</nav>
{entries.isPending && <p className="hint">Loading…</p>}
{entries.error && <p role="alert">{entries.error.message}</p>}
{entries.data?.length === 0 && <p className="hint">No secrets in {where} yet.</p>}
+35 -10
View File
@@ -1095,14 +1095,6 @@ button.link:hover:not(:disabled) {
align-items: start;
}
.secrets-browser .crumbs {
margin-top: 0;
}
.secrets-browser .crumbs select {
min-width: 0;
}
.secrets-browser .entries {
max-height: 70vh;
overflow-y: auto;
@@ -1501,11 +1493,44 @@ button.danger-solid:hover:not(:disabled) {
white-space: pre-wrap;
}
/* Create / settings / delete panel for a secrets engine mount. */
/* Top of the Secrets page: New, then the engine picker with its actions, then (KV) the breadcrumbs. */
.mount-new {
margin-bottom: var(--s4);
}
.mount-bar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--s3);
margin-bottom: var(--s2);
}
.mount-pick {
display: flex;
align-items: center;
gap: var(--s2);
min-width: 0;
}
.mount-pick label {
font-weight: 500;
white-space: nowrap;
}
.mount-pick select {
min-width: 12rem;
max-width: 100%;
}
.mount-actions {
display: flex;
gap: var(--s2);
margin-bottom: var(--s4);
}
.mount-bar + .crumbs,
.mount-dialog + .crumbs {
margin-top: var(--s2);
}
.mount-dialog {
+3 -2
View File
@@ -22,7 +22,7 @@ test.each([
expect(screen.getByRole('heading', { name: heading })).toBeInTheDocument()
})
test('redirects / to identities', () => {
test('redirects / to the connect page while signed out', () => {
const router = createMemoryRouter(routes, { initialEntries: ['/'] })
render(
<Providers>
@@ -31,5 +31,6 @@ test('redirects / to identities', () => {
</SessionProvider>
</Providers>,
)
expect(screen.getByRole('heading', { name: 'Identities' })).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Connect' })).toBeInTheDocument()
expect(router.state.location.pathname).toBe('/connect')
})
+3 -2
View File
@@ -1,15 +1,16 @@
import { Navigate, type RouteObject } from 'react-router'
import type { RouteObject } from 'react-router'
import { ConnectPage } from './features/connect/ConnectPage'
import { GraphPage } from './features/graph/GraphPage'
import { IdentitiesPage } from './features/identities/IdentitiesPage'
import { SecretsPage } from './features/secrets/SecretsPage'
import { Home } from './Home'
import { Layout } from './Layout'
export const routes: RouteObject[] = [
{
element: <Layout />,
children: [
{ index: true, element: <Navigate to="/identities" replace /> },
{ index: true, element: <Home /> },
{ path: 'connect', element: <ConnectPage /> },
{ path: 'identities', element: <IdentitiesPage /> },
{ path: 'secrets', element: <SecretsPage /> },