feat(webui): Identities on the shared components

Replaces raw inputs, buttons and scoped CSS with the shared controls:
lifecycle as status pills, inline rename instead of a browser prompt, and
Retire behind a confirmation dialog.
This commit is contained in:
sam committed 2026-09-25 15:25:33 +10:00
1 parent e9d6c113a5
commit c2470698dd
3 files changed
+129 -126

No files matched your search

+116 -114
View File
@@ -1,139 +1,141 @@
<script setup lang="ts">
import { ref } from "vue";
import { Bot, KeyRound, Plus, ShieldCheck, User } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { StatusPill } from "@/components/ui/status-pill";
import { useIdentitiesStore, type Identity } from "@/stores/identities";
const store = useIdentitiesStore();
const name = ref("");
const kind = ref<Identity["kind"]>("bot");
store.watch();
const name = ref("");
const kind = ref<Identity["kind"]>("bot");
async function create(): Promise<void> {
if (await store.create(name.value, kind.value)) name.value = "";
if (await store.create(name.value.trim(), kind.value)) name.value = "";
}
async function rename(value: Identity): Promise<void> {
const next = window.prompt("Display name", value.display_name);
if (next && next !== value.display_name)
await store.command(value, "rename", next);
const renaming = ref<string | null>(null);
const draftName = ref("");
function startRename(value: Identity) {
renaming.value = value.id;
draftName.value = value.display_name;
}
async function retire(value: Identity): Promise<void> {
if (window.confirm(`Retire ${value.display_name}? This cannot be undone.`))
await store.command(value, "retire");
async function finishRename(value: Identity) {
// Enter and the blur that follows it both land here; only the first commits.
if (renaming.value !== value.id) return;
const next = draftName.value.trim();
renaming.value = null;
if (next && next !== value.display_name) await store.command(value, "rename", next);
}
const retiring = ref<Identity | null>(null);
async function retire() {
if (retiring.value) await store.command(retiring.value, "retire");
retiring.value = null;
}
const icons = { system: ShieldCheck, bot: Bot, service_account: KeyRound, user: User };
const lifecycle = {
active: { tone: "neutral", dot: "live" },
suspended: { tone: "warn", dot: "warn" },
retired: { tone: "neutral", dot: "idle" },
} as const;
</script>
<template>
<main class="page identities-page">
<div>
<PageHeader title="Identities" />
<p v-if="store.error" role="alert" class="error">{{ store.error }}</p>
<form class="identity-create" @submit.prevent="create">
<input
v-model.trim="name"
required
aria-label="Display name"
placeholder="Display name"
/>
<select v-model="kind" aria-label="Kind">
<option value="bot">Bot</option>
<option value="service_account">Service account</option>
<option value="user">User</option>
</select>
<button type="submit" :disabled="!name || !!store.busy">Create</button>
<p class="-mt-4 mb-8 text-sm text-fg-muted">The actors Archie acts as and on behalf of. Changes apply at once.</p>
<p v-if="store.error" role="alert" class="mb-4 text-sm text-danger">{{ store.error }}</p>
<form class="mb-6 flex flex-wrap gap-2" @submit.prevent="create">
<Input v-model="name" class="max-w-64" placeholder="Display name" aria-label="Display name" required />
<Select v-model="kind">
<SelectTrigger class="w-44" aria-label="Kind"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="bot">Bot</SelectItem>
<SelectItem value="service_account">Service account</SelectItem>
<SelectItem value="user">User</SelectItem>
</SelectContent>
</Select>
<Button type="submit" size="sm" :disabled="!name.trim() || !!store.busy"><Plus data-icon="inline-start" /> Create</Button>
</form>
<section aria-label="Identity list" class="identity-list">
<article
v-for="value in store.identities"
:key="value.id"
class="identity-row"
>
<div>
<strong>{{ value.display_name }}</strong
><span
>{{ value.kind.replace("_", " ") }} · {{ value.lifecycle }}</span
>
<ul class="divide-y divide-border rounded-lg border border-border bg-card" aria-label="Identities">
<li v-for="value in store.identities" :key="value.id" class="flex flex-wrap items-center gap-3 px-4 py-3">
<span class="grid size-8 shrink-0 place-items-center rounded-md bg-secondary text-muted-foreground">
<component :is="icons[value.kind]" class="size-4" aria-hidden="true" />
</span>
<div class="min-w-0 flex-1">
<Input
v-if="renaming === value.id"
v-model="draftName"
class="max-w-64"
aria-label="Display name"
autofocus
@keydown.enter="finishRename(value)"
@keydown.esc="renaming = null"
@blur="finishRename(value)"
/>
<p v-else class="truncate text-sm font-medium" :class="value.lifecycle === 'retired' && 'text-fg-subtle'">
{{ value.display_name }}
</p>
<p class="text-xs text-fg-subtle">{{ value.kind.replace("_", " ") }}</p>
</div>
<div v-if="value.kind !== 'system'" class="actions">
<button
:disabled="!!store.busy || value.lifecycle === 'retired'"
@click="rename(value)"
>
Rename
</button>
<button
<StatusPill :tone="lifecycle[value.lifecycle].tone" :dot="lifecycle[value.lifecycle].dot" class="capitalize">
{{ value.lifecycle }}
</StatusPill>
<div v-if="value.kind !== 'system' && value.lifecycle !== 'retired'" class="flex gap-1">
<Button variant="ghost" size="sm" :disabled="!!store.busy" @click="startRename(value)">Rename</Button>
<Button
v-if="value.lifecycle === 'active'"
variant="ghost"
size="sm"
:disabled="!!store.busy"
@click="store.command(value, 'suspend')"
>Suspend</Button
>
Suspend
</button>
<button
v-if="value.lifecycle === 'suspended'"
:disabled="!!store.busy"
@click="store.command(value, 'reactivate')"
<Button v-else variant="ghost" size="sm" :disabled="!!store.busy" @click="store.command(value, 'reactivate')"
>Reactivate</Button
>
Reactivate
</button>
<button
class="danger"
:disabled="!!store.busy || value.lifecycle === 'retired'"
@click="retire(value)"
>
Retire
</button>
<Button variant="ghost" size="sm" class="text-danger" :disabled="!!store.busy" @click="retiring = value">Retire</Button>
</div>
</article>
</section>
</main>
</template>
</li>
<li v-if="!store.identities.length" class="px-4 py-8 text-center text-sm text-fg-muted">No identities yet.</li>
</ul>
<style scoped>
.identities-page {
max-width: 960px;
}
.identity-create {
display: flex;
gap: 0.75rem;
margin: 1.5rem 0;
}
.identity-create input {
flex: 1;
}
.identity-create input,
.identity-create select,
.identity-create button,
.actions button {
border: 1px solid var(--border);
border-radius: 0.5rem;
background: var(--surface);
color: inherit;
padding: 0.6rem 0.8rem;
}
.identity-list {
border-top: 1px solid var(--border);
}
.identity-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1rem 0;
border-bottom: 1px solid var(--border);
}
.identity-row span {
display: block;
color: var(--muted-foreground);
font-size: 0.85rem;
margin-top: 0.2rem;
text-transform: capitalize;
}
.actions {
display: flex;
gap: 0.5rem;
}
.actions .danger {
color: var(--destructive);
}
.error {
color: var(--destructive);
}
</style>
<AlertDialog :open="!!retiring" @update:open="(open) => !open && (retiring = null)">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Retire {{ retiring?.display_name }}?</AlertDialogTitle>
<AlertDialogDescription>A retired identity cannot act again, and this cannot be undone.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction class="bg-destructive text-destructive-foreground" @click="retire">Retire</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</template>