mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
test(webui): visual harness and Workbench table widgets
This commit is contained in:
@@ -197,3 +197,13 @@
|
||||
radial-gradient(farthest-side at 0 50%, oklch(0 0 0 / 0.22), transparent) 0 0 / 0.6rem 100% no-repeat scroll,
|
||||
radial-gradient(farthest-side at 100% 50%, oklch(0 0 0 / 0.22), transparent) 100% 0 / 0.6rem 100% no-repeat scroll;
|
||||
}
|
||||
|
||||
/* Workbench table: 8px grid, 12px cell inset, 32px body rows, 30px header row. */
|
||||
.wb-table table { table-layout: auto; }
|
||||
.wb-table :is(th, td) { padding-inline: 12px; }
|
||||
.wb-table thead :is(th) { height: 30px; padding-block: 0; }
|
||||
.wb-table tbody :is(td, th) { height: 32px; padding-block: 0; }
|
||||
.wb-table [data-numeric] { display: block; text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; line-height: 20px; }
|
||||
.wb-table :is(th, td).wb-num { text-align: right; }
|
||||
.wb-table th.wb-num > * { justify-content: flex-end; }
|
||||
.wb-table .wb-share-bar { min-width: 96px; }
|
||||
|
||||
@@ -95,7 +95,7 @@ function onRange(value: string): void {
|
||||
/>
|
||||
<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')">
|
||||
<Button variant="outline" size="sm" aria-label="Search ⌘K" @click="emit('openPalette')">
|
||||
<Icon :icon="faMagnifyingGlass" size="sm" />
|
||||
<span class="hidden sm:inline">Search</span>
|
||||
<Kbd>⌘K</Kbd>
|
||||
|
||||
@@ -49,12 +49,12 @@ function onNavigate(item: { id?: string }, event: MouseEvent): void {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell v-model:collapsed="collapsed" v-model:open="open" drawer-breakpoint="lg" sidebar-label="Primary">
|
||||
<AppShell v-model:collapsed="collapsed" v-model:open="open" drawer-breakpoint="lg" sidebar-width="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" />
|
||||
<SidebarNav v-model:collapsed="collapsed" class="w-full" :groups="groups" :current="nav.page" label="Primary" @navigate="onNavigate" />
|
||||
</template>
|
||||
<div class="min-w-0 p-4">
|
||||
<slot />
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { wbColumns } from '@/lib/wb-columns'
|
||||
|
||||
describe('wbColumns', () => {
|
||||
it('number columns are numeric right aligned', () => {
|
||||
const [col] = wbColumns([{ key: 'req', header: 'Requests', kind: 'number' }])
|
||||
expect(col.numeric).toBe(true)
|
||||
expect(col.align).toBe('right')
|
||||
expect(col.class).toContain('wb-num')
|
||||
})
|
||||
|
||||
it('share columns are not sortable by default', () => {
|
||||
const [def, opt] = wbColumns([
|
||||
{ key: 'share', header: 'Share', kind: 'share' },
|
||||
{ key: 'share2', header: 'Share', kind: 'share', sortable: true },
|
||||
])
|
||||
expect(def.sortable).toBe(false)
|
||||
expect(opt.sortable).toBe(true)
|
||||
})
|
||||
|
||||
it('limit columns render badge slot', () => {
|
||||
const [col] = wbColumns([{ key: 'limit', header: 'Limit', kind: 'limit' }])
|
||||
expect(col.kind).toBe('limit')
|
||||
expect(col.class).toContain('wb-limit')
|
||||
expect(col.align).not.toBe('right')
|
||||
})
|
||||
|
||||
it('text, status and time columns are left aligned; text and time sort by default', () => {
|
||||
const cols = wbColumns([
|
||||
{ key: 'a', header: 'A', kind: 'text' },
|
||||
{ key: 'b', header: 'B', kind: 'status' },
|
||||
{ key: 'c', header: 'C', kind: 'time', width: '8rem' },
|
||||
])
|
||||
expect(cols.map((c) => c.numeric ?? false)).toEqual([false, false, false])
|
||||
expect(cols.map((c) => c.sortable)).toEqual([true, false, true])
|
||||
expect(cols[2].width).toBe('8rem')
|
||||
})
|
||||
|
||||
it('explicit sortable wins over the kind default', () => {
|
||||
const [col] = wbColumns([{ key: 'a', header: 'A', kind: 'number', sortable: false }])
|
||||
expect(col.sortable).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { DataTableColumn } from '@perfect-design/ui'
|
||||
|
||||
export type WbKind = 'text' | 'number' | 'share' | 'limit' | 'status' | 'time'
|
||||
|
||||
export interface WbColumnDef {
|
||||
key: string
|
||||
header: string
|
||||
kind: WbKind
|
||||
sortable?: boolean
|
||||
width?: string
|
||||
}
|
||||
|
||||
/** A DataTable column that remembers its Workbench kind, so WbTable can pick the cell renderer. */
|
||||
export type WbColumn<T = unknown> = DataTableColumn<T> & { kind: WbKind }
|
||||
|
||||
const KIND_CLASS: Record<WbKind, string> = {
|
||||
text: 'wb-text',
|
||||
number: 'wb-num',
|
||||
share: 'wb-share',
|
||||
limit: 'wb-limit',
|
||||
status: 'wb-status',
|
||||
time: 'wb-time',
|
||||
}
|
||||
|
||||
// Share bars and status chips carry no useful order of their own.
|
||||
const UNSORTABLE_BY_DEFAULT: ReadonlySet<WbKind> = new Set(['share', 'status'])
|
||||
|
||||
/** Expands compact column definitions into DataTable columns with the Workbench alignment rules. */
|
||||
export function wbColumns<T = unknown>(defs: WbColumnDef[]): WbColumn<T>[] {
|
||||
return defs.map((d) => {
|
||||
const col: WbColumn<T> = {
|
||||
key: d.key,
|
||||
header: d.header,
|
||||
kind: d.kind,
|
||||
sortable: d.sortable ?? !UNSORTABLE_BY_DEFAULT.has(d.kind),
|
||||
class: KIND_CLASS[d.kind],
|
||||
}
|
||||
if (d.width) col.width = d.width
|
||||
if (d.kind === 'number') {
|
||||
col.numeric = true
|
||||
col.align = 'right'
|
||||
}
|
||||
return col
|
||||
})
|
||||
}
|
||||
@@ -91,3 +91,19 @@ describe('useNavStore panels', () => {
|
||||
expect(nav.panelPushed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('useNavStore no-op navigation', () => {
|
||||
it('goTo to the identical page and params with replace:false does not leave a push pending', () => {
|
||||
const nav = useNavStore()
|
||||
nav.goTo('users', { q: 'a' })
|
||||
nav.goTo('users', { q: 'a' }, { replace: false })
|
||||
expect(nav.pushPending).toBe(false)
|
||||
})
|
||||
|
||||
it('goTo that changes params still pushes with replace:false', () => {
|
||||
const nav = useNavStore()
|
||||
nav.goTo('users', { q: 'a' })
|
||||
nav.goTo('users', { q: 'b' }, { replace: false })
|
||||
expect(nav.pushPending).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,6 +5,11 @@ import type { PageId } from '@/lib/pages'
|
||||
import { formatSel, parseSel } from '@/lib/panel-selection'
|
||||
import type { PanelKind, PanelSelection } from '@/lib/panel-selection'
|
||||
|
||||
function sameParams(a: Record<string, string>, b: Record<string, string>): boolean {
|
||||
const keys = Object.keys(a)
|
||||
return keys.length === Object.keys(b).length && keys.every((k) => a[k] === b[k])
|
||||
}
|
||||
|
||||
/**
|
||||
* useNavStore is the redesign's single navigation store (redesign-plan.md
|
||||
* section 3.3, replacing the old activeTab/usageQuery shape): which page
|
||||
@@ -45,9 +50,11 @@ export const useNavStore = defineStore('nav', {
|
||||
* one hash rewrite — composables/useHashState.ts's own watcher).
|
||||
*/
|
||||
goTo(page: PageId, params: Record<string, string> = {}, opts: { replace?: boolean } = {}): void {
|
||||
const unchanged = this.page === page && sameParams(this.params, params)
|
||||
this.page = page
|
||||
this.params = params
|
||||
this.pushPending = opts.replace === false
|
||||
// An unchanged hash never reaches useHashState's watcher, which is what clears this flag.
|
||||
this.pushPending = opts.replace === false && !unchanged
|
||||
this.panelPushed = false
|
||||
},
|
||||
/** Opens a detail panel and pushes a history entry, so Back closes it. */
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '@perfect-design/ui'
|
||||
|
||||
import type { PanelKind } from '@/lib/panel-selection'
|
||||
|
||||
defineProps<{ kind: PanelKind; id: string; title: string }>()
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
|
||||
function onOpen(open: boolean): void {
|
||||
if (!open) emit('close')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Sheet :open="true" @update:open="onOpen">
|
||||
<SheetContent side="right" size="lg" :data-panel-kind="kind" :data-panel-id="id">
|
||||
<SheetHeader>
|
||||
<SheetTitle class="truncate">{{ title }}</SheetTitle>
|
||||
<SheetDescription class="sr-only">{{ kind }} details for {{ title }}</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div class="min-w-0 flex-1 overflow-y-auto">
|
||||
<slot />
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { Badge } from '@perfect-design/ui'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { formatCompactCount } from '@/lib/format'
|
||||
|
||||
const props = defineProps<{ limit: number | null | undefined; unit?: string; hot?: boolean }>()
|
||||
|
||||
const has = computed(() => typeof props.limit === 'number' && Number.isFinite(props.limit) && props.limit > 0)
|
||||
const text = computed(() => (has.value ? `${formatCompactCount(props.limit as number)}${props.unit ? `/${props.unit}` : ''}` : 'none'))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Badge class="wb-limit-badge font-mono" variant="outline" size="sm" :tone="hot ? 'danger' : 'neutral'" :data-limit="has ? 'set' : 'none'">
|
||||
{{ text }}
|
||||
</Badge>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { StatBar } from '@perfect-design/ui'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{ value: number | null | undefined; label?: string }>(), { label: 'Share' })
|
||||
|
||||
const pct = computed(() => (Number.isFinite(props.value) ? Math.min(100, Math.max(0, (props.value as number) * 100)) : null))
|
||||
const text = computed(() => (pct.value === null ? '—' : `${pct.value < 10 && pct.value > 0 ? pct.value.toFixed(1) : Math.round(pct.value)}%`))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<StatBar
|
||||
class="wb-share-bar"
|
||||
:label="label"
|
||||
:value="pct ?? 0"
|
||||
:max="100"
|
||||
:value-text="text"
|
||||
tone="primary"
|
||||
size="sm"
|
||||
layout="inline"
|
||||
hide-label
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import { EmptyState, ErrorState, LoadingState, StaleNotice } from '@perfect-design/ui'
|
||||
|
||||
export type ViewState = 'loading' | 'empty' | 'error' | 'ready'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
state: ViewState
|
||||
/** Fetch time of the data on screen; a stale one shows the notice above the content. */
|
||||
updatedAt?: number | string | Date | null
|
||||
emptyTitle?: string
|
||||
emptyDescription?: string
|
||||
errorTitle?: string
|
||||
errorMessage?: string
|
||||
retryable?: boolean
|
||||
rows?: number
|
||||
}>(),
|
||||
{ emptyTitle: 'Nothing here yet', errorTitle: 'Could not load data', retryable: true, rows: 5 },
|
||||
)
|
||||
const emit = defineEmits<{ retry: [] }>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<LoadingState v-if="state === 'loading'" variant="table" :rows="rows" label="Loading" />
|
||||
<ErrorState
|
||||
v-else-if="state === 'error'"
|
||||
:title="errorTitle"
|
||||
:message="errorMessage"
|
||||
:retryable="retryable"
|
||||
@retry="emit('retry')"
|
||||
/>
|
||||
<EmptyState v-else-if="state === 'empty'" :title="emptyTitle" :description="emptyDescription">
|
||||
<template v-if="$slots.action" #action><slot name="action" /></template>
|
||||
</EmptyState>
|
||||
<template v-else>
|
||||
<StaleNotice v-if="updatedAt" variant="inline" :timestamp="updatedAt" hide-when-fresh />
|
||||
<slot />
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts" generic="T extends object">
|
||||
import { DataTable } from '@perfect-design/ui'
|
||||
import type { DataTableCellSlotProps } from '@perfect-design/ui'
|
||||
|
||||
import LimitBadge from '@/widgets/LimitBadge.vue'
|
||||
import ShareCell from '@/widgets/ShareCell.vue'
|
||||
import type { WbColumn } from '@/lib/wb-columns'
|
||||
|
||||
type RowId = string | number
|
||||
|
||||
defineProps<{
|
||||
columns: WbColumn<T>[]
|
||||
rows: T[]
|
||||
rowKey?: keyof T | ((row: T, index: number) => RowId)
|
||||
label: string
|
||||
loading?: boolean
|
||||
}>()
|
||||
const activeKey = defineModel<RowId | null | undefined>('activeKey')
|
||||
const emit = defineEmits<{ 'row-activate': [row: T, key: RowId] }>()
|
||||
|
||||
function num(v: unknown): string {
|
||||
return typeof v === 'number' && Number.isFinite(v) ? v.toLocaleString('en-US') : v == null || v === '' ? '—' : String(v)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DataTable
|
||||
v-model:active-key="activeKey"
|
||||
class="wb-table"
|
||||
density="compact"
|
||||
size="sm"
|
||||
sticky-header
|
||||
layout="cards"
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
:row-key="rowKey"
|
||||
:label="label"
|
||||
:loading="loading"
|
||||
@row-activate="(row, key) => emit('row-activate', row, key)"
|
||||
>
|
||||
<template v-for="col in columns" :key="col.key" #[`cell-${col.key}`]="p: DataTableCellSlotProps<T>">
|
||||
<span v-if="col.kind === 'number'" data-numeric class="wb-num"><slot :name="`cell-${col.key}`" v-bind="p">{{ num(p.value) }}</slot></span>
|
||||
<slot v-else-if="col.kind === 'share'" :name="`cell-${col.key}`" v-bind="p"><ShareCell :value="p.value as number" /></slot>
|
||||
<slot v-else-if="col.kind === 'limit'" :name="`cell-${col.key}`" v-bind="p"><LimitBadge :limit="p.value as number" /></slot>
|
||||
<slot v-else :name="`cell-${col.key}`" v-bind="p">{{ p.value ?? '—' }}</slot>
|
||||
</template>
|
||||
<template #empty><slot name="empty" /></template>
|
||||
</DataTable>
|
||||
</template>
|
||||
Reference in New Issue
Block a user