fix(ui): label the add source form

This commit is contained in:
sam committed 2026-11-24 07:50:57 +11:00
1 parent ef3b5f98ea
commit 19b273a87b
1 file changed
+62 -26
+62 -26
View File
@@ -8,11 +8,12 @@ import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { MoreMenu } from "@/components/ui/more-menu";
import { ReadError } from "@/components/ui/read-error";
import { Section } from "@/components/ui/section";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Skeleton } from "@/components/ui/skeleton";
import { errors } from "@/copy/errors";
@@ -114,6 +115,12 @@ async function saveKeyFields(): Promise<void> {
}
}
const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c.name));
const connectorPlaceholder = computed(() => {
if (connectorNames.value.length) return "Select a connector";
if (connectors.loading.value) return "Loading connectors…";
if (connectors.error.value) return "Connectors unavailable";
return "No connectors installed";
});
</script>
<template>
@@ -147,33 +154,62 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
</template>
<Dialog v-model:open="adding">
<DialogContent>
<DialogContent class="top-[50dvh] left-[50dvw] max-w-[calc(100dvw-2rem)]">
<DialogHeader><DialogTitle>{{ editing ? `Edit ${editing.label}` : "Add source" }}</DialogTitle></DialogHeader>
<form id="add-source" class="space-y-3" @submit.prevent="add">
<Input v-model="draft.label" aria-label="Name" :disabled="!!editing" placeholder="Alertmanager" required />
<Select v-model="draft.connector" required>
<SelectTrigger class="w-full" aria-label="Connector"><SelectValue placeholder="Connector that parses its events" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="name in connectorNames" :key="name" :value="name">{{ name }}</SelectItem>
</SelectContent>
</Select>
<Select v-model="draft.verification">
<SelectTrigger class="w-full" aria-label="Verification"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="token">Bearer token</SelectItem>
<SelectItem value="hmac">HMAC signature</SelectItem>
<SelectItem value="none">None</SelectItem>
</SelectContent>
</Select>
<template v-if="draft.verification === 'hmac'">
<Input v-model="draft.hmac_header" aria-label="Signature header" placeholder="X-Hub-Signature-256" required />
<Input v-model="draft.hmac_prefix" aria-label="Signature prefix" placeholder="sha256=" />
<Input v-model="draft.hmac_secret" type="password" aria-label="Signing secret" autocomplete="off" :required="!secretOptional" :placeholder="secretOptional ? 'Leave blank to keep the current secret' : ''" />
</template>
<p v-if="connectors.error.value" class="text-caption text-danger">{{ connectors.error.value }}</p>
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
<form id="add-source" @submit.prevent="add">
<FieldGroup class="grid grid-cols-[7.5rem_minmax(0,1fr)] gap-2 [&>[data-slot=field]]:col-span-2 [&>[data-slot=field]]:grid [&>[data-slot=field]]:grid-cols-subgrid [&>[data-slot=field]]:items-center">
<Field :data-disabled="!!editing">
<FieldLabel for="source-name">Source name</FieldLabel>
<Input id="source-name" v-model="draft.label" :disabled="!!editing" required />
</Field>
<Field>
<FieldLabel for="source-connector">Connector</FieldLabel>
<Select v-model="draft.connector" :disabled="!connectorNames.length" required>
<SelectTrigger id="source-connector" class="w-full">
<SelectValue :placeholder="connectorPlaceholder" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="name in connectorNames" :key="name" :value="name">{{ name }}</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel for="source-verification">Verification</FieldLabel>
<Select v-model="draft.verification">
<SelectTrigger id="source-verification" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem value="token">Bearer token</SelectItem>
<SelectItem value="hmac">HMAC signature</SelectItem>
<SelectItem value="none">None</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</Field>
<template v-if="draft.verification === 'hmac'">
<Field>
<FieldLabel for="source-signature-header">Signature header</FieldLabel>
<Input id="source-signature-header" v-model="draft.hmac_header" placeholder="X-Hub-Signature-256" required />
</Field>
<Field>
<FieldLabel for="source-signature-prefix">Signature prefix (optional)</FieldLabel>
<Input id="source-signature-prefix" v-model="draft.hmac_prefix" placeholder="sha256=" />
</Field>
<Field>
<FieldLabel for="source-signing-secret">{{ secretOptional ? "New signing secret (optional)" : "Signing secret" }}</FieldLabel>
<Input id="source-signing-secret" v-model="draft.hmac_secret" type="password" autocomplete="off" :required="!secretOptional" />
</Field>
</template>
<p v-if="actionError" role="alert" class="col-span-2 text-caption text-danger">{{ actionError }}</p>
</FieldGroup>
</form>
<DialogFooter><Button type="submit" form="add-source" :disabled="addDisabled">{{ editing ? "Save" : "Add" }}</Button></DialogFooter>
<ReadError v-if="connectors.error.value" :message="connectors.error.value" retry-label="Retry" @retry="connectors.reload" />
<DialogFooter class="flex-row justify-end">
<Button type="button" variant="outline" @click="adding = false">Cancel</Button>
<Button type="submit" form="add-source" :disabled="addDisabled">{{ editing ? "Save changes" : "Add source" }}</Button>
</DialogFooter>
</DialogContent>
</Dialog>