Files
archie/ui/src/workflows/SpecList.vue
T
sam 3bebdb2af7 fix(ui): keep the workflows toolbar readable on the 36px ladder
The run selector is the only control that gives up width, and beside the
workflow list it had none left: Open and the run's version move into the one
menu at every width, so the picked run stays readable from 390 to 1440.

Step editor and binding fields take the next rung (h-8) so they match the
selects and switches they sit beside.
2026-10-18 22:42:14 +11:00

49 lines
2.7 KiB
Vue

<script setup lang="ts">
import { computed } from "vue";
import { Plus, Trash2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import OptionSelect from "./OptionSelect.vue";
import { setWorkflowField, workflowField } from "./workflow-edit";
// A workflow's declared inputs or outputs: name, type and whether required.
const props = defineProps<{ yaml: string; field: "inputs" | "outputs" }>();
const emit = defineEmits<{ "update:yaml": [string] }>();
type Spec = { type?: string; required?: boolean };
const TYPES = ["string", "number", "bool", "object", "array", "any"].map((value) => ({ value, label: value }));
const list = computed(() => Object.entries((workflowField(props.yaml, props.field) as Record<string, Spec> | undefined) ?? {}));
function write(entries: [string, Spec][]): void {
emit("update:yaml", setWorkflowField(props.yaml, props.field, Object.fromEntries(entries.filter(([name]) => name))));
}
function edit(index: number, name: string, spec: Spec): void {
write(list.value.map((entry, i) => (i === index ? [name, spec] : entry)));
}
function add(): void {
const stem = props.field.slice(0, -1);
let n = list.value.length + 1;
while (list.value.some(([name]) => name === `${stem}_${n}`)) n++;
write([...list.value, [`${stem}_${n}`, { type: "string" }]]);
}
</script>
<template>
<section class="space-y-1.5">
<div class="flex items-center text-xs font-medium text-fg-muted">
{{ field === "inputs" ? "Inputs" : "Outputs" }}
<Button type="button" variant="ghost" size="xs" class="ml-auto" @click="add"><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-8 min-w-0 flex-1 font-mono text-xs" :aria-label="`${field} name`" @change="edit(i, ($event.target as HTMLInputElement).value.trim(), spec)" />
<OptionSelect :model-value="spec.type ?? 'string'" :options="TYPES" class="w-24" :aria-label="`${name} type`" @update:model-value="edit(i, name, { ...spec, type: $event })" />
<Switch :model-value="spec.required === true" :title="spec.required ? 'Required' : 'Optional'" :aria-label="`${name} required`" @update:model-value="edit(i, name, { ...spec, required: $event || undefined })" />
<Button type="button" variant="ghost" size="icon-xs" :aria-label="`Remove ${name}`" @click="write(list.filter((_, j) => j !== i))"><Trash2 /></Button>
</div>
</div>
</section>
</template>