mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-10 21:18:56 +00:00
e37403edf1
Frontend design remediation, Phase 1 (Foundation Primitives + Toast).
Builds the six reusable UI primitives every later phase consumes;
migrates the audit-enumerated destructive-action callsites; humanises
the StatusBadge wire keys; and wraps the bulk-action bar in a
Transition with a post-action toast affordance.
Six new primitives + their .test.tsx siblings
=============================================
web/src/components/Toaster.tsx — Sonner wrapper, mounted
once at the root next to
QueryClientProvider. Pages
import { toast } from
"sonner" directly.
web/src/components/ConfirmDialog.tsx — Headless UI Dialog primitive
with optional typed-
confirmation friction for
the most-irreversible actions
(archive-certificate uses
typedConfirmation="archive").
web/src/components/Tooltip.tsx — Floating-UI tooltip with
hover + focus triggers,
aria-describedby wiring,
ESC-to-dismiss. Migrations
of the 103 native title=
sites stay in subsequent
per-page PRs per the audit
prompt's explicit "DO NOT"
on one-mega-PR sweeps.
web/src/components/EmptyState.tsx — Empty-state primitive with
optional icon / title /
description / primary +
secondary CTAs. DataTable
adds a new emptyState slot
(legacy emptyMessage string
prop preserved for backward
compat).
web/src/components/Combobox.tsx — Headless UI typeahead-
select primitive. Migrations
of the 53 native <select>
sites stay in subsequent
per-page PRs.
web/src/components/Banner.tsx — Severity-variant alert
banner with role="alert" on
error/warning, role="status"
on success/info. Migrating
the ~102 inline
bg-(red|amber|yellow)-50
sites stays as page-touch
rolling work.
Each primitive ships with a sibling .test.tsx asserting the
behavioural contract — render at rest, fire callbacks, ARIA wiring,
keyboard nav, variant styling. Total new test count: 109 assertions
across 7 files (6 primitives + extended StatusBadge).
UX-H5 closure — StatusBadge display strings
============================================
web/src/components/StatusBadge.tsx gets a statusDisplay map paired
with the existing statusStyles map. Wire keys stay byte-identical
to the Go enums per the D-1 closure comment block — only the
rendered text changes. PascalCase + snake_case + lowercase enums
now render as spaced sentence-case:
"RenewalInProgress" → "Renewal in progress"
"AwaitingCSR" → "Awaiting CSR"
"cert_mismatch" → "Certificate mismatch"
"dead" → "Dead-lettered"
Unmapped keys flow through a titleCase() helper that humanises
PascalCase / snake_case to lower-bound readability.
StatusBadge.test.tsx extends to 75 assertions: 38 D-1 + 5 dead-key
+ 31 UX-H5 display-string + 5 titleCase + 1 parity. All wire-keys
pinned byte-exact.
UX-H2 closure — window.confirm sites migrated to ConfirmDialog
==============================================================
Audit said 8 destructive-action sites. Live count was 24 across
17 files — the audit missed 11 files (auth/SessionsPage,
auth/UsersPage, auth/GroupMappingsPage, auth/OIDCProvidersPage,
auth/OIDCProviderDetailPage, auth/RolesPage, TeamsPage,
PoliciesPage, IssuersPage, ProfilesPage, RenewalPoliciesPage).
Phase 1 migrates the 7 audit-enumerated destructive sites in the
6 priority files:
- CertificateDetailPage archive (typedConfirmation="archive" —
most-irreversible action gets the
strongest friction)
- OwnersPage delete owner
- TargetsPage delete target
- AgentGroupsPage delete agent group
- auth/KeysPage revoke role grant
- auth/RoleDetailPage delete role
The remaining 11 confirm sites in audit-missed files stay open
and ship as a Phase 1 follow-up (mechanical pattern repeat — same
Edit shape × ~11 files).
UX-H3 closure — alert() → toast.error, top mutations wired
===========================================================
All 5 alert() sites migrated to toast.error:
- OwnersPage / CertificateDetailPage × 2 / TeamsPage /
RenewalPoliciesPage
Eight high-traffic mutations now fire toast.success on resolve +
toast.error on failure: deleteOwner, deleteTarget, deleteAgentGroup,
deleteTeam, deleteRenewalPolicy, archiveCertificate,
authRevokeKeyRole, authDeleteRole. The bulk-renew flow on
CertificatesPage gets a toast with a "View N jobs" action button
that deep-links to /jobs?certificate_ids=… (paired UX-L5 work).
Toaster mounted at web/src/main.tsx next to QueryClientProvider —
single import discipline. Sonner asserts at runtime if multiple
toasters are mounted; centralising the position + duration config
in Toaster.tsx avoids the mistake.
UX-M3 closure — DataTable empty-state slot
==========================================
web/src/components/DataTable.tsx gains an optional emptyState
ReactNode prop. The existing emptyMessage string prop is
preserved for backward compat — every ~18 list-page call site
that passes emptyMessage="…" keeps working unchanged. New CTAs:
pages pass <EmptyState ... /> for first-run experiences. Wiring
EmptyState on the top-5 list pages (Certificates, Issuers,
Targets, Owners, Agents) is per-page rolling work — primitive
+ slot ship in Phase 1; CTAs follow.
UX-L5 closure — Bulk-action bar transition + post-action toast
==============================================================
web/src/pages/CertificatesPage.tsx wraps the bulk-action bar
conditional render in Headless UI <Transition>. Slide-in/out
(200ms enter, 150ms leave, -translate-y-2 → 0). The
prefers-reduced-motion respect comes for free from the global
@media block landed in Phase 0.
Post-renewal toast.success fires with an action button "View N
jobs" that navigate()s to /jobs filtered to the certificate_ids
we just renewed. Closes the audit's "what just happened" gap.
Audit-accuracy callouts
=======================
* UX-H2 undercount — live 24 sites vs audit's 8. Phase 1 closes
the 7 audit-enumerated destructive confirms across 6 priority
files. The remaining 11 sites in audit-missed files stay open
for follow-up.
* UX-M2 title= count — live 103 (matches audit). Tooltip
primitive built; per-page migrations explicitly deferred per
the prompt's "DO NOT" sweep rule.
* UX-M4 native <select> sites — Combobox primitive built;
callsite migrations deferred to per-page rolling PRs.
* FE-M4 inline bg-(red|amber|yellow)-50 — Banner primitive
built; callsite migrations deferred to page-touch work.
Verification
============
$ npx tsc --noEmit
(exit 0, no type errors)
$ npx vitest run src/components/{Toaster,ConfirmDialog,EmptyState,Banner,Tooltip,Combobox}.test.tsx src/components/StatusBadge.test.tsx
Test Files 7 passed (7)
Tests 109 passed (109)
$ npx vitest run src/pages/{OwnersPage,AgentGroupsPage,TargetsPage,CertificatesPage,CertificateDetailPage,TeamsPage,RenewalPoliciesPage}.test.tsx src/pages/auth/{KeysPage,RoleDetailPage}.test.tsx
Test Files 9 passed (9)
Tests 52 passed (52)
(TargetsPage.test.tsx updated — the existing Delete confirm
test stubbed window.confirm; new test clicks the dialog's
destructive Delete button.)
$ npx vite build
✓ built in 2.89s
dist/assets/index-DZ1ZcRdP.js 1,110.61 kB (was 1,028.66 kB)
+82 KB / +26 KB gzipped from sonner + @headlessui + @floating-ui.
Bundle code-splitting is a separate phase (FE-M5).
Residual risks + follow-ups
============================
* 11 remaining window.confirm sites in audit-missed files. Phase 1
follow-up commit will sweep them with the same ConfirmDialog
pattern — mechanical work.
* The discard-unsaved-changes confirm in EditRoleModal (and 2
sibling modal sub-components) stays as window.confirm; treated
as a UX safety guardrail rather than a destructive-action
confirmation. Migrating to ConfirmDialog is fine but not
audit-priority.
* Tooltip + Combobox + Banner callsite migrations are explicit
per-page rolling work for subsequent phases — primitives
landed; per the audit prompt's "DO NOT" rule the migrations
don't sweep here.
* Optimistic-update wiring on the 5 priority mutations
(mark-notification-read, dismiss-discovery, archive-cert,
claim-discovered-cert, role-assignment) is staged for Phase 2
TQ-M3 per the prompt's explicit "DO NOT add new mutations to
the optimistic-update list beyond the 5 priority ones".
266 lines
9.3 KiB
TypeScript
266 lines
9.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { toast } from 'sonner';
|
|
import { useTrackedMutation } from '../hooks/useTrackedMutation';
|
|
import { getTeams, deleteTeam, createTeam, updateTeam } from '../api/client';
|
|
import PageHeader from '../components/PageHeader';
|
|
import DataTable from '../components/DataTable';
|
|
import type { Column } from '../components/DataTable';
|
|
import ErrorState from '../components/ErrorState';
|
|
import { formatDateTime } from '../api/utils';
|
|
import type { Team } from '../api/types';
|
|
|
|
interface CreateTeamModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onSuccess: () => void;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
}
|
|
|
|
function CreateTeamModal({ isOpen, onClose, onSuccess, isLoading, error }: CreateTeamModalProps) {
|
|
const [name, setName] = useState('');
|
|
const [description, setDescription] = useState('');
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!name.trim()) return;
|
|
await createTeam({
|
|
name: name.trim(),
|
|
description: description.trim(),
|
|
});
|
|
setName('');
|
|
setDescription('');
|
|
onSuccess();
|
|
};
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={onClose}>
|
|
<div className="bg-surface border border-surface-border rounded p-5 w-full max-w-md shadow-xl" onClick={e => e.stopPropagation()}>
|
|
<h2 className="text-lg font-semibold text-ink mb-4">Create Team</h2>
|
|
{error && <div className="mb-4 p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700">{error}</div>}
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-ink mb-1">Name *</label>
|
|
<input
|
|
value={name}
|
|
onChange={e => setName(e.target.value)}
|
|
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400"
|
|
placeholder="e.g., Platform Team"
|
|
required
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-ink mb-1">Description</label>
|
|
<textarea
|
|
value={description}
|
|
onChange={e => setDescription(e.target.value)}
|
|
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400"
|
|
placeholder="Optional team description"
|
|
rows={2}
|
|
/>
|
|
</div>
|
|
<div className="flex gap-2 pt-4">
|
|
<button
|
|
type="submit"
|
|
disabled={isLoading}
|
|
className="flex-1 btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
{isLoading ? 'Creating...' : 'Create Team'}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="flex-1 btn btn-ghost"
|
|
>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// EditTeamModal — B-1 master closure (cat-b-31ceb6aaa9f1). Mirrors
|
|
// CreateTeamModal; pre-populates from the editing team; calls
|
|
// updateTeam(id, fields) to close the destructive-rename hazard.
|
|
interface EditTeamModalProps {
|
|
team: Team | null;
|
|
onClose: () => void;
|
|
onSuccess: () => void;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
}
|
|
|
|
function EditTeamModal({ team, onClose, onSuccess, isLoading, error }: EditTeamModalProps) {
|
|
const [name, setName] = useState('');
|
|
const [description, setDescription] = useState('');
|
|
|
|
useEffect(() => {
|
|
if (team) {
|
|
setName(team.name);
|
|
setDescription(team.description || '');
|
|
}
|
|
}, [team]);
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!team || !name.trim()) return;
|
|
await updateTeam(team.id, { name: name.trim(), description: description.trim() });
|
|
onSuccess();
|
|
};
|
|
|
|
if (!team) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={onClose}>
|
|
<div className="bg-surface border border-surface-border rounded p-5 w-full max-w-md shadow-xl" onClick={e => e.stopPropagation()}>
|
|
<h2 className="text-lg font-semibold text-ink mb-4">Edit Team</h2>
|
|
<p className="text-xs text-ink-muted mb-4 font-mono">{team.id}</p>
|
|
{error && <div className="mb-4 p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700">{error}</div>}
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-ink mb-1">Name *</label>
|
|
<input value={name} onChange={e => setName(e.target.value)} required
|
|
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400" />
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-ink mb-1">Description</label>
|
|
<textarea value={description} onChange={e => setDescription(e.target.value)} rows={2}
|
|
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400" />
|
|
</div>
|
|
<div className="flex gap-2 pt-4">
|
|
<button type="submit" disabled={isLoading} className="flex-1 btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed">
|
|
{isLoading ? 'Saving...' : 'Save Changes'}
|
|
</button>
|
|
<button type="button" onClick={onClose} className="flex-1 btn btn-ghost">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function TeamsPage() {
|
|
const queryClient = useQueryClient();
|
|
const [showCreate, setShowCreate] = useState(false);
|
|
const [editingTeam, setEditingTeam] = useState<Team | null>(null);
|
|
|
|
const { data, isLoading, error, refetch } = useQuery({
|
|
queryKey: ['teams'],
|
|
queryFn: () => getTeams(),
|
|
});
|
|
|
|
const deleteMutation = useTrackedMutation({
|
|
mutationFn: deleteTeam,
|
|
invalidates: [['teams']],
|
|
onSuccess: () => toast.success('Team deleted'),
|
|
onError: (err: Error) => toast.error(`Delete failed: ${err.message}`),
|
|
});
|
|
|
|
const createMutation = useTrackedMutation({
|
|
mutationFn: createTeam,
|
|
invalidates: [['teams']],
|
|
onSuccess: () => {
|
|
setShowCreate(false);
|
|
},
|
|
});
|
|
|
|
const updateMutation = useTrackedMutation({
|
|
mutationFn: ({ id, data }: { id: string; data: Partial<Team> }) => updateTeam(id, data),
|
|
invalidates: [['teams']],
|
|
onSuccess: () => {
|
|
setEditingTeam(null);
|
|
},
|
|
});
|
|
|
|
const columns: Column<Team>[] = [
|
|
{
|
|
key: 'name',
|
|
label: 'Team',
|
|
render: (t) => (
|
|
<div>
|
|
<div className="font-medium text-ink">{t.name}</div>
|
|
<div className="text-xs text-ink-faint font-mono">{t.id}</div>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
key: 'description',
|
|
label: 'Description',
|
|
render: (t) => (
|
|
<span className="text-ink text-sm max-w-sm truncate block">{t.description || '\u2014'}</span>
|
|
),
|
|
},
|
|
{
|
|
key: 'created',
|
|
label: 'Created',
|
|
render: (t) => <span className="text-xs text-ink-muted">{formatDateTime(t.created_at)}</span>,
|
|
},
|
|
{
|
|
key: 'actions',
|
|
label: '',
|
|
render: (t) => (
|
|
<div className="flex gap-3 justify-end">
|
|
<button
|
|
onClick={(e) => { e.stopPropagation(); setEditingTeam(t); }}
|
|
className="text-xs text-brand-400 hover:text-brand-500 transition-colors"
|
|
>
|
|
Edit
|
|
</button>
|
|
<button
|
|
onClick={(e) => { e.stopPropagation(); if (confirm(`Delete team ${t.name}?`)) deleteMutation.mutate(t.id); }}
|
|
className="text-xs text-red-600 hover:text-red-700 transition-colors"
|
|
>
|
|
Delete
|
|
</button>
|
|
</div>
|
|
),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title="Teams"
|
|
subtitle={data ? `${data.total} teams` : undefined}
|
|
action={
|
|
<button onClick={() => setShowCreate(true)} className="btn btn-primary">
|
|
+ New Team
|
|
</button>
|
|
}
|
|
/>
|
|
<div className="flex-1 overflow-y-auto">
|
|
{error ? (
|
|
<ErrorState error={error as Error} onRetry={() => refetch()} />
|
|
) : (
|
|
<DataTable columns={columns} data={data?.data || []} isLoading={isLoading} emptyMessage="No teams configured" />
|
|
)}
|
|
</div>
|
|
<CreateTeamModal
|
|
isOpen={showCreate}
|
|
onClose={() => setShowCreate(false)}
|
|
onSuccess={() => {
|
|
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
setShowCreate(false);
|
|
}}
|
|
isLoading={createMutation.isPending}
|
|
error={createMutation.error ? (createMutation.error as Error).message : null}
|
|
/>
|
|
<EditTeamModal
|
|
team={editingTeam}
|
|
onClose={() => setEditingTeam(null)}
|
|
onSuccess={() => {
|
|
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
setEditingTeam(null);
|
|
}}
|
|
isLoading={updateMutation.isPending}
|
|
error={updateMutation.error ? (updateMutation.error as Error).message : null}
|
|
/>
|
|
</>
|
|
);
|
|
}
|