193 lines
8.1 KiB
Vue
193 lines
8.1 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import HistoryLink from "@/settings/HistoryLink.vue";
|
|
import { computed, onMounted } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { DurationInput } from "@/components/ui/duration-input";
|
|
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import {
|
|
NumberField,
|
|
NumberFieldContent,
|
|
NumberFieldDecrement,
|
|
NumberFieldIncrement,
|
|
NumberFieldInput,
|
|
} from "@/components/ui/number-field";
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
import { Section } from "@/components/ui/section";
|
|
import { useSessionStore } from "@/stores/session";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import DraftHint from "./DraftHint.vue";
|
|
import { fieldInvalid } from "./settings-form";
|
|
|
|
const KIND = "scheduling-policy";
|
|
|
|
interface SchedulingPolicy {
|
|
poll_interval: string;
|
|
max_retries: number;
|
|
intake_per_pass: number;
|
|
label?: string;
|
|
dispatch: { trigger: string; ack_reaction: string };
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
// Polling and the retry cap belong to the one daemon, so only the system
|
|
// org's admin sees them.
|
|
const instance = computed(() => useSessionStore().sections?.settings !== false);
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
onMounted(store.load);
|
|
|
|
const resources = computed(() => resourcesForPage(catalog.value, "scheduling"));
|
|
const form = computed(() => store.formFor(KIND));
|
|
const policy = computed(() => store.draftValue(KIND) as SchedulingPolicy | undefined);
|
|
const error = computed(() => store.pageErrorFor(KIND));
|
|
|
|
const triggers = [
|
|
{ value: "assignee", label: "Assignee" },
|
|
{ value: "label", label: "Label" },
|
|
{ value: "either", label: "Either" },
|
|
];
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Scheduling policy">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
|
|
|
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
|
|
{{ catalogError || error }}
|
|
</AlertDescription></Alert>
|
|
|
|
<KindGate v-if="!form" :kind="KIND" />
|
|
<template v-if="form">
|
|
<Section title="Dispatch">
|
|
<FieldGroup class="@container/field-group">
|
|
<form.Field v-slot="{ field }" name="dispatch.trigger">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel>Trigger</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<ToggleGroup
|
|
type="single"
|
|
variant="outline"
|
|
size="sm"
|
|
:model-value="field.state.value"
|
|
aria-label="Trigger"
|
|
@update:model-value="(value) => { if (value) field.handleChange(value as string); }"
|
|
>
|
|
<ToggleGroupItem v-for="option in triggers" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
|
|
</ToggleGroup>
|
|
<DraftHint :kind="KIND" path="dispatch.trigger" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-if="policy?.dispatch.trigger !== 'assignee'" v-slot="{ field }" name="label">
|
|
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
|
|
<FieldContent><FieldLabel for="sp-label">Label</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<Input
|
|
id="sp-label"
|
|
:model-value="field.state.value ?? ''"
|
|
class="max-w-sm font-mono"
|
|
:aria-invalid="fieldInvalid(field)"
|
|
@blur="field.handleBlur"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="label" />
|
|
</div>
|
|
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="dispatch.ack_reaction">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel for="sp-ack">Ack reaction</FieldLabel>
|
|
<FieldDescription>Empty: none.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Input
|
|
id="sp-ack"
|
|
:model-value="field.state.value"
|
|
class="max-w-xs font-mono"
|
|
@blur="field.handleBlur"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="dispatch.ack_reaction" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
</FieldGroup>
|
|
</Section>
|
|
|
|
<Section v-if="instance" title="Retries and polling">
|
|
<FieldGroup class="@container/field-group">
|
|
<form.Field v-slot="{ field }" name="max_retries">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Max retries</FieldLabel>
|
|
<FieldDescription>Then marked dead.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
|
|
<NumberFieldContent>
|
|
<NumberFieldDecrement />
|
|
<NumberFieldInput class="font-mono" aria-label="Max retries" />
|
|
<NumberFieldIncrement />
|
|
</NumberFieldContent>
|
|
</NumberField>
|
|
<DraftHint :kind="KIND" path="max_retries" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="intake_per_pass">
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel>Tasks per poll</FieldLabel>
|
|
<FieldDescription>Most tasks one poll creates. The rest follow on later polls.</FieldDescription>
|
|
</FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
|
|
<NumberFieldContent>
|
|
<NumberFieldDecrement />
|
|
<NumberFieldInput class="font-mono" aria-label="Tasks per poll" />
|
|
<NumberFieldIncrement />
|
|
</NumberFieldContent>
|
|
</NumberField>
|
|
<DraftHint :kind="KIND" path="intake_per_pass" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<form.Field v-slot="{ field }" name="poll_interval">
|
|
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
|
|
<FieldContent><FieldLabel for="sp-poll">Poll interval</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<DurationInput
|
|
id="sp-poll"
|
|
:model-value="field.state.value"
|
|
:units="['s', 'm', 'h']"
|
|
:aria-invalid="fieldInvalid(field)"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
<DraftHint :kind="KIND" path="poll_interval" />
|
|
</div>
|
|
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
</FieldGroup>
|
|
</Section>
|
|
</template>
|
|
</div>
|
|
</template>
|