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:
2026-11-08 02:32:09 +00:00
parent 0a05dfc035
commit 8c5e4fbcda
6 changed files with 155 additions and 63 deletions
+36
View File
@@ -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)
})
})
+24
View File
@@ -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()
}
}