mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
refactor(webui): remove shadcn-vue, chart.js and replaced components
Delete 89 files that no live entry imports, drop chart.js, vue-chartjs, @tanstack/vue-table and the FontAwesome runtime, and replace the Vue FontAwesome wrapper with a small SVG component. Limit Tailwind source scanning to the perfect-design components the app bundles. Add the bundle gate script and spec: gzip JS+CSS of dist/assets must stay at or below 324300 bytes.
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { useSearchQuery } from './useSearchQuery'
|
||||
|
||||
describe('useSearchQuery', () => {
|
||||
it('normalized trims leading/trailing whitespace', () => {
|
||||
const { query, normalized } = useSearchQuery()
|
||||
query.value = ' alice '
|
||||
expect(normalized.value).toBe('alice')
|
||||
})
|
||||
|
||||
it('normalized lowercases the query', () => {
|
||||
const { query, normalized } = useSearchQuery()
|
||||
query.value = 'AlIcE'
|
||||
expect(normalized.value).toBe('alice')
|
||||
})
|
||||
|
||||
it('hasQuery is false for a whitespace-only query', () => {
|
||||
const { query, hasQuery } = useSearchQuery()
|
||||
query.value = ' '
|
||||
expect(hasQuery.value).toBe(false)
|
||||
})
|
||||
|
||||
// F9 (hash-state): a caller can supply the ref this composable reads and
|
||||
// writes instead of a private local one, so the query round-trips
|
||||
// through an external owner (e.g. ConsumerDirectory.vue's own
|
||||
// `nav.params.q`-backed computed, or EventsView.vue's store-backed
|
||||
// `userFilter` — useSearchQuery.ts's own doc comment) rather than being
|
||||
// lost on remount.
|
||||
describe('with an external ref', () => {
|
||||
it('reads and derives from the external ref\'s current value, rather than starting blank', () => {
|
||||
const external = ref('preset')
|
||||
const { query, normalized, hasQuery } = useSearchQuery(external)
|
||||
|
||||
expect(query.value).toBe('preset')
|
||||
expect(normalized.value).toBe('preset')
|
||||
expect(hasQuery.value).toBe(true)
|
||||
})
|
||||
|
||||
it('writes THROUGH to the external ref — the same ref instance, not a copy', () => {
|
||||
const external = ref('')
|
||||
const { query } = useSearchQuery(external)
|
||||
|
||||
query.value = 'typed'
|
||||
|
||||
expect(external.value).toBe('typed')
|
||||
})
|
||||
|
||||
it('reflects a change made directly to the external ref (bidirectional, not a one-time snapshot)', () => {
|
||||
const external = ref('')
|
||||
const { query, normalized } = useSearchQuery(external)
|
||||
|
||||
external.value = 'set-elsewhere'
|
||||
|
||||
expect(query.value).toBe('set-elsewhere')
|
||||
expect(normalized.value).toBe('set-elsewhere')
|
||||
})
|
||||
|
||||
it('without an external ref, two calls own independent state (no accidental sharing)', () => {
|
||||
const a = useSearchQuery()
|
||||
const b = useSearchQuery()
|
||||
|
||||
a.query.value = 'alice'
|
||||
|
||||
expect(b.query.value).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,43 +0,0 @@
|
||||
import type { Ref } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
/**
|
||||
* useSearchQuery is the one raw-query → {normalized, hasQuery} adapter
|
||||
* every search filter in this panel uses — ProviderHealthPanel's
|
||||
* model/provider search, ConsumerDirectory's user/group search
|
||||
* (lib/usage-search.ts), EventsView's user/group filter, TargetsView's
|
||||
* target search, each with its own matching logic but the identical
|
||||
* query/normalizedQuery/hasQuery pairing; extracted so it exists once
|
||||
* (vue.md: "if you've written it twice, you owe an abstraction"). Callers
|
||||
* still own their own matching logic entirely — this only normalizes the
|
||||
* raw input the same way every call site already agreed on: trimmed,
|
||||
* lowercased.
|
||||
*
|
||||
* No `clear()` here — clearing is just setting `query.value = ''`, and
|
||||
* every caller already gets that for free from SearchInput.vue's own
|
||||
* clear button emitting `update:modelValue('')` through the `v-model`
|
||||
* binding, so a separate clear function would be dead API surface no
|
||||
* caller needs.
|
||||
*
|
||||
* `external` (F9, hash-state) lets a caller supply the ref this composable
|
||||
* reads and writes instead of owning a private local one, so that ref's
|
||||
* own search text round-trips through the URL hash. Two current callers
|
||||
* pass it: ConsumerDirectory.vue binds a local `computed` get/set over
|
||||
* `nav.params.q` directly (stores/nav.ts's own `params` is opaque, so the
|
||||
* page owns interpreting/writing its own `q` key — see that computed's
|
||||
* own doc comment for why this replaced an earlier, page-specific
|
||||
* `nav.usageQuery` special case), and EventsView.vue binds
|
||||
* `storeToRefs(events).userFilter`, which composables/useHashState.ts
|
||||
* reads/writes directly against the same hash. Every OTHER caller
|
||||
* (ProviderHealthPanel's model/provider search, TargetsView's target
|
||||
* search) omits it and keeps its private, hash-independent ref instead —
|
||||
* passing `external` changes nothing about `normalized`/`hasQuery`'s own
|
||||
* derivation, only where the raw value itself lives.
|
||||
*/
|
||||
export function useSearchQuery(external?: Ref<string>) {
|
||||
const query = external ?? ref('')
|
||||
const normalized = computed(() => query.value.trim().toLowerCase())
|
||||
const hasQuery = computed(() => normalized.value.length > 0)
|
||||
|
||||
return { query, normalized, hasQuery }
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
/**
|
||||
* useThemeColors exposes the current computed values of the design
|
||||
* tokens Chart.js needs to draw axis/grid/legend text (main.css) — Chart.js
|
||||
* paints to a <canvas>, so it cannot pick up CSS variables the way a DOM
|
||||
* element does; the caller must read them and hand them to Chart.js as
|
||||
* plain color strings. Every color literal in main.css is oklch()/hex,
|
||||
* both valid canvas fillStyle values in current evergreen browsers (the
|
||||
* only ones this admin panel targets — see vite.config.ts's
|
||||
* modulePreload note for the same reasoning), so no conversion is needed.
|
||||
*
|
||||
* Re-reads when the `class` of <html> changes (perfect-design's theme
|
||||
* store toggles `.dark` there, including on an OS flip in "system" mode),
|
||||
* so an open chart repaints on a theme switch.
|
||||
*/
|
||||
export function useThemeColors() {
|
||||
const foreground = ref('')
|
||||
const mutedForeground = ref('')
|
||||
const border = ref('')
|
||||
|
||||
function sync(): void {
|
||||
const style = getComputedStyle(document.documentElement)
|
||||
foreground.value = style.getPropertyValue('--foreground').trim()
|
||||
mutedForeground.value = style.getPropertyValue('--muted-foreground').trim()
|
||||
border.value = style.getPropertyValue('--border').trim()
|
||||
}
|
||||
|
||||
let observer: MutationObserver | undefined
|
||||
onMounted(() => {
|
||||
sync()
|
||||
observer = new MutationObserver(sync)
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
observer?.disconnect()
|
||||
})
|
||||
|
||||
return { foreground, mutedForeground, border }
|
||||
}
|
||||
Reference in New Issue
Block a user