mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(admin-ui): clear data on key change and show empty Spend chart
A new API key kept the previous key's data on screen until each store refreshed. All data stores now reset when the key changes. The Spend breakdown chart showed a column of identical zero ticks for an empty range, so it now shows an empty message. A stray quote in the Reliability page markup is removed.
This commit is contained in:
+74
-56
File diff suppressed because one or more lines are too long
+10
-1
@@ -2,7 +2,7 @@
|
|||||||
import type { Component } from 'vue'
|
import type { Component } from 'vue'
|
||||||
import { faGithub } from '@fortawesome/free-brands-svg-icons'
|
import { faGithub } from '@fortawesome/free-brands-svg-icons'
|
||||||
import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons'
|
import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { computed, defineAsyncComponent, onMounted } from 'vue'
|
import { computed, defineAsyncComponent, onMounted, watch } from 'vue'
|
||||||
|
|
||||||
import AuthGate from '@/components/AuthGate.vue'
|
import AuthGate from '@/components/AuthGate.vue'
|
||||||
import ConfigWarningsBanner from '@/components/ConfigWarningsBanner.vue'
|
import ConfigWarningsBanner from '@/components/ConfigWarningsBanner.vue'
|
||||||
@@ -17,6 +17,7 @@ import type { PageId } from '@/lib/pages'
|
|||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import { useDashboardStore } from '@/stores/dashboard'
|
import { useDashboardStore } from '@/stores/dashboard'
|
||||||
import { useNavStore } from '@/stores/nav'
|
import { useNavStore } from '@/stores/nav'
|
||||||
|
import { resetSessionData } from '@/stores/session'
|
||||||
|
|
||||||
/** The module path (go.mod / .traefik.yml `import:`) — same repo the plugin ships from, so this is the one canonical URL rather than a guess. */
|
/** The module path (go.mod / .traefik.yml `import:`) — same repo the plugin ships from, so this is the one canonical URL rather than a guess. */
|
||||||
const GITHUB_REPO_URL = 'https://github.com/lukaszraczylo/traefik-llmgateway'
|
const GITHUB_REPO_URL = 'https://github.com/lukaszraczylo/traefik-llmgateway'
|
||||||
@@ -85,6 +86,14 @@ const statusText = computed<string>(() => {
|
|||||||
/** isInitialStatusLoad gates the header status line's skeleton — the FIRST dashboard poll only (states-plan.md item 1: a skeleton only when there is no data yet, never on a background refresh — dashboard.lastUpdated stays set through every later poll, success or failure). */
|
/** isInitialStatusLoad gates the header status line's skeleton — the FIRST dashboard poll only (states-plan.md item 1: a skeleton only when there is no data yet, never on a background refresh — dashboard.lastUpdated stays set through every later poll, success or failure). */
|
||||||
const isInitialStatusLoad = computed<boolean>(() => !dashboard.error && !dashboard.lastUpdated)
|
const isInitialStatusLoad = computed<boolean>(() => !dashboard.error && !dashboard.lastUpdated)
|
||||||
|
|
||||||
|
// A different key may carry different privileges, so never keep the previous key's data on screen.
|
||||||
|
watch(
|
||||||
|
() => auth.apiKey,
|
||||||
|
(next, prev) => {
|
||||||
|
if (next !== prev) resetSessionData()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
dashboard.startPolling()
|
dashboard.startPolling()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ onMounted(() => void reliability.fetch())
|
|||||||
title="Timeouts by provider"
|
title="Timeouts by provider"
|
||||||
:state="timeoutState"
|
:state="timeoutState"
|
||||||
show-empty
|
show-empty
|
||||||
empty-title="No timeouts in this range.""
|
empty-title="No timeouts in this range."
|
||||||
:error="reliability.error"
|
:error="reliability.error"
|
||||||
:on-retry="reliability.fetch"
|
:on-retry="reliability.fetch"
|
||||||
:labels="bucketLabels"
|
:labels="bucketLabels"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { useNow } from '@/composables/useNow'
|
|||||||
import { cacheSavingsStatus } from '@/lib/cache-savings'
|
import { cacheSavingsStatus } from '@/lib/cache-savings'
|
||||||
import { BREAKDOWN_PALETTE, seriesColor } from '@/lib/chart-palette'
|
import { BREAKDOWN_PALETTE, seriesColor } from '@/lib/chart-palette'
|
||||||
import { formatBucketLabel, formatCompactCount, formatCostAxis, formatCostDisplay } from '@/lib/format'
|
import { formatBucketLabel, formatCompactCount, formatCostAxis, formatCostDisplay } from '@/lib/format'
|
||||||
import { loadState } from '@/lib/load-state'
|
import { emptyWhenAllZero, loadState } from '@/lib/load-state'
|
||||||
import { parseScope, scopeBudgetLimits, scopeId } from '@/lib/scope'
|
import { parseScope, scopeBudgetLimits, scopeId } from '@/lib/scope'
|
||||||
import { useCatalogStore } from '@/stores/catalog'
|
import { useCatalogStore } from '@/stores/catalog'
|
||||||
import { useDashboardStore } from '@/stores/dashboard'
|
import { useDashboardStore } from '@/stores/dashboard'
|
||||||
@@ -182,8 +182,11 @@ const cacheSavingsNote = computed<string | null>(() => cacheSavingsStatusResult.
|
|||||||
// --- skeleton/error states (verify-ui-states.md #7: "Spend and Reliability
|
// --- skeleton/error states (verify-ui-states.md #7: "Spend and Reliability
|
||||||
// pages got no skeletons or ErrorState") -----------------------------------
|
// pages got no skeletons or ErrorState") -----------------------------------
|
||||||
|
|
||||||
/** breakdownState gates the main breakdown chart's own skeleton/error — hasData is bucket presence (a real response landed), not "every value is non-zero", so a genuinely zero-traffic range still reads 'ready' and the chart draws its own honest zero line. BurnDownChart.vue computes its own identical state internally now (it owns its own Card/CardHeader, verify-ui-states.md fix) — SpendPage.vue just forwards spend.burndownLoading/spend.burndownError as props. */
|
/** breakdownLoadState gates the main breakdown chart's own skeleton/error — hasData is bucket presence (a real response landed), not "every value is non-zero", so a genuinely zero-traffic range still reads 'ready'. BurnDownChart.vue computes its own identical state internally now (it owns its own Card/CardHeader, verify-ui-states.md fix) — SpendPage.vue just forwards spend.burndownLoading/spend.burndownError as props. */
|
||||||
const breakdownState = computed(() => loadState({ loading: spend.loading, hasData: spend.buckets.length > 0, error: spend.breakdownError }))
|
const breakdownLoadState = computed(() => loadState({ loading: spend.loading, hasData: spend.buckets.length > 0, error: spend.breakdownError }))
|
||||||
|
|
||||||
|
/** An all-zero range shows a message instead of a flat line over a column of identical "$0" ticks. */
|
||||||
|
const breakdownState = computed(() => emptyWhenAllZero(breakdownLoadState.value, breakdownDatasets.value))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retryPricingHealthTable (verify-ui-states-2.md #9 fix) is
|
* retryPricingHealthTable (verify-ui-states-2.md #9 fix) is
|
||||||
@@ -220,7 +223,7 @@ function retryPricingHealthTable(): Promise<void> {
|
|||||||
</div>
|
</div>
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<p class="text-xs font-medium text-muted-foreground">{{ SPEND_METRIC_LABEL[metric] }} in range</p>
|
<p class="text-xs font-medium text-muted-foreground">{{ SPEND_METRIC_LABEL[metric] }} in range</p>
|
||||||
<p class="text-2xl font-semibold tabular-nums">{{ breakdownState === 'ready' ? valueFormatter(totalInRange) : '—' }}</p>
|
<p class="text-2xl font-semibold tabular-nums">{{ breakdownLoadState === 'ready' ? valueFormatter(totalInRange) : '—' }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="byDisabled" class="text-sm text-muted-foreground">
|
<p v-if="byDisabled" class="text-sm text-muted-foreground">
|
||||||
@@ -258,6 +261,8 @@ function retryPricingHealthTable(): Promise<void> {
|
|||||||
<ChartCard
|
<ChartCard
|
||||||
bare
|
bare
|
||||||
:state="breakdownState"
|
:state="breakdownState"
|
||||||
|
show-empty
|
||||||
|
empty-title="No usage in this range."
|
||||||
:error="spend.breakdownError"
|
:error="spend.breakdownError"
|
||||||
:on-retry="spend.refresh"
|
:on-retry="spend.refresh"
|
||||||
:labels="breakdownLabels"
|
:labels="breakdownLabels"
|
||||||
@@ -274,7 +279,7 @@ function retryPricingHealthTable(): Promise<void> {
|
|||||||
precedence), so the ErrorState above never mounts. Without this line the
|
precedence), so the ErrorState above never mounts. Without this line the
|
||||||
failure was invisible: the chart kept the old series under the new
|
failure was invisible: the chart kept the old series under the new
|
||||||
labels/formatter with no indication anything had gone wrong. -->
|
labels/formatter with no indication anything had gone wrong. -->
|
||||||
<p v-if="spend.breakdownError && breakdownState === 'ready'" class="text-sm break-words text-destructive">{{ spend.breakdownError }}</p>
|
<p v-if="spend.breakdownError && breakdownLoadState === 'ready'" class="text-sm break-words text-destructive">{{ spend.breakdownError }}</p>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 items-start gap-4 lg:grid-cols-2">
|
<div class="grid grid-cols-1 items-start gap-4 lg:grid-cols-2">
|
||||||
<BurnDownChart
|
<BurnDownChart
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { createPinia, setActivePinia } from 'pinia'
|
||||||
|
import { beforeEach, describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
import { useConsumersStore } from '@/stores/consumers'
|
||||||
|
import { useEventsStore } from '@/stores/events'
|
||||||
|
import { useFiltersStore } from '@/stores/filters'
|
||||||
|
import { resetSessionData } from '@/stores/session'
|
||||||
|
import type { AdminEventView } from '@/types/api'
|
||||||
|
|
||||||
|
describe('resetSessionData', () => {
|
||||||
|
beforeEach(() => setActivePinia(createPinia()))
|
||||||
|
|
||||||
|
it('clears API data held by data stores', () => {
|
||||||
|
const events = useEventsStore()
|
||||||
|
events.events = [{ kind: 'x' } as unknown as AdminEventView]
|
||||||
|
events.error = 'boom'
|
||||||
|
resetSessionData()
|
||||||
|
expect(events.events).toEqual([])
|
||||||
|
expect(events.error).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns a populated consumers store to its initial state', () => {
|
||||||
|
const consumers = useConsumersStore()
|
||||||
|
const initial = JSON.stringify(consumers.$state)
|
||||||
|
consumers.error = 'stale'
|
||||||
|
resetSessionData()
|
||||||
|
expect(JSON.stringify(consumers.$state)).toBe(initial)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps UI state such as the global filters', () => {
|
||||||
|
const filters = useFiltersStore()
|
||||||
|
const before = JSON.stringify(filters.$state)
|
||||||
|
resetSessionData()
|
||||||
|
expect(JSON.stringify(filters.$state)).toBe(before)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { useCatalogStore } from '@/stores/catalog'
|
||||||
|
import { useConfigStore } from '@/stores/config'
|
||||||
|
import { useConsumersStore } from '@/stores/consumers'
|
||||||
|
import { useDashboardStore } from '@/stores/dashboard'
|
||||||
|
import { useEventsStore } from '@/stores/events'
|
||||||
|
import { useModelsStore } from '@/stores/models'
|
||||||
|
import { useReliabilityStore } from '@/stores/reliability'
|
||||||
|
import { useSpendStore } from '@/stores/spend'
|
||||||
|
|
||||||
|
/** resetSessionData drops every store that holds admin API data, so a different key never shows the previous key's numbers. Filters, nav and toasts are UI state and stay. */
|
||||||
|
export function resetSessionData(): void {
|
||||||
|
for (const store of [
|
||||||
|
useCatalogStore(),
|
||||||
|
useConfigStore(),
|
||||||
|
useConsumersStore(),
|
||||||
|
useDashboardStore(),
|
||||||
|
useEventsStore(),
|
||||||
|
useModelsStore(),
|
||||||
|
useReliabilityStore(),
|
||||||
|
useSpendStore(),
|
||||||
|
]) {
|
||||||
|
store.$reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user