Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(ui): make API tokens responsive

rcourtman1e4791df4bc3
diff --git a/.gitleaksignore b/.gitleaksignore
new file mode 100644
index 0000000000..748197b601
--- /dev/null
+++ b/.gitleaksignore
@@ -0,0 +1,4 @@
+# browser-verification.json stores a SHA-256 digest beside the APITokenManager
+# source path. That path context makes the generic API-key rule classify the
+# required content digest as a credential; suppress only that exact fingerprint.
+frontend-modern/browser-verification.json:generic-api-key:10
diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.json
index caed04b1a4..3a76189c33 100644
--- a/frontend-modern/browser-verification.json
+++ b/frontend-modern/browser-verification.json
@@ -1,32 +1,35 @@
{
"version": 1,
- "base_sha": "cd03c8b44d6552bd41a7ab232fdd68850baa630d",
- "verified_at": "2026-08-04T18:16:29Z",
+ "base_sha": "ba8da5ab2927b327a915b0793800e4ed1c631221",
+ "verified_at": "2026-08-04T18:37:57Z",
"result": "passed",
"changed_paths": [
- "frontend-modern/src/features/docker/DockerSwarmNodesTable.tsx"
+ "frontend-modern/src/components/Settings/APITokenManager.tsx"
],
"content_sha256": {
- "frontend-modern/src/features/docker/DockerSwarmNodesTable.tsx": "8cfdbdf7d74f429e39b4c1e2ab196d857c59bc83c5785bb1777ed25e73c1312b"
+ "frontend-modern/src/components/Settings/APITokenManager.tsx": "2e11671670ee8cc23c2ada2f10ba1f5195e066f2873cd52520020756bcf2e02b"
},
"routes": [
- "/docker/swarm"
+ "/settings/security/api"
],
"viewports": [
- { "width": 320, "height": 700 },
{ "width": 375, "height": 812 },
{ "width": 768, "height": 900 },
- { "width": 1280, "height": 900 }
+ { "width": 1280, "height": 900 },
+ { "width": 1536, "height": 960 },
+ { "width": 1600, "height": 960 }
],
"states": [
- "Rendered all six Swarm inventory tables with mock data at 320px and 375px without document or table overflow",
- "Rendered Swarm Nodes with the compact Node, Role, Avail, and Mem headings below the first container reveal breakpoint",
- "Rendered Swarm Nodes with full Availability and Memory headings at tablet width",
- "Rendered all eight Swarm Nodes diagnostic columns with full headings at wide desktop width"
+ "Rendered five token inventory cards with name, hint, scopes, usage, created time, last-used time, and management actions at phone width",
+ "Rendered the single-column token card inventory at tablet width without document or component overflow",
+ "Rendered the token inventory as a two-column card grid at 1280px and 1536px without horizontal scrolling",
+ "Rendered the complete seven-column token table at 1600px with equal table-shell client and scroll widths",
+ "Rendered the Edit API token scopes and Revoke API token confirmation dialogs at phone width"
],
"interactions": [
- "Cycled the Availability sortable heading through ascending, descending, and default order and confirmed the aria-sort state and indicator updated each time",
- "Inspected final phone pixels for Swarm Tasks, Nodes, Secrets, and Configs and confirmed identity, operational state, and capacity remain readable",
- "Measured the Swarm Nodes table after hot reload at every recorded viewport and confirmed its client width equals its scroll width"
+ "Opened Edit scopes from a specific compact token card, verified the dialog stayed within the 375px viewport, and cancelled without mutation",
+ "Opened Revoke from the same compact token card, verified the confirmation stayed within the 375px viewport, and cancelled without revoking the token",
+ "Inspected final phone pixels and confirmed every compact-card field and both management actions remain visible without horizontal scrolling",
+ "Measured the compact list and wide table at every recorded breakpoint and confirmed each active presentation has equal client and scroll widths"
]
}
diff --git a/frontend-modern/src/components/Settings/APITokenManager.tsx b/frontend-modern/src/components/Settings/APITokenManager.tsx
index 7206d6e3dd..24df9b23ca 100644
--- a/frontend-modern/src/components/Settings/APITokenManager.tsx
+++ b/frontend-modern/src/components/Settings/APITokenManager.tsx
@@ -117,6 +117,112 @@ export const APITokenManager: Component<APITokenManagerProps> = (props) => {
}
};
+ const renderTokenScopes = (token: APITokenRecord) => {
+ const rawScopes = effectiveScopes(token);
+ const scopeBadges = rawScopes.includes('*')
+ ? [{ value: '*', label: 'Full' }]
+ : rawScopes.map((scope) => ({
+ value: scope,
+ label: API_SCOPE_LABELS[scope] ?? scope,
+ }));
+
+ return (
+ <div class="flex flex-wrap gap-1.5">
+ <For each={scopeBadges}>
+ {(scope) => {
+ const isWildcard = scope.value === '*';
+ return (
+ <span
+ class={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
+ isWildcard
+ ? 'bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200'
+ : 'bg-surface-alt text-base-content'
+ }`}
+ title={scope.value}
+ >
+ {scope.label}
+ </span>
+ );
+ }}
+ </For>
+ </div>
+ );
+ };
+
+ const renderTokenUsage = (token: APITokenRecord) => {
+ const dockerUsageEntry = dockerTokenUsage().get(token.id);
+ const agentUsageEntry = agentTokenUsage().get(token.id);
+ const usageSegments: string[] = [];
+ const usageTitleSegments: string[] = [];
+ if (dockerUsageEntry) {
+ usageSegments.push(getAPITokenDockerPodmanUsageSummary(dockerUsageEntry));
+ usageTitleSegments.push(getAPITokenDockerPodmanUsageTitle(dockerUsageEntry));
+ }
+ if (agentUsageEntry) {
+ usageSegments.push(
+ agentUsageEntry.count === 1
+ ? `${agentUsageEntry.items[0]?.label ?? 'Agent'}`
+ : `${agentUsageEntry.count} agents`,
+ );
+ usageTitleSegments.push(
+ `Agents: ${agentUsageEntry.items.map((agent) => agent.label).join(', ')}`,
+ );
+ }
+ const usageSummary = usageSegments.length > 0 ? usageSegments.join(' • ') : '—';
+
+ return (
+ <div
+ class="flex flex-wrap items-center gap-2"
+ title={usageTitleSegments.length > 0 ? usageTitleSegments.join('\n') : undefined}
+ >
+ <span class="text-muted">{usageSummary}</span>
+ <Show when={agentUsageEntry && agentUsageEntry.count > 1}>
+ <span class="inline-flex items-center gap-1 rounded-full bg-amber-100 px-2 py-0.5 text-[11px] font-semibold text-amber-800 dark:bg-amber-900 dark:text-amber-200">
+ <svg class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor">
+ <path
+ fill-rule="evenodd"
+ d="M8.257 3.099c.764-1.36 2.722-1.36 3.486 0l6.518 11.62c.75 1.338-.213 3.005-1.743 3.005H3.482c-1.53 0-2.493-1.667-1.743-3.005l6.518-11.62ZM11 5a1 1 0 1 0-2 0v4.5a1 1 0 1 0 2 0V5Zm0 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ Agents sharing this token ({agentUsageEntry!.count})
+ </span>
+ </Show>
+ </div>
+ );
+ };
+
+ const renderTokenActions = (token: APITokenRecord, compact = false) => (
+ <div
+ class={
+ compact
+ ? 'flex w-full items-center gap-2 border-t border-border pt-3'
+ : 'flex items-center justify-end gap-1'
+ }
+ >
+ <button
+ type="button"
+ onClick={() => openScopeEditor(token)}
+ disabled={!canManage()}
+ class={`inline-flex min-h-10 items-center justify-center rounded-md px-2.5 py-1.5 text-sm font-semibold text-blue-600 transition hover:bg-blue-50 hover:text-blue-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-blue-300 dark:hover:bg-blue-900 dark:hover:text-blue-200 ${
+ compact ? 'flex-1 border border-blue-200 dark:border-blue-800' : 'sm:min-h-9'
+ }`}
+ >
+ Edit scopes
+ </button>
+ <button
+ type="button"
+ onClick={() => setTokenToRevoke(token)}
+ disabled={!canManage()}
+ class={`inline-flex min-h-10 items-center justify-center rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 transition hover:bg-red-50 hover:text-red-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-red-400 dark:hover:bg-red-900 dark:hover:text-red-300 ${
+ compact ? 'flex-1 border border-red-200 dark:border-red-900' : 'sm:min-h-9'
+ }`}
+ >
+ Revoke
+ </button>
+ </div>
+ );
+
return (
<div class="space-y-5">
<Card padding="none" class="border border-border shadow-sm">
@@ -318,7 +424,61 @@ export const APITokenManager: Component<APITokenManagerProps> = (props) => {
</button>
</div>
+ <div
+ data-testid="api-token-compact-list"
+ class="grid gap-px bg-border xl:grid-cols-2 min-[1600px]:hidden"
+ >
+ <For each={sortedTokens()}>
+ {(token) => (
+ <article
+ aria-label={`API token ${token.name || 'Untitled'}`}
+ class="space-y-3 bg-surface p-4 sm:p-5"
+ data-api-token-card={token.id}
+ >
+ <div class="flex min-w-0 items-start justify-between gap-3">
+ <div class="min-w-0">
+ <h5 class="break-words text-sm font-semibold text-base-content">
+ {token.name || 'Untitled'}
+ </h5>
+ <div class="mt-1 font-mono text-xs text-muted">{tokenHint(token)}</div>
+ </div>
+ <div class="shrink-0 text-right">
+ <div class="text-[0.65rem] font-semibold uppercase tracking-wide text-muted">
+ Last used
+ </div>
+ <div class="mt-1 text-xs text-base-content">
+ {token.lastUsedAt
+ ? formatRelativeTime(new Date(token.lastUsedAt).getTime())
+ : 'Never'}
+ </div>
+ </div>
+ </div>
+
+ <dl class="grid gap-3 text-xs sm:grid-cols-2">
+ <div class="space-y-1 sm:col-span-2">
+ <dt class="font-semibold uppercase tracking-wide text-muted">Scopes</dt>
+ <dd>{renderTokenScopes(token)}</dd>
+ </div>
+ <div class="space-y-1">
+ <dt class="font-semibold uppercase tracking-wide text-muted">Usage</dt>
+ <dd>{renderTokenUsage(token)}</dd>
+ </div>
+ <div class="space-y-1">
+ <dt class="font-semibold uppercase tracking-wide text-muted">Created</dt>
+ <dd class="text-base-content">
+ {formatRelativeTime(new Date(token.createdAt).getTime())}
+ </dd>
+ </div>
+ </dl>
+
+ {renderTokenActions(token, true)}
+ </article>
+ )}
+ </For>
+ </div>
+
<PulseDataGrid
+ class="hidden min-[1600px]:block"
data={sortedTokens()}
columns={[
{
@@ -338,83 +498,12 @@ export const APITokenManager: Component<APITokenManagerProps> = (props) => {
{
key: 'scopes',
label: 'Scopes',
- render: (token) => {
- const rawScopes = token.scopes && token.scopes.length > 0 ? token.scopes : ['*'];
- const scopeBadges = rawScopes.includes('*')
- ? [{ value: '*', label: 'Full' }]
- : rawScopes.map((scope) => ({
- value: scope,
- label: API_SCOPE_LABELS[scope] ?? scope,
- }));
- return (
- <div class="flex flex-wrap gap-1.5">
- <For each={scopeBadges}>
- {(scope) => {
- const isWildcard = scope.value === '*';
- return (
- <span
- class={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
- isWildcard
- ? 'bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200'
- : 'bg-surface-alt text-base-content'
- }`}
- title={scope.value}
- >
- {scope.label}
- </span>
- );
- }}
- </For>
- </div>
- );
- },
+ render: renderTokenScopes,
},
{
key: 'usage',
label: 'Usage',
- render: (token) => {
- const dockerUsageEntry = dockerTokenUsage().get(token.id);
- const agentUsageEntry = agentTokenUsage().get(token.id);
- const usageSegments: string[] = [];
- const usageTitleSegments: string[] = [];
- if (dockerUsageEntry) {
- usageSegments.push(getAPITokenDockerPodmanUsageSummary(dockerUsageEntry));
- usageTitleSegments.push(getAPITokenDockerPodmanUsageTitle(dockerUsageEntry));
- }
- if (agentUsageEntry) {
- usageSegments.push(
- agentUsageEntry.count === 1
- ? `${agentUsageEntry.items[0]?.label ?? 'Agent'}`
- : `${agentUsageEntry.count} agents`,
- );
- usageTitleSegments.push(
- `Agents: ${agentUsageEntry.items.map((agent) => agent.label).join(', ')}`,
- );
- }
- const usageSummary = usageSegments.length > 0 ? usageSegments.join(' • ') : '—';
- return (
- <div
- class="flex flex-wrap items-center gap-2"
- title={
- usageTitleSegments.length > 0 ? usageTitleSegments.join('\n') : undefined
- }
- >
- <span class="text-muted">{usageSummary}</span>
- <Show when={agentUsageEntry && agentUsageEntry.count > 1}>
- <span class="inline-flex items-center gap-1 rounded-full bg-amber-100 px-2 py-0.5 text-[11px] font-semibold text-amber-800 dark:bg-amber-900 dark:text-amber-200">
- <svg class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor">
- <path
- fill-rule="evenodd"
- d="M8.257 3.099c.764-1.36 2.722-1.36 3.486 0l6.518 11.62c.75 1.338-.213 3.005-1.743 3.005H3.482c-1.53 0-2.493-1.667-1.743-3.005l6.518-11.62ZM11 5a1 1 0 1 0-2 0v4.5a1 1 0 1 0 2 0V5Zm0 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
- clip-rule="evenodd"
- />
- </svg>
- Agents sharing this token ({agentUsageEntry!.count})
- </span>
- </Show>
- </div>
- );
- },
+ render: renderTokenUsage,
},
{
key: 'createdAt',
@@ -440,30 +529,11 @@ export const APITokenManager: Component<APITokenManagerProps> = (props) => {
key: 'action',
label: 'Actions',
align: 'right',
- render: (token) => (
- <div class="flex items-center justify-end gap-1">
- <button
- type="button"
- onClick={() => openScopeEditor(token)}
- disabled={!canManage()}
- class="inline-flex min-h-10 sm:min-h-9 items-center rounded-md px-2.5 py-1.5 text-sm font-semibold text-blue-600 transition hover:bg-blue-50 hover:text-blue-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-blue-300 dark:hover:bg-blue-900 dark:hover:text-blue-200"
- >
- Edit scopes
- </button>
- <button
- type="button"
- onClick={() => setTokenToRevoke(token)}
- disabled={!canManage()}
- class="inline-flex min-h-10 sm:min-h-9 items-center rounded-md px-2.5 py-1.5 text-sm font-semibold text-red-600 transition hover:bg-red-50 hover:text-red-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-red-400 dark:hover:bg-red-900 dark:hover:text-red-300"
- >
- Revoke
- </button>
- </div>
- ),
+ render: renderTokenActions,
},
]}
keyExtractor={(token) => token.id}
- desktopMinWidth="1000px"
+ desktopMinWidth="960px"
frame="flush"
/>
</Card>
diff --git a/frontend-modern/src/components/Settings/__tests__/APITokenManager.test.tsx b/frontend-modern/src/components/Settings/__tests__/APITokenManager.test.tsx
index 916d511f26..6905a182ea 100644
--- a/frontend-modern/src/components/Settings/__tests__/APITokenManager.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/APITokenManager.test.tsx
@@ -132,6 +132,22 @@ const renderAPIAccessPanel = () =>
</Router>
));
+const getTokenTableRow = (name: string): HTMLTableRowElement => {
+ const row = screen
+ .getAllByText(name)
+ .map((element) => element.closest('tr'))
+ .find(
+ (candidate): candidate is HTMLTableRowElement => candidate instanceof HTMLTableRowElement,
+ );
+ if (!row) throw new Error(`Could not find desktop token row for ${name}`);
+ return row;
+};
+
+const findTokenTableRow = async (name: string): Promise<HTMLTableRowElement> => {
+ await screen.findAllByText(name);
+ return getTokenTableRow(name);
+};
+
describe('APITokenManager security surface', () => {
// The API Access tab is the canonical security surface for
// operator-controlled machine access. Pulse Intelligence owns
@@ -269,7 +285,7 @@ describe('APITokenManager', () => {
);
await waitFor(() => {
- expect(screen.getAllByText('Container automation')).toHaveLength(2);
+ expect(screen.getAllByText('Container automation')).toHaveLength(3);
expect(screen.getByText(/Token generated:/)).toBeInTheDocument();
expect(
screen.getAllByText('Docker / Podman lifecycle management').length,
@@ -496,18 +512,12 @@ describe('APITokenManager', () => {
render(() => <APITokenManager onTokensChanged={vi.fn()} canManage />);
- const runtimeName = await screen.findByText('Runtime token');
- const row = runtimeName.closest('tr');
- expect(row).toBeTruthy();
- expect(
- within(row as HTMLTableRowElement).getByText('Docker Edge • Edge Agent'),
- ).toBeInTheDocument();
- expect(
- within(row as HTMLTableRowElement).queryByText(/container runtime/i),
- ).not.toBeInTheDocument();
- expect(within(row as HTMLTableRowElement).getByText('Agent reporting')).toBeInTheDocument();
+ const row = await findTokenTableRow('Runtime token');
+ expect(within(row).getByText('Docker Edge • Edge Agent')).toBeInTheDocument();
+ expect(within(row).queryByText(/container runtime/i)).not.toBeInTheDocument();
+ expect(within(row).getByText('Agent reporting')).toBeInTheDocument();
- fireEvent.click(within(row as HTMLTableRowElement).getByRole('button', { name: 'Revoke' }));
+ fireEvent.click(within(row).getByRole('button', { name: 'Revoke' }));
// Confirm modal opens — click "Revoke token" to actually trigger the delete.
const confirmBtn = await screen.findByRole('button', { name: 'Revoke token' });
@@ -530,10 +540,39 @@ describe('APITokenManager', () => {
await waitFor(() => {
expect(screen.queryByText('Runtime token')).not.toBeInTheDocument();
- expect(screen.getByText('Unused token')).toBeInTheDocument();
+ expect(screen.getAllByText('Unused token')).toHaveLength(2);
});
});
+ it('presents the complete token inventory as manageable compact cards below 1600px', async () => {
+ listTokensMock.mockResolvedValue([
+ makeToken({
+ id: 'token-compact',
+ name: 'Phone-managed token',
+ scopes: [DOCKER_REPORT_SCOPE, AGENT_REPORT_SCOPE],
+ }),
+ ]);
+
+ render(() => <APITokenManager onTokensChanged={vi.fn()} canManage />);
+
+ const compactList = await screen.findByTestId('api-token-compact-list');
+ expect(compactList).toHaveClass('min-[1600px]:hidden');
+ const card = compactList.querySelector('[data-api-token-card="token-compact"]');
+ expect(card).not.toBeNull();
+ const compactCard = within(card as HTMLElement);
+ expect(compactCard.getByRole('heading', { name: 'Phone-managed token' })).toBeInTheDocument();
+ expect(compactCard.getByText('Scopes')).toBeInTheDocument();
+ expect(compactCard.getByText('Docker / Podman reporting')).toBeInTheDocument();
+ expect(compactCard.getByText('Agent reporting')).toBeInTheDocument();
+ expect(compactCard.getByText('Usage')).toBeInTheDocument();
+ expect(compactCard.getByText('Created')).toBeInTheDocument();
+ expect(compactCard.getByText('Last used')).toBeInTheDocument();
+ expect(compactCard.getByRole('button', { name: 'Edit scopes' })).toBeInTheDocument();
+ expect(compactCard.getByRole('button', { name: 'Revoke' })).toBeInTheDocument();
+ expect(apiTokenManagerSource).toContain('class="hidden min-[1600px]:block"');
+ expect(apiTokenManagerSource).toContain('desktopMinWidth="960px"');
+ });
+
it('edits a token scope set in place without rotating or revoking it', async () => {
const onTokensChanged = vi.fn();
listTokensMock.mockResolvedValue([
@@ -553,12 +592,8 @@ describe('APITokenManager', () => {
render(() => <APITokenManager onTokensChanged={onTokensChanged} canManage />);
- const tokenName = await screen.findByText('Editable token');
- const row = tokenName.closest('tr');
- expect(row).toBeTruthy();
- fireEvent.click(
- within(row as HTMLTableRowElement).getByRole('button', { name: 'Edit scopes' }),
- );
+ const row = await findTokenTableRow('Editable token');
+ fireEvent.click(within(row).getByRole('button', { name: 'Edit scopes' }));
const dialog = await screen.findByRole('dialog', { name: 'Edit API token scopes' });
expect(within(dialog).getByText(/take effect on its next request/i)).toBeInTheDocument();
@@ -588,13 +623,9 @@ describe('APITokenManager', () => {
screen.queryByRole('dialog', { name: 'Edit API token scopes' }),
).not.toBeInTheDocument();
});
- const updatedRow = screen.getByText('Editable token').closest('tr');
- expect(
- within(updatedRow as HTMLTableRowElement).getByText('Monitoring & alerts (read)'),
- ).toBeInTheDocument();
- expect(
- within(updatedRow as HTMLTableRowElement).queryByText('Docker / Podman reporting'),
- ).not.toBeInTheDocument();
+ const updatedRow = getTokenTableRow('Editable token');
+ expect(within(updatedRow).getByText('Monitoring & alerts (read)')).toBeInTheDocument();
+ expect(within(updatedRow).queryByText('Docker / Podman reporting')).not.toBeInTheDocument();
});
it('requires at least one changed scope and keeps failed edits open', async () => {
@@ -609,11 +640,8 @@ describe('APITokenManager', () => {
render(() => <APITokenManager onTokensChanged={vi.fn()} canManage />);
- const tokenName = await screen.findByText('Protected token');
- const row = tokenName.closest('tr');
- fireEvent.click(
- within(row as HTMLTableRowElement).getByRole('button', { name: 'Edit scopes' }),
- );
+ const row = await findTokenTableRow('Protected token');
+ fireEvent.click(within(row).getByRole('button', { name: 'Edit scopes' }));
const dialog = await screen.findByRole('dialog', { name: 'Edit API token scopes' });
const save = within(dialog).getByRole('button', { name: 'Save scopes' });
@@ -676,14 +704,10 @@ describe('APITokenManager', () => {
render(() => <APITokenManager onTokensChanged={vi.fn()} canManage />);
- const runtimeName = await screen.findByText('Runtime token');
- const row = runtimeName.closest('tr');
- expect(row).toBeTruthy();
- expect(within(row as HTMLTableRowElement).getByText('PBS Main')).toBeInTheDocument();
+ const row = await findTokenTableRow('Runtime token');
+ expect(within(row).getByText('PBS Main')).toBeInTheDocument();
expect(
- within(row as HTMLTableRowElement).queryByText(
- 'backup server resource; status online; sources pbs',
- ),
+ within(row).queryByText('backup server resource; status online; sources pbs'),
).not.toBeInTheDocument();
});