Label to workflow rules and a default workflow are the intake-routes resource: ordered, case-insensitive, first rule wins, seeded with bug to tdd, feature to feasibility, default triage. A write naming an undefined workflow or an empty label is refused. The daemon reads it through the workflow definitions client when pinning a task and at intake. The kind indirection only carried this routing, so it is removed: the per-kind NATS subjects (every consumer already bound archie.task.>) are one subject, the envelope and playbook triggers lose their kind, and x-intake-routes is dropped. The dashboard gets an Issue routing page under Automation; the trigger card reads the same setting.
120 lines
4.9 KiB
Vue
120 lines
4.9 KiB
Vue
<script setup lang="ts">
|
|
import { ArrowDown, ArrowUp, Trash2 } from "@lucide/vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import OptionSelect from "@/components/OptionSelect.vue";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Section } from "@/components/ui/section";
|
|
import { SettingRow } from "@/components/ui/setting-row";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import { useWorkflowsStore } from "@/stores/workflows";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
import KindGate from "./KindGate.vue";
|
|
|
|
const KIND = "intake-routes";
|
|
|
|
interface IntakeRoutes {
|
|
rules: { label: string; workflow: string }[];
|
|
default: string;
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
const workflows = useWorkflowsStore();
|
|
onMounted(store.load);
|
|
|
|
const form = computed(() => store.formFor(KIND));
|
|
const routes = computed(() => store.draftValue(KIND) as IntakeRoutes | undefined);
|
|
const rules = computed(() => routes.value?.rules ?? []);
|
|
const error = computed(() => store.catalogError || store.pageErrorFor(KIND));
|
|
const options = computed(() => workflows.collection.definitions.map(({ id }) => ({ value: id, label: id })));
|
|
|
|
const label = ref("");
|
|
const workflow = ref("");
|
|
const canAdd = computed(() => label.value.trim() !== "" && workflow.value !== "");
|
|
|
|
function edit(next: Partial<IntakeRoutes>) {
|
|
if (routes.value) store.setDraftValue(KIND, { ...routes.value, ...next });
|
|
}
|
|
function add() {
|
|
if (!canAdd.value) return;
|
|
edit({ rules: [...rules.value, { label: label.value.trim(), workflow: workflow.value }] });
|
|
label.value = "";
|
|
}
|
|
function remove(index: number) {
|
|
edit({ rules: rules.value.filter((_, i) => i !== index) });
|
|
}
|
|
function move(index: number, by: -1 | 1) {
|
|
const next = [...rules.value];
|
|
const [rule] = next.splice(index, 1);
|
|
next.splice(index + by, 0, rule!);
|
|
edit({ rules: next });
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Issue routing"><HistoryLink :kinds="[KIND]" /></PageHeader>
|
|
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
|
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
|
|
|
<KindGate v-if="!form" :kind="KIND" />
|
|
<template v-else>
|
|
<Section title="Rules">
|
|
<form class="mb-4 flex flex-wrap items-center gap-2" @submit.prevent="add">
|
|
<Input v-model="label" aria-label="Label" placeholder="Label" class="max-w-48 font-mono" />
|
|
<OptionSelect v-model="workflow" :options="options" aria-label="Workflow" placeholder="Workflow" class="w-44" />
|
|
<Button type="submit" :disabled="!canAdd">Add rule</Button>
|
|
</form>
|
|
<Empty v-if="!rules.length"><EmptyHeader><EmptyTitle>No rules</EmptyTitle></EmptyHeader></Empty>
|
|
<ol v-else class="divide-y divide-border border-y border-border">
|
|
<li v-for="(_, i) in rules" :key="i" class="flex flex-wrap items-center gap-2 py-2">
|
|
<form.Field v-slot="{ field }" :name="`rules[${i}].label`">
|
|
<Input
|
|
:model-value="field.state.value"
|
|
:aria-label="`Label of rule ${i + 1}`"
|
|
class="max-w-48 font-mono"
|
|
@blur="field.handleBlur"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
</form.Field>
|
|
<form.Field v-slot="{ field }" :name="`rules[${i}].workflow`">
|
|
<OptionSelect
|
|
:model-value="field.state.value"
|
|
:options="options"
|
|
:aria-label="`Workflow of rule ${i + 1}`"
|
|
class="w-44"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
</form.Field>
|
|
<div class="ml-auto flex items-center">
|
|
<Button variant="ghost" size="icon" :disabled="i === 0" :aria-label="`Move rule ${i + 1} up`" @click="move(i, -1)"><ArrowUp /></Button>
|
|
<Button variant="ghost" size="icon" :disabled="i === rules.length - 1" :aria-label="`Move rule ${i + 1} down`" @click="move(i, 1)"><ArrowDown /></Button>
|
|
<Button variant="ghost" size="icon" :aria-label="`Remove rule ${i + 1}`" @click="remove(i)"><Trash2 /></Button>
|
|
</div>
|
|
</li>
|
|
</ol>
|
|
</Section>
|
|
|
|
<Section title="Default">
|
|
<SettingRow label="Default workflow" for="routing-default" class="border-t-0 py-0">
|
|
<form.Field v-slot="{ field }" name="default">
|
|
<OptionSelect
|
|
id="routing-default"
|
|
:model-value="field.state.value"
|
|
:options="options"
|
|
aria-label="Default workflow"
|
|
class="w-44"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
</form.Field>
|
|
</SettingRow>
|
|
</Section>
|
|
</template>
|
|
</div>
|
|
</template>
|