Phone-width layout fixes (ENB-23)
Checked at 390px and 360px in a headless mobile Chrome; no horizontal overflow on any page. - Tables become stacked cards on phones, with column names from data-label and row actions underneath instead of off the edge. - Nav fits on one line; chips no longer wrap mid-name; less nested padding. - Graph opens at a fixed readable zoom on phones with a pan/zoom hint, and scrolls to the details card when a node or label is tapped. - Add the missing headings and wide layout to the user, entity and group forms (previously only the token form had them). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0882d35123
commit
61bb6d912a
11 files changed
+154
-23
No files matched your search
@@ -114,7 +114,7 @@ export function AccessEditor({ client, target, onClose }: Props) {
|
||||
<code>{row.display}</code>
|
||||
{row.wildcard && <span className="tag">everything inside</span>}
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Can">
|
||||
<CapabilityChips capabilities={row.capabilities} />
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import type { Ref } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { revokeAccess } from '../../api/grants'
|
||||
import type { AccessGraph, GraphEdge, GraphNode, PolicyInput } from '../../model/graph'
|
||||
@@ -14,6 +15,7 @@ interface Props {
|
||||
policies: PolicyInput[]
|
||||
selection: Selection | null
|
||||
onRevoked: () => void
|
||||
ref?: Ref<HTMLElement>
|
||||
}
|
||||
|
||||
const nodeById = (g: AccessGraph, id: string) => g.nodes.find((n) => n.id === id)
|
||||
@@ -210,7 +212,7 @@ function EdgeDetails({ client, edge, full, policies, onRevoked }: { client: BaoC
|
||||
)
|
||||
}
|
||||
|
||||
export function Details({ client, full, policies, selection, onRevoked }: Props) {
|
||||
export function Details({ client, full, policies, selection, onRevoked, ref }: Props) {
|
||||
let body = <p className="detail-empty">Select a node or a line to see what it grants.</p>
|
||||
if (selection?.kind === 'node') {
|
||||
const node = nodeById(full, selection.id)
|
||||
@@ -220,7 +222,7 @@ export function Details({ client, full, policies, selection, onRevoked }: Props)
|
||||
if (edge) body = <EdgeDetails client={client} edge={edge} full={full} policies={policies} onRevoked={onRevoked} />
|
||||
}
|
||||
return (
|
||||
<aside className="graph-details" aria-label="Details">
|
||||
<aside ref={ref} className="graph-details" aria-label="Details">
|
||||
{body}
|
||||
</aside>
|
||||
)
|
||||
|
||||
@@ -9,13 +9,14 @@ import {
|
||||
} from '@xyflow/react'
|
||||
import '@xyflow/react/dist/style.css'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { BaoClient } from '../../api/bao'
|
||||
import { buildAccessGraph, type AccessGraph } from '../../model/graph'
|
||||
import { filterGraph } from '../../model/graphFilter'
|
||||
import { layoutColumns } from '../../model/layout'
|
||||
import { RequireConnection } from '../shared/RequireConnection'
|
||||
import { useAccessInputs } from '../shared/useAccessInputs'
|
||||
import { useNarrow } from '../shared/useNarrow'
|
||||
import { Details, type Selection } from './Details'
|
||||
import { GrantEdge, type GrantEdgeData } from './GraphEdge'
|
||||
import { GraphNodeCard } from './GraphNode'
|
||||
@@ -79,6 +80,13 @@ function GraphView({ client }: { client: BaoClient }) {
|
||||
const [path, setPath] = useState('')
|
||||
const [hideDefault, setHideDefault] = useState(true)
|
||||
const [selected, setSelected] = useState<Selection | null>(null)
|
||||
const narrow = useNarrow()
|
||||
const detailsRef = useRef<HTMLElement>(null)
|
||||
|
||||
// On a phone the details sit below the canvas, so bring them into view when something is picked.
|
||||
useEffect(() => {
|
||||
if (narrow && selected) detailsRef.current?.scrollIntoView({ block: 'start', behavior: 'smooth' })
|
||||
}, [narrow, selected])
|
||||
|
||||
const full = useMemo(
|
||||
() => (inputs.data ? buildAccessGraph(inputs.data.identities, inputs.data.policies) : null),
|
||||
@@ -131,6 +139,7 @@ function GraphView({ client }: { client: BaoClient }) {
|
||||
</li>
|
||||
<li>Dashed: policy is attached but missing</li>
|
||||
<li className="grow">Identities include policies inherited through entities and groups.</li>
|
||||
<li className="graph-hint">Drag to pan, pinch to zoom, tap a node or label for details.</li>
|
||||
</ul>
|
||||
</div>
|
||||
{inputs.data.notes.map((n) => (
|
||||
@@ -144,11 +153,15 @@ function GraphView({ client }: { client: BaoClient }) {
|
||||
<div className="graph-layout">
|
||||
<div className="graph-canvas" data-testid="graph-canvas">
|
||||
<ReactFlow
|
||||
// A phone can't fit the whole graph at a readable size: open at a fixed zoom and let people pan.
|
||||
key={narrow ? 'narrow' : 'wide'}
|
||||
nodes={flow.nodes}
|
||||
edges={flow.edges}
|
||||
nodeTypes={nodeTypes}
|
||||
edgeTypes={edgeTypes}
|
||||
fitView
|
||||
fitView={!narrow}
|
||||
defaultViewport={narrow ? { x: 16, y: 16, zoom: 0.8 } : undefined}
|
||||
minZoom={narrow ? 0.3 : undefined}
|
||||
nodesDraggable={false}
|
||||
nodesConnectable={false}
|
||||
elementsSelectable
|
||||
@@ -161,7 +174,7 @@ function GraphView({ client }: { client: BaoClient }) {
|
||||
<Controls showInteractive={false} />
|
||||
</ReactFlow>
|
||||
</div>
|
||||
<Details client={client} full={full} policies={inputs.data.policies} selection={selected} onRevoked={() => setSelected(null)} />
|
||||
<Details ref={detailsRef} client={client} full={full} policies={inputs.data.policies} selection={selected} onRevoked={() => setSelected(null)} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -74,10 +74,10 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
{entities.data?.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td>{e.name}</td>
|
||||
<td>
|
||||
<td data-label="Aliases">
|
||||
<NameChips names={e.aliases.map((a) => a.name)} />
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Policies">
|
||||
<PolicyChips policies={e.policies} />
|
||||
</td>
|
||||
<td>
|
||||
@@ -110,7 +110,8 @@ export function EntitiesTab({ client }: { client: BaoClient }) {
|
||||
</button>
|
||||
)}
|
||||
{draft && (
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New entity' : `Edit ${draft.name}`}>
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New entity' : `Edit ${draft.name}`} className="wide">
|
||||
<h3>{draft.isNew ? 'New entity' : `Edit ${draft.name}`}</h3>
|
||||
<label>
|
||||
Name
|
||||
<input value={draft.name} disabled={!draft.isNew} onChange={(e) => setDraft({ ...draft, name: e.target.value })} required />
|
||||
|
||||
@@ -57,10 +57,10 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
{groups.data?.map((g) => (
|
||||
<tr key={g.id}>
|
||||
<td>{g.name}</td>
|
||||
<td>
|
||||
<td data-label="Members">
|
||||
<NameChips names={g.member_entity_ids.map(nameOf)} />
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Policies">
|
||||
<PolicyChips policies={g.policies} />
|
||||
</td>
|
||||
<td>
|
||||
@@ -92,7 +92,8 @@ export function GroupsTab({ client }: { client: BaoClient }) {
|
||||
</button>
|
||||
)}
|
||||
{draft && (
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New group' : `Edit ${draft.name}`}>
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New group' : `Edit ${draft.name}`} className="wide">
|
||||
<h3>{draft.isNew ? 'New group' : `Edit ${draft.name}`}</h3>
|
||||
<label>
|
||||
Name
|
||||
<input value={draft.name} disabled={!draft.isNew} onChange={(e) => setDraft({ ...draft, name: e.target.value })} required />
|
||||
|
||||
@@ -104,11 +104,11 @@ export function TokensTab({ client }: { client: BaoClient }) {
|
||||
{t.display_name || '—'}
|
||||
{isSelf ? ' (you)' : ''}
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Policies">
|
||||
<PolicyChips policies={t.policies} />
|
||||
</td>
|
||||
<td>{formatTtl(t.ttl)}</td>
|
||||
<td>
|
||||
<td data-label="Expires">{formatTtl(t.ttl)}</td>
|
||||
<td data-label="Accessor">
|
||||
<code>{t.accessor.slice(0, 8)}…</code>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -33,6 +33,15 @@ test('lists users', async () => {
|
||||
expect(within(row).getByText('dev')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('the user form has a heading that says what it is for', async () => {
|
||||
const user = setup()
|
||||
await user.click(await screen.findByRole('button', { name: 'New user' }))
|
||||
expect(screen.getByRole('heading', { name: 'New user' })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Edit alice' }))
|
||||
expect(screen.getByRole('heading', { name: 'Edit alice' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('creates a user with selected policies', async () => {
|
||||
const user = setup()
|
||||
await user.click(await screen.findByRole('button', { name: 'New user' }))
|
||||
|
||||
@@ -58,7 +58,7 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
{users.data?.map((u) => (
|
||||
<tr key={u.name}>
|
||||
<td>{u.name}</td>
|
||||
<td>
|
||||
<td data-label="Policies">
|
||||
<PolicyChips policies={u.policies} />
|
||||
</td>
|
||||
<td>
|
||||
@@ -90,7 +90,8 @@ export function UsersTab({ client }: { client: BaoClient }) {
|
||||
</button>
|
||||
)}
|
||||
{draft && (
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New user' : `Edit ${draft.name}`}>
|
||||
<form onSubmit={submit} aria-label={draft.isNew ? 'New user' : `Edit ${draft.name}`} className="wide">
|
||||
<h3>{draft.isNew ? 'New user' : `Edit ${draft.name}`}</h3>
|
||||
<label>
|
||||
Username
|
||||
<input value={draft.name} disabled={!draft.isNew} onChange={(e) => setDraft({ ...draft, name: e.target.value })} required />
|
||||
|
||||
@@ -54,10 +54,10 @@ function Entries({ data, path }: { data: NonNullable<ReturnType<typeof useAccess
|
||||
<td>
|
||||
<span>{e.identity.name}</span> <span className="tag">{e.identity.kind}</span>
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Via policy">
|
||||
<code>{e.policy}</code>
|
||||
</td>
|
||||
<td>
|
||||
<td data-label="Can">
|
||||
<CapabilityChips capabilities={e.capabilities} />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useSyncExternalStore } from 'react'
|
||||
|
||||
const QUERY = '(max-width: 40rem)'
|
||||
const supported = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function'
|
||||
|
||||
/** True on phone-width screens (matches the 40rem breakpoint in index.css). */
|
||||
export function useNarrow(): boolean {
|
||||
return useSyncExternalStore(
|
||||
(onChange) => {
|
||||
if (!supported()) return () => {}
|
||||
const m = window.matchMedia(QUERY)
|
||||
m.addEventListener('change', onChange)
|
||||
return () => m.removeEventListener('change', onChange)
|
||||
},
|
||||
() => supported() && window.matchMedia(QUERY).matches,
|
||||
() => false,
|
||||
)
|
||||
}
|
||||
+90
-4
@@ -998,6 +998,7 @@ dd {
|
||||
}
|
||||
|
||||
.chips li {
|
||||
white-space: nowrap;
|
||||
padding: 0 var(--s2);
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
@@ -1230,17 +1231,101 @@ button.primary:hover:not(:disabled) {
|
||||
}
|
||||
}
|
||||
|
||||
.graph-hint {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
/* Wide tables scroll sideways inside themselves rather than widening the page. */
|
||||
table {
|
||||
/*
|
||||
* Tables become stacked cards: the first cell is the title, other cells show their column name
|
||||
* (from data-label) above the value, and row actions sit underneath instead of off the edge.
|
||||
*/
|
||||
table,
|
||||
tbody,
|
||||
tr,
|
||||
td {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
tr {
|
||||
padding: var(--s3) var(--s4);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
|
||||
tbody tr:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: var(--s1) 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
td[data-label]::before {
|
||||
content: attr(data-label);
|
||||
display: block;
|
||||
color: var(--ink-faint);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
td:last-child:has(button) {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--s2);
|
||||
padding-top: var(--s2);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
td:last-child button + button {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
/* Five nav items have to fit on one line. */
|
||||
.shell > nav {
|
||||
gap: 0;
|
||||
padding: 0 var(--s2);
|
||||
}
|
||||
|
||||
.shell > nav strong {
|
||||
margin-right: var(--s2);
|
||||
}
|
||||
|
||||
.shell > nav a {
|
||||
padding: var(--s3) var(--s2);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
.shell > nav .whoami {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Less nested padding so cards inside cards keep their width. */
|
||||
form,
|
||||
.secret-detail {
|
||||
padding: var(--s4);
|
||||
}
|
||||
|
||||
.access-head {
|
||||
padding: var(--s3) var(--s4);
|
||||
}
|
||||
|
||||
.access-body {
|
||||
padding: var(--s3);
|
||||
}
|
||||
|
||||
.graph-hint {
|
||||
display: list-item;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.graph-toolbar label:not(.check),
|
||||
.graph-toolbar input:not([type='checkbox']) {
|
||||
width: 100%;
|
||||
@@ -1250,8 +1335,9 @@ button.primary:hover:not(:disabled) {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
/* The legend is already most of a screen on a phone; drop the long note. */
|
||||
.graph-legend .grow {
|
||||
margin-left: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.access-head,
|
||||
|
||||
Reference in new issue
Block a user