The list has a filter and a right-click menu, an error column and fixed widths. The run page merges its details and where the run came from, and leaves out sections that have nothing in them.
69 lines
2.9 KiB
Vue
69 lines
2.9 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { RouterLink } from "vue-router";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { ReadError } from "@/components/ui/read-error";
|
|
import { Section } from "@/components/ui/section";
|
|
import { Timestamp } from "@/components/ui/timestamp";
|
|
import { errors } from "@/copy/errors";
|
|
import { api, describeError } from "@/lib/api";
|
|
import { usePoll, useRead } from "@/lib/use-read";
|
|
import { answerApproval } from "@/runs/answer";
|
|
import { stateLabel } from "./state";
|
|
import { useLiveResource } from "@/stores/session";
|
|
|
|
/** Waiting approvals are a filter on runs: each asks a person to allow one
|
|
* action a run wants to take. With `run`, only that run's. */
|
|
const props = defineProps<{ run?: string }>();
|
|
const emit = defineEmits<{ answered: [] }>();
|
|
|
|
const { data, error, reload } = useRead(() => api.approvals());
|
|
onMounted(reload);
|
|
useLiveResource(null, () => void reload());
|
|
usePoll(reload);
|
|
|
|
const waiting = computed(() =>
|
|
(data.value ?? []).filter((a) => a.state === "pending" && (!props.run || a.run_id === props.run)),
|
|
);
|
|
const busy = ref("");
|
|
const answerError = ref("");
|
|
async function answer(id: string, approved: boolean): Promise<void> {
|
|
busy.value = id;
|
|
answerError.value = "";
|
|
try {
|
|
await answerApproval(id, approved);
|
|
emit("answered");
|
|
} catch (cause) {
|
|
answerError.value = describeError(cause, errors.common.unknown);
|
|
} finally {
|
|
busy.value = "";
|
|
await reload();
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="reload" />
|
|
<Section v-else-if="waiting.length" title="Waiting for approval">
|
|
<p v-if="answerError" role="alert" class="mb-2 text-caption text-danger">{{ answerError }}</p>
|
|
<ul class="divide-y divide-border">
|
|
<li v-for="approval in waiting" :key="approval.id" class="flex flex-wrap items-center gap-x-3 gap-y-1 py-2">
|
|
<div class="min-w-0 flex-1">
|
|
<p class="text-label">{{ approval.summary || approval.action }}</p>
|
|
<p class="text-caption text-fg-muted">
|
|
<span class="font-mono">{{ approval.action }}</span>
|
|
<template v-if="approval.target"> on <span class="font-mono">{{ approval.target }}</span></template>
|
|
<template v-if="!run"> · <RouterLink class="underline" :to="`/runs/${approval.run_id}`">run</RouterLink></template>
|
|
<template v-if="approval.deadline"> · due <Timestamp :at="approval.deadline" /></template>
|
|
</p>
|
|
</div>
|
|
<Badge variant="outline">{{ stateLabel(approval.level) }}</Badge>
|
|
<Button size="sm" variant="outline" :disabled="busy === approval.id" @click="answer(approval.id, false)">Deny</Button>
|
|
<Button size="sm" :disabled="busy === approval.id" @click="answer(approval.id, true)">Approve</Button>
|
|
</li>
|
|
</ul>
|
|
</Section>
|
|
</template>
|