mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): make the dashboard responsive and add loading and empty states
Every tab row scrolls sideways instead of being clipped by its card. On phones this hid tabs, such as the Config change helper's last forms at 360-390px. The login button has a larger touch target, and long names are truncated with a tooltip. Loading and empty states: - Skeletons show only while a selection has no data yet, never over data already on screen during a refresh. - Empty states name the next step to take. - Error states offer a Retry button that shows progress, and each card keeps its own error. - Toasts confirm copies and key generation, and report background failures once per streak through polite and assertive live regions. Other changes: - The access matrix switches between Models, MCP servers and Agents, and says "none configured" only once its data has loaded. - Home ranks the top 5 users by cost, requests or tokens. It requests only the needed metrics and warns before a range exceeds the server's key cap. - MCP and agent deep links accept a bare target name. admin_assets_gen.go is regenerated. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
@@ -2,24 +2,41 @@
|
||||
import { faCheck, faTriangleExclamation, faXmark } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed, onMounted } from 'vue'
|
||||
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||
import { buildAccessMatrix } from '@/lib/access-matrix'
|
||||
import type { AccessCell } from '@/lib/access-matrix'
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { buildAccessMatrix, MATRIX_KIND_LABEL, MATRIX_KINDS, matrixColumnsState } from '@/lib/access-matrix'
|
||||
import type { AccessCell, MatrixKind } from '@/lib/access-matrix'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { useConsumersStore } from '@/stores/consumers'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
|
||||
/**
|
||||
* AccessMatrix (redesign-plan.md section 3.4) is the Consumers page's
|
||||
* `view=matrix` alternative to ConsumerDirectory: rows are groups, columns
|
||||
* are every configured provider (allowed check + "n/m models", from GET
|
||||
* /admin/api/consumers' AllowedProviders/modelAccess) and every configured
|
||||
* MCP server/agent target (from GET /admin/api/targets' own `access`
|
||||
* list). Pure data shaping lives in lib/access-matrix.ts; this component
|
||||
* only fetches, lays out columns, and renders.
|
||||
* AccessMatrix (redesign-plan.md section 3.4; P4 three-view split) is the
|
||||
* Consumers page's `view=matrix` alternative to ConsumerDirectory: rows
|
||||
* are groups, columns are ONE of three kinds at a time — providers
|
||||
* (allowed check + "n/m models", from GET /admin/api/consumers'
|
||||
* AllowedProviders/modelAccess), MCP servers, or agents (both from GET
|
||||
* /admin/api/targets' own `access` list) — switched by a Tabs control in
|
||||
* the card header, CONTROLLED via the `kind` prop/`update:kind` emit the
|
||||
* same way AttributionDrilldown.vue's `drill` prop works: this component
|
||||
* owns no navigation state itself, ConsumersPage.vue keeps `kind` in
|
||||
* nav.params (lib/access-matrix.ts's own `matrix` hash param) so a
|
||||
* reload or shared link restores the same view. Pure data shaping lives
|
||||
* in lib/access-matrix.ts; this component only fetches, lays out the
|
||||
* selected kind's columns, and renders.
|
||||
*/
|
||||
const props = defineProps<{ kind: MatrixKind }>()
|
||||
const emit = defineEmits<{ 'update:kind': [kind: MatrixKind] }>()
|
||||
|
||||
const consumers = useConsumersStore()
|
||||
const dashboard = useDashboardStore()
|
||||
const nav = useNavStore()
|
||||
|
||||
onMounted(() => {
|
||||
void consumers.ensureConsumers()
|
||||
@@ -29,27 +46,81 @@ const providerNames = computed(() => (dashboard.overview?.providers ?? []).map((
|
||||
const mcpServers = computed(() => dashboard.targets?.mcpServers ?? [])
|
||||
const agents = computed(() => dashboard.targets?.agents ?? [])
|
||||
|
||||
/** MatrixColumn flattens the three heterogeneous column groups (providers, MCP servers, agents) into one ordered list — a single v-for renders every header AND every cell, rather than three near-identical template blocks. */
|
||||
/** MatrixSection is the AccessMatrixRow key each kind reads its cells from. */
|
||||
type MatrixSection = 'providers' | 'mcpServers' | 'agents'
|
||||
|
||||
/** KIND_SECTION maps the page-facing MatrixKind to the row-shape key buildAccessMatrix produced it under (lib/access-matrix.ts's own AccessMatrixRow). */
|
||||
const KIND_SECTION: Record<MatrixKind, MatrixSection> = {
|
||||
models: 'providers',
|
||||
mcp: 'mcpServers',
|
||||
agents: 'agents',
|
||||
}
|
||||
|
||||
/** KIND_DESCRIPTION is the CardDescription text for the currently selected kind. */
|
||||
const KIND_DESCRIPTION: Record<MatrixKind, string> = {
|
||||
models: "Which groups can reach which providers, and how many of each provider's models.",
|
||||
mcp: 'Which groups can reach which MCP servers.',
|
||||
agents: 'Which groups can reach which agents.',
|
||||
}
|
||||
|
||||
/** KIND_EMPTY_MESSAGE is shown instead of a table with zero columns — distinct from the "no groups configured" state below, since groups can exist while this kind's own column list is empty (e.g. no MCP servers configured at all). */
|
||||
const KIND_EMPTY_MESSAGE: Record<MatrixKind, string> = {
|
||||
models: 'No providers configured.',
|
||||
mcp: 'No MCP servers configured.',
|
||||
agents: 'No agents configured.',
|
||||
}
|
||||
|
||||
/** MatrixColumn is one header/cell column of the currently selected kind — no more "(MCP)"/"(agent)" label suffix, since the Tabs control already says which kind is showing. */
|
||||
interface MatrixColumn {
|
||||
key: string
|
||||
label: string
|
||||
section: 'providers' | 'mcpServers' | 'agents'
|
||||
section: MatrixSection
|
||||
}
|
||||
|
||||
const columns = computed<MatrixColumn[]>(() => [
|
||||
...providerNames.value.map((name): MatrixColumn => ({ key: name, label: name, section: 'providers' })),
|
||||
...mcpServers.value.map((t): MatrixColumn => ({ key: t.name, label: `${t.name} (MCP)`, section: 'mcpServers' })),
|
||||
...agents.value.map((t): MatrixColumn => ({ key: t.name, label: `${t.name} (agent)`, section: 'agents' })),
|
||||
])
|
||||
const columns = computed<MatrixColumn[]>(() => {
|
||||
const section = KIND_SECTION[props.kind]
|
||||
if (props.kind === 'models') return providerNames.value.map((name): MatrixColumn => ({ key: name, label: name, section }))
|
||||
const targets = props.kind === 'mcp' ? mcpServers.value : agents.value
|
||||
return targets.map((t): MatrixColumn => ({ key: t.name, label: t.name, section }))
|
||||
})
|
||||
|
||||
const rows = computed(() => buildAccessMatrix(consumers.data?.groups ?? [], providerNames.value, mcpServers.value, agents.value))
|
||||
|
||||
/** sourceLoaded is whether the CURRENT kind's own raw dashboard field has loaded at least once — dashboard.overview for 'models', dashboard.targets for 'mcp'/'agents' — read straight off the store rather than the derived `columns` list, which maps a not-yet-loaded source to `[]` indistinguishably from a genuinely empty one (lib/access-matrix.ts's matrixColumnsState doc comment). */
|
||||
const sourceLoaded = computed(() => (props.kind === 'models' ? dashboard.overview !== null : dashboard.targets !== null))
|
||||
|
||||
/** columnsState is the current kind's own loading/error/empty/ready state (lib/access-matrix.ts's matrixColumnsState) — drives which CardContent branch renders below, independent of the groups-only groupsLoadState/noGroupsConfigured checks above it. */
|
||||
const columnsState = computed(() => matrixColumnsState(sourceLoaded.value, columns.value.length, dashboard.error))
|
||||
|
||||
/**
|
||||
* groupsLoadState (lib/load-state.ts) replaces the old bare
|
||||
* `consumers.error`/`consumers.loading` checks — those used to show the
|
||||
* error text UNCONDITIONALLY whenever consumers.error was set, even with
|
||||
* perfectly good stale group rows already in `rows` from a PRIOR
|
||||
* successful fetch (fetchConsumers, stores/consumers.ts, never clears
|
||||
* `data` on a failed refetch) — states-plan.md item 1's own "never wipe
|
||||
* rendered data on a background failure" rule, the same class of bug
|
||||
* this states pass fixes everywhere else. 'ready' once consumers.data has
|
||||
* loaded at least once, even with zero groups — `noGroupsConfigured`
|
||||
* below is the separate "loaded, but genuinely nothing configured" case.
|
||||
*/
|
||||
const groupsLoadState = computed(() => loadState({ loading: consumers.loading, hasData: consumers.data !== null, error: consumers.error }))
|
||||
|
||||
/** noGroupsConfigured (states-plan.md item 2: "Consumers: 'No groups configured' + hint to the Config page change helper") is true only once groups have genuinely loaded with none configured — not while still loading or errored (groupsLoadState handles those first, see the template below). */
|
||||
const noGroupsConfigured = computed(() => groupsLoadState.value === 'ready' && rows.value.length === 0)
|
||||
|
||||
const EMPTY_CELL: AccessCell = { allowed: false }
|
||||
|
||||
function cellFor(row: (typeof rows.value)[number], column: MatrixColumn): AccessCell {
|
||||
return row[column.section][column.key] ?? EMPTY_CELL
|
||||
}
|
||||
|
||||
/** setKind forwards a Tabs selection as `update:kind`, guarding the `unknown` reka-ui hands back down to a real MatrixKind (mirrors ConsumersPage.vue's own setView / ChangeHelper.vue's setHelper). */
|
||||
function setKind(next: unknown): void {
|
||||
if (typeof next !== 'string' || !(MATRIX_KINDS as readonly string[]).includes(next)) return
|
||||
emit('update:kind', next as MatrixKind)
|
||||
}
|
||||
|
||||
/**
|
||||
* cellSrText is the ONLY accessible text a screen reader announces for
|
||||
* one cell — the visible icon is aria-hidden and the visible detail span
|
||||
@@ -84,24 +155,45 @@ function cellIconClass(cell: AccessCell): string {
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Access matrix</CardTitle>
|
||||
<CardDescription>Which groups can reach which providers, MCP servers, and agents.</CardDescription>
|
||||
<CardDescription>{{ KIND_DESCRIPTION[props.kind] }}</CardDescription>
|
||||
<Tabs :model-value="props.kind" @update:model-value="setKind">
|
||||
<TabsList>
|
||||
<TabsTrigger v-for="k in MATRIX_KINDS" :key="k" :value="k">{{ MATRIX_KIND_LABEL[k] }}</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</CardHeader>
|
||||
<CardContent v-if="consumers.error" class="text-sm text-destructive">{{ consumers.error }}</CardContent>
|
||||
<CardContent v-else-if="rows.length === 0" class="py-6 text-center text-sm text-muted-foreground">
|
||||
{{ consumers.loading ? 'loading…' : 'no groups configured' }}
|
||||
<CardContent v-if="groupsLoadState === 'error'">
|
||||
<ErrorState :message="consumers.error" :on-retry="consumers.fetchConsumers" />
|
||||
</CardContent>
|
||||
<CardContent v-else-if="groupsLoadState === 'skeleton'">
|
||||
<SkeletonTable :rows="4" :cols="4" />
|
||||
</CardContent>
|
||||
<CardContent v-else-if="noGroupsConfigured">
|
||||
<EmptyState title="No groups configured." description="Grant a group access from the Config page's change helper.">
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config', { helper: 'grant' })">Open change helper</Button>
|
||||
</EmptyState>
|
||||
</CardContent>
|
||||
<CardContent v-else-if="columnsState === 'error'">
|
||||
<ErrorState :message="dashboard.error" />
|
||||
</CardContent>
|
||||
<CardContent v-else-if="columnsState === 'loading'">
|
||||
<SkeletonTable :rows="rows.length" :cols="4" />
|
||||
</CardContent>
|
||||
<CardContent v-else-if="columnsState === 'empty'">
|
||||
<EmptyState :title="KIND_EMPTY_MESSAGE[props.kind]" />
|
||||
</CardContent>
|
||||
<CardContent v-else class="overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Group</TableHead>
|
||||
<TableHead v-for="column in columns" :key="column.key + column.section">{{ column.label }}</TableHead>
|
||||
<TableHead v-for="column in columns" :key="column.key">{{ column.label }}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="row in rows" :key="row.group">
|
||||
<TableHead scope="row" class="font-medium">{{ row.group }}</TableHead>
|
||||
<TableCell v-for="column in columns" :key="column.key + column.section" class="text-center" :title="cellFor(row, column).detail">
|
||||
<TableCell v-for="column in columns" :key="column.key" class="text-center" :title="cellFor(row, column).detail">
|
||||
<FontAwesomeIcon :icon="cellIcon(cellFor(row, column))" :class="cellIconClass(cellFor(row, column))" class="size-3.5" aria-hidden="true" />
|
||||
<span v-if="cellFor(row, column).detail" aria-hidden="true" class="ml-1 text-xs text-muted-foreground">{{ cellFor(row, column).detail }}</span>
|
||||
<span class="sr-only">{{ cellSrText(cellFor(row, column)) }}</span>
|
||||
|
||||
@@ -7,9 +7,17 @@ import { computed, h, ref } from 'vue'
|
||||
import ClampedRangeNotice from '@/components/ClampedRangeNotice.vue'
|
||||
import CompactNumber from '@/components/CompactNumber.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import EntityLink from '@/components/EntityLink.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import TryLongerRangeButton from '@/components/TryLongerRangeButton.vue'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { formatCost } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import { SPEND_METRIC_LABEL } from '@/stores/spend'
|
||||
import type { AdminTotalsResponse, HistoryMetric, HistoryWindow } from '@/types/api'
|
||||
|
||||
@@ -44,10 +52,26 @@ const props = defineProps<{
|
||||
/** The global filters store's current window/span (N3 fix) — ClampedRangeNotice's own props, forwarded so this stays a controlled, props-driven component rather than reaching into stores/filters.ts itself. */
|
||||
window: HistoryWindow
|
||||
span: number
|
||||
/** spend.drilldownLoading (verify-ui-states.md #3 fix) — this card had no loading/error input at all: `spend.drilldownRows` starts as [], so the very first Spend load, and any failed drilldown fetch, rendered the identical "No traffic in this range." a genuinely empty group/user/model list gets. */
|
||||
loading: boolean
|
||||
/**
|
||||
* spend.drilldownLoaded (verify-ui-states-2.md #2 fix) — "has a fetch
|
||||
* completed for the current window/span/drill selection", not
|
||||
* `rows.length > 0`: the 60s poll flips `loading` true on every tick, and
|
||||
* a genuinely empty level (e.g. a group with no users) used to flash a
|
||||
* skeleton back on for each tick. `noTrafficInRange` below still checks
|
||||
* `rows.length` directly for EmptyState vs. the real table.
|
||||
*/
|
||||
loaded: boolean
|
||||
error: string
|
||||
/** Renders ErrorState's own "Retry" button — SpendPage.vue's own spend.fetchDrilldown. */
|
||||
onRetry?: () => void | Promise<void>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ 'update:drill': [value: string] }>()
|
||||
|
||||
const nav = useNavStore()
|
||||
|
||||
type Level = { kind: 'group' } | { kind: 'user'; group: string } | { kind: 'usermodel'; user: string }
|
||||
|
||||
const level = computed<Level>(() => {
|
||||
@@ -122,6 +146,22 @@ const columns = computed<ColumnDef<DrilldownRow, unknown>[]>(() => [
|
||||
])
|
||||
|
||||
const showUserModelHint = computed<boolean>(() => level.value.kind === 'user' && (!props.userModelStatsEnabled || props.disabled))
|
||||
|
||||
const state = computed(() => loadState({ loading: props.loading, hasData: props.loaded, error: props.error }))
|
||||
|
||||
/**
|
||||
* noTrafficInRange (states-plan.md item 2: "Spend/Models/Home lists: 'No
|
||||
* traffic in this range'") is the genuine "nothing to show" case — gated
|
||||
* directly on `rows.length === 0` (verify-ui-states-2.md #2 fix; `state`
|
||||
* no longer distinguishes empty from non-empty once `loaded` is true, see
|
||||
* this component's own `loaded` prop doc comment), the same way
|
||||
* UserDetail.vue's own "Models used" table checks `!modelRows.length`. The
|
||||
* template below still checks `state === 'skeleton'`/`'error'` FIRST, so a
|
||||
* first/failed fetch never reaches this branch. Never true alongside
|
||||
* showUserModelHint, which takes precedence in the template below (that
|
||||
* state has its own, more specific copy).
|
||||
*/
|
||||
const noTrafficInRange = computed<boolean>(() => !showUserModelHint.value && props.rows.length === 0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -149,15 +189,19 @@ const showUserModelHint = computed<boolean>(() => level.value.kind === 'user' &&
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<ClampedRangeNotice v-if="level.kind === 'usermodel'" :window="window" :span="span" />
|
||||
<p v-if="showUserModelHint" class="text-sm text-muted-foreground">
|
||||
Per-model attribution for this user needs <code class="font-mono text-xs">admin.stats.userModel</code> enabled.
|
||||
</p>
|
||||
<DataTable
|
||||
v-else
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
:empty-message="level.kind === 'group' ? 'No group has spend in this range.' : 'Nothing in this range.'"
|
||||
/>
|
||||
<Alert v-if="showUserModelHint" variant="warn">
|
||||
<AlertTitle>Per-user-model statistics are off</AlertTitle>
|
||||
<AlertDescription class="flex flex-wrap items-center gap-2">
|
||||
<span>Enable <code class="font-mono text-xs">admin.stats.userModel</code> in the middleware config to see per-model attribution for this user.</span>
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config')">Open Config</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<SkeletonTable v-else-if="state === 'skeleton'" :rows="5" :cols="metrics.length + 1" />
|
||||
<ErrorState v-else-if="state === 'error'" :message="error" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="noTrafficInRange" title="No traffic in this range.">
|
||||
<TryLongerRangeButton />
|
||||
</EmptyState>
|
||||
<DataTable v-else :columns="columns" :data="rows" empty-message="none" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -115,7 +115,7 @@ watch(() => auth.error, (err) => {
|
||||
<FontAwesomeIcon :icon="showKey ? faEyeSlash : faEye" class="size-3.5" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button type="submit" class="w-full" :disabled="!canSubmit">
|
||||
<Button type="submit" class="h-10 w-full" :disabled="!canSubmit">
|
||||
Continue
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonChart from '@/components/SkeletonChart.vue'
|
||||
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
|
||||
import type { TimeSeriesDataset } from '@/components/TimeSeriesChart.vue'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { cumulative, runOutDate } from '@/lib/burndown'
|
||||
import { formatBucketLabel, formatCost } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
|
||||
/**
|
||||
* BurnDownChart (redesign-plan.md section 3.4) renders the current UTC
|
||||
@@ -34,8 +37,15 @@ const props = defineProps<{
|
||||
/** The scope's configured cost/month budget in micro-USD, or null when none is configured. */
|
||||
budgetMicros: number | null
|
||||
now: Date
|
||||
/** spend.burndownLoading (verify-ui-states.md #7 fix, Spend page gap) — this card had no loading/error input at all before: `buckets` starts as [], so the very first Spend load, and any failed burn-down fetch, rendered a flat all-zero chart with no indication either was happening. */
|
||||
loading?: boolean
|
||||
error?: string
|
||||
/** Renders ErrorState's own "Retry" button — SpendPage.vue's own spend.refresh (fetchBurndown has no standalone public retry of its own). */
|
||||
onRetry?: () => void | Promise<void>
|
||||
}>()
|
||||
|
||||
const state = computed(() => loadState({ loading: props.loading ?? false, hasData: props.buckets.length > 0, error: props.error ?? '' }))
|
||||
|
||||
const labels = computed<string[]>(() => props.buckets.map((b) => formatBucketLabel(b, 'day')))
|
||||
const cumulativePoints = computed<number[]>(() => cumulative(props.points))
|
||||
const spentMicros = computed<number>(() => cumulativePoints.value.at(-1) ?? 0)
|
||||
@@ -60,33 +70,37 @@ const willExceed = computed<boolean>(() => props.budgetMicros !== null && spentM
|
||||
<CardDescription>Cumulative spend this UTC calendar month against the configured budget.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-2 gap-4 text-sm sm:grid-cols-3">
|
||||
<div>
|
||||
<p class="text-muted-foreground">Spent so far</p>
|
||||
<p class="text-lg font-semibold tabular-nums" :class="willExceed ? 'text-destructive' : undefined">
|
||||
{{ formatCost(spentMicros) }}
|
||||
</p>
|
||||
<SkeletonChart v-if="state === 'skeleton'" />
|
||||
<ErrorState v-else-if="state === 'error'" :message="error ?? ''" :on-retry="onRetry" />
|
||||
<template v-else>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm sm:grid-cols-3">
|
||||
<div>
|
||||
<p class="text-muted-foreground">Spent so far</p>
|
||||
<p class="text-lg font-semibold tabular-nums" :class="willExceed ? 'text-destructive' : undefined">
|
||||
{{ formatCost(spentMicros) }}
|
||||
</p>
|
||||
</div>
|
||||
<div v-if="budgetMicros !== null">
|
||||
<p class="text-muted-foreground">Budget</p>
|
||||
<p class="text-lg font-semibold tabular-nums">{{ formatCost(budgetMicros) }}</p>
|
||||
</div>
|
||||
<div v-if="budgetMicros !== null">
|
||||
<p class="text-muted-foreground">Projected run-out</p>
|
||||
<p v-if="runOut === null" class="text-sm text-muted-foreground">not enough data yet</p>
|
||||
<p v-else class="text-lg font-semibold tabular-nums" :class="willExceed ? 'text-destructive' : undefined">
|
||||
{{ runOut.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="budgetMicros !== null">
|
||||
<p class="text-muted-foreground">Budget</p>
|
||||
<p class="text-lg font-semibold tabular-nums">{{ formatCost(budgetMicros) }}</p>
|
||||
</div>
|
||||
<div v-if="budgetMicros !== null">
|
||||
<p class="text-muted-foreground">Projected run-out</p>
|
||||
<p v-if="runOut === null" class="text-sm text-muted-foreground">not enough data yet</p>
|
||||
<p v-else class="text-lg font-semibold tabular-nums" :class="willExceed ? 'text-destructive' : undefined">
|
||||
{{ runOut.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="budgetMicros === null" class="text-sm text-muted-foreground">No budget configured for this scope.</p>
|
||||
<TimeSeriesChart
|
||||
:labels="labels"
|
||||
:datasets="datasets"
|
||||
:comparison-datasets="comparisonDatasets"
|
||||
:value-formatter="formatCost"
|
||||
ariaLabel="Cumulative spend this month against the configured budget"
|
||||
/>
|
||||
<p v-if="budgetMicros === null" class="text-sm text-muted-foreground">No budget configured for this scope.</p>
|
||||
<TimeSeriesChart
|
||||
:labels="labels"
|
||||
:datasets="datasets"
|
||||
:comparison-datasets="comparisonDatasets"
|
||||
:value-formatter="formatCost"
|
||||
ariaLabel="Cumulative spend this month against the configured budget"
|
||||
/>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -6,11 +6,16 @@ import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import CompactNumber from '@/components/CompactNumber.vue'
|
||||
import CostForecastCard from '@/components/CostForecastCard.vue'
|
||||
import CsvExportButton from '@/components/CsvExportButton.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import ModelChip from '@/components/ModelChip.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
import SkeletonList from '@/components/SkeletonList.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import SortHeaderButton from '@/components/SortHeaderButton.vue'
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { valueUpdater } from '@/components/ui/table'
|
||||
import UsageBar from '@/components/UsageBar.vue'
|
||||
@@ -19,6 +24,7 @@ import { useNow } from '@/composables/useNow'
|
||||
import { useSearchQuery } from '@/composables/useSearchQuery'
|
||||
import { headroom, monthProgress, projectMonthEnd } from '@/lib/forecast'
|
||||
import { formatCost, formatExactInt, formatLimits } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { type ExpandState, clearExpandOverrides, computeExpandedItems, toggleItemExpand } from '@/lib/search-expand'
|
||||
import { BUDGET_RATIO_LABEL, type BudgetRatio, budgetRatios } from '@/lib/usage-bars'
|
||||
import { usageColumns } from '@/lib/usage-columns'
|
||||
@@ -46,6 +52,23 @@ const consumers = useConsumersStore()
|
||||
const nav = useNavStore()
|
||||
const usage = computed(() => dashboard.usage)
|
||||
|
||||
/**
|
||||
* dashboardLoadState (verify-ui-states.md #3) gates the Groups/Users
|
||||
* cards' own skeleton/error — `hasData` is "has GET /admin/api/usage EVER
|
||||
* landed", not "are there any groups/users": a fleet with genuinely zero
|
||||
* groups/users still reads 'ready' and falls through to the EXISTING
|
||||
* noGroupsConfigured/usersEmptyMessage copy below, unchanged. Mirrors
|
||||
* HomePage.vue's own identical kpiTilesState convention (verify-ui-states-2.
|
||||
* md #11: this comment named the old kpiTilesLoading identifier, since
|
||||
* renamed) — both read the same polled dashboard store. Previously
|
||||
* `noGroupsConfigured`/
|
||||
* `usersEmptyMessage` read `usage.value?.groups/users.length ?? 0 === 0`
|
||||
* directly, which was ALSO true before the first successful fetch (or
|
||||
* after a failed one) — "No groups/users configured" rendered as a false
|
||||
* fleet fact while the real state was "not loaded yet" or "failed".
|
||||
*/
|
||||
const dashboardLoadState = computed(() => loadState({ loading: !dashboard.lastUpdated, hasData: usage.value !== null, error: dashboard.error }))
|
||||
|
||||
onMounted(() => {
|
||||
void consumers.ensureConsumers()
|
||||
})
|
||||
@@ -117,6 +140,9 @@ const groupsEmptyMessage = computed(() =>
|
||||
!usage.value?.groups.length ? 'none configured' : hasQuery.value ? `no groups match "${userQuery.value}"` : 'none',
|
||||
)
|
||||
|
||||
/** noGroupsConfigured (states-plan.md item 2: "Consumers: 'No groups configured' + hint to the Config page change helper") — mirrors AccessMatrix.vue's identical own noGroupsConfigured, the Access matrix view's own copy of this same "Consumers" page fact. Only true when genuinely nothing is configured, never while a search query merely matches none (groupsEmptyMessage's own "no groups match" case keeps its plain inline text — a filter producing zero rows is a routine interaction, not a fleet-configuration fact worth the same visual weight). */
|
||||
const noGroupsConfigured = computed(() => (usage.value?.groups.length ?? 0) === 0 && !hasQuery.value)
|
||||
|
||||
/** filteredUsers is every user matching the query directly, PLUS every member of a group that matched by NAME. */
|
||||
const filteredUsers = computed<AdminUsageEntryView[]>(() => {
|
||||
const all = usage.value?.users ?? []
|
||||
@@ -301,6 +327,9 @@ function groupsCsv(): string {
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonList v-if="dashboardLoadState === 'skeleton'" :rows="3" />
|
||||
<ErrorState v-else-if="dashboardLoadState === 'error'" :message="dashboard.error" :on-retry="dashboard.refresh" />
|
||||
<template v-else>
|
||||
<div v-if="sortedGroupRows.length" class="mb-3 flex flex-wrap gap-x-4 gap-y-1 text-xs font-medium text-muted-foreground">
|
||||
<SortHeaderButton v-for="header in toolbarHeaders" :key="header.id" :header="header" />
|
||||
</div>
|
||||
@@ -334,7 +363,8 @@ function groupsCsv(): string {
|
||||
:key="providerName"
|
||||
as="span"
|
||||
variant="secondary"
|
||||
class="font-mono font-normal"
|
||||
class="max-w-full truncate font-mono font-normal"
|
||||
:title="providerName"
|
||||
>
|
||||
{{ providerName }}
|
||||
</Badge>
|
||||
@@ -348,7 +378,7 @@ function groupsCsv(): string {
|
||||
<div v-if="row.original.models?.length" class="flex flex-wrap gap-1.5">
|
||||
<template v-for="modelId in row.original.models" :key="modelId">
|
||||
<ModelChip v-if="!isGlobPattern(modelId)" :id="modelId" />
|
||||
<Badge v-else as="span" variant="secondary" class="font-mono font-normal">{{ modelId }}</Badge>
|
||||
<Badge v-else as="span" variant="secondary" class="max-w-full truncate font-mono font-normal" :title="modelId">{{ modelId }}</Badge>
|
||||
</template>
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground">All models</span>
|
||||
@@ -363,7 +393,8 @@ function groupsCsv(): string {
|
||||
:key="serverName"
|
||||
as="span"
|
||||
variant="secondary"
|
||||
class="font-mono font-normal"
|
||||
class="max-w-full truncate font-mono font-normal"
|
||||
:title="serverName"
|
||||
>
|
||||
{{ serverName }}
|
||||
</Badge>
|
||||
@@ -375,7 +406,14 @@ function groupsCsv(): string {
|
||||
<dt class="text-xs text-muted-foreground" :title="GLOB_HINT">Agents</dt>
|
||||
<dd>
|
||||
<div v-if="row.original.agents?.length" class="flex flex-wrap gap-1.5">
|
||||
<Badge v-for="agentName in row.original.agents" :key="agentName" as="span" variant="secondary" class="font-mono font-normal">
|
||||
<Badge
|
||||
v-for="agentName in row.original.agents"
|
||||
:key="agentName"
|
||||
as="span"
|
||||
variant="secondary"
|
||||
class="max-w-full truncate font-mono font-normal"
|
||||
:title="agentName"
|
||||
>
|
||||
{{ agentName }}
|
||||
</Badge>
|
||||
</div>
|
||||
@@ -467,7 +505,11 @@ function groupsCsv(): string {
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
<EmptyState v-else-if="noGroupsConfigured" title="No groups configured." description="Grant a group access from the Config page's change helper.">
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config', { helper: 'grant' })">Open change helper</Button>
|
||||
</EmptyState>
|
||||
<p v-else class="py-6 text-center text-sm text-muted-foreground">{{ groupsEmptyMessage }}</p>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -482,7 +524,10 @@ function groupsCsv(): string {
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonTable v-if="dashboardLoadState === 'skeleton'" :rows="5" :cols="5" />
|
||||
<ErrorState v-else-if="dashboardLoadState === 'error'" :message="dashboard.error" :on-retry="dashboard.refresh" />
|
||||
<UsageTable
|
||||
v-else
|
||||
id-label="Name"
|
||||
secondary-column-label="Group"
|
||||
:entries="filteredUsers"
|
||||
|
||||
@@ -60,6 +60,14 @@ async function onClick(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
try {
|
||||
// Inline feedback ONLY (verify-ui-states.md #9 fix) — this used to
|
||||
// ALSO push a toast on failure, on top of the button's own "Export
|
||||
// failed" label/icon swap right at the click target: two
|
||||
// notifications for the one event, exactly the double-notify
|
||||
// states-plan.md item 3 says to avoid ("keep one, don't
|
||||
// double-notify"). The inline state is immediate, contextual, and
|
||||
// already dismisses itself after FEEDBACK_MS — a toast added nothing
|
||||
// a reader watching the button they just clicked wouldn't already see.
|
||||
feedback.value = await downloadText(props.filename, props.build())
|
||||
clearFeedbackAfterDelay()
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { faInbox } from '@fortawesome/free-solid-svg-icons'
|
||||
import type { IconDefinition } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
/**
|
||||
* EmptyState is the ONE shared "nothing to show, and that's expected"
|
||||
* placeholder every table/list/card in this panel uses instead of an
|
||||
* ad-hoc "no X configured"/"no traffic" text line (states-plan.md item
|
||||
* 2) — an icon, a short title, a one-line description, and an optional
|
||||
* action (a button/link via the default slot, e.g. "Try a longer range"
|
||||
* or a link to the Config page's change helper). `role="status"` — this
|
||||
* is informational, not an error, so it is announced politely
|
||||
* (aria-live="polite" semantics), matching ErrorState.vue's own
|
||||
* `role="alert"` counterpart for the destructive case.
|
||||
*/
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
icon?: IconDefinition
|
||||
title: string
|
||||
description?: string
|
||||
}>(),
|
||||
{ icon: () => faInbox },
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div role="status" class="flex flex-col items-center gap-2 px-4 py-8 text-center">
|
||||
<FontAwesomeIcon :icon="icon" class="size-6 text-muted-foreground/60" aria-hidden="true" />
|
||||
<p class="text-sm font-medium text-foreground">{{ title }}</p>
|
||||
<p v-if="description" class="max-w-sm text-sm text-muted-foreground">{{ description }}</p>
|
||||
<div v-if="$slots.default" class="mt-1">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -27,6 +27,19 @@ const props = defineProps<{
|
||||
kind: 'user' | 'model'
|
||||
/** The raw entity id (never pre-formatted as "kind:id" — this component builds nav.goTo's own params itself). */
|
||||
id: string
|
||||
/**
|
||||
* Applied to the inner label `<span>`, never the root `<button>`
|
||||
* (verify-ui-states.md #10 fix). A caller that used to pass `truncate`
|
||||
* through the root's own fallthrough `class` got a hard clip with no
|
||||
* "…" and the trailing icon clipped away too: `text-overflow: ellipsis`
|
||||
* only renders on the element whose own overflow is hidden, and
|
||||
* `min-width: auto` on an inline-flex child ignores the parent's
|
||||
* shrunk width — the label never actually shrank enough to overflow.
|
||||
* Passing `truncate` here instead lets the label span (which also gets
|
||||
* `min-w-0` unconditionally, see the template) genuinely truncate with
|
||||
* an ellipsis while the icon (`shrink-0`) stays fully visible.
|
||||
*/
|
||||
labelClass?: string
|
||||
}>()
|
||||
|
||||
const nav = useNavStore()
|
||||
@@ -48,10 +61,10 @@ function onClick(event: MouseEvent): void {
|
||||
type="button"
|
||||
:aria-label="`View ${label} in ${TARGET[kind].noun}`"
|
||||
:title="`View ${label} in ${TARGET[kind].noun}`"
|
||||
class="inline-flex cursor-pointer items-center gap-1 rounded-sm text-inherit hover:text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
|
||||
class="inline-flex min-w-0 cursor-pointer items-center gap-1 rounded-sm text-inherit hover:text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
|
||||
@click="onClick"
|
||||
>
|
||||
<span>{{ label }}</span>
|
||||
<FontAwesomeIcon :icon="faArrowUpRightFromSquare" class="size-3" aria-hidden="true" />
|
||||
<span class="min-w-0" :class="labelClass">{{ label }}</span>
|
||||
<FontAwesomeIcon :icon="faArrowUpRightFromSquare" class="size-3 shrink-0" aria-hidden="true" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { faArrowRotateRight, faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
/**
|
||||
* ErrorState is EmptyState.vue's destructive counterpart (states-plan.md
|
||||
* item 2) — a fetch for the CURRENT selection failed and there is no
|
||||
* data underneath it to fall back to (lib/load-state.ts's loadState:
|
||||
* 'error', not 'ready' — a background refresh failure while data is
|
||||
* ALREADY shown never reaches this component, it surfaces via a toast
|
||||
* instead, stores/toasts.ts). `message` is the server/network error
|
||||
* string already surfaced by lib/api.ts's AdminApiError, shown verbatim
|
||||
* — never re-worded, so what the reader sees matches what actually
|
||||
* failed. `onRetry`, when given, renders a "Retry" button calling the
|
||||
* store's own refresh/ensure action; omitted for a view with no single
|
||||
* refresh action to re-run (rare — most stores in this panel expose
|
||||
* one). `role="alert"` announces this assertively, unlike EmptyState's
|
||||
* polite `role="status"`.
|
||||
*/
|
||||
const props = defineProps<{
|
||||
message: string
|
||||
onRetry?: () => void | Promise<void>
|
||||
}>()
|
||||
|
||||
/**
|
||||
* retrying (verify-ui-states.md #6 lows: "Retry shows progress (disabled +
|
||||
* spinner/text) while retrying") is LOCAL, not read off the caller's own
|
||||
* store loading flag — several call sites' `onRetry` (consumers.
|
||||
* fetchConsumers, events.refresh) do not clear their store's `error`
|
||||
* before re-fetching, so `loadState` would stay 'error' with no in-flight
|
||||
* signal at all if this depended on that. Tracking the retry promise here
|
||||
* instead works for every caller uniformly, and disabling the button while
|
||||
* it is in flight also closes the "repeated clicks fire parallel requests"
|
||||
* gap those same actions have no guard against.
|
||||
*/
|
||||
const retrying = ref(false)
|
||||
|
||||
async function onRetryClick(): Promise<void> {
|
||||
if (!props.onRetry || retrying.value) return
|
||||
retrying.value = true
|
||||
try {
|
||||
await props.onRetry()
|
||||
} finally {
|
||||
retrying.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div role="alert" class="flex flex-col items-center gap-2 px-4 py-8 text-center">
|
||||
<FontAwesomeIcon :icon="faTriangleExclamation" class="size-6 text-destructive" aria-hidden="true" />
|
||||
<p class="max-w-full break-words text-sm font-medium text-destructive">{{ message }}</p>
|
||||
<Button v-if="onRetry" type="button" variant="outline" size="sm" class="mt-1" :disabled="retrying" @click="onRetryClick">
|
||||
<FontAwesomeIcon
|
||||
:icon="faArrowRotateRight"
|
||||
class="size-3.5"
|
||||
:class="retrying ? 'animate-spin motion-reduce:animate-none' : undefined"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{{ retrying ? 'Retrying…' : 'Retry' }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,16 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'
|
||||
import { faCircleCheck, faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed, onMounted, onUnmounted } from 'vue'
|
||||
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { useSearchQuery } from '@/composables/useSearchQuery'
|
||||
import { eventsColumns } from '@/lib/events-columns'
|
||||
import { EVENT_KIND_LABEL, EVENT_KINDS, filterEvents } from '@/lib/events-filter'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { useEventsStore } from '@/stores/events'
|
||||
|
||||
// This component backs the new "Events" tab (App.vue, F3) — GET
|
||||
@@ -49,21 +53,42 @@ function onKindChange(value: unknown): void {
|
||||
const columns = eventsColumns()
|
||||
|
||||
/**
|
||||
* emptyMessage mirrors TargetsView.vue/ConsumerDirectory.vue's own
|
||||
* three-way pattern: distinguishes "nothing recorded at all" from
|
||||
* "nothing matches the active filter".
|
||||
*
|
||||
* P9 review fix: gated on events.lastUpdated (null until the first fetch
|
||||
* settles, stores/events.ts) — this used to read events.events.length
|
||||
* directly, which is an empty array from the store's OWN initial state,
|
||||
* before any fetch has even started. That produced "no events recorded"
|
||||
* for a fraction of a second (or longer, on a slow poll) on every mount,
|
||||
* indistinguishable from the real "genuinely nothing has ever happened"
|
||||
* case — a false negative, not a loading state.
|
||||
* eventsLoadState (lib/load-state.ts) replaces the old lone
|
||||
* `!events.lastUpdated` check this view used everywhere: 'skeleton' for
|
||||
* the first fetch, 'error' when that first fetch itself failed (P9's own
|
||||
* false-negative bug — an initial-load FAILURE used to render the exact
|
||||
* same "loading…" text as a genuine in-flight load, forever, since
|
||||
* events.error was never even read here), 'ready' once there is a
|
||||
* successful fetch to show (an EMPTY events list after a successful
|
||||
* fetch is still 'ready' — DataTable's own emptyMessage below renders
|
||||
* the real "no events recorded" row, not this card-level state). A
|
||||
* LATER background-poll failure, with events already on screen, stays
|
||||
* 'ready' too (stores/events.ts's own toast covers that case instead —
|
||||
* states-plan.md item 3 — so content is never wiped/replaced by a
|
||||
* skeleton or error here).
|
||||
*/
|
||||
const eventsLoadState = computed(() => loadState({ loading: events.refreshing, hasData: events.lastUpdated !== null, error: events.error }))
|
||||
|
||||
/**
|
||||
* noEventsRecorded is the GENUINE "nothing has ever happened" case
|
||||
* (states-plan.md item 2: "Events/Reliability: 'No failures recorded'
|
||||
* (positive tone, success icon)") — renders EmptyState instead of an
|
||||
* empty DataTable row, since a clean fleet is worth a reassuring visual,
|
||||
* not just quiet table text. Distinct from "nothing matches the active
|
||||
* filter" below, which stays a plain inline DataTable row: a filter
|
||||
* producing zero rows is a routine, low-stakes interaction, not a
|
||||
* fleet-health signal worth the same visual weight.
|
||||
*
|
||||
* The copy below deliberately does NOT say "in this range" (verify-ui-
|
||||
* states.md #11 fix): the events store fetches the last EVENTS_LIMIT
|
||||
* events (stores/events.ts: GET /admin/api/events?limit=200), unscoped by
|
||||
* the global range filter — "in this range" would misleadingly imply a
|
||||
* narrower window filtered this list down to zero.
|
||||
*/
|
||||
const noEventsRecorded = computed(() => events.events.length === 0)
|
||||
|
||||
/** emptyMessage is DataTable's own inline empty-row text for the "some events exist, but the active filter matches none" case — only ever rendered while noEventsRecorded is false (see the template below). */
|
||||
const emptyMessage = computed(() => {
|
||||
if (!events.lastUpdated) return 'loading…'
|
||||
if (events.events.length === 0) return 'no events recorded'
|
||||
if (kindFilter.value !== '' || normalizedUserQuery.value) return 'no events match the current filter'
|
||||
return 'none'
|
||||
})
|
||||
@@ -71,17 +96,11 @@ const emptyMessage = computed(() => {
|
||||
/**
|
||||
* sourceCaption states plainly whether the list below is fleet-wide or
|
||||
* this-replica-only — the Events view must never present a replica-only
|
||||
* fallback as if it were the fleet-wide picture.
|
||||
*
|
||||
* P9 review fix: gated on events.lastUpdated, mirroring emptyMessage's own
|
||||
* doc comment above — the store's initial state (source: 'replica',
|
||||
* replica: '', capacity: 0) otherwise rendered as "This replica only
|
||||
* (unknown) — Redis is unreachable or unconfigured" before the first
|
||||
* fetch had even resolved, misreporting a genuine degraded-Redis state
|
||||
* that had not actually been observed yet.
|
||||
* fallback as if it were the fleet-wide picture. Only rendered while
|
||||
* eventsLoadState is 'ready' (see the template below), so this never
|
||||
* reads the store's pristine initial source/replica/capacity values.
|
||||
*/
|
||||
const sourceCaption = computed(() => {
|
||||
if (!events.lastUpdated) return 'loading…'
|
||||
if (events.source === 'redis') return 'Fleet-wide, across every replica'
|
||||
return `This replica only (${events.replica || 'unknown'}) — Redis is unreachable or unconfigured`
|
||||
})
|
||||
@@ -109,9 +128,8 @@ onUnmounted(() => {
|
||||
<CardHeader class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Events</CardTitle>
|
||||
<!-- P9: a loading state until the first fetch settles (events.lastUpdated), instead of showing the store's initial (pre-fetch) source/capacity as if it were real. -->
|
||||
<CardDescription v-if="!events.lastUpdated">Loading…</CardDescription>
|
||||
<CardDescription v-else>
|
||||
<!-- Only rendered once there is a real fetch to describe (eventsLoadState 'ready') — 'skeleton'/'error' show nothing here, the CardContent body below already signals which of those it is. -->
|
||||
<CardDescription v-if="eventsLoadState === 'ready'">
|
||||
{{ sourceCaption }} — rate limit, budget, and upstream events, newest first (capacity
|
||||
{{ events.capacity }}).
|
||||
</CardDescription>
|
||||
@@ -130,8 +148,15 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p v-if="events.error" class="mb-3 text-sm text-destructive">{{ events.error }}</p>
|
||||
<DataTable :columns="columns" :data="filteredEvents" :empty-message="emptyMessage" />
|
||||
<SkeletonTable v-if="eventsLoadState === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="eventsLoadState === 'error'" :message="events.error" :on-retry="events.refresh" />
|
||||
<EmptyState
|
||||
v-else-if="noEventsRecorded"
|
||||
:icon="faCircleCheck"
|
||||
title="No failures recorded."
|
||||
description="Rate-limit, budget, and upstream events will show up here as they happen."
|
||||
/>
|
||||
<DataTable v-else :columns="columns" :data="filteredEvents" :empty-message="emptyMessage" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -2,12 +2,18 @@
|
||||
import { computed } from 'vue'
|
||||
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { filterModelRows } from '@/lib/model-filter'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { modelCatalogColumns } from '@/lib/model-table-columns'
|
||||
import type { ModelCatalogRow } from '@/lib/model-table-columns'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
|
||||
/**
|
||||
* ModelCatalogTable (redesign-plan.md section 3.4, Models & providers
|
||||
@@ -27,17 +33,35 @@ const props = defineProps<{
|
||||
/** GET /admin/api/performance's own latencyEnabled (AdminPerfResponse) — false means admin.stats.latency is off, so p50/p95 read "—" for every row, not "no traffic yet". */
|
||||
latencyEnabled: boolean
|
||||
loading: boolean
|
||||
/** models.error (verify-ui-states.md #3 fix) — ModelsPage.vue's own current-fetch error, '' when there is none. Previously this component always passed error: '' into loadState below, so a fetch that failed with no rows yet rendered "No models configured." (a false fleet fact) instead of ErrorState. */
|
||||
error?: string
|
||||
/** Renders ErrorState's own "Retry" button — ModelsPage.vue's own models.fetch. */
|
||||
onRetry?: () => void | Promise<void>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ 'update:query': [value: string] }>()
|
||||
|
||||
const nav = useNavStore()
|
||||
|
||||
const filtered = computed<ModelCatalogRow[]>(() => filterModelRows(props.rows, props.query))
|
||||
|
||||
const columns = modelCatalogColumns()
|
||||
|
||||
/**
|
||||
* catalogLoadState (lib/load-state.ts, verify-ui-states.md #3 fix) now
|
||||
* reads the REAL `error` prop, not a hardcoded ''. A not-yet-loaded (or
|
||||
* failed) catalog used to render "No models configured." — a false fleet
|
||||
* fact — for BOTH "still fetching" and "the fetch failed with zero rows"
|
||||
* cases alike, since `error: ''` meant loadState could only ever resolve
|
||||
* to 'skeleton' or 'empty', never 'error'. ModelsPage.vue's own top-level
|
||||
* `models.error` paragraph stays alongside this (it also covers a
|
||||
* background refresh failure while rows are already on screen, which
|
||||
* never reaches this component's own ErrorState — loadState's 'ready'
|
||||
* precedence keeps existing rows on screen through that case).
|
||||
*/
|
||||
const catalogLoadState = computed(() => loadState({ loading: props.loading, hasData: props.rows.length > 0, error: props.error ?? '' }))
|
||||
|
||||
const emptyMessage = computed<string>(() => {
|
||||
if (props.loading) return 'loading…'
|
||||
if (props.rows.length === 0) return 'no models configured'
|
||||
if (props.query.trim()) return `no models match "${props.query}"`
|
||||
return 'none'
|
||||
})
|
||||
@@ -59,11 +83,16 @@ const emptyMessage = computed<string>(() => {
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<Alert v-if="!latencyEnabled" variant="warn">
|
||||
<AlertDescription>
|
||||
Latency percentiles (p50/p95) are off for this deployment. Enable <code>admin.stats.latency</code> to see them.
|
||||
<AlertTitle>Latency statistics are off</AlertTitle>
|
||||
<AlertDescription class="flex flex-wrap items-center gap-2">
|
||||
<span>Enable <code>admin.stats.latency</code> in the middleware config to see fleet p50/p95.</span>
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config')">Open Config</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<DataTable :columns="columns" :data="filtered" :empty-message="emptyMessage" />
|
||||
<SkeletonTable v-if="catalogLoadState === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="catalogLoadState === 'error'" :message="error ?? ''" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="catalogLoadState === 'empty'" title="No models configured." />
|
||||
<DataTable v-else :columns="columns" :data="filtered" :empty-message="emptyMessage" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { computed, onUnmounted, ref, useTemplateRef } from 'vue'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { copyText } from '@/lib/clipboard'
|
||||
import { formatContextWindow, formatModelCostHover } from '@/lib/format'
|
||||
import { useToastsStore } from '@/stores/toasts'
|
||||
|
||||
/**
|
||||
* ModelChip is one clickable, copyable model-id chip, used anywhere a
|
||||
@@ -51,6 +52,7 @@ const props = defineProps<{
|
||||
const labelRef = useTemplateRef<HTMLElement>('label')
|
||||
const state = ref<'idle' | 'copied' | 'selected' | 'failed'>('idle')
|
||||
let resetTimer: ReturnType<typeof setTimeout> | undefined
|
||||
const toasts = useToastsStore()
|
||||
|
||||
function scheduleReset(): void {
|
||||
clearTimeout(resetTimer)
|
||||
@@ -64,8 +66,13 @@ async function onClick(): Promise<void> {
|
||||
// 'failed' (neither the Clipboard API nor the selection fallback
|
||||
// worked) gets its own visible state rather than a silent no-op — a
|
||||
// click that visibly does nothing reads as a broken button, not as
|
||||
// "nothing to report".
|
||||
// "nothing to report". Only a FAILURE also gets a toast (states-plan.md
|
||||
// item 3) — 'copied'/'selected' already have clear, accessible inline
|
||||
// feedback right at the click target (the icon swap plus this same
|
||||
// title/aria-label text), so a success toast on top would double-notify
|
||||
// for something the reader is already looking straight at.
|
||||
state.value = result
|
||||
if (result === 'failed') toasts.push({ kind: 'error', message: `Could not copy ${props.id}.` })
|
||||
scheduleReset()
|
||||
}
|
||||
|
||||
@@ -123,13 +130,13 @@ onUnmounted(() => {
|
||||
as="button"
|
||||
type="button"
|
||||
variant="secondary"
|
||||
class="cursor-pointer gap-1 font-mono text-xs font-normal transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
class="max-w-full cursor-pointer gap-1 truncate font-mono text-xs font-normal transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
:class="state === 'failed' ? 'text-destructive' : ''"
|
||||
:title="title"
|
||||
:aria-label="title"
|
||||
@click="onClick"
|
||||
>
|
||||
<span ref="label" class="select-text">{{ id }}</span>
|
||||
<span ref="label" class="min-w-0 truncate select-text">{{ id }}</span>
|
||||
<FontAwesomeIcon :icon="icon[state]" class="size-2.5 shrink-0" aria-hidden="true" />
|
||||
</Badge>
|
||||
</template>
|
||||
|
||||
@@ -5,11 +5,16 @@ import { computed, h } from 'vue'
|
||||
import CompactNumber from '@/components/CompactNumber.vue'
|
||||
import CsvExportButton from '@/components/CsvExportButton.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import EntityLink from '@/components/EntityLink.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import TryLongerRangeButton from '@/components/TryLongerRangeButton.vue'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { toCsv } from '@/lib/csv'
|
||||
import { formatContextWindow, formatCost, formatModelCostHover } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { joinPricingHealth, pricingHealthOrder } from '@/lib/pricing-health'
|
||||
import type { PricingHealthRow } from '@/lib/pricing-health'
|
||||
import type { AdminCatalogModel, AdminUsageModelEntry, PriceSource } from '@/types/api'
|
||||
@@ -21,14 +26,37 @@ import type { AdminCatalogModel, AdminUsageModelEntry, PriceSource } from '@/typ
|
||||
* destructive badge (pricingHealthOrder) — the row an operator most needs
|
||||
* to act on (a served model billing at $0 because no pricing rule
|
||||
* matched) is always the first thing they see, before any manual sort.
|
||||
*
|
||||
* `loading`/`error` (verify-ui-states.md #3/#7 fix): this card had NO
|
||||
* loading or error input at all before — `spend.pricingHealthRanking` /
|
||||
* `catalog.modelsById` both start empty, so the very first Spend load, and
|
||||
* any failed Spend/catalog fetch, rendered the identical "No traffic in
|
||||
* this range." a genuinely empty fleet gets, with no way to tell the three
|
||||
* apart.
|
||||
*
|
||||
* `loaded` (verify-ui-states-2.md #2 fix): `hasData` below is "has a fetch
|
||||
* completed for the current range" (spend.pricingHealthLoaded), not
|
||||
* `rows.length > 0` — the 60s poll (stores/spend.ts's own refresh())
|
||||
* flips `loading` true on every tick, and a genuinely empty pricing-health
|
||||
* table used to flash a skeleton back on for each of those ticks. The
|
||||
* template below still checks `rows.length` directly for EmptyState vs.
|
||||
* the real table, the same way UserDetail.vue's own "Models used" table
|
||||
* does.
|
||||
*/
|
||||
const props = defineProps<{
|
||||
models: AdminUsageModelEntry[]
|
||||
catalog: Map<string, AdminCatalogModel>
|
||||
loading: boolean
|
||||
loaded: boolean
|
||||
error: string
|
||||
/** Renders ErrorState's own "Retry" button — SpendPage.vue's own spend.fetchPricingHealthRanking. */
|
||||
onRetry?: () => void | Promise<void>
|
||||
}>()
|
||||
|
||||
const rows = computed<PricingHealthRow[]>(() => pricingHealthOrder(joinPricingHealth(props.models, props.catalog)))
|
||||
|
||||
const state = computed(() => loadState({ loading: props.loading, hasData: props.loaded, error: props.error }))
|
||||
|
||||
const unpricedCount = computed<number>(() => rows.value.filter((r) => r.priceSource === 'unpriced').length)
|
||||
|
||||
/** SOURCE_BADGE_VARIANT mirrors lib/model-table-columns.ts's own priceCell badge treatment (WP-F, ModelCatalogTable.vue) so the two tables read consistently: destructive for unpriced (needs attention), secondary for a deliberate free model, outline for an explicit rule. */
|
||||
@@ -143,10 +171,17 @@ function pricingHealthCsv(): string {
|
||||
<CardDescription>Every model served in range, joined with its billing price source.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<DataTable :columns="columns" :data="rows" empty-message="No model served any traffic in this range." />
|
||||
<div class="flex justify-end">
|
||||
<CsvExportButton filename="pricing-health.csv" :build="pricingHealthCsv" />
|
||||
</div>
|
||||
<SkeletonTable v-if="state === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="state === 'error'" :message="error" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="rows.length === 0" title="No traffic in this range.">
|
||||
<TryLongerRangeButton />
|
||||
</EmptyState>
|
||||
<template v-else>
|
||||
<DataTable :columns="columns" :data="rows" empty-message="none" />
|
||||
<div class="flex justify-end">
|
||||
<CsvExportButton filename="pricing-health.csv" :build="pricingHealthCsv" />
|
||||
</div>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -9,12 +9,15 @@ import { computed, h, reactive, watch } from 'vue'
|
||||
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EntityLink from '@/components/EntityLink.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import ModelChip from '@/components/ModelChip.vue'
|
||||
import ProviderRateBadge from '@/components/ProviderRateBadge.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
import SkeletonList from '@/components/SkeletonList.vue'
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -24,6 +27,7 @@ import {
|
||||
} from '@/components/ui/card'
|
||||
import { useSearchQuery } from '@/composables/useSearchQuery'
|
||||
import { formatAgo, formatContextWindow, formatLatencyMs, formatUntil, refreshDetailLabel, refreshLabel, routableModelId } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { isModelDegraded } from '@/lib/provider-rate'
|
||||
import { type ExpandState, clearExpandOverrides, computeExpandedItems, toggleItemExpand } from '@/lib/search-expand'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
@@ -86,6 +90,19 @@ function aliasMatches(a: AdminAliasView): boolean {
|
||||
return a.alias.toLowerCase().includes(normalizedQuery.value) || a.target.toLowerCase().includes(normalizedQuery.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* providersLoadState (live-preview fix, same class of bug as
|
||||
* lib/access-matrix.ts's matrixColumnsState / TargetsView.vue's
|
||||
* targetsLoadState) — `overview` maps a not-yet-loaded dashboard.overview
|
||||
* straight to `[]` via `?? []` below, which the template used to render as
|
||||
* a confirmed "none" (no providers configured at all) before the 5s
|
||||
* dashboard poll's first response had even landed. `loading: true` mirrors
|
||||
* those same two call sites' own idiom: it is only ever consulted once
|
||||
* `hasData` (dashboard.overview !== null) is already false, so there is
|
||||
* nothing else to fall back to but a skeleton or the dashboard's own error.
|
||||
*/
|
||||
const providersLoadState = computed(() => loadState({ loading: true, hasData: overview.value !== null, error: dashboard.error }))
|
||||
|
||||
const filteredProviders = computed<AdminProviderView[]>(() => {
|
||||
const all = overview.value?.providers ?? []
|
||||
return hasQuery.value ? all.filter(providerMatches) : all
|
||||
@@ -340,11 +357,15 @@ const aliasEmptyMessage = computed(() =>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<Alert v-if="!models.latencyEnabled" variant="warn">
|
||||
<AlertDescription>
|
||||
Fleet p50/p95 are off for this deployment. Enable <code>admin.stats.latency</code> to see them.
|
||||
<AlertTitle>Latency statistics are off</AlertTitle>
|
||||
<AlertDescription class="flex flex-wrap items-center gap-2">
|
||||
<span>Enable <code>admin.stats.latency</code> in the middleware config to see fleet p50/p95.</span>
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config')">Open Config</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<p v-if="!overview?.providers.length" class="py-6 text-center text-sm text-muted-foreground">none</p>
|
||||
<SkeletonList v-if="providersLoadState === 'skeleton'" :rows="3" />
|
||||
<ErrorState v-else-if="providersLoadState === 'error'" :message="dashboard.error" :on-retry="dashboard.refresh" />
|
||||
<p v-else-if="!overview?.providers.length" class="py-6 text-center text-sm text-muted-foreground">none</p>
|
||||
<p
|
||||
v-else-if="hasQuery && filteredProviders.length === 0"
|
||||
class="py-6 text-center text-sm text-muted-foreground"
|
||||
@@ -485,14 +506,14 @@ const aliasEmptyMessage = computed(() =>
|
||||
</div>
|
||||
</dl>
|
||||
<div v-if="visibleModels(p).length" class="flex flex-wrap gap-1.5">
|
||||
<span v-for="m in visibleModels(p)" :key="m" class="inline-flex items-center gap-1">
|
||||
<span v-for="m in visibleModels(p)" :key="m" class="inline-flex min-w-0 max-w-full items-center gap-1">
|
||||
<ModelChip
|
||||
:id="routableModelId(p.name, m)"
|
||||
:context-tokens="modelMetaFor(p, m).contextTokens"
|
||||
:input-per-m-tok-usd="modelMetaFor(p, m).inputPerMTokUsd"
|
||||
:output-per-m-tok-usd="modelMetaFor(p, m).outputPerMTokUsd"
|
||||
/>
|
||||
<EntityLink :label="routableModelId(p.name, m)" kind="model" :id="routableModelId(p.name, m)" />
|
||||
<EntityLink :label="routableModelId(p.name, m)" kind="model" :id="routableModelId(p.name, m)" class="min-w-0" label-class="truncate" />
|
||||
<span
|
||||
v-if="modelMetaFor(p, m).contextTokens !== undefined"
|
||||
title="context window"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
/**
|
||||
* SkeletonChart is a fixed-aspect placeholder matching
|
||||
* TimeSeriesChart.vue's own container exactly (`h-72 w-full`) — every
|
||||
* chart in this panel (Spend's breakdown, Reliability's per-provider
|
||||
* error rate, BurnDownChart, UserDetail's per-user charts) renders inside
|
||||
* that same fixed height, so swapping this in for the first load never
|
||||
* shifts the layout once the real chart mounts.
|
||||
*/
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-72 w-full">
|
||||
<Skeleton class="h-full w-full" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
/**
|
||||
* SkeletonKpiTile mirrors KpiTile.vue's own Card/CardContent structure
|
||||
* and spacing exactly — label, value, and delta lines at the same
|
||||
* heights — so a KPI grid swapping this in for real tiles on first load
|
||||
* causes no layout shift once the real values arrive.
|
||||
*/
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card>
|
||||
<CardContent class="flex flex-col gap-1 px-4 py-3">
|
||||
<Skeleton class="h-3 w-20" />
|
||||
<Skeleton class="h-7 w-16" />
|
||||
<Skeleton class="h-3 w-28" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
/**
|
||||
* SkeletonList mirrors TopList.vue's own ranked-row shape (rank number,
|
||||
* label, right-aligned value) — `rows` pulsing rows, defaulting to 5 to
|
||||
* match "top 5" lists, so a list card swapping this in for its first load
|
||||
* causes no layout shift once real rows arrive.
|
||||
*/
|
||||
withDefaults(defineProps<{ rows?: number }>(), { rows: 5 })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ol class="flex flex-col gap-1.5">
|
||||
<li v-for="r in rows" :key="r" class="flex items-center justify-between gap-3">
|
||||
<span class="flex min-w-0 flex-1 items-center gap-2">
|
||||
<Skeleton class="h-3 w-4 shrink-0" />
|
||||
<Skeleton class="h-4 w-full max-w-40" />
|
||||
</span>
|
||||
<Skeleton class="h-4 w-12 shrink-0" />
|
||||
</li>
|
||||
</ol>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||
|
||||
/**
|
||||
* SkeletonTable is a placeholder shaped exactly like DataTable.vue's own
|
||||
* rendered table — the same Table/TableRow/TableHead/TableCell
|
||||
* primitives, `rows` x `cols` pulsing cells — so a table view swapping
|
||||
* this in for its first load causes no layout shift once real rows
|
||||
* arrive. `cols` defaults to 4, the panel's most common table width;
|
||||
* callers with a narrower or wider table pass their own column count.
|
||||
*/
|
||||
withDefaults(defineProps<{ rows?: number; cols?: number }>(), { rows: 5, cols: 4 })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead v-for="c in cols" :key="c">
|
||||
<Skeleton class="h-4 w-16" />
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="r in rows" :key="r">
|
||||
<TableCell v-for="c in cols" :key="c">
|
||||
<Skeleton class="h-4 w-full max-w-32" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</template>
|
||||
@@ -4,6 +4,7 @@ import { onUnmounted, ref, useTemplateRef } from 'vue'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { copyText } from '@/lib/clipboard'
|
||||
import { useToastsStore } from '@/stores/toasts'
|
||||
|
||||
/**
|
||||
* SnippetBlock (redesign-plan.md section 3.4) is the one "here is text to
|
||||
@@ -22,9 +23,15 @@ const props = defineProps<{
|
||||
const preRef = useTemplateRef<HTMLElement>('pre')
|
||||
const state = ref<'idle' | 'copied' | 'selected' | 'failed'>('idle')
|
||||
let resetTimer: ReturnType<typeof setTimeout> | undefined
|
||||
const toasts = useToastsStore()
|
||||
|
||||
async function onCopy(): Promise<void> {
|
||||
state.value = await copyText(props.text, preRef.value ?? undefined)
|
||||
// Only a FAILURE also gets a toast (states-plan.md item 3) — see
|
||||
// ModelChip.vue's own identical doc comment: 'copied'/'selected'
|
||||
// already have clear inline feedback (the button's own icon/label
|
||||
// swap right below), so a success toast would double-notify.
|
||||
if (state.value === 'failed') toasts.push({ kind: 'error', message: 'Could not copy the snippet.' })
|
||||
clearTimeout(resetTimer)
|
||||
resetTimer = setTimeout(() => {
|
||||
state.value = 'idle'
|
||||
|
||||
@@ -3,8 +3,11 @@ import { computed, ref, watch } from 'vue'
|
||||
|
||||
import ClampedRangeNotice from '@/components/ClampedRangeNotice.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { adminFetch } from '@/lib/api'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { dayOrMonthWindow, totalsUrl } from '@/lib/range'
|
||||
import { targetCallerColumns } from '@/lib/target-columns'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
@@ -47,7 +50,8 @@ const filters = useFiltersStore()
|
||||
|
||||
const rows = ref<AdminTotalsResponse['rows']>([])
|
||||
const loading = ref(false)
|
||||
const loaded = ref(false)
|
||||
/** loadedOk is true only right after a SUCCESSFUL fetch for the CURRENT selection (even with zero rows — a genuine "no callers" answer is still data) — reset synchronously at the top of every load() call, not just on props.target changing, so a range change gets the identical "skeleton while this NEW selection's own fetch is in flight" treatment (states-plan.md item 1: a skeleton only for the current selection's own missing data, never stale data from the previous one). */
|
||||
const loadedOk = ref(false)
|
||||
const error = ref('')
|
||||
/** reqId guards against an out-of-order response overwriting a newer one (latest-request-wins, stores/catalog.ts's own convention) — a quick target switch, or a range change mid-flight, no longer risks showing a STALE target's callers under the new heading. */
|
||||
let reqId = 0
|
||||
@@ -55,6 +59,9 @@ let reqId = 0
|
||||
async function load(): Promise<void> {
|
||||
const requestId = ++reqId
|
||||
loading.value = true
|
||||
rows.value = []
|
||||
loadedOk.value = false
|
||||
error.value = ''
|
||||
try {
|
||||
const { window, span } = dayOrMonthWindow(filters.window, filters.span)
|
||||
const res = await adminFetch<AdminTotalsResponse>(
|
||||
@@ -62,15 +69,12 @@ async function load(): Promise<void> {
|
||||
)
|
||||
if (requestId !== reqId) return
|
||||
rows.value = res.rows
|
||||
error.value = ''
|
||||
loadedOk.value = true
|
||||
} catch (err) {
|
||||
if (requestId !== reqId) return
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
if (requestId === reqId) {
|
||||
loading.value = false
|
||||
loaded.value = true
|
||||
}
|
||||
if (requestId === reqId) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +86,8 @@ watch(
|
||||
|
||||
const columns = computed(() => targetCallerColumns(!props.target))
|
||||
|
||||
const emptyMessage = computed(() => {
|
||||
if (!loaded.value) return 'loading…'
|
||||
return 'no callers recorded in this window'
|
||||
})
|
||||
/** callersLoadState (lib/load-state.ts) replaces the old "loading…" text this view used to render inline as a fake DataTable empty-row — it no longer distinguished a still-loading fetch from one that had already FAILED (an initial-fetch failure rendered the identical "loading…" text forever, the same class of bug EventsView.vue's own P9 fix addressed). */
|
||||
const callersLoadState = computed(() => loadState({ loading: loading.value, hasData: loadedOk.value, error: error.value }))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -96,8 +98,9 @@ const emptyMessage = computed(() => {
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<ClampedRangeNotice :window="filters.window" :span="filters.span" />
|
||||
<p v-if="error" class="text-sm text-destructive">{{ error }}</p>
|
||||
<DataTable :columns="columns" :data="rows" :empty-message="emptyMessage" />
|
||||
<SkeletonTable v-if="callersLoadState === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="callersLoadState === 'error'" :message="error" :on-retry="load" />
|
||||
<DataTable v-else :columns="columns" :data="rows" empty-message="no callers recorded in this window" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
import { computed } from 'vue'
|
||||
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SearchInput from '@/components/SearchInput.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { useSearchQuery } from '@/composables/useSearchQuery'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { composeTargetId, targetColumns } from '@/lib/target-columns'
|
||||
import type { TargetKind } from '@/lib/target-columns'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
@@ -62,6 +66,33 @@ function emptyMessage(configuredCount: number, filteredCount: number): string {
|
||||
const mcpEmptyMessage = computed(() => emptyMessage(targets.value?.mcpServers.length ?? 0, filteredMCPServers.value.length))
|
||||
const agentsEmptyMessage = computed(() => emptyMessage(targets.value?.agents.length ?? 0, filteredAgents.value.length))
|
||||
|
||||
/**
|
||||
* targetsLoadState (lib/load-state.ts) — GET /admin/api/targets used to
|
||||
* have NO loading/error handling at all here: `targets` mapped a
|
||||
* not-yet-loaded/errored dashboard.targets straight to `[]` (`?? []`
|
||||
* above), which DataTable then rendered as a confirmed, empty table —
|
||||
* exactly the same class of bug lib/access-matrix.ts's matrixColumnsState
|
||||
* fixed for the Access matrix (Task A). 'ready' once dashboard.targets
|
||||
* has loaded at least once, even if both lists are genuinely empty —
|
||||
* `noTargetsAtAll` below is the SEPARATE "loaded, but nothing configured"
|
||||
* check, same split as matrixColumnsState's own loaded-vs-empty
|
||||
* precedence.
|
||||
*/
|
||||
const targetsLoadState = computed(() => loadState({ loading: true, hasData: dashboard.targets !== null, error: dashboard.error }))
|
||||
|
||||
/**
|
||||
* noTargetsAtAll (states-plan.md item 2: "MCP & Agents: 'No MCP servers
|
||||
* or agents configured'") is true only once targets have genuinely
|
||||
* loaded with BOTH lists empty — read off the raw configured counts, not
|
||||
* the filtered ones, so an active search query never flips this true (a
|
||||
* query matching nothing is `mcpEmptyMessage`/`agentsEmptyMessage`'s own
|
||||
* "no targets match" case instead, a routine filter interaction, not a
|
||||
* fleet-configuration fact worth the same combined empty-state).
|
||||
*/
|
||||
const noTargetsAtAll = computed(
|
||||
() => targetsLoadState.value === 'ready' && (targets.value?.mcpServers.length ?? 0) === 0 && (targets.value?.agents.length ?? 0) === 0,
|
||||
)
|
||||
|
||||
// Two separate column-def sets (lib/target-columns.ts) — MCP servers and
|
||||
// Agents each close over their own fixed `kind` (see onSelect above) so a
|
||||
// name click composes the right "mcp/…"/"agent/…" id. Stateless ColumnDef
|
||||
@@ -75,30 +106,45 @@ const agentColumns = targetColumns(onSelect('agent'))
|
||||
<div class="flex flex-col gap-6">
|
||||
<SearchInput v-model="query" placeholder="Filter MCP servers or agents" class="max-w-sm" />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>MCP servers</CardTitle>
|
||||
<CardDescription>
|
||||
Configured MCP proxy targets, the groups allowed to reach them, and their request counters. Click a name to see its
|
||||
callers.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<Card v-if="noTargetsAtAll">
|
||||
<CardContent>
|
||||
<DataTable :columns="mcpColumns" :data="filteredMCPServers" :empty-message="mcpEmptyMessage" />
|
||||
<EmptyState
|
||||
title="No MCP servers or agents configured."
|
||||
description="Add an mcpServers or agents entry to the middleware config to see them here."
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Agents</CardTitle>
|
||||
<CardDescription>
|
||||
Configured A2A agent proxy targets, the groups allowed to reach them, and their request counters. Click a name to
|
||||
see its callers.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<DataTable :columns="agentColumns" :data="filteredAgents" :empty-message="agentsEmptyMessage" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<template v-else>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>MCP servers</CardTitle>
|
||||
<CardDescription>
|
||||
Configured MCP proxy targets, the groups allowed to reach them, and their request counters. Click a name to see
|
||||
its callers.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonTable v-if="targetsLoadState === 'skeleton'" :rows="3" :cols="mcpColumns.length" />
|
||||
<ErrorState v-else-if="targetsLoadState === 'error'" :message="dashboard.error" />
|
||||
<DataTable v-else :columns="mcpColumns" :data="filteredMCPServers" :empty-message="mcpEmptyMessage" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Agents</CardTitle>
|
||||
<CardDescription>
|
||||
Configured A2A agent proxy targets, the groups allowed to reach them, and their request counters. Click a name to
|
||||
see its callers.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonTable v-if="targetsLoadState === 'skeleton'" :rows="3" :cols="agentColumns.length" />
|
||||
<ErrorState v-else-if="targetsLoadState === 'error'" :message="dashboard.error" />
|
||||
<DataTable v-else :columns="agentColumns" :data="filteredAgents" :empty-message="agentsEmptyMessage" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { faCheck, faCircleInfo, faTriangleExclamation, faXmark } from '@fortawesome/free-solid-svg-icons'
|
||||
import type { IconDefinition } from '@fortawesome/free-solid-svg-icons'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import type { Toast, ToastKind } from '@/stores/toasts'
|
||||
import { useToastsStore } from '@/stores/toasts'
|
||||
|
||||
/**
|
||||
* ToastViewport (states-plan.md item 3) is the panel's one toast stack —
|
||||
* mounted ONCE in App.vue, reading stores/toasts.ts. Bottom-right, a
|
||||
* fixed width, on desktop; a full-width bottom sheet on mobile, inset by
|
||||
* the device's own safe area (the `pb-[calc(env(safe-area-inset-bottom)…
|
||||
* )]` arbitrary value below, not an inline style — this panel styles
|
||||
* with Tailwind only).
|
||||
*
|
||||
* TWO always-mounted live regions (verify-ui-states.md #5/#6 fix,
|
||||
* replacing the earlier per-toast `role="status"`/`role="alert"`
|
||||
* approach): a live region must exist in the DOM BEFORE its content
|
||||
* changes to be reliably announced — a `role="status"`/`role="alert"`
|
||||
* node inserted already filled with text is often missed entirely
|
||||
* (NVDA/JAWS, and VoiceOver in some cases). `politeRegion` below
|
||||
* (`aria-live="polite"`) is present from this component's first render
|
||||
* and holds success/info toasts; `assertiveRegion` (`aria-live="assertive"`)
|
||||
* is likewise always present and holds error toasts — toasts render AS
|
||||
* CHILDREN into whichever already-mounted region matches their kind,
|
||||
* so only their own text content changes, which every live-region
|
||||
* implementation reliably announces. `motion-reduce:transition-none` on
|
||||
* both TransitionGroups honors prefers-reduced-motion instead of
|
||||
* animating regardless.
|
||||
*/
|
||||
const toasts = useToastsStore()
|
||||
|
||||
const ICON: Record<ToastKind, IconDefinition> = {
|
||||
success: faCheck,
|
||||
error: faTriangleExclamation,
|
||||
info: faCircleInfo,
|
||||
}
|
||||
|
||||
const ICON_CLASS: Record<ToastKind, string> = {
|
||||
success: 'text-chart-requests',
|
||||
error: 'text-destructive',
|
||||
info: 'text-muted-foreground',
|
||||
}
|
||||
|
||||
/** politeToasts/assertiveToasts split the store's single ordered list by kind — success/info are politely announced, error assertively, matching each region's own aria-live level. */
|
||||
const politeToasts = computed<Toast[]>(() => toasts.toasts.filter((t) => t.kind !== 'error'))
|
||||
const assertiveToasts = computed<Toast[]>(() => toasts.toasts.filter((t) => t.kind === 'error'))
|
||||
|
||||
function onDismiss(toast: Toast): void {
|
||||
toasts.dismiss(toast.id)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="pointer-events-none fixed inset-x-0 bottom-0 z-50 flex flex-col-reverse gap-2 p-4 pb-[calc(env(safe-area-inset-bottom)+1rem)] sm:inset-x-auto sm:right-4 sm:bottom-4 sm:w-96"
|
||||
>
|
||||
<div aria-live="assertive" class="flex flex-col-reverse gap-2">
|
||||
<TransitionGroup
|
||||
tag="div"
|
||||
class="flex flex-col-reverse gap-2"
|
||||
enter-active-class="transition duration-150 ease-out motion-reduce:transition-none"
|
||||
enter-from-class="translate-y-2 opacity-0"
|
||||
leave-active-class="transition duration-150 ease-in motion-reduce:transition-none"
|
||||
leave-to-class="opacity-0"
|
||||
>
|
||||
<div
|
||||
v-for="toast in assertiveToasts"
|
||||
:key="toast.id"
|
||||
class="pointer-events-auto flex items-start gap-2 rounded-lg border bg-popover px-3 py-2.5 text-popover-foreground shadow-lg"
|
||||
>
|
||||
<FontAwesomeIcon :icon="ICON[toast.kind]" class="mt-0.5 size-3.5 shrink-0" :class="ICON_CLASS[toast.kind]" aria-hidden="true" />
|
||||
<p class="min-w-0 flex-1 text-sm">{{ toast.message }}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="-mt-1 -mr-1 size-6 shrink-0 text-muted-foreground hover:text-foreground"
|
||||
:aria-label="`Dismiss: ${toast.message}`"
|
||||
@click="onDismiss(toast)"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faXmark" class="size-3" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</TransitionGroup>
|
||||
</div>
|
||||
<div aria-live="polite" class="flex flex-col-reverse gap-2">
|
||||
<TransitionGroup
|
||||
tag="div"
|
||||
class="flex flex-col-reverse gap-2"
|
||||
enter-active-class="transition duration-150 ease-out motion-reduce:transition-none"
|
||||
enter-from-class="translate-y-2 opacity-0"
|
||||
leave-active-class="transition duration-150 ease-in motion-reduce:transition-none"
|
||||
leave-to-class="opacity-0"
|
||||
>
|
||||
<div
|
||||
v-for="toast in politeToasts"
|
||||
:key="toast.id"
|
||||
class="pointer-events-auto flex items-start gap-2 rounded-lg border bg-popover px-3 py-2.5 text-popover-foreground shadow-lg"
|
||||
>
|
||||
<FontAwesomeIcon :icon="ICON[toast.kind]" class="mt-0.5 size-3.5 shrink-0" :class="ICON_CLASS[toast.kind]" aria-hidden="true" />
|
||||
<p class="min-w-0 flex-1 text-sm">{{ toast.message }}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="-mt-1 -mr-1 size-6 shrink-0 text-muted-foreground hover:text-foreground"
|
||||
:aria-label="`Dismiss: ${toast.message}`"
|
||||
@click="onDismiss(toast)"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faXmark" class="size-3" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</TransitionGroup>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,6 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import EntityLink from '@/components/EntityLink.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import SkeletonList from '@/components/SkeletonList.vue'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
|
||||
/** One TopList.vue row — an entity id/label, its formatted value, and which EntityLink.vue target it opens. */
|
||||
export interface TopListItem {
|
||||
@@ -19,28 +25,82 @@ export interface TopListItem {
|
||||
* so clicking a user opens Consumers pre-filtered to them, a model opens
|
||||
* Models — the SAME "jump to detail" affordance every table's id column
|
||||
* (usage-columns.ts, model-table-columns.ts) offers, reused here rather
|
||||
* than a plain unlinked list.
|
||||
* than a plain unlinked list. The optional `controls` slot renders below
|
||||
* the title (e.g. HomePage.vue's top-users Cost/Requests/Tokens Tabs
|
||||
* switch, lib/top-users.ts) — omitted by callers with no mode switch of
|
||||
* their own, like the plain top-models card, so this stays one shared
|
||||
* component rather than a near-duplicate per card.
|
||||
*
|
||||
* States (states-plan.md item 1/3, verify-ui-states.md #1/#3/#4,
|
||||
* verify-ui-states-2.md #2) are decided via lib/load-state.ts's own
|
||||
* loadState off `loading`/`error`/`loaded` — NOT a bare
|
||||
* `loading && items.length === 0` check, and NOT `items.length > 0`
|
||||
* either: `hasData` here means "a fetch has completed for the CURRENT
|
||||
* selection" (the `loaded` prop, e.g. HomePage.vue's own per-mode
|
||||
* topUsersCache presence), not "there happen to be rows right now". A
|
||||
* caller's genuinely empty, already-settled selection must keep reading
|
||||
* as empty across a background poll's own `loading` flips (skeleton is
|
||||
* for a selection's FIRST fetch only) — using `items.length` for
|
||||
* `hasData` used to flip a settled EmptyState back to a skeleton on
|
||||
* every poll tick for exactly that case. Once `state` is not 'skeleton'
|
||||
* or 'error', the template below decides EmptyState vs. the real list by
|
||||
* checking `items.length` directly, the same way UserDetail.vue's own
|
||||
* "Models used" table does.
|
||||
*/
|
||||
defineProps<{
|
||||
title: string
|
||||
items: TopListItem[]
|
||||
/** Shown in place of the list when `items` is empty — e.g. "no traffic in this range yet". */
|
||||
emptyText: string
|
||||
}>()
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
title: string
|
||||
items: TopListItem[]
|
||||
/** Shown in place of the list when `items` is empty (and not loading, not erroring) — e.g. "No traffic in this range." */
|
||||
emptyText: string
|
||||
loading?: boolean
|
||||
/**
|
||||
* True once a fetch has completed for the CURRENT selection (mode/
|
||||
* range), even if it resolved with zero items — the caller's own
|
||||
* per-selection flag (verify-ui-states-2.md #2), reset whenever the
|
||||
* caller's selection genuinely changes. Distinct from `items.length >
|
||||
* 0`: see this component's own States doc comment above.
|
||||
*/
|
||||
loaded?: boolean
|
||||
/** The current fetch's error message, '' (default) when there is none — mirrors lib/load-state.ts's own LoadStateInput.error. A background refresh's failure with `items` already populated never reaches ErrorState (loadState's 'ready' precedence) — stores/toasts.ts covers that case instead. */
|
||||
error?: string
|
||||
/** Renders a "Retry" button on ErrorState — the caller's own refetch action. */
|
||||
onRetry?: () => void | Promise<void>
|
||||
/**
|
||||
* A distinct, higher-precedence notice (e.g. HomePage.vue's top-users
|
||||
* "too many configured users for this range", lib/top-users.ts's
|
||||
* topUsersCapExceeded) that takes over the card's content entirely —
|
||||
* it names a KNOWN reason no data will load until the reader acts
|
||||
* (narrow the range), not a transient loading/error/empty state, so it
|
||||
* is checked before all three.
|
||||
*/
|
||||
notice?: string
|
||||
noticeDescription?: string
|
||||
}>(),
|
||||
{ loading: false, loaded: false, error: '' },
|
||||
)
|
||||
|
||||
const state = computed(() => loadState({ loading: props.loading, hasData: props.loaded, error: props.error ?? '' }))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{{ title }}</CardTitle>
|
||||
<slot name="controls" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p v-if="items.length === 0" class="text-sm text-muted-foreground">{{ emptyText }}</p>
|
||||
<EmptyState v-if="notice" :title="notice" :description="noticeDescription" />
|
||||
<SkeletonList v-else-if="state === 'skeleton'" :rows="5" />
|
||||
<ErrorState v-else-if="state === 'error'" :message="error ?? ''" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="items.length === 0" :title="emptyText">
|
||||
<slot name="empty-action" />
|
||||
</EmptyState>
|
||||
<ol v-else class="flex flex-col gap-1.5">
|
||||
<li v-for="(item, i) in items" :key="item.id" class="flex items-center justify-between gap-3 text-sm">
|
||||
<span class="flex min-w-0 items-center gap-2">
|
||||
<span class="w-4 shrink-0 text-right text-xs text-muted-foreground">{{ i + 1 }}</span>
|
||||
<EntityLink :label="item.label" :kind="item.kind" :id="item.id" class="min-w-0 truncate" />
|
||||
<EntityLink :label="item.label" :kind="item.kind" :id="item.id" class="min-w-0" label-class="truncate" />
|
||||
</span>
|
||||
<span class="shrink-0 font-medium tabular-nums">{{ item.value }}</span>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { RANGE_KEYS } from '@/lib/range'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
|
||||
/**
|
||||
* TryLongerRangeButton is the shared action every "No traffic in this
|
||||
* range" empty state offers (states-plan.md item 2: Spend/Models/Home
|
||||
* lists) — steps the global range to the NEXT LONGER preset in
|
||||
* RANGE_KEYS (verify-ui-states.md #7 fix), via stores/filters.ts, rather
|
||||
* than each empty state re-deriving its own inline click handler
|
||||
* (vue.md: "if you've written it twice, you owe an abstraction" — this
|
||||
* one appears on Home's two TopLists, the Spend page's Attribution
|
||||
* drilldown, and PricingHealthTable).
|
||||
*
|
||||
* Previously this always jumped straight to a fixed '30d' — on 3mo/6mo/
|
||||
* 12mo (lib/range.ts's RANGE_KEYS, already LONGER than 30d) that
|
||||
* SHORTENED the range instead of lengthening it, and did nothing at all
|
||||
* when already on 30d itself. Stepping to `RANGE_KEYS[currentIndex + 1]`
|
||||
* is always strictly longer than the current range, and the button hides
|
||||
* itself entirely at '12mo' (the longest preset — there is nothing
|
||||
* longer left to try).
|
||||
*/
|
||||
const filters = useFiltersStore()
|
||||
|
||||
const nextLongerRange = computed<string | null>(() => {
|
||||
const index = RANGE_KEYS.indexOf(filters.range)
|
||||
const next = RANGE_KEYS[index + 1]
|
||||
return next ?? null
|
||||
})
|
||||
|
||||
function onClick(): void {
|
||||
if (nextLongerRange.value) filters.setFilters({ range: nextLongerRange.value as (typeof RANGE_KEYS)[number] })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Button v-if="nextLongerRange" type="button" variant="outline" size="sm" @click="onClick">Try a longer range</Button>
|
||||
</template>
|
||||
@@ -4,9 +4,14 @@ import { computed, onMounted, onUnmounted, watch } from 'vue'
|
||||
|
||||
import ClampedRangeNotice from '@/components/ClampedRangeNotice.vue'
|
||||
import CompactNumber from '@/components/CompactNumber.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import ModelChip from '@/components/ModelChip.vue'
|
||||
import SkeletonChart from '@/components/SkeletonChart.vue'
|
||||
import SkeletonTable from '@/components/SkeletonTable.vue'
|
||||
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import TryLongerRangeButton from '@/components/TryLongerRangeButton.vue'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
@@ -15,11 +20,13 @@ import UsageBar from '@/components/UsageBar.vue'
|
||||
import { useNow } from '@/composables/useNow'
|
||||
import { runOutDate as computeRunOutDate } from '@/lib/burndown'
|
||||
import { formatBucketLabel, formatCost, formatExactInt, formatLimits, formatTimestamp } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { BUDGET_RATIO_LABEL, budgetRatios } from '@/lib/usage-bars'
|
||||
import { useConsumersStore } from '@/stores/consumers'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useEventsStore } from '@/stores/events'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
|
||||
/**
|
||||
* UserDetail (redesign-plan.md section 3.4) is the Consumers page's
|
||||
@@ -35,6 +42,7 @@ const dashboard = useDashboardStore()
|
||||
const consumers = useConsumersStore()
|
||||
const events = useEventsStore()
|
||||
const filters = useFiltersStore()
|
||||
const nav = useNavStore()
|
||||
const { now, start: startClock, stop: stopClock } = useNow()
|
||||
onMounted(startClock)
|
||||
onUnmounted(stopClock)
|
||||
@@ -47,12 +55,19 @@ const consumerUser = computed(() => consumers.data?.users.find((u) => u.name ===
|
||||
|
||||
const featuresUserModelStats = computed(() => dashboard.overview?.features.userModelStats ?? false)
|
||||
|
||||
function loadDetail(): void {
|
||||
void consumers.fetchUserDetail(props.userId, filters.window, filters.span, featuresUserModelStats.value)
|
||||
/**
|
||||
* loadDetail (verify-ui-states-2.md #6 fix) returns fetchUserDetail's own
|
||||
* promise rather than `void`-ing it — ErrorState.onRetryClick (ErrorState.
|
||||
* vue) awaits `onRetry()` to drive its own local `retrying` spinner/disable
|
||||
* state; with this returning `void`, that await resolved immediately and
|
||||
* the Retry button showed no in-flight feedback at all.
|
||||
*/
|
||||
function loadDetail(): Promise<void> {
|
||||
return consumers.fetchUserDetail(props.userId, filters.window, filters.span, featuresUserModelStats.value)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadDetail()
|
||||
void loadDetail()
|
||||
void events.refresh()
|
||||
})
|
||||
// featuresUserModelStats is included alongside userId/range: on a deep
|
||||
@@ -87,6 +102,24 @@ const costDatasets = computed(() => [
|
||||
{ label: 'Cost', data: (detail.value?.costSeries?.series[0]?.points ?? []).map((v) => v), color: '--chart-cost' },
|
||||
])
|
||||
|
||||
/**
|
||||
* reqState/costState/modelState (verify-ui-states.md #4 fix) replace the
|
||||
* old bare `detail?.loading` skeleton check, which flipped a skeleton
|
||||
* back on over already-valid, already-rendered data in three cases:
|
||||
* (a) re-opening a cached user (consumers.detail[userId] keeps its
|
||||
* series, but loading flips true again on every fetchUserDetail call);
|
||||
* (b) the featuresUserModelStats watch's own follow-up refetch once the
|
||||
* overview lands; (c) a Retry click. `hasData` (reqSeries/costSeries/
|
||||
* modelRows non-null/non-empty) now takes precedence over `loading` —
|
||||
* lib/load-state.ts's own 'ready' precedence — so a background refetch
|
||||
* with data already on screen never shows a skeleton, and each chart/
|
||||
* table reads only its OWN error field (stores/consumers.ts's
|
||||
* UserDetailState split), so an unrelated section's failure never
|
||||
* blanks a perfectly valid one.
|
||||
*/
|
||||
const reqState = computed(() => loadState({ loading: detail.value?.loading ?? false, hasData: detail.value?.reqSeries != null, error: detail.value?.reqError ?? '' }))
|
||||
const costState = computed(() => loadState({ loading: detail.value?.loading ?? false, hasData: detail.value?.costSeries != null, error: detail.value?.costError ?? '' }))
|
||||
|
||||
/** showUserModelHint mirrors AttributionDrilldown.vue's own convention (Spend page): the hint shows when the client's own feature flag reads off, OR the usermodel call itself came back 404 (stores/consumers.ts's modelTotalsUnavailable) — the second case catches a stale/not-yet-loaded overview on a deep link or reload, where featuresUserModelStats can read true for a moment while the server still says otherwise. */
|
||||
const showUserModelHint = computed(() => !featuresUserModelStats.value || detail.value?.modelTotalsUnavailable === true)
|
||||
|
||||
@@ -96,6 +129,21 @@ const modelRows = computed(() => {
|
||||
return [...rows].sort((a, b) => (b.values.cost ?? b.values.req ?? 0) - (a.values.cost ?? a.values.req ?? 0))
|
||||
})
|
||||
|
||||
/**
|
||||
* modelState mirrors reqState/costState above for the "Models used" table
|
||||
* — only reachable once showUserModelHint is false (the template checks
|
||||
* that Alert first), so 'error'/'skeleton' here are always a genuine fetch
|
||||
* problem, not the feature simply being off. `hasData` (verify-ui-states-2.
|
||||
* md #2 fix) is `detail.modelTotals != null`, not `modelRows.length > 0` —
|
||||
* a user with genuinely zero per-model rows used to flash a skeleton back
|
||||
* on over the "No traffic in this range." EmptyState on a re-open, a
|
||||
* Retry, or the featuresUserModelStats follow-up refetch (every one of
|
||||
* which flips `detail.loading` true again). The template's own
|
||||
* `!modelRows.length` check (below) still routes an empty result to
|
||||
* EmptyState.
|
||||
*/
|
||||
const modelState = computed(() => loadState({ loading: detail.value?.loading ?? false, hasData: detail.value?.modelTotals != null, error: detail.value?.modelError ?? '' }))
|
||||
|
||||
/** recentErrors filters the shared Events store (WP-F, read-only import) down to this user — the newest 10, matching the store's own newest-first order. */
|
||||
const recentErrors = computed(() => events.events.filter((e) => e.user === props.userId).slice(0, 10))
|
||||
|
||||
@@ -131,7 +179,7 @@ const runOutDate = computed(() => {
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<CardTitle class="font-mono">{{ userId }}</CardTitle>
|
||||
<CardTitle class="min-w-0 break-all font-mono">{{ userId }}</CardTitle>
|
||||
<Badge v-if="consumerUser?.admin" variant="destructive">admin</Badge>
|
||||
<Badge v-if="consumerUser?.source" variant="secondary">{{ consumerUser.source }}</Badge>
|
||||
</div>
|
||||
@@ -184,8 +232,8 @@ const runOutDate = computed(() => {
|
||||
<CardTitle>Requests over time</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p v-if="detail?.loading" class="text-sm text-muted-foreground">loading…</p>
|
||||
<p v-else-if="detail?.error" class="text-sm text-destructive">{{ detail.error }}</p>
|
||||
<SkeletonChart v-if="reqState === 'skeleton'" />
|
||||
<ErrorState v-else-if="reqState === 'error'" :message="detail?.reqError ?? ''" :on-retry="loadDetail" />
|
||||
<TimeSeriesChart v-else :labels="reqLabels" :datasets="reqDatasets" :ariaLabel="`Requests over time for ${userId}`" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -195,8 +243,8 @@ const runOutDate = computed(() => {
|
||||
<CardTitle>Cost over time</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p v-if="detail?.loading" class="text-sm text-muted-foreground">loading…</p>
|
||||
<p v-else-if="detail?.error" class="text-sm text-destructive">{{ detail.error }}</p>
|
||||
<SkeletonChart v-if="costState === 'skeleton'" />
|
||||
<ErrorState v-else-if="costState === 'error'" :message="detail?.costError ?? ''" :on-retry="loadDetail" />
|
||||
<TimeSeriesChart v-else :labels="costLabels" :datasets="costDatasets" :value-formatter="formatCost" :ariaLabel="`Cost over time for ${userId}`" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -208,9 +256,18 @@ const runOutDate = computed(() => {
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<ClampedRangeNotice :window="filters.window" :span="filters.span" />
|
||||
<Alert v-if="showUserModelHint" variant="warn">
|
||||
<AlertDescription>Enable admin.stats.userModel in the plugin config to see a per-model breakdown for this user.</AlertDescription>
|
||||
<AlertTitle>Per-user-model statistics are off</AlertTitle>
|
||||
<AlertDescription class="flex flex-wrap items-center gap-2">
|
||||
<span>Enable <code class="font-mono text-xs">admin.stats.userModel</code> in the middleware config to see a per-model breakdown for this user.</span>
|
||||
<Button type="button" variant="outline" size="sm" @click="nav.goTo('config')">Open Config</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<Table v-else-if="modelRows.length">
|
||||
<SkeletonTable v-else-if="modelState === 'skeleton'" :rows="3" :cols="3" />
|
||||
<ErrorState v-else-if="modelState === 'error'" :message="detail?.modelError ?? ''" :on-retry="loadDetail" />
|
||||
<EmptyState v-else-if="!modelRows.length" title="No traffic in this range.">
|
||||
<TryLongerRangeButton />
|
||||
</EmptyState>
|
||||
<Table v-else>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Model</TableHead>
|
||||
@@ -226,7 +283,6 @@ const runOutDate = computed(() => {
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
<p v-else class="py-6 text-center text-sm text-muted-foreground">no model usage in this range</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -257,7 +313,14 @@ const runOutDate = computed(() => {
|
||||
<div>
|
||||
<p class="mb-1.5 text-xs text-muted-foreground">Providers</p>
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
<Badge v-for="name in consumerUser?.providers ?? []" :key="name" as="span" variant="secondary" class="font-mono font-normal">
|
||||
<Badge
|
||||
v-for="name in consumerUser?.providers ?? []"
|
||||
:key="name"
|
||||
as="span"
|
||||
variant="secondary"
|
||||
class="max-w-full truncate font-mono font-normal"
|
||||
:title="name"
|
||||
>
|
||||
{{ name }}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { API_KEY_PLACEHOLDER, generateApiKey, isValidUserName, userJsonLine, validatePersonalGrant } from '@/lib/snippets'
|
||||
import { useToastsStore } from '@/stores/toasts'
|
||||
|
||||
/**
|
||||
* UserForm (ChangeHelper, redesign-plan.md section 3.4) builds a whole new
|
||||
@@ -28,8 +29,26 @@ const providersRaw = ref('')
|
||||
const modelsRaw = ref('')
|
||||
const admin = ref(false)
|
||||
|
||||
const toasts = useToastsStore()
|
||||
|
||||
/**
|
||||
* generate (states-plan.md item 3) confirms a fresh key via toast — unlike
|
||||
* the copy-to-clipboard actions elsewhere in this panel, nothing else on
|
||||
* screen visibly draws the eye to the API-key input changing (it is one
|
||||
* field among many, above the fold but easy to miss), so this one gets a
|
||||
* success toast, not just the failure-only treatment ModelChip/
|
||||
* SnippetBlock/CsvExportButton use. generateApiKey (lib/snippets.ts) reads
|
||||
* crypto.getRandomValues, which can theoretically throw in a context with
|
||||
* no Web Crypto — caught defensively rather than left to bubble into an
|
||||
* unhandled click-handler rejection.
|
||||
*/
|
||||
function generate(): void {
|
||||
apiKey.value = generateApiKey()
|
||||
try {
|
||||
apiKey.value = generateApiKey()
|
||||
toasts.push({ kind: 'success', message: 'Generated a new API key.' })
|
||||
} catch (err) {
|
||||
toasts.push({ kind: 'error', message: err instanceof Error ? `Could not generate an API key: ${err.message}` : 'Could not generate an API key.' })
|
||||
}
|
||||
}
|
||||
|
||||
function parseList(raw: string): string[] {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
/**
|
||||
* Skeleton is shadcn-vue's own loading-placeholder primitive
|
||||
* (shadcn-vue.com/docs/components/skeleton): a plain pulsing block, sized
|
||||
* by whatever `class` the caller passes (e.g. `h-4 w-24`). Every composed
|
||||
* skeleton in this panel (SkeletonKpiTile, SkeletonTable, SkeletonChart,
|
||||
* SkeletonList) is built from one or more of these, each sized to match
|
||||
* the final layout's own dimensions so data arriving causes no layout
|
||||
* shift (states-plan.md item 1). `motion-reduce:animate-none` honors
|
||||
* prefers-reduced-motion instead of pulsing regardless.
|
||||
*/
|
||||
const props = defineProps<{ class?: HTMLAttributes['class'] }>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div data-slot="skeleton" :class="cn('animate-pulse rounded-md bg-muted motion-reduce:animate-none', props.class)" />
|
||||
</template>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Skeleton } from './Skeleton.vue'
|
||||
@@ -16,7 +16,16 @@ const forwardedProps = useForwardProps(delegatedProps)
|
||||
<TabsTrigger
|
||||
data-slot="tabs-trigger"
|
||||
:class="cn(
|
||||
'gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0',
|
||||
// group-data-horizontal/tabs:shrink-0/flex-none: every trigger keeps
|
||||
// its natural (content) width in a horizontal strip instead of
|
||||
// flex-1-shrinking to fit — TabsList (index.ts) is the thing that
|
||||
// scrolls, not the individual triggers squeezing into an unreadable
|
||||
// sliver. Vertical orientation is unaffected (still
|
||||
// group-data-vertical/tabs:w-full below).
|
||||
// group-data-horizontal/tabs:flex-none alone covers both
|
||||
// flex-grow:0 and flex-shrink:0 (P3 lows fix, verify-ui-states.md
|
||||
// #11) — the separate `shrink-0` utility next to it was redundant.
|
||||
'gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-horizontal/tabs:flex-none group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0',
|
||||
'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent',
|
||||
'data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground',
|
||||
'after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100',
|
||||
|
||||
@@ -7,7 +7,34 @@ export { default as TabsList } from './TabsList.vue'
|
||||
export { default as TabsTrigger } from './TabsTrigger.vue'
|
||||
|
||||
export const tabsListVariants = cva(
|
||||
'rounded-lg p-0.75 group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list inline-flex w-fit items-center justify-center text-muted-foreground group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col',
|
||||
// Horizontal orientation (the only one this app actually uses, in every
|
||||
// tab strip switching between pages/kinds/forms) is capped to the
|
||||
// available width and made horizontally scrollable instead of letting
|
||||
// `w-fit` push it wider than its container — every Card (ui/card)
|
||||
// clips overflow with `overflow-hidden` by design (rounded corners), so
|
||||
// an uncapped TabsList wider than its Card doesn't spill onto the page
|
||||
// (confirmed via live audit: zero page-level scrollWidth overflow
|
||||
// anywhere) — it just gets silently CLIPPED with no scrollbar and no
|
||||
// way to reach the hidden triggers. That silent clipping, not page
|
||||
// overflow, is what broke "switching tabs on mobile" (measured live:
|
||||
// the 5-trigger Config change-helper strip loses its last ~1.5 triggers
|
||||
// under its Card at 360-390px). `justify-start` overrides the default
|
||||
// centering only for this case: centering an overflowing flex row can
|
||||
// otherwise leave its first item unreachable by scroll in some browsers
|
||||
// (the well-known justify-content/overflow interaction) — reka-ui's own
|
||||
// roving-tabindex keyboard handling on TabsTrigger is untouched by any
|
||||
// of this, so arrow-key/Home/End navigation still works.
|
||||
//
|
||||
// `overflow-x-auto` alone (verify-ui-states.md #2) makes the computed
|
||||
// `overflow-y` resolve to `auto` too (the CSS `overflow` shorthand
|
||||
// behavior when only one axis is set explicitly) — combined with
|
||||
// TabsTrigger's own active-indicator pseudo-element extending 5px below
|
||||
// the 32px-tall list (`after:bottom-[-5px]`), that produced a real,
|
||||
// always-visible vertical scrollbar on every TabsList on any platform
|
||||
// that shows classic (non-overlay) scrollbars. `overflow-y-hidden`
|
||||
// clips that harmless 5px indicator overflow without touching the
|
||||
// horizontal scroll this rule exists for.
|
||||
'rounded-lg p-0.75 group-data-horizontal/tabs:h-8 group-data-horizontal/tabs:max-w-full group-data-horizontal/tabs:justify-start group-data-horizontal/tabs:overflow-x-auto group-data-horizontal/tabs:overflow-y-hidden data-[variant=line]:rounded-none group/tabs-list inline-flex w-fit items-center justify-center text-muted-foreground group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
|
||||
Reference in New Issue
Block a user