Files
archie/ui/src/tasks/TaskRowActions.vue
T
sam 493eb43944 fix(ui/topbar): replace Jump to with a command palette, drop filler chrome (#1650)
* fix(ui/topbar): replace Jump to with a command palette, drop filler chrome

Jump to opens a shadcn-vue Command dialog that finds pages, tasks and
workflows by name. The connection indicator shows only when the stream is
lost, the dead documentation link is gone, and the profile menu label has
no stray whitespace.

* fix(ui): trim stray whitespace from template text and drop em dashes from copy

Element text that started or ended with a line break rendered with leading
and trailing spaces. Also removes the unused 'soon' nav state and the nav
group components no route reaches.

* fix(ui): drop the space a hidden spinner left before button text

* fix(ui/status): one dense Status page, full-width settings, problems-only apply status

Status drops its tabs and the duplicate health card; services list only
what is wrong. Settings pages use the full width, the resizable sidebar
handle is gone, and apply status shows only processes that have not
applied a change. PageHeader puts the title and actions on one line.

* refactor(ui): use shadcn ToggleGroup and Badge, drop SegmentedControl and StatusPill

Status badges show only when a state needs attention: no Running, Enabled,
Active, Listening or live pills next to healthy rows. Removes the unused
pagination, radio-group and scroll-area components.

* fix(ui/history): use the shadcn Table with fixed columns so nothing is clipped

* fix(ui/workflows): apply ?workflow= only once the workflow is listed

Selecting it before the definitions loaded opened an empty canvas.

* refactor(ui/workflows): use shadcn Input, NativeSelect, Checkbox and Button in editors

Replaces hand-rolled inputs, selects, the repository mode switch and icon
buttons in the workflow editor, bind dialog, harness page, sources panel
and review gate. Adds the upstream shadcn-vue NativeSelect.

* style(ui): rounded-rectangle controls instead of pills

Halves the radius scale so inputs, selects and buttons stop reading as
pills, and badges and chips lose their full rounding.

* fix(ui/alerts): centre the bell's failed state and stop it contradicting Needs you

* fix(ui/tasks): one header line, aligned columns, no placeholder issue numbers

Tasks puts its filters beside the title and drops the stat tiles the
dashboard already shows. Sort headers align with their cells, chat tasks
no longer show their synthetic issue number, and Logs and the task
not-found page use the shared header.

* fix(ui/dashboard): shared header and cards, empty cards stay silent

Needs you uses the shadcn Card and drops its duplicate Open button; quality
gates and token outlook render only when there is something to show; the
throughput strip moves into the dashboard, its only user.

* refactor(ui/stores): one Pinia store per feature

Splits the site-wide control-plane store and the module-level refs into
settings, workflows, tasks, events, org and session stores. Identity
requests move into lib/api. Drops store fields nothing read: per-resource
stream state, the states map and loadApplyStatus.

* fix(ui/org): one header for the org area, sections drop their repeated titles

The org name is the page title with the admin's org switcher and New org
beside it; Members and Workspaces tables sit in cards like other pages.

* fix(ui/events): shadcn Tabs for the capture, map and bind steps

Replaces the numbered step strip with line tabs that carry each step's
count; the Listening pill is gone and Capture off shows only when it is.

* fix(ui/workflows): confirm a workflow delete in an AlertDialog, not window.confirm

* style(ui/settings): denser setting rows
2026-10-12 04:40:21 +11:00

447 lines
15 KiB
Vue

<script setup lang="ts">
import { Ellipsis } from "@lucide/vue";
import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import { RadioGroupItem, RadioGroupRoot } from "reka-ui";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
import { actionFor, retryModes, type ActionMeta } from "@/lib/task-meta";
import type { Task } from "./TaskRow.vue";
import { shownActionIds } from "./task-actions";
import { reviewGateOffer } from "./review-gate";
import {
initialRetryChoice,
retryChoices,
retryPayload,
} from "./retry-mode";
/**
* The lifecycle controls for one task. A task offers whatever the server says
* it offers, so the decisions here are presentation only: which variant a
* control wears, whether it needs confirming, and how a refusal reads. A
* caller may narrow the list to the controls it has room for (`only`), and
* narrowing can only remove -- see task-actions.ts.
*/
/** A control with its forge target already resolved. */
interface Control {
id: string;
label: string;
kind: string;
confirm?: string;
href: string;
}
type ControlVariant = "default" | "ghost" | "destructive";
const props = defineProps<{
task: Task;
/** Render only these action ids, still only if the server offered them. */
only?: string[];
findings?: string[];
}>();
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
const router = useRouter();
const gate = computed(() => props.task.status === "waiting_human" ? reviewGateOffer(props.task.review_gate) : null);
// An empty selection means all findings to the server.
const approveDisabled = computed(() => !!gate.value && props.findings?.length === 0);
const inFlight = ref(false);
const error = ref<{ kind: ActionErrorKind; message: string } | null>(null);
// The dialog's open flag and the action it will run are two refs, not one:
// pressing the dialog's action closes it, and that close clears the open flag
// before the action's own handler reads it.
const confirming = ref<string | null>(null);
const confirmingId = ref<string | null>(null);
// A re-review carries instructions the plain confirm dialog cannot collect
// (docs/prds/pr-review-operator-response.md, Decision 1), and the server
// refuses a re-review without them, so it opens a dialog of its own.
const rereviewOpen = ref(false);
const rereviewId = ref<string | null>(null);
const instructions = ref("");
// A retry carries the operator's worktree mode (taskstate.RetryMode). The
// dialog opens on the task's persisted choice -- so a remediation retry keeps
// continuing its branch -- and the operator may pick the other mode. The
// chosen value travels in the action body and is persisted on the task.
const retryOpen = ref(false);
const retryId = ref<string | null>(null);
const retryMode = ref("");
const retryOptions = computed(() =>
retryChoices(retryModes(), props.task.branch),
);
const controls = computed<Control[]>(() =>
shownActionIds(props.task.actions, props.only)
.map((id) => actionFor(id))
.filter((meta): meta is ActionMeta => meta !== null)
.map((meta) => ({
...meta,
href: meta.kind === "link" ? forgeLink(meta.id) : "",
})),
);
//
// One primary plus overflow: a server-declared action list can hold seven
// controls and two forge links, and a row that shows all of them as buttons in
// one line is unreadable. So the first non-link control keeps a visible button
// of its own; every other non-link control folds behind a '···' menu that runs
// the identical request path, and the forge links stay inline after the
// primary because they navigate rather than act.
const nonLinkControls = computed<Control[]>(() =>
controls.value.filter((c) => c.kind !== "link"),
);
const primaryControl = computed<Control | null>(
() => nonLinkControls.value[0] ?? null,
);
const overflowControls = computed<Control[]>(() =>
nonLinkControls.value.slice(1),
);
const linkControls = computed<Control[]>(() =>
controls.value.filter((c) => c.kind === "link"),
);
const menuOpen = ref(false);
const confirmingMeta = computed(() =>
confirmingId.value ? actionFor(confirmingId.value) : null,
);
const confirmText = computed(() =>
confirmingMeta.value?.confirm
? confirmingMeta.value.confirm.replaceAll(
"{title}",
props.task.title || "this task",
)
: "",
);
const confirmLabel = computed(() => confirmingMeta.value?.label || "Confirm");
// A refused action ("you can't do that" -- bad input, a conflicting task state)
// is the operator's to correct; a broken one (5xx, network drop, timeout) is
// the daemon's, and says so. Authentication failures are surfaced by the app
// shell because they affect every request, not only this row.
const errorText = computed(() => {
if (!error.value) return "";
if (error.value.kind === "session-expired")
return "Dashboard authentication is required.";
if (error.value.kind === "refused")
return `${error.value.message}. You can't do that.`;
return `${error.value.message}. Try again, or check the daemon.`;
});
// A link control points at the forge artefact the action names. Chat-sourced
// work has no issue on a forge, and a task that never opened a pull request has
// no PR to point at, so the control is disabled rather than a dead link.
function forgeLink(id: string): string {
if (id === "open_pr") {
return props.task.pr_url && props.task.pr_number ? props.task.pr_url : "";
}
if (id === "open_issue") {
if (props.task.source === "chat" || !props.task.issue_number) return "";
return props.task.issue_url ?? "";
}
return "";
}
function variantFor(kind: string): ControlVariant {
if (kind === "quiet") return "ghost";
if (kind === "danger") return "destructive";
return "default";
}
// A control that names a consequence is confirmed first; the two that only open
// a forge page are not, because they change nothing. A re-review needs
// instructions, which its own dialog collects; a retry needs a worktree mode,
// which its own dialog collects.
function request(id: string) {
error.value = null;
if (id === "approve" && gate.value && props.findings === undefined) {
void router.push(`/tasks/${props.task.id}`);
return;
}
if (id === "rereview") {
rereviewId.value = id;
rereviewOpen.value = true;
return;
}
if (id === "retry") {
retryId.value = id;
retryMode.value = initialRetryChoice(
retryOptions.value,
props.task.retry_mode,
);
retryOpen.value = true;
return;
}
if (actionFor(id)?.confirm) {
confirmingId.value = id;
confirming.value = id;
return;
}
void run(id);
}
async function run(
id: string,
payload?: { instructions?: string; retry_mode?: string; findings?: string[] },
) {
if (id === "approve" && gate.value) {
if (!props.findings?.length) return;
payload = { ...payload, findings: props.findings };
}
confirming.value = null;
inFlight.value = true;
error.value = null;
try {
// The route path and the API both address a task by string; the list serves
// ids as numbers, so the row's own id is narrowed once, here.
await api.taskAction(String(props.task.id), id, payload);
emit("done", props.task.id);
} catch (err) {
error.value = classifyActionError(err);
} finally {
inFlight.value = false;
}
}
function onRereviewOpen(open: boolean) {
rereviewOpen.value = open;
if (!open) instructions.value = "";
}
function submitRereview() {
const id = rereviewId.value;
const text = instructions.value.trim();
if (!id || !text) return;
rereviewOpen.value = false;
void run(id, { instructions: text });
}
function onRetryOpen(open: boolean) {
retryOpen.value = open;
}
function submitRetry() {
const id = retryId.value;
if (!id || !retryMode.value) return;
retryOpen.value = false;
void run(id, retryPayload(retryMode.value));
}
function onConfirmationOpen(open: boolean) {
if (!open) confirming.value = null;
}
// A menu item must close its menu before the dialog can take focus, so both
// surfaces funnel through the same request() once the menu is down; the
// inFlight disabling and the error handling stay identical either way.
function requestFromMenu(id: string) {
menuOpen.value = false;
request(id);
}
</script>
<template>
<div class="flex flex-col items-end gap-1">
<Alert
v-if="error"
variant="destructive"
class="w-56 gap-0.5 px-2 py-1.5 text-xs whitespace-normal"
>
<AlertTitle v-if="error.kind === 'session-expired'" class="text-xs"
>Authentication required</AlertTitle
>
<AlertDescription class="text-xs">{{ errorText }}</AlertDescription>
</Alert>
<!--
One line, never wrapped: three controls on two lines doubled the height of
every actionable row. The one-primary-plus-overflow rule (see the script)
keeps the line short; keystrokes stop at this container rather than
bubbling to the row, which would open the task as well as press the
button.
-->
<div class="flex items-center gap-1" @keydown.stop>
<Button
v-if="primaryControl"
:variant="variantFor(primaryControl.kind)"
size="sm"
:disabled="inFlight || (primaryControl.id === 'approve' && approveDisabled)"
@click.stop="request(primaryControl.id)"
>
{{ primaryControl.label }}
</Button>
<template v-for="control in linkControls" :key="control.id">
<Button v-if="control.href" as-child variant="ghost" size="sm">
<a
:href="control.href"
target="_blank"
rel="noreferrer"
@click.stop
>{{ control.label }}</a
>
</Button>
<Button
v-else
variant="ghost"
size="sm"
disabled
:title="`${control.label} is unavailable`"
>
{{ control.label }}
</Button>
</template>
<DropdownMenu v-if="overflowControls.length" v-model:open="menuOpen">
<DropdownMenuTrigger as-child>
<Button
variant="ghost"
size="icon-sm"
aria-label="More actions"
:disabled="inFlight"
@click.stop
>
<Ellipsis :size="14" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
v-for="control in overflowControls"
:key="control.id"
:variant="control.kind === 'danger' ? 'destructive' : 'default'"
:disabled="inFlight || (control.id === 'approve' && approveDisabled)"
@click.stop="requestFromMenu(control.id)"
>
{{ control.label }}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<Dialog :open="rereviewOpen" @update:open="onRereviewOpen">
<DialogContent class="sm:max-w-lg">
<DialogHeader>
<DialogTitle>Re-review this pull request?</DialogTitle>
<DialogDescription>Two re-reviews allowed; this is the
{{ props.task.rereview_rounds ? "next" : "first" }}.</DialogDescription>
</DialogHeader>
<div class="flex flex-col gap-2">
<Label for="review-instructions"
>What should the reviewers focus on?</Label
>
<Textarea
id="review-instructions"
v-model="instructions"
class="min-h-24"
placeholder="e.g. check the migration ordering and the SQL path"
:disabled="inFlight"
/>
</div>
<DialogFooter>
<Button variant="ghost" :disabled="inFlight" @click="onRereviewOpen(false)">Keep waiting</Button>
<Button
:disabled="inFlight || !instructions.trim()"
@click="submitRereview"
>Re-review</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<!--
A retry opens this dialog rather than firing immediately: the operator
picks where the retry starts (taskstate.RetryMode), the choice rides the
action body and is persisted on the task, and the daemon's worktree
preparation reads it. Preselecting the task's persisted mode keeps a
remediation retry continuing its branch.
-->
<Dialog :open="retryOpen" @update:open="onRetryOpen">
<DialogContent class="sm:max-w-lg">
<DialogHeader>
<DialogTitle>Retry this task?</DialogTitle>
<DialogDescription>Choose where the retry starts.</DialogDescription>
</DialogHeader>
<RadioGroupRoot
v-model="retryMode"
class="grid grid-cols-1 gap-2"
aria-label="Retry worktree mode"
loop
>
<label
v-for="option in retryOptions"
:key="option.id"
class="flex items-start gap-3 rounded-md border border-border bg-card px-3 py-2.5 text-left transition-colors"
:class="
option.disabled
? 'cursor-not-allowed opacity-60'
: 'cursor-pointer hover:bg-secondary'
"
>
<RadioGroupItem
:value="option.id"
:disabled="option.disabled || inFlight"
class="mt-0.5 shrink-0"
/>
<span class="grid gap-0.5">
<span class="text-[13px] font-medium">{{ option.label }}</span>
<span class="text-xs text-fg-subtle">{{ option.description }}</span>
</span>
</label>
</RadioGroupRoot>
<DialogFooter>
<Button variant="ghost" :disabled="inFlight" @click="onRetryOpen(false)">Keep it parked</Button>
<Button :disabled="inFlight || !retryMode" @click="submitRetry">Retry</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<AlertDialog :open="confirming !== null" @update:open="onConfirmationOpen">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{{ confirmLabel }} this task?</AlertDialogTitle>
<AlertDialogDescription>{{ confirmText }}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Keep it</AlertDialogCancel>
<AlertDialogAction
:variant="variantFor(confirmingMeta?.kind ?? '')"
@click="confirmingId && run(confirmingId)"
>
{{ confirmLabel }}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</template>