Files
archie/ui/src/tasks/TaskApproval.vue
T

58 lines
2.2 KiB
Vue

<script setup lang="ts">
import { computed, ref } from "vue";
import { ChevronDown } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Section } from "@/components/ui/section";
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
import type { TaskRecord } from "./task-run";
import type { Task } from "./task";
import TaskRowActions from "./TaskRowActions.vue";
/**
* The decision a task waiting on a plan asks for: the plan, and the two
* answers beside it. A long plan is held to a readable height until opened,
* so the decision stays in reach.
*/
const props = defineProps<{ task: TaskRecord }>();
const emit = defineEmits<{ done: [] }>();
const plan = computed(() => props.task.plan?.trim() ?? "");
// A plan's own heading names what is being decided; the card shows it once.
const heading = computed(() => plan.value.match(/^#{1,3}\s+(.+)$/m)?.[1]?.replace(/[`*_]/g, "").trim() ?? "");
const body = computed(() =>
heading.value ? plan.value.replace(/^#{1,3}\s+.+$/m, "").trim() : plan.value,
);
const open = ref(false);
// A plan short enough to read whole is never folded.
const long = computed(() => body.value.length > 1200);
</script>
<template>
<Section
title="Approve the plan"
:description="heading || undefined"
class="mt-4 mb-0 max-w-3xl ring-1 ring-warn/40"
>
<template #action>
<div class="flex items-center gap-2">
<TaskRowActions :task="task as Task" :only="['reject']" @done="emit('done')" />
<TaskRowActions :task="task as Task" :only="['approve']" @done="emit('done')" />
</div>
</template>
<div class="relative">
<div :class="['overflow-hidden text-sm leading-relaxed', long && !open && 'max-h-96']">
<ChatMarkdown :text="body" />
</div>
<div
v-if="long && !open"
class="pointer-events-none absolute inset-x-0 bottom-0 h-20 bg-gradient-to-t from-card to-transparent"
/>
</div>
<Button v-if="long" variant="ghost" size="sm" class="mt-2" :aria-expanded="open" @click="open = !open">
{{ open ? "Collapse plan" : "Read the full plan" }}
<ChevronDown :class="['size-4 transition-transform motion-reduce:transition-none', open && 'rotate-180']" />
</Button>
</Section>
</template>