feat(admin-ui): hide runaway budget line and link form errors to inputs

The burn-down chart drew the budget line even when it was more than ten times the spend, which flattened the spend curve. The line now hides with a note. Limits, pricing, model metadata and grant forms mark invalid inputs with aria-invalid and aria-describedby.
This commit is contained in:
2026-11-08 02:28:27 +00:00
parent 1ec8aacee7
commit e985fded45
7 changed files with 72 additions and 11 deletions
+5 -2
View File
@@ -5,7 +5,7 @@ import ChartCard from '@/components/ChartCard.vue'
import StatItem from '@/components/StatItem.vue'
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
import type { TimeSeriesDataset } from '@/components/TimeSeriesChart.vue'
import { cumulative, runOutDate } from '@/lib/burndown'
import { BUDGET_LINE_MAX_RATIO, budgetLineVisible, cumulative, runOutDate } from '@/lib/burndown'
import { NOT_ENOUGH_DATA } from '@/lib/forecast'
import { formatBucketLabel, formatCostAxis, formatCostDisplay, formatShortDate } from '@/lib/format'
import { loadState } from '@/lib/load-state'
@@ -53,7 +53,7 @@ const spentMicros = computed<number>(() => cumulativePoints.value.at(-1) ?? 0)
const datasets = computed<TimeSeriesDataset[]>(() => [{ label: 'Spent (MTD)', data: cumulativePoints.value, color: '--chart-cost' }])
const comparisonDatasets = computed<TimeSeriesDataset[]>(() => {
if (props.budgetMicros === null) return []
if (props.budgetMicros === null || !budgetLineVisible(spentMicros.value, props.budgetMicros)) return []
const flat = new Array<number>(cumulativePoints.value.length).fill(props.budgetMicros)
return [{ label: 'Budget', data: flat, color: '--destructive' }]
})
@@ -85,6 +85,9 @@ const willExceed = computed<boolean>(() => props.budgetMicros !== null && spentM
</StatItem>
</div>
<p v-if="budgetMicros === null" class="text-sm text-muted-foreground">No budget configured for this scope.</p>
<p v-else-if="comparisonDatasets.length === 0" class="text-sm text-muted-foreground">
Budget line hidden: it is more than {{ BUDGET_LINE_MAX_RATIO }}× current spend and would flatten the curve.
</p>
<TimeSeriesChart
:labels="labels"
:datasets="datasets"
+8 -2
View File
@@ -79,7 +79,13 @@ const snippet = computed<string | null>(() => {
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
<div class="flex flex-col gap-1">
<label for="grant-providers" class="text-xs font-medium text-muted-foreground">Providers (comma-separated, empty = all)</label>
<Input id="grant-providers" v-model="providersRaw" placeholder="anthropic, openai" />
<Input
id="grant-providers"
v-model="providersRaw"
placeholder="anthropic, openai"
:aria-invalid="grantError ? true : undefined"
:aria-describedby="grantError ? 'grant-error' : undefined"
/>
</div>
<div class="flex flex-col gap-1">
<label for="grant-models" class="text-xs font-medium text-muted-foreground">Models (comma-separated, empty = all)</label>
@@ -97,7 +103,7 @@ const snippet = computed<string | null>(() => {
</template>
</div>
<Alert v-if="grantError" variant="destructive">
<Alert v-if="grantError" id="grant-error" variant="destructive">
<AlertDescription>{{ grantError }}</AlertDescription>
</Alert>
+7 -1
View File
@@ -58,6 +58,10 @@ const raw = reactive<Record<keyof LimitsConfig, string>>({
const invalidFields = computed(() =>
FIELDS.filter(({ key }) => raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label),
)
/** fieldInvalid is the per-input twin of invalidFields, so each input can carry aria-invalid. */
function fieldInvalid(key: (typeof FIELDS)[number]['key']): boolean {
return raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))
}
const invalidIntegerFields = computed(() =>
FIELDS.filter(({ key }) => INTEGER_FIELDS.has(key) && raw[key].trim() !== '' && !fieldValid(key, Number(raw[key]))).map((f) => f.label),
)
@@ -104,11 +108,13 @@ const snippet = computed<string | null>(() => {
min="0"
:step="INTEGER_FIELDS.has(field.key) ? '1' : 'any'"
placeholder="unset"
:aria-invalid="fieldInvalid(field.key) || undefined"
:aria-describedby="fieldInvalid(field.key) ? 'limits-errors' : undefined"
/>
</div>
</div>
<Alert v-if="invalidFields.length" variant="destructive">
<Alert v-if="invalidFields.length" id="limits-errors" variant="destructive">
<AlertDescription>
<p v-if="invalidIntegerFields.length">Enter a non-negative whole number for: {{ invalidIntegerFields.join(', ') }}.</p>
<p v-if="invalidDecimalFields.length">Enter a non-negative number for: {{ invalidDecimalFields.join(', ') }}.</p>
+11 -2
View File
@@ -46,7 +46,16 @@ const snippet = computed<string | null>(() => {
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 sm:items-end">
<div class="flex flex-col gap-1">
<label for="modelmeta-context" class="text-xs font-medium text-muted-foreground">Context window (tokens)</label>
<Input id="modelmeta-context" v-model="contextRaw" type="number" min="1" step="1" placeholder="131072" />
<Input
id="modelmeta-context"
v-model="contextRaw"
type="number"
min="1"
step="1"
placeholder="131072"
:aria-invalid="contextEntered && !contextValid ? true : undefined"
:aria-describedby="contextEntered && !contextValid ? 'modelmeta-context-error' : undefined"
/>
</div>
<label class="flex items-center gap-2 pb-1.5 text-sm">
<input id="modelmeta-free" v-model="free" type="checkbox" class="size-4 rounded border-input" />
@@ -54,7 +63,7 @@ const snippet = computed<string | null>(() => {
</label>
</div>
<Alert v-if="contextEntered && !contextValid" variant="destructive">
<Alert v-if="contextEntered && !contextValid" id="modelmeta-context-error" variant="destructive">
<AlertDescription>Context window must be a positive whole number of tokens.</AlertDescription>
</Alert>
+21 -3
View File
@@ -54,15 +54,33 @@ const snippet = computed<string | null>(() => {
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2">
<div class="flex flex-col gap-1">
<label for="pricing-input" class="text-xs font-medium text-muted-foreground">Input price / MTok (USD)</label>
<Input id="pricing-input" v-model="inputRaw" type="number" min="0" step="any" placeholder="0.50" />
<Input
id="pricing-input"
v-model="inputRaw"
type="number"
min="0"
step="any"
placeholder="0.50"
:aria-invalid="errors.length > 0 && !inputValid ? true : undefined"
:aria-describedby="errors.length > 0 && !inputValid ? 'pricing-errors' : undefined"
/>
</div>
<div class="flex flex-col gap-1">
<label for="pricing-output" class="text-xs font-medium text-muted-foreground">Output price / MTok (USD)</label>
<Input id="pricing-output" v-model="outputRaw" type="number" min="0" step="any" placeholder="1.50" />
<Input
id="pricing-output"
v-model="outputRaw"
type="number"
min="0"
step="any"
placeholder="1.50"
:aria-invalid="errors.length > 0 && !outputValid ? true : undefined"
:aria-describedby="errors.length > 0 && !outputValid ? 'pricing-errors' : undefined"
/>
</div>
</div>
<Alert v-if="errors.length" variant="destructive">
<Alert v-if="errors.length" id="pricing-errors" variant="destructive">
<AlertDescription>
<p v-for="(error, index) in errors" :key="index">{{ error }}</p>
</AlertDescription>
+12 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { cumulative, currentMonthDaySpan, MIN_ELAPSED_DAYS, runOutDate } from './burndown'
import { budgetLineVisible, BUDGET_LINE_MAX_RATIO, cumulative, currentMonthDaySpan, MIN_ELAPSED_DAYS, runOutDate } from './burndown'
describe('currentMonthDaySpan', () => {
it('returns the UTC day-of-month', () => {
@@ -63,3 +63,14 @@ describe('runOutDate', () => {
expect(MIN_ELAPSED_DAYS).toBe(1)
})
})
describe('budgetLineVisible', () => {
it.each([
{ spent: 0, budget: 1, visible: false },
{ spent: 1_000, budget: 1_000 * BUDGET_LINE_MAX_RATIO, visible: true },
{ spent: 1_000, budget: 1_000 * BUDGET_LINE_MAX_RATIO + 1, visible: false },
{ spent: 5_000, budget: 1_000, visible: true },
])('spent=$spent budget=$budget -> $visible', ({ spent, budget, visible }) => {
expect(budgetLineVisible(spent, budget)).toBe(visible)
})
})
+8
View File
@@ -91,3 +91,11 @@ export function runOutDate(mtdMicros: number, limitMicros: number, now: Date): D
const daysToExhaust = remainingMicros / dailyRateMicros
return new Date(now.getTime() + daysToExhaust * MS_PER_DAY)
}
/** BUDGET_LINE_MAX_RATIO is how far above spend the budget may sit before its line is hidden. */
export const BUDGET_LINE_MAX_RATIO = 10
/** budgetLineVisible hides a budget line so far above spend that it flattens the spend curve against the axis. */
export function budgetLineVisible(spentMicros: number, budgetMicros: number): boolean {
return budgetMicros <= BUDGET_LINE_MAX_RATIO * spentMicros
}