feat(ui): workflow canvas cards expand in place instead of side panels
This commit is contained in:
21 files changed
+691
-610
No files matched your search
@@ -2,63 +2,28 @@
|
||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
|
||||
import { computed, ref, onMounted } from "vue";
|
||||
import { Plus, Trash2, X } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { statusKind, statusLabel, type Binding } from "@/bindings/binding-draft";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Identity } from "@/stores/org";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import BindEvent from "./BindEvent.vue";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import OptionSelect from "./OptionSelect.vue";
|
||||
import SpecList from "./SpecList.vue";
|
||||
import { setWorkflowField, workflowField } from "./workflow-edit";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
|
||||
const props = defineProps<{ yaml: string; triggers: WorkflowTrigger[] }>();
|
||||
const emit = defineEmits<{ "update:yaml": [string]; close: []; bound: [] }>();
|
||||
|
||||
// The bind flow replaces the settings in this panel; null binding is a new one.
|
||||
const binding = ref<Binding | null | undefined>();
|
||||
function bound(): void {
|
||||
binding.value = undefined;
|
||||
emit("bound");
|
||||
}
|
||||
|
||||
type Spec = { type?: string; required?: boolean };
|
||||
const TYPES = ["string", "number", "bool", "object", "array", "any"];
|
||||
// Kept out of the template: a literal reference there would close the
|
||||
// template's own interpolation.
|
||||
const EMPTY = {
|
||||
inputs: "Takes none. Steps read declared inputs as {{ inputs.name }}.",
|
||||
outputs: "Writes none. A calling workflow can read declared outputs.",
|
||||
};
|
||||
const props = defineProps<{ yaml: string }>();
|
||||
const emit = defineEmits<{ "update:yaml": [string] }>();
|
||||
|
||||
const text = (key: string) => {
|
||||
const value = workflowField(props.yaml, key);
|
||||
return typeof value === "string" ? value : "";
|
||||
};
|
||||
const specs = (key: "inputs" | "outputs") =>
|
||||
computed(() => Object.entries((workflowField(props.yaml, key) as Record<string, Spec> | undefined) ?? {}));
|
||||
const inputs = specs("inputs");
|
||||
const outputs = specs("outputs");
|
||||
|
||||
function set(key: string, value: unknown): void {
|
||||
emit("update:yaml", setWorkflowField(props.yaml, key, value));
|
||||
}
|
||||
function setSpec(key: "inputs" | "outputs", entries: [string, Spec][]): void {
|
||||
set(key, Object.fromEntries(entries.filter(([name]) => name)));
|
||||
}
|
||||
function editSpec(key: "inputs" | "outputs", list: [string, Spec][], index: number, name: string, spec: Spec): void {
|
||||
setSpec(key, list.map((entry, i) => (i === index ? [name, spec] : entry)));
|
||||
}
|
||||
function addSpec(key: "inputs" | "outputs", list: [string, Spec][]): void {
|
||||
let n = list.length + 1;
|
||||
while (list.some(([name]) => name === `${key.slice(0, -1)}_${n}`)) n++;
|
||||
setSpec(key, [...list, [`${key.slice(0, -1)}_${n}`, { type: "string" }]]);
|
||||
}
|
||||
|
||||
// The identity a run acts as must be an agent, never a person; a workflow
|
||||
// naming none is refused when it runs, so it defaults to the agent identity
|
||||
@@ -82,6 +47,19 @@ async function loadAgents(): Promise<void> {
|
||||
} finally { identitiesLoading.value = false; }
|
||||
}
|
||||
onMounted(loadAgents);
|
||||
const identityOptions = computed(() => {
|
||||
const current = text("identity");
|
||||
const options = agents.value.map((agent) => ({ value: agent.id, label: agent.display_name }));
|
||||
return current && !agents.value.some((agent) => agent.id === current) ? [{ value: current, label: `${current} (unknown)`, disabled: true }, ...options] : options;
|
||||
});
|
||||
|
||||
const settings = useSettingsStore();
|
||||
const profileOptions = computed(() => {
|
||||
const names = Object.keys((settings.stateFor("agent-profiles").resource?.value ?? {}) as Record<string, unknown>).sort();
|
||||
const current = text("profile");
|
||||
if (current && !names.includes(current)) names.unshift(current);
|
||||
return [{ value: "", label: "Default" }, ...names.map((name) => ({ value: name, label: name }))];
|
||||
});
|
||||
|
||||
const MODES = [
|
||||
{ value: "required", label: "Repository", hint: "Clones the task's repository" },
|
||||
@@ -97,160 +75,70 @@ const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => {
|
||||
const value = workflowField(props.yaml, "needs");
|
||||
return value && typeof value === "object" ? (value as { captures?: boolean; gate_retries?: number }) : {};
|
||||
});
|
||||
function setNeeds(next: { captures?: boolean; gate_retries?: number }): void {
|
||||
set("needs", next);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="flex h-full w-[24rem] max-w-full flex-col border-l border-border bg-card shadow-xl">
|
||||
<BindEvent v-if="binding !== undefined" :yaml="yaml" :binding="binding" @back="binding = undefined" @saved="bound" />
|
||||
<template v-else>
|
||||
<header class="flex items-center gap-2 border-b border-border px-4 py-3">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-medium">Workflow settings</div>
|
||||
</div>
|
||||
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close" @click="emit('close')"><X /></Button>
|
||||
</header>
|
||||
|
||||
<div class="flex-1 space-y-5 overflow-y-auto px-4 py-4">
|
||||
<section class="space-y-1.5">
|
||||
<div class="text-xs font-medium text-muted-foreground">Works on</div>
|
||||
<div class="space-y-4 px-3 py-3">
|
||||
<div class="divide-y divide-border rounded-md border border-border">
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Runs as</span>
|
||||
<OptionSelect
|
||||
:model-value="text('identity')"
|
||||
:options="identityOptions"
|
||||
aria-label="Execution identity"
|
||||
:placeholder="identitiesLoading ? 'Loading agents…' : 'Choose an agent'"
|
||||
:disabled="identitiesLoading || !!identitiesError"
|
||||
class="w-44"
|
||||
@update:model-value="set('identity', $event)"
|
||||
/>
|
||||
</label>
|
||||
<p v-if="identitiesError" role="alert" class="px-3 py-2 text-xs text-danger">{{ identitiesError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></p>
|
||||
<p v-else-if="!identitiesLoading && !agents.length" class="px-3 py-2 text-xs text-fg-subtle">No active agents in your organisation.</p>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Container profile</span>
|
||||
<OptionSelect :model-value="text('profile')" :options="profileOptions" aria-label="Container profile" class="w-44" @update:model-value="set('profile', $event || undefined)" />
|
||||
</label>
|
||||
<div class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Works on</span>
|
||||
<ToggleGroup
|
||||
type="single"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full"
|
||||
:model-value="repository"
|
||||
aria-label="Works on"
|
||||
@update:model-value="(value) => { if (value) set('repository', value === 'required' ? undefined : String(value)); }"
|
||||
>
|
||||
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint" class="flex-1">{{ mode.label }}</ToggleGroupItem>
|
||||
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint">{{ mode.label }}</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</section>
|
||||
|
||||
<section v-for="[key, list] in [['inputs', inputs], ['outputs', outputs]] as const" :key="key" class="space-y-1.5">
|
||||
<div class="flex items-center text-xs font-medium text-muted-foreground">
|
||||
{{ key === "inputs" ? "Inputs" : "Outputs" }}
|
||||
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="addSpec(key, list)"><Plus data-icon="inline-start" />Add</Button>
|
||||
</div>
|
||||
<div v-if="list.length" class="divide-y divide-border rounded-md border border-border">
|
||||
<div v-for="([name, spec], i) in list" :key="i" class="flex items-center gap-2 px-2 py-1.5">
|
||||
<Input
|
||||
:model-value="name"
|
||||
class="h-7 min-w-0 flex-1 font-mono text-xs"
|
||||
:aria-label="`${key} name`"
|
||||
@change="editSpec(key, list, i, ($event.target as HTMLInputElement).value.trim(), spec)"
|
||||
/>
|
||||
<NativeSelect
|
||||
size="sm"
|
||||
:model-value="spec.type ?? 'string'"
|
||||
@update:model-value="(value) => editSpec(key, list, i, name, { ...spec, type: String(value) })"
|
||||
>
|
||||
<NativeSelectOption v-for="type in TYPES" :key="type" :value="type">{{ type }}</NativeSelectOption>
|
||||
</NativeSelect>
|
||||
<Switch
|
||||
:model-value="spec.required === true"
|
||||
:title="spec.required ? 'Required' : 'Optional'"
|
||||
@update:model-value="editSpec(key, list, i, name, { ...spec, required: $event || undefined })"
|
||||
/>
|
||||
<Button type="button" variant="ghost" size="icon-xs" :aria-label="`Remove ${name}`" @click="setSpec(key, list.filter((_: unknown, j: number) => j !== i))">
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="text-xs text-fg-subtle">
|
||||
{{ EMPTY[key] }}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="space-y-1.5">
|
||||
<label for="workflow-instructions" class="text-xs font-medium text-muted-foreground">Instructions</label>
|
||||
<Textarea
|
||||
id="workflow-instructions"
|
||||
:model-value="text('instructions')"
|
||||
:rows="5"
|
||||
class="font-mono text-[13px]"
|
||||
@change="set('instructions', ($event.target as HTMLTextAreaElement).value)"
|
||||
</div>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]" title="Stages return structured output through capture tools">Captures</span>
|
||||
<Switch :model-value="needs.captures === true" @update:model-value="set('needs', { ...needs, captures: $event || undefined })" />
|
||||
</label>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Gate retries</span>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
placeholder="0"
|
||||
class="h-7 w-20 text-right text-[13px]"
|
||||
:model-value="needs.gate_retries ?? ''"
|
||||
@update:model-value="(value) => set('needs', { ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section class="space-y-1.5">
|
||||
<div class="text-xs font-medium text-muted-foreground">Runs as</div>
|
||||
<div class="divide-y divide-border rounded-md border border-border">
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Identity</span>
|
||||
<NativeSelect
|
||||
:model-value="text('identity')"
|
||||
aria-label="Execution identity"
|
||||
:disabled="identitiesLoading || !!identitiesError"
|
||||
class="w-44 text-[13px]"
|
||||
@update:model-value="(value) => set('identity', String(value))"
|
||||
>
|
||||
<NativeSelectOption v-if="!text('identity')" value="" disabled>{{ identitiesLoading ? 'Loading agents…' : 'Choose an agent' }}</NativeSelectOption>
|
||||
<NativeSelectOption v-if="text('identity') && !agents.some((agent) => agent.id === text('identity'))" :value="text('identity')" disabled>{{ text('identity') }} (unknown)</NativeSelectOption>
|
||||
<NativeSelectOption v-for="agent in agents" :key="agent.id" :value="agent.id">{{ agent.display_name }}</NativeSelectOption>
|
||||
</NativeSelect>
|
||||
</label>
|
||||
<p v-if="identitiesError" role="alert" class="px-3 py-2 text-xs text-danger">{{ identitiesError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></p>
|
||||
<p v-else-if="!identitiesLoading && !agents.length" class="px-3 py-2 text-xs text-fg-subtle">No active agents are assigned to your organisation.</p>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Container profile</span>
|
||||
<Input
|
||||
:model-value="text('profile')"
|
||||
placeholder="default"
|
||||
class="h-7 w-44 text-[13px]"
|
||||
@change="set('profile', ($event.target as HTMLInputElement).value.trim())"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="space-y-1.5">
|
||||
<div class="text-xs font-medium text-muted-foreground">Run needs</div>
|
||||
<div class="divide-y divide-border rounded-md border border-border">
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Captures</span>
|
||||
<Switch :model-value="needs.captures === true" @update:model-value="setNeeds({ ...needs, captures: $event || undefined })" />
|
||||
</label>
|
||||
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
|
||||
<span class="flex-1 text-[13px]">Gate retries</span>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
placeholder="0"
|
||||
class="h-7 w-20 text-right text-[13px]"
|
||||
:model-value="needs.gate_retries ?? ''"
|
||||
@update:model-value="(value) => setNeeds({ ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="space-y-1.5">
|
||||
<div class="flex items-center text-xs font-medium text-muted-foreground">Starts when
|
||||
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="binding = null"><Plus data-icon="inline-start" />Bind an event</Button>
|
||||
</div>
|
||||
<ul v-if="triggers.length" class="divide-y divide-border rounded-md border border-border">
|
||||
<li v-for="trigger in triggers" :key="trigger.kind + trigger.label" class="text-[13px]">
|
||||
<button v-if="trigger.binding" type="button" class="flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-secondary" @click="binding = trigger.binding">
|
||||
<span class="truncate">{{ trigger.label }}</span>
|
||||
<Badge v-if="trigger.binding.status !== 'armed'" :variant="statusKind(trigger.binding.status)">{{ statusLabel(trigger.binding.status) }}</Badge>
|
||||
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
|
||||
</button>
|
||||
<RouterLink v-else-if="trigger.kind==='workflow' || trigger.kind==='playbook'" :to="trigger.kind==='workflow'?{path:'/workflows',query:{workflow:trigger.label}}:{path:'/org/playbooks'}" class="flex items-center gap-2 px-3 py-2 hover:bg-secondary">
|
||||
<span class="truncate">{{trigger.label}}</span><span class="ml-auto truncate text-xs text-fg-subtle">{{trigger.detail}}</span>
|
||||
</RouterLink>
|
||||
<div v-else class="flex items-center gap-2 px-3 py-2" title="Built-in issue routing. Disable this workflow to stop it running automatically.">
|
||||
<span class="truncate">{{ trigger.label }}</span>
|
||||
<Badge v-if="trigger.kind==='issue'" variant="outline" class="ml-auto">Built-in</Badge>
|
||||
<span v-if="trigger.detail" class="ml-auto truncate text-xs text-fg-subtle">{{ trigger.detail }}</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-xs text-fg-subtle">Nothing starts it automatically.</p>
|
||||
</section>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
</aside>
|
||||
|
||||
<section class="space-y-1.5">
|
||||
<label for="workflow-instructions" class="text-xs font-medium text-muted-foreground">Instructions</label>
|
||||
<Textarea
|
||||
id="workflow-instructions"
|
||||
:model-value="text('instructions')"
|
||||
:rows="4"
|
||||
class="font-mono text-[13px]"
|
||||
@change="set('instructions', ($event.target as HTMLTextAreaElement).value)"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<SpecList :yaml="yaml" field="outputs" @update:yaml="emit('update:yaml', $event)" />
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user