mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): perfect-design app shell, command palette and theme boot
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<script setup lang="ts">
|
||||
import { faArrowRightArrowLeft, faBars, faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons'
|
||||
import { Button, Icon, Input, Kbd, OfflineIndicator, SegmentedControl, StaleNotice, ThemeToggle } from '@perfect-design/ui'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
import { SCOPE_PATTERN } from '@/lib/hash-state'
|
||||
import { RANGE_KEYS } from '@/lib/range'
|
||||
import type { RangeKey } from '@/lib/range'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { DEFAULT_SCOPE, useFiltersStore } from '@/stores/filters'
|
||||
|
||||
defineProps<{ triggerProps: Record<string, string> }>()
|
||||
const emit = defineEmits<{ toggleSidebar: []; openPalette: [] }>()
|
||||
|
||||
const RANGE_OPTIONS = RANGE_KEYS.map((key) => ({ value: key, label: key }))
|
||||
/** Matches the dashboard store's 5s poll: data older than this means polling has stalled. */
|
||||
const STALE_AFTER_MS = 30_000
|
||||
|
||||
const filters = useFiltersStore()
|
||||
const dashboard = useDashboardStore()
|
||||
|
||||
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}`
|
||||
})
|
||||
|
||||
// A draft buffer: a half-typed scope must not refetch every store per keystroke, and an invalid commit reverts the field only.
|
||||
const scopeDraft = ref(filters.scope)
|
||||
watch(
|
||||
() => filters.scope,
|
||||
(scope) => {
|
||||
scopeDraft.value = scope
|
||||
},
|
||||
)
|
||||
|
||||
function commitScope(): void {
|
||||
const value = String(scopeDraft.value).trim() || DEFAULT_SCOPE
|
||||
if (SCOPE_PATTERN.test(value)) filters.setFilters({ scope: value })
|
||||
else scopeDraft.value = filters.scope
|
||||
}
|
||||
|
||||
function onRange(value: string): void {
|
||||
filters.setFilters({ range: value as RangeKey })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-full flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2">
|
||||
<Button variant="ghost" size="sm" class="lg:hidden" aria-label="Toggle navigation" v-bind="triggerProps" @click="emit('toggleSidebar')">
|
||||
<Icon :icon="faBars" size="sm" />
|
||||
</Button>
|
||||
<span class="text-sm font-semibold tracking-tight">LLM Gateway</span>
|
||||
|
||||
<div class="max-w-full overflow-x-auto">
|
||||
<SegmentedControl :model-value="filters.range" :options="RANGE_OPTIONS" size="sm" aria-label="Time range" @update:model-value="onRange" />
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:aria-pressed="filters.cmp === 'prev'"
|
||||
:disabled="cmpDisabled"
|
||||
:title="cmpTitle"
|
||||
@click="filters.toggleCmp()"
|
||||
>
|
||||
<Icon :icon="faArrowRightArrowLeft" size="sm" />
|
||||
vs previous
|
||||
</Button>
|
||||
|
||||
<Input
|
||||
v-model="scopeDraft"
|
||||
size="sm"
|
||||
class="w-40"
|
||||
placeholder="scope: all"
|
||||
aria-label="Scope"
|
||||
title="all, group:<name>, user:<name>, or provider:<name>"
|
||||
@keyup.enter="commitScope"
|
||||
@blur="commitScope"
|
||||
/>
|
||||
|
||||
<div class="ml-auto flex items-center gap-2">
|
||||
<StaleNotice
|
||||
v-if="dashboard.lastUpdated"
|
||||
variant="inline"
|
||||
:timestamp="dashboard.lastUpdated"
|
||||
:stale-after="STALE_AFTER_MS"
|
||||
:refreshing="dashboard.refreshing"
|
||||
refreshable
|
||||
hide-when-fresh
|
||||
@refresh="dashboard.refresh()"
|
||||
/>
|
||||
<OfflineIndicator variant="pill" />
|
||||
<span v-if="dashboard.error" class="text-destructive text-xs" role="status">refresh failed</span>
|
||||
<Button variant="outline" size="sm" aria-label="Open command palette" @click="emit('openPalette')">
|
||||
<Icon :icon="faMagnifyingGlass" size="sm" />
|
||||
<span class="hidden sm:inline">Search</span>
|
||||
<Kbd>⌘K</Kbd>
|
||||
</Button>
|
||||
<ThemeToggle />
|
||||
<span v-if="dashboard.overview?.version" class="text-muted-foreground hidden text-xs md:inline">
|
||||
v{{ dashboard.overview.version }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { AppShell, SidebarNav, Toaster } from '@perfect-design/ui'
|
||||
import type { SidebarNavGroup } from '@perfect-design/ui'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import AppHeader from '@/layout/AppHeader.vue'
|
||||
import CommandPalette from '@/layout/CommandPalette.vue'
|
||||
import { NAV_GROUPS, navCounts } from '@/lib/nav-groups'
|
||||
import type { PageId } from '@/lib/pages'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
|
||||
const nav = useNavStore()
|
||||
const dashboard = useDashboardStore()
|
||||
|
||||
const collapsed = ref(false)
|
||||
const open = ref(false)
|
||||
const paletteOpen = ref(false)
|
||||
|
||||
const counts = computed(() => navCounts(dashboard.overview, dashboard.usage, dashboard.targets))
|
||||
|
||||
const groups = computed<SidebarNavGroup[]>(() =>
|
||||
NAV_GROUPS.map((g, i) => ({
|
||||
id: `group-${i}`,
|
||||
label: g.label ?? undefined,
|
||||
items: g.items.map((item) => ({
|
||||
id: item.id,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
active: nav.page === item.id,
|
||||
badge: item.countKey ? counts.value[item.countKey] : undefined,
|
||||
})),
|
||||
})),
|
||||
)
|
||||
|
||||
useEventListener(window, 'keydown', (e: KeyboardEvent) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
||||
e.preventDefault()
|
||||
paletteOpen.value = !paletteOpen.value
|
||||
}
|
||||
})
|
||||
|
||||
function onNavigate(item: { id?: string }, event: MouseEvent): void {
|
||||
event.preventDefault()
|
||||
if (item.id) nav.goTo(item.id as PageId)
|
||||
open.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell v-model:collapsed="collapsed" v-model:open="open" drawer-breakpoint="lg" sidebar-label="Primary">
|
||||
<template #header="{ toggle, triggerProps }">
|
||||
<AppHeader :trigger-props="triggerProps" @toggle-sidebar="toggle" @open-palette="paletteOpen = true" />
|
||||
</template>
|
||||
<template #sidebar>
|
||||
<SidebarNav v-model:collapsed="collapsed" :groups="groups" :current="nav.page" label="Primary" @navigate="onNavigate" />
|
||||
</template>
|
||||
<div class="min-w-0 p-4">
|
||||
<slot />
|
||||
</div>
|
||||
</AppShell>
|
||||
<CommandPalette v-model:open="paletteOpen" />
|
||||
<Toaster />
|
||||
</template>
|
||||
@@ -0,0 +1,100 @@
|
||||
<script setup lang="ts">
|
||||
import { faArrowRightArrowLeft, faClock, faCircleHalfStroke } from '@fortawesome/free-solid-svg-icons'
|
||||
import {
|
||||
CommandDialog,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
Icon,
|
||||
useThemeStore,
|
||||
} from '@perfect-design/ui'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { NAV_GROUPS } from '@/lib/nav-groups'
|
||||
import { paletteEntities } from '@/lib/palette-items'
|
||||
import { PANEL_PAGE } from '@/lib/panel-selection'
|
||||
import type { PanelKind } from '@/lib/panel-selection'
|
||||
import { RANGE_KEYS } from '@/lib/range'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
|
||||
const nav = useNavStore()
|
||||
const filters = useFiltersStore()
|
||||
const dashboard = useDashboardStore()
|
||||
const theme = useThemeStore()
|
||||
|
||||
const search = ref('')
|
||||
const pages = NAV_GROUPS.flatMap((g) => g.items)
|
||||
const entities = computed(() => paletteEntities(dashboard.overview, dashboard.usage, dashboard.targets))
|
||||
|
||||
/** Runs an action, then closes the palette and resets the query. */
|
||||
function run(action: () => void): void {
|
||||
action()
|
||||
open.value = false
|
||||
search.value = ''
|
||||
}
|
||||
|
||||
function openEntity(kind: PanelKind, id: string): void {
|
||||
run(() => {
|
||||
nav.goTo(PANEL_PAGE[kind])
|
||||
nav.openPanel(kind, id)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<CommandDialog v-model:open="open" v-model:search="search" title="Command palette" description="Jump to a page or entity, or run an action.">
|
||||
<CommandInput placeholder="Search pages, entities and actions" />
|
||||
<CommandList>
|
||||
<CommandEmpty>No matches.</CommandEmpty>
|
||||
<CommandGroup heading="Pages">
|
||||
<CommandItem v-for="p in pages" :key="p.id" :value="`page ${p.label}`" @select="run(() => nav.goTo(p.id))">
|
||||
<Icon :icon="p.icon" size="sm" />
|
||||
{{ p.label }}
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
<CommandGroup heading="Range">
|
||||
<CommandItem
|
||||
v-for="r in RANGE_KEYS"
|
||||
:key="r"
|
||||
:value="`range ${r}`"
|
||||
@select="run(() => filters.setFilters({ range: r }))"
|
||||
>
|
||||
<Icon :icon="faClock" size="sm" />
|
||||
Range {{ r }}
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
<CommandGroup heading="Actions">
|
||||
<CommandItem value="action toggle comparison previous period" @select="run(() => filters.toggleCmp())">
|
||||
<Icon :icon="faArrowRightArrowLeft" size="sm" />
|
||||
Toggle comparison with previous period
|
||||
</CommandItem>
|
||||
<CommandItem
|
||||
v-for="m in (['light', 'dark', 'system'] as const)"
|
||||
:key="m"
|
||||
:value="`action theme ${m}`"
|
||||
@select="run(() => theme.setMode(m))"
|
||||
>
|
||||
<Icon :icon="faCircleHalfStroke" size="sm" />
|
||||
Theme: {{ m }}
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
<CommandGroup v-if="entities.length" heading="Entities">
|
||||
<CommandItem
|
||||
v-for="e in entities"
|
||||
:key="`${e.kind}:${e.id}`"
|
||||
:value="`${e.kind} ${e.label}`"
|
||||
@select="openEntity(e.kind, e.id)"
|
||||
>
|
||||
<span class="text-muted-foreground w-16 shrink-0 text-xs">{{ e.kind }}</span>
|
||||
<span class="truncate">{{ e.label }}</span>
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</CommandDialog>
|
||||
</template>
|
||||
Reference in New Issue
Block a user