feature: Surface Existing Unused APIs
CI / backend (push) Successful in 5m58s
CI / frontend (push) Failing after 1m15s

This commit is contained in:
2026-08-12 04:56:06 +08:00
parent 4085aaa549
commit 00f832aa73
19 changed files with 1453 additions and 17 deletions
@@ -0,0 +1,157 @@
<template>
<details
ref="root"
class="mt-2 group workstation-form-section !p-3"
data-testid="audit-trail-panel"
@toggle="onToggle"
>
<summary
class="text-sm font-medium text-primary-700 cursor-pointer hover:text-primary-800 list-none flex items-center gap-2"
>
<span
class="inline-flex h-5 w-5 items-center justify-center rounded border border-line text-xs text-ink-secondary group-open:rotate-90 transition-transform"
aria-hidden="true"
>
›
</span>
Audit trail
<span v-if="events.length > 0" class="text-ink-secondary font-normal">
({{ events.length }}{{ hasMore ? '+' : '' }} events)
</span>
</summary>
<div class="mt-3">
<p v-if="loading && events.length === 0" class="text-sm text-ink-secondary">
Loading events…
</p>
<p v-else-if="error" class="text-sm text-clinical-danger" role="alert">
{{ error }}
</p>
<p v-else-if="!loading && events.length === 0" class="text-sm text-ink-secondary">
No audit events for this batch yet.
</p>
<div v-else class="overflow-x-auto">
<table class="w-full min-w-[520px] text-sm">
<thead>
<tr class="border-b border-line text-left text-ink-secondary">
<th class="py-2 px-2 font-medium w-[28%]">Timestamp</th>
<th class="py-2 px-2 font-medium">Event</th>
<th class="py-2 px-2 font-medium w-[22%]">Actor</th>
<th class="py-2 px-2 font-medium w-[22%]">Details</th>
</tr>
</thead>
<tbody>
<tr
v-for="event in events"
:key="event.id"
class="border-b border-line last:border-0 align-top"
>
<td class="py-2 px-2 text-ink-secondary whitespace-nowrap">
{{ formatDateTime(event.occurredAt) }}
</td>
<td class="py-2 px-2">
<span class="font-medium text-ink-strong">
{{ formatEventType(event.eventType) }}
</span>
</td>
<td class="py-2 px-2 text-ink">
{{ event.actorFullName || event.actorUsername || '—' }}
</td>
<td class="py-2 px-2 text-ink-secondary text-xs">
{{ summarizePayload(event.metadataJson) }}
</td>
</tr>
</tbody>
</table>
</div>
<button
v-if="hasMore"
type="button"
class="mt-3 text-sm font-medium text-primary-700 hover:text-primary-800 disabled:opacity-50"
:disabled="loading"
data-testid="audit-trail-load-more"
@click="loadMore"
>
{{ loading ? 'Loading…' : 'Load more' }}
</button>
</div>
</details>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useBatchStore } from '../stores/batches'
const props = defineProps<{
batchId: string
}>()
const batchStore = useBatchStore()
const { events, eventsLoading: loading, eventsError: error, eventsHasMore: hasMore } =
storeToRefs(batchStore)
const root = ref<HTMLDetailsElement | null>(null)
let loadedForBatchId: string | null = null
watch(
() => props.batchId,
async (id) => {
loadedForBatchId = null
batchStore.clearEvents()
if (root.value?.open) {
loadedForBatchId = id
await batchStore.fetchEvents(id)
}
}
)
async function onToggle(e: Event) {
const el = e.currentTarget as HTMLDetailsElement
if (!el.open) return
if (loadedForBatchId === props.batchId) return
loadedForBatchId = props.batchId
await batchStore.fetchEvents(props.batchId)
}
async function loadMore() {
await batchStore.fetchEvents(props.batchId, batchStore.eventsNextCursor ?? undefined)
}
function formatEventType(type: string): string {
return type
.replace(/_/g, ' ')
.replace(/\b\w/g, (c) => c.toUpperCase())
}
function formatDateTime(iso: string): string {
try {
return new Date(iso).toLocaleString()
} catch {
return iso
}
}
function summarizePayload(metadataJson: string | null): string {
if (!metadataJson) return '—'
try {
const meta = JSON.parse(metadataJson) as Record<string, unknown>
const parts: string[] = []
const prev = meta.previousStatus ?? meta.previous_status ?? meta.fromStatus
const next = meta.newStatus ?? meta.new_status ?? meta.toStatus ?? meta.status
if (typeof prev === 'string' && typeof next === 'string') {
parts.push(`${prev} → ${next}`)
} else if (typeof next === 'string') {
parts.push(String(next))
}
const reason = meta.reason ?? meta.rejectionReason
if (typeof reason === 'string' && reason.trim()) {
parts.push(reason.trim().length > 80 ? `${reason.trim().slice(0, 80)}…` : reason.trim())
}
return parts.length > 0 ? parts.join(' · ') : '—'
} catch {
return '—'
}
}
</script>