87 lines
4.1 KiB
Vue
87 lines
4.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref, watch } from "vue";
|
|
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Section } from "@/components/ui/section";
|
|
import { useExtensionsStore, type Extension } from "@/stores/extensions";
|
|
import SecretRefField from "./SecretRefField.vue";
|
|
|
|
const props = defineProps<{
|
|
extension: Extension;
|
|
/** The messaging service's report for this channel, when it has one. */
|
|
status?: { state?: string; detail?: string };
|
|
}>();
|
|
|
|
const store = useExtensionsStore();
|
|
const draft = ref<Record<string, string>>({});
|
|
watch(() => props.extension.settings, (saved) => { draft.value = { ...saved }; }, { immediate: true });
|
|
|
|
const dirty = computed(() => {
|
|
const saved = props.extension.settings;
|
|
return props.extension.settings_schema.some((spec) => (draft.value[spec.key] ?? "").trim() !== (saved[spec.key] ?? ""));
|
|
});
|
|
const missing = computed(() =>
|
|
props.extension.settings_schema.filter((spec) => spec.required && !(draft.value[spec.key] ?? "").trim()).map((spec) => spec.label),
|
|
);
|
|
|
|
function secretRef(key: string): { engine: string; key: string } {
|
|
const [engine = "", ...rest] = (draft.value[key] ?? "").split(":");
|
|
return { engine, key: rest.join(":") };
|
|
}
|
|
function setSecretRef(key: string, value: { engine: string; key: string }): void {
|
|
draft.value = { ...draft.value, [key]: value.engine || value.key ? `${value.engine}:${value.key}` : "" };
|
|
}
|
|
function setValue(key: string, value: string | number): void {
|
|
draft.value = { ...draft.value, [key]: String(value) };
|
|
}
|
|
|
|
const badge = computed(() => {
|
|
if (!props.extension.enabled) return { label: "Off", tone: "idle" } as const;
|
|
const state = props.status?.state;
|
|
if (state === "failed") return { label: "Failed", tone: "danger" } as const;
|
|
if (state === "degraded") return { label: "Degraded", tone: "warn" } as const;
|
|
if (state === "stopped") return { label: "Stopped", tone: "idle" } as const;
|
|
return undefined;
|
|
});
|
|
// The service reports why an enabled channel did not start: missing settings,
|
|
// or the error its last run ended with.
|
|
const problem = computed(() => (props.extension.enabled && props.status?.state !== "running" ? props.status?.detail : ""));
|
|
</script>
|
|
|
|
<template>
|
|
<Section :title="extension.display_name || extension.name">
|
|
<template #action>
|
|
<Badge v-if="badge" :variant="badge.tone">{{ badge.label }}</Badge>
|
|
</template>
|
|
<Alert v-if="problem" variant="destructive"><AlertDescription>{{ problem }}</AlertDescription></Alert>
|
|
<FieldGroup class="@container/field-group">
|
|
<Field v-for="spec in extension.settings_schema" :key="spec.key" orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel :for="`${extension.name}-${spec.key}`">{{ spec.label }}</FieldLabel>
|
|
<FieldDescription v-if="spec.description">{{ spec.description }}</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<div v-if="spec.secret" :id="`${extension.name}-${spec.key}`" role="group" :aria-label="spec.label" class="contents">
|
|
<SecretRefField :model-value="secretRef(spec.key)" :id-prefix="`${extension.name}-${spec.key}`" @update:model-value="(value) => setSecretRef(spec.key, value)" />
|
|
</div>
|
|
<Input
|
|
v-else
|
|
:id="`${extension.name}-${spec.key}`"
|
|
:model-value="draft[spec.key] ?? ''"
|
|
class="max-w-md font-mono"
|
|
@update:model-value="(value) => setValue(spec.key, value)"
|
|
/>
|
|
</div>
|
|
</Field>
|
|
</FieldGroup>
|
|
<div class="flex flex-wrap items-center justify-end gap-3">
|
|
<span v-if="dirty && missing.length" class="text-caption text-fg-muted">Missing {{ missing.join(", ") }}</span>
|
|
<Button size="sm" :disabled="!dirty || store.busy === extension.name" @click="store.saveSettings(extension.name, draft)">Save</Button>
|
|
</div>
|
|
</Section>
|
|
</template>
|