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
+1 -1
View File
@@ -116,7 +116,7 @@ function sourceOf(entry: AdminUsageEntryView): string | undefined {
// the old nav.usageQuery special case.
const usageQuery = computed<string>({
get: () => nav.params.q ?? '',
set: (value) => nav.goTo('consumers', { ...nav.params, q: value }),
set: (value) => nav.goTo('users', { ...nav.params, q: value }),
})
const { query: userQuery, normalized: normalizedQuery, hasQuery } = useSearchQuery(usageQuery)
+2 -2
View File
@@ -47,8 +47,8 @@ const props = defineProps<{
const nav = useNavStore()
const { isAlias } = useAliasNames()
const TARGET: Record<'user' | 'model', { page: 'consumers' | 'models'; paramKey: 'user' | 'model'; noun: string }> = {
user: { page: 'consumers', paramKey: 'user', noun: 'Consumers' },
const TARGET: Record<'user' | 'model', { page: 'users' | 'models'; paramKey: 'user' | 'model'; noun: string }> = {
user: { page: 'users', paramKey: 'user', noun: 'Consumers' },
model: { page: 'models', paramKey: 'model', noun: 'Models' },
}
-125
View File
@@ -1,125 +0,0 @@
<script setup lang="ts">
import { faArrowRightArrowLeft } from '@fortawesome/free-solid-svg-icons'
import { computed, ref, watch } from 'vue'
import LabeledSelect from '@/components/LabeledSelect.vue'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { SCOPE_PATTERN } from '@/lib/hash-state'
import { RANGE_KEYS } from '@/lib/range'
import type { RangeKey } from '@/lib/range'
import { DEFAULT_SCOPE, useFiltersStore } from '@/stores/filters'
/** RANGE_LABEL is the range Select's display text per lib/range.ts's RangeKey — kept here (not lib/range.ts) since it is pure presentation, not logic a store or another page's fetch needs. */
const RANGE_LABEL: Record<RangeKey, string> = {
'24h': 'Last 24 hours',
'48h': 'Last 48 hours',
'7d': 'Last 7 days',
'14d': 'Last 14 days',
'30d': 'Last 30 days',
'3mo': 'Last 3 months',
'6mo': 'Last 6 months',
'12mo': 'Last 12 months',
}
const RANGE_OPTIONS = RANGE_KEYS.map((key) => ({ value: key, label: RANGE_LABEL[key] }))
/**
* GlobalFilterBar (redesign-plan.md section 3.1) is the shell's one
* control surface for the three global filters (stores/filters.ts):
* time range, "vs previous period" comparison, and an optional
* group/user/provider scope narrowing. Every page reads the SAME filters
* store; this bar is mounted once, in App.vue's header, not per-page.
*/
const filters = useFiltersStore()
function onRangeUpdate(value: unknown): void {
if (typeof value !== 'string') return
filters.setFilters({ range: value as RangeKey })
}
/**
* toggleCmp (P3 item 19): turning the comparison OFF is always allowed,
* even when the CURRENT range does not support one — a `cmp=prev` value
* restored from the hash (e.g. loaded directly onto a 48h/30d/12mo range,
* where 2*span exceeds the retention ceiling) used to leave the button
* permanently pressed-and-disabled, with no way to turn it off short of
* changing the range first. filters.cmpSpec.requested already gates the
* actual fetch on availability (stores/filters.ts's own doc comment), so
* this was purely a stuck AFFORDANCE, never a bad request. Turning it ON
* still requires availability — there is nothing to compare against
* otherwise.
*/
function toggleCmp(): void {
if (filters.cmp === 'prev') {
filters.setFilters({ cmp: 'none' })
return
}
if (!filters.cmpSpec.available) return
filters.setFilters({ cmp: 'prev' })
}
/** cmpDisabled only blocks turning the toggle ON when unavailable — turning an already-on comparison OFF is never blocked (toggleCmp's own doc comment). */
const cmpDisabled = computed<boolean>(() => filters.cmp !== 'prev' && !filters.cmpSpec.available)
const cmpTitle = computed<string>(() => {
if (filters.cmp === 'prev' && !filters.cmpSpec.available) {
return `Comparison unavailable for this range (${filters.cmpSpec.reason}) — click to turn off`
}
if (filters.cmpSpec.available) return 'Compare against the previous equal-length period'
return `Comparison unavailable for this range: ${filters.cmpSpec.reason}`
})
// scopeDraft is a local editing buffer, not bound straight to
// filters.scope: a partially-typed value ("group:") must not spam
// setFilters/refetch every store on every keystroke, and an invalid
// commit (onBlur/Enter, below) must revert the FIELD, not the store —
// the store keeps whatever scope was last valid.
const scopeDraft = ref(filters.scope)
watch(
() => filters.scope,
(scope) => {
scopeDraft.value = scope
},
)
function commitScope(): void {
const value = scopeDraft.value.trim() || DEFAULT_SCOPE
if (SCOPE_PATTERN.test(value)) {
filters.setFilters({ scope: value })
} else {
// Invalid — revert the field to the store's own current value rather than keeping the bad text on screen.
scopeDraft.value = filters.scope
}
}
</script>
<template>
<div class="flex flex-wrap items-end gap-3">
<LabeledSelect label="Range" :model-value="filters.range" :options="RANGE_OPTIONS" trigger-class="w-36" @update:model-value="onRangeUpdate" />
<Button
type="button"
variant="outline"
:aria-pressed="filters.cmp === 'prev'"
:disabled="cmpDisabled"
:title="cmpTitle"
@click="toggleCmp"
>
<FontAwesomeIcon :icon="faArrowRightArrowLeft" class="size-3.5" aria-hidden="true" />
vs previous period
</Button>
<div class="flex flex-col gap-1">
<label for="global-filter-scope" class="text-xs font-medium text-muted-foreground">Scope</label>
<Input
id="global-filter-scope"
v-model="scopeDraft"
class="w-48"
placeholder="all"
title="all, group:<name>, user:<name>, or provider:<name>"
@keyup.enter="commitScope"
@blur="commitScope"
/>
</div>
</div>
</template>
-40
View File
@@ -1,40 +0,0 @@
<script setup lang="ts">
import { PAGE_NAV } from '@/lib/pages'
import { useNavStore } from '@/stores/nav'
/**
* SidebarNav (redesign-plan.md section 3.1) is the shell's primary
* navigation: a vertical list of pages on a normal-width viewport,
* collapsing to a horizontally-scrollable bar on a narrow one (the
* `md:` breakpoint below) rather than a hamburger/drawer — every page is
* still one tap away, and the panel is an internal admin tool with no
* phone-first audience to justify hiding the list behind an extra tap.
*
* Real `<button>` elements, not `<a href>` (mirrors EntityLink.vue's own
* structural note): activating one is a programmatic Pinia navigation
* (nav.goTo), not a traditional link follow, and there is no separate
* URL to navigate to server-side — the hash is derived FROM this state
* (composables/useHashState.ts), not the other way around.
*/
const nav = useNavStore()
</script>
<template>
<nav
aria-label="Primary"
class="flex gap-1 overflow-x-auto border-b border-border pb-2 md:w-52 md:shrink-0 md:flex-col md:border-r md:border-b-0 md:pr-3 md:pb-0"
>
<button
v-for="entry in PAGE_NAV"
:key="entry.id"
type="button"
:aria-current="nav.page === entry.id ? 'page' : undefined"
class="flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium whitespace-nowrap transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 md:w-full"
:class="nav.page === entry.id ? 'bg-accent text-accent-foreground' : 'text-muted-foreground hover:bg-muted hover:text-foreground'"
@click="nav.goTo(entry.id)"
>
<FontAwesomeIcon :icon="entry.icon" class="size-4" aria-hidden="true" />
<span>{{ entry.label }}</span>
</button>
</nav>
</template>