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:
@@ -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