refactor(webui): reuse entity links and formatters; drop stale component comments

This commit is contained in:
2026-11-25 12:11:21 +00:00
parent dccf04f840
commit 13a38a6631
8 changed files with 21 additions and 25 deletions
+1
View File
@@ -20,6 +20,7 @@ const view = computed(() => {
:data-prefix="icon.prefix"
:data-icon="icon.iconName"
:role="title ? 'img' : undefined"
:aria-label="title"
:aria-hidden="title ? undefined : 'true'"
focusable="false"
:viewBox="view.box"
+2 -3
View File
@@ -12,7 +12,7 @@ import { useToastsStore } from '@/stores/toasts'
* paste into a file" surface every ChangeHelper form and ConfigTree.vue
* share — a `<pre>` plus a copy button (lib/clipboard.ts's copyText, same
* Clipboard-API-with-selection-fallback convention CsvExportButton.vue's
* download path and ModelChip.vue's own click-to-copy already use).
* download path already uses).
*/
const props = defineProps<{
/** The exact text to display and copy — YAML (lib/snippets.ts) or a single-line JSON fragment, verbatim, never re-formatted by this component. */
@@ -29,8 +29,7 @@ async function onCopy(): Promise<void> {
const result = await copyText(props.text, preRef.value ?? undefined)
setCopyFeedback(result)
// Only a FAILURE also gets a toast (states-plan.md item 3) — see
// ModelChip.vue's own identical doc comment: 'copied'/'selected'
// already have clear inline feedback (the button's own icon/label
// 'copied'/'selected' already have clear inline feedback (the button's own icon/label
// swap right below), so a success toast would double-notify.
if (result === 'failed') toasts.push({ kind: 'error', message: 'Could not copy the snippet.' })
}
+2 -2
View File
@@ -36,8 +36,8 @@ const toasts = useToastsStore()
* the copy-to-clipboard actions elsewhere in this panel, nothing else on
* screen visibly draws the eye to the API-key input changing (it is one
* field among many, above the fold but easy to miss), so this one gets a
* success toast, not just the failure-only treatment ModelChip/
* SnippetBlock/CsvExportButton use. generateApiKey (lib/snippets.ts) reads
* success toast, not just the failure-only treatment SnippetBlock/
* CsvExportButton use. generateApiKey (lib/snippets.ts) reads
* crypto.getRandomValues, which can theoretically throw in a context with
* no Web Crypto — caught defensively rather than left to bubble into an
* unhandled click-handler rejection.
+5 -6
View File
@@ -1,9 +1,9 @@
import { onUnmounted, ref, type Ref } from 'vue'
/** RESET_MS is how long a copy-feedback state (`copied`/`selected`/`failed`) stays visible before reverting to `idle` — SnippetBlock.vue's and ModelChip.vue's own identical 1500ms. */
/** RESET_MS is how long a copy-feedback state (`copied`/`selected`/`failed`) stays visible before reverting to `idle` */
const RESET_MS = 1500
/** CopyFeedbackState mirrors lib/clipboard.ts's copyText own return union, plus the resting `idle` state neither SnippetBlock.vue nor ModelChip.vue had a name for before this composable. */
/** CopyFeedbackState mirrors lib/clipboard.ts's copyText own return union, plus the resting `idle` state. */
export type CopyFeedbackState = 'idle' | 'copied' | 'selected' | 'failed'
export interface UseCopyFeedback {
@@ -15,10 +15,9 @@ export interface UseCopyFeedback {
/**
* useCopyFeedback (reuse-audit.md F10) is the ONE "show a transient copy
* outcome, then revert to idle after 1500ms" composable SnippetBlock.vue
* and ModelChip.vue used to each hand-roll — the same `state` ref/
* `resetTimer`/`clearTimeout`-on-unmount triple, with the identical
* 1500ms magic number declared independently in both. Calls
* outcome, then revert to idle after 1500ms" composable: one `state` ref/
* `resetTimer`/`clearTimeout`-on-unmount triple behind a single 1500ms
* constant. Calls
* `onUnmounted` itself (this composable is only ever invoked from a
* component's own `setup()`/`<script setup>`, same as every other
* composable in this panel), so a caller no longer needs its own cleanup
+3 -5
View File
@@ -12,9 +12,9 @@ import {
} from '@perfect-design/ui'
import { computed, ref } from 'vue'
import { useEntityLinks } from '@/composables/useEntityLinks'
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'
@@ -39,11 +39,9 @@ function run(action: () => void): void {
search.value = ''
}
const { openEntity: openEntityLink } = useEntityLinks()
function openEntity(kind: PanelKind, id: string): void {
run(() => {
nav.goTo(PANEL_PAGE[kind])
nav.openPanel(kind, id)
})
run(() => openEntityLink(kind, id))
}
</script>
+1 -1
View File
@@ -5,7 +5,7 @@ import type { ModelCatalogRow } from '@/lib/model-table-columns'
* (lib/model-table-columns.ts's ModelCatalogRow, built from GET
* /admin/api/catalog + usage/models + performance) to whichever match a
* free-text query (redesign-plan.md section 3.1's Models page `q` param) —
* against the canonical id (ModelChip's own copyable text) OR any of the
* against the canonical id (the copyable model name) OR any of the
* model's own aliases, case-insensitively. An empty/whitespace-only query
* is "no filter", returning `rows` unchanged (the pre-redesign
* filterModelsByPrefix this function replaces made the identical choice).
+1 -1
View File
@@ -66,7 +66,7 @@ export function providerRateStatus(rate: number | null): ProviderRateStatus {
/**
* isModelDegraded reports whether a model's OWN day-window rate should
* show a badge beside its ModelChip at all — the spec's "only when that
* show a badge beside its model name at all — the spec's "only when that
* model is degraded (<99% w/ attempts>0)" rule: a healthy or no-traffic
* model gets no badge, so the accordion is not cluttered with a badge
* beside every single model.
+6 -7
View File
@@ -3,7 +3,7 @@ import { Badge, Button, DescriptionItem, DescriptionList, Heatmap, StatBar } fro
import { computed, ref, watch } from 'vue'
import RouterForm from '@/components/forms/RouterForm.vue'
import { formatCompactCount } from '@/lib/format'
import { formatCompactCount, formatExactInt } from '@/lib/format'
import { formatSel } from '@/lib/panel-selection'
import { routerPanelModel } from '@/lib/router-panel'
import { useModelsStore } from '@/stores/models'
@@ -35,7 +35,6 @@ const agreement = computed(() => {
return total > 0 ? Math.round((same * 100) / total) : null
})
const num = (n: number): string => n.toLocaleString('en-US')
const tierValue = (count: number, pct: number): string => `${formatCompactCount(count)} · ${pct}%`
function openModel(id: string): void {
@@ -57,7 +56,7 @@ watch(() => props.id, () => (snippetOpen.value = false))
<div class="flex h-6 items-center gap-2 text-sm">
<span class="font-mono font-medium">{{ t.name }}</span>
<Badge v-if="t.isDefault" tone="neutral" variant="outline" size="sm">default</Badge>
<span class="text-muted-foreground ml-auto font-mono text-xs tabular-nums">min score {{ num(t.minScore) }}</span>
<span class="text-muted-foreground ml-auto font-mono text-xs tabular-nums">min score {{ formatExactInt(t.minScore) }}</span>
</div>
<ul class="m-0 flex list-none flex-col p-0">
<li v-for="m in t.models" :key="m" class="flex min-h-8 items-center">
@@ -77,7 +76,7 @@ watch(() => props.id, () => (snippetOpen.value = false))
</ul>
</PanelSection>
<PanelSection :title="`Tier split · ${num(requests)} requests`">
<PanelSection :title="`Tier split · ${formatExactInt(requests)} requests`">
<p v-if="requests === 0" class="text-muted-foreground m-0 text-sm">No routed requests yet.</p>
<div v-else class="flex flex-col gap-3">
<StatBar
@@ -98,7 +97,7 @@ watch(() => props.id, () => (snippetOpen.value = false))
<p v-if="model.reasons.length === 0" class="text-muted-foreground m-0 text-sm">No reasons recorded.</p>
<DescriptionList v-else variant="inline" size="sm" density="compact">
<DescriptionItem v-for="r in model.reasons" :key="r.name" :term="r.name">
<span class="font-mono tabular-nums">{{ num(r.count) }}<span class="text-muted-foreground"> · {{ reasonTotal > 0 ? Math.round((r.count * 100) / reasonTotal) : 0 }}%</span></span>
<span class="font-mono tabular-nums">{{ formatExactInt(r.count) }}<span class="text-muted-foreground"> · {{ reasonTotal > 0 ? Math.round((r.count * 100) / reasonTotal) : 0 }}%</span></span>
</DescriptionItem>
</DescriptionList>
</PanelSection>
@@ -122,7 +121,7 @@ watch(() => props.id, () => (snippetOpen.value = false))
<PanelSection v-if="escalations.length > 0" title="Escalations">
<DescriptionList variant="inline" size="sm" density="compact">
<DescriptionItem v-for="e in escalations" :key="`${e.from}>${e.to}`" :term="`${e.from} → ${e.to}`">
<span class="font-mono tabular-nums">{{ num(e.count) }}</span>
<span class="font-mono tabular-nums">{{ formatExactInt(e.count) }}</span>
</DescriptionItem>
</DescriptionList>
</PanelSection>
@@ -142,7 +141,7 @@ watch(() => props.id, () => (snippetOpen.value = false))
:min="0"
show-legend
label="Live tier by shadow tier request counts"
:cell-title="(v: number | null, r: string, c: string) => `live ${r}, shadow ${c}: ${num(v ?? 0)}`"
:cell-title="(v: number | null, r: string, c: string) => `live ${r}, shadow ${c}: ${formatExactInt(v ?? 0)}`"
/>
</div>
</PanelSection>