feat(webui): perfect-design app shell, command palette and theme boot

This commit is contained in:
2026-11-25 11:52:35 +00:00
parent c6da612215
commit 5177b2209c
33 changed files with 898 additions and 462 deletions
+5
View File
@@ -44,6 +44,11 @@ export const useFiltersStore = defineStore('filters', {
},
},
actions: {
/** Flips comparison. Turning it OFF is always allowed; turning it ON needs a range that supports one. */
toggleCmp(): void {
if (this.cmp === 'prev') this.cmp = 'none'
else if (this.cmpSpec.available) this.cmp = 'prev'
},
/** setFilters applies any subset of range/cmp/scope in one call — omitted fields keep their current value, the same "apply a partial update, one atomic write" convention the pre-redesign stores/history.ts's own setSelection (deleted; this store replaces it) used, and stores/spend.ts's own setSelection still follows today. */
setFilters(next: { range?: RangeKey; cmp?: CmpMode; scope?: string }): void {
if (next.range !== undefined) this.range = next.range
+53 -8
View File
@@ -1,6 +1,7 @@
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import { PAGE_IDS } from '@/lib/pages'
import { useNavStore } from '@/stores/nav'
beforeEach(() => {
@@ -10,7 +11,7 @@ beforeEach(() => {
describe('useNavStore: initial state', () => {
it('defaults page to "home" and params to an empty record', () => {
const nav = useNavStore()
expect(nav.page).toBe('home')
expect(nav.page).toBe('overview')
expect(nav.params).toEqual({})
})
})
@@ -18,31 +19,75 @@ describe('useNavStore: initial state', () => {
describe('useNavStore.goTo', () => {
it('sets page and params together', () => {
const nav = useNavStore()
nav.goTo('consumers', { user: 'alice' })
expect(nav.page).toBe('consumers')
nav.goTo('users', { user: 'alice' })
expect(nav.page).toBe('users')
expect(nav.params).toEqual({ user: 'alice' })
})
it('defaults params to an empty record when omitted', () => {
const nav = useNavStore()
nav.goTo('models', { model: 'openai/gpt-5' })
nav.goTo('spend')
expect(nav.page).toBe('spend')
nav.goTo('usage')
expect(nav.page).toBe('usage')
expect(nav.params).toEqual({})
})
it('replaces, never merges, the previous page\'s params', () => {
const nav = useNavStore()
nav.goTo('consumers', { user: 'alice', view: 'directory' })
nav.goTo('consumers', { view: 'matrix' })
nav.goTo('users', { user: 'alice', view: 'directory' })
nav.goTo('users', { view: 'matrix' })
expect(nav.params).toEqual({ view: 'matrix' })
})
it('accepts every page id', () => {
const nav = useNavStore()
for (const page of ['home', 'spend', 'consumers', 'models', 'reliability', 'config', 'targets'] as const) {
for (const page of PAGE_IDS) {
nav.goTo(page)
expect(nav.page).toBe(page)
}
})
})
describe('useNavStore panels', () => {
it('openPanel sets sel, keeps other params and requests a history push', () => {
const nav = useNavStore()
nav.goTo('models', { q: 'gpt' })
nav.openPanel('model', 'uni/glm-5.3-flash')
expect(nav.params).toEqual({ q: 'gpt', sel: 'model:uni%2Fglm-5.3-flash' })
expect(nav.pushPending).toBe(true)
expect(nav.selection).toEqual({ kind: 'model', id: 'uni/glm-5.3-flash' })
})
it('openPanel on the already-open panel does not request a second push', () => {
const nav = useNavStore()
nav.openPanel('user', 'alice')
nav.pushPending = false
nav.openPanel('user', 'alice')
expect(nav.pushPending).toBe(false)
})
it('closePanel without a pushed entry clears sel in place and requests no push', () => {
const nav = useNavStore()
nav.goTo('users', { q: 'a', sel: 'user:alice' })
nav.closePanel()
expect(nav.params).toEqual({ q: 'a' })
expect(nav.pushPending).toBe(false)
expect(nav.selection).toBeNull()
})
it('goTo with replace:false requests a push; default does not', () => {
const nav = useNavStore()
nav.goTo('users')
expect(nav.pushPending).toBe(false)
nav.goTo('models', {}, { replace: false })
expect(nav.pushPending).toBe(true)
})
it('goTo resets the pushed-panel marker so a later close replaces', () => {
const nav = useNavStore()
nav.openPanel('user', 'alice')
expect(nav.panelPushed).toBe(true)
nav.goTo('users', { sel: 'user:alice' })
expect(nav.panelPushed).toBe(false)
})
})
+33 -1
View File
@@ -2,6 +2,8 @@ import { defineStore } from 'pinia'
import { DEFAULT_PAGE } from '@/lib/pages'
import type { PageId } from '@/lib/pages'
import { formatSel, parseSel } from '@/lib/panel-selection'
import type { PanelKind, PanelSelection } from '@/lib/panel-selection'
/**
* useNavStore is the redesign's single navigation store (redesign-plan.md
@@ -23,7 +25,15 @@ export const useNavStore = defineStore('nav', {
state: () => ({
page: DEFAULT_PAGE as PageId,
params: {} as Record<string, string>,
/** Set by openPanel / goTo(replace:false); composables/useHashState.ts consumes it to choose pushState over replaceState. */
pushPending: false,
/** True while the current history entry was created by openPanel, so closePanel can go Back instead of stacking another entry. */
panelPushed: false,
}),
getters: {
/** The open detail panel parsed from the `sel` param, or null. */
selection: (state): PanelSelection | null => parseSel(state.params.sel),
},
actions: {
/**
* goTo navigates to `page` with `params` as that page's complete
@@ -34,9 +44,31 @@ export const useNavStore = defineStore('nav', {
* single click is always one atomic state change (and, downstream,
* one hash rewrite — composables/useHashState.ts's own watcher).
*/
goTo(page: PageId, params: Record<string, string> = {}): void {
goTo(page: PageId, params: Record<string, string> = {}, opts: { replace?: boolean } = {}): void {
this.page = page
this.params = params
this.pushPending = opts.replace === false
this.panelPushed = false
},
/** Opens a detail panel and pushes a history entry, so Back closes it. */
openPanel(kind: PanelKind, id: string): void {
const sel = formatSel(kind, id)
if (this.params.sel === sel) return
this.params = { ...this.params, sel }
this.pushPending = true
this.panelPushed = true
},
/** Goes Back when the panel owns the last history entry; otherwise drops `sel` in place. */
closePanel(): void {
if (this.panelPushed && typeof window !== 'undefined') {
this.panelPushed = false
window.history.back()
return
}
const { sel: _sel, ...rest } = this.params
this.params = rest
this.pushPending = false
this.panelPushed = false
},
},
})