feat(ui): use Archie components for activity and approvals
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 file changed
+126
-64
+126
-64
@@ -1,12 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { ArrowDownToLine, ArrowUpRight, ChevronDown, ClipboardCheck, Inbox, Radio, ShieldAlert } from "@lucide/vue";
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CardTitle } from "@/components/ui/card";
|
||||
import { Card, CardAction, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||
import { Empty, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Item, ItemActions, ItemContent, ItemMedia, ItemTitle } from "@/components/ui/item";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
@@ -33,6 +36,12 @@ const controller = new AbortController();
|
||||
let approvalRead = 0;
|
||||
let following = false;
|
||||
|
||||
const activityKinds = {
|
||||
notification: { icon: Radio, label: "Workflow update" },
|
||||
approval_request: { icon: ShieldAlert, label: "Approval requested" },
|
||||
approval_answer: { icon: ClipboardCheck, label: "Decision recorded" },
|
||||
} satisfies Record<Message["kind"], { icon: typeof Radio; label: string }>;
|
||||
|
||||
async function loadApprovals() {
|
||||
const read = ++approvalRead;
|
||||
try {
|
||||
@@ -69,6 +78,11 @@ function updateReadingPosition() {
|
||||
if (view) atLatest.value = view.scrollHeight - view.clientHeight - view.scrollTop <= 2;
|
||||
}
|
||||
|
||||
async function updateAfterDisclosure() {
|
||||
await nextTick();
|
||||
updateReadingPosition();
|
||||
}
|
||||
|
||||
function showLatest(focus = false) {
|
||||
const view = activity.value;
|
||||
if (!view) return;
|
||||
@@ -137,89 +151,137 @@ onBeforeUnmount(() => controller.abort());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-w-0">
|
||||
<div class="flex min-w-0 flex-col gap-4">
|
||||
<Spinner v-if="loading" />
|
||||
<ReadError v-else-if="error" :message="error" retry-label="Retry" @retry="load" />
|
||||
<template v-else>
|
||||
<Section v-if="approvals.length || approvalReadFailed" title="Action required">
|
||||
<Section v-if="approvals.length || approvalReadFailed" title="Action required" class="mb-0 ring-warn/40">
|
||||
<template #action>
|
||||
<Badge v-if="approvals.length" variant="secondary">{{ approvals.length }} pending</Badge>
|
||||
<Badge v-if="approvals.length" variant="warn" class="tabular-nums">
|
||||
{{ approvals.length }} awaiting approval
|
||||
</Badge>
|
||||
</template>
|
||||
<ReadError v-if="approvalReadFailed" message="Couldn't load pending approvals." retry-label="Retry" @retry="loadApprovals" />
|
||||
<ul v-else class="max-h-[24dvh] divide-y overflow-y-auto">
|
||||
<li v-for="request in approvals" :key="request.id" class="py-2 first:pt-0 last:pb-0">
|
||||
<details class="text-label">
|
||||
<summary class="cursor-pointer font-medium break-words">{{ request.action }}</summary>
|
||||
<p class="mt-2 whitespace-pre-wrap break-words">{{ request.summary }}</p>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-caption text-muted-foreground">
|
||||
<span>Respond by <Timestamp :at="request.step_deadline || request.deadline" absolute /></span>
|
||||
<RouterLink
|
||||
v-if="request.run_id && request.run_id !== '00000000-0000-0000-0000-000000000000'"
|
||||
:to="{ name: 'run', params: { id: request.run_id } }"
|
||||
:aria-label="`View run for ${request.action} (${request.run_id})`"
|
||||
class="underline"
|
||||
>View run</RouterLink>
|
||||
<ul v-else class="flex max-h-[24dvh] flex-col gap-2 overflow-y-auto p-1">
|
||||
<Item v-for="request in approvals" :key="request.id" as="li" variant="outline" class="items-start">
|
||||
<ItemMedia variant="icon" class="mt-1 text-warn">
|
||||
<ShieldAlert aria-hidden="true" />
|
||||
</ItemMedia>
|
||||
<Collapsible v-slot="{ open }" class="min-w-0 flex-1">
|
||||
<ItemTitle class="w-auto break-words">{{ request.action }}</ItemTitle>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<span class="text-caption text-muted-foreground">
|
||||
Respond by <Timestamp :at="request.step_deadline || request.deadline" absolute />
|
||||
</span>
|
||||
<CollapsibleTrigger as-child>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:aria-label="`${open ? 'Hide' : 'Review'} approval for ${request.action}`"
|
||||
>
|
||||
{{ open ? "Hide approval" : "Review approval" }}
|
||||
<ChevronDown :class="open && 'rotate-180'" aria-hidden="true" data-icon="inline-end" />
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
</div>
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
<Button size="sm" :disabled="answering !== null" @click="answer(request, true)">Approve</Button>
|
||||
<Button variant="outline" size="sm" :disabled="answering !== null" @click="answer(request, false)">Deny</Button>
|
||||
</div>
|
||||
</details>
|
||||
</li>
|
||||
<CollapsibleContent class="mt-3 border-t pt-3">
|
||||
<p class="whitespace-pre-wrap break-words leading-relaxed">{{ request.summary }}</p>
|
||||
<ItemActions class="mt-3 flex-wrap">
|
||||
<Button size="sm" :disabled="answering !== null" @click="answer(request, true)">Approve</Button>
|
||||
<Button variant="outline" size="sm" :disabled="answering !== null" @click="answer(request, false)">Deny</Button>
|
||||
<Button
|
||||
v-if="request.run_id && request.run_id !== '00000000-0000-0000-0000-000000000000'"
|
||||
variant="link"
|
||||
size="sm"
|
||||
as-child
|
||||
>
|
||||
<RouterLink
|
||||
:to="{ name: 'run', params: { id: request.run_id } }"
|
||||
:aria-label="`View run for ${request.action} (${request.run_id})`"
|
||||
>View run <ArrowUpRight aria-hidden="true" data-icon="inline-end" /></RouterLink>
|
||||
</Button>
|
||||
</ItemActions>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</Item>
|
||||
</ul>
|
||||
</Section>
|
||||
<div class="min-w-0">
|
||||
<div class="mb-2 flex min-h-8 flex-wrap items-center justify-between gap-2">
|
||||
<Card class="gap-0 pb-0">
|
||||
<CardHeader class="mb-3">
|
||||
<CardTitle id="composer-activity">Recent activity</CardTitle>
|
||||
<Button v-if="!atLatest && messages.length" size="sm" variant="outline" @click="showLatest(true)">Jump to latest</Button>
|
||||
</div>
|
||||
<CardDescription v-if="messages.length" id="composer-activity-scope">Earlier activity is not shown.</CardDescription>
|
||||
<CardAction v-if="!atLatest && messages.length">
|
||||
<Button size="sm" variant="outline" @click="showLatest(true)">
|
||||
<ArrowDownToLine aria-hidden="true" data-icon="inline-start" /> Jump to latest
|
||||
</Button>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<Empty v-if="messages.length === 0">
|
||||
<EmptyHeader><EmptyTitle>No messages yet</EmptyTitle></EmptyHeader>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant="icon"><Inbox aria-hidden="true" /></EmptyMedia>
|
||||
<EmptyTitle>No messages yet</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
<div
|
||||
v-else
|
||||
ref="activity"
|
||||
role="region"
|
||||
aria-labelledby="composer-activity"
|
||||
aria-describedby="composer-activity-scope"
|
||||
tabindex="0"
|
||||
class="max-h-[55dvh] overflow-y-auto rounded-lg border"
|
||||
class="max-h-[44dvh] overflow-y-auto border-t focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring sm:max-h-[55dvh]"
|
||||
@scroll.passive="updateReadingPosition"
|
||||
@toggle.capture="updateReadingPosition"
|
||||
>
|
||||
<ol class="divide-y">
|
||||
<li v-for="m in messages" :key="m.id" class="min-w-0 px-3 py-2">
|
||||
<div class="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<p class="min-w-0 flex-1 text-label font-medium break-words">{{ m.title }}</p>
|
||||
<Timestamp :at="m.created_at" class="text-caption text-muted-foreground" />
|
||||
<RouterLink
|
||||
v-if="m.run_id"
|
||||
:to="{ name: 'run', params: { id: m.run_id } }"
|
||||
:aria-label="`View run for ${m.title} (${m.run_id})`"
|
||||
class="text-caption text-muted-foreground underline"
|
||||
>View run</RouterLink>
|
||||
</div>
|
||||
<details v-if="m.body" class="mt-1 text-caption">
|
||||
<summary class="cursor-pointer text-muted-foreground">Details<span class="sr-only"> for {{ m.title }}</span></summary>
|
||||
<p class="mt-1 whitespace-pre-wrap break-words text-label">{{ m.body }}</p>
|
||||
</details>
|
||||
<details v-if="m.attempts?.length" class="mt-1 text-caption">
|
||||
<summary class="cursor-pointer text-muted-foreground">Delivery attempts</summary>
|
||||
<ul class="mt-1 flex flex-col gap-1">
|
||||
<li v-for="a in m.attempts" :key="`${a.channel}:${a.attempt}`" class="flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">{{ a.channel }}</span>
|
||||
<span class="text-muted-foreground">Attempt {{ a.attempt }}</span>
|
||||
<Badge :variant="a.ok ? 'secondary' : 'danger'">{{ a.ok ? "Delivered" : "Failed" }}</Badge>
|
||||
<span class="tabular-nums text-muted-foreground">{{ a.duration_ms }} ms</span>
|
||||
<Timestamp :at="a.at" />
|
||||
<span v-if="a.response" class="font-mono break-all">{{ a.response }}</span>
|
||||
<span v-if="a.error" class="text-destructive break-all">{{ a.error }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
<ol class="divide-y divide-border">
|
||||
<Item v-for="m in messages" :key="m.id" as="li" class="flex-nowrap items-start gap-3 rounded-none border-0 px-4 py-2">
|
||||
<ItemMedia variant="icon" class="mt-1 text-muted-foreground">
|
||||
<component :is="activityKinds[m.kind].icon" aria-hidden="true" />
|
||||
</ItemMedia>
|
||||
<ItemContent class="min-w-0">
|
||||
<div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
|
||||
<ItemTitle class="min-w-0 break-words">
|
||||
<span class="sr-only">{{ activityKinds[m.kind].label }}: </span>{{ m.title }}
|
||||
</ItemTitle>
|
||||
<Timestamp :at="m.created_at" class="text-caption text-muted-foreground" />
|
||||
</div>
|
||||
<Collapsible v-if="m.body || m.attempts?.length || m.run_id" v-slot="{ open }" @update:open="updateAfterDisclosure">
|
||||
<ItemActions class="-ml-2 flex-wrap">
|
||||
<CollapsibleTrigger v-if="m.body || m.attempts?.length" as-child>
|
||||
<Button variant="ghost" size="xs" :aria-label="`${open ? 'Hide' : 'View'} details for ${m.title}`">
|
||||
{{ open ? "Hide details" : "View details" }}
|
||||
<ChevronDown :class="open && 'rotate-180'" aria-hidden="true" data-icon="inline-end" />
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<Button v-if="m.run_id" variant="link" size="xs" as-child>
|
||||
<RouterLink
|
||||
:to="{ name: 'run', params: { id: m.run_id } }"
|
||||
:aria-label="`View run for ${m.title} (${m.run_id})`"
|
||||
>View run <ArrowUpRight aria-hidden="true" data-icon="inline-end" /></RouterLink>
|
||||
</Button>
|
||||
</ItemActions>
|
||||
<CollapsibleContent v-if="m.body || m.attempts?.length" class="mt-2 rounded-lg bg-muted/50 p-3">
|
||||
<p v-if="m.body" class="whitespace-pre-wrap break-words leading-relaxed">{{ m.body }}</p>
|
||||
<details v-if="m.attempts?.length" :class="m.body && 'mt-2'" class="text-caption" @toggle="updateReadingPosition">
|
||||
<summary class="cursor-pointer font-medium">Delivery attempts</summary>
|
||||
<ul class="mt-2 flex flex-col gap-2">
|
||||
<li v-for="a in m.attempts" :key="`${a.channel}:${a.attempt}`" class="flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">{{ a.channel }}</span>
|
||||
<span class="text-muted-foreground">Attempt {{ a.attempt }}</span>
|
||||
<Badge :variant="a.ok ? 'secondary' : 'danger'">{{ a.ok ? "Delivered" : "Failed" }}</Badge>
|
||||
<span class="tabular-nums text-muted-foreground">{{ a.duration_ms }} ms</span>
|
||||
<Timestamp :at="a.at" />
|
||||
<span v-if="a.response" class="font-mono break-all">{{ a.response }}</span>
|
||||
<span v-if="a.error" class="text-destructive break-all">{{ a.error }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</details>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</ItemContent>
|
||||
</Item>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user