From 940d9cb73f9200e3ec27809342c70e48bd0b82e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Malka=20Lacombe?= Date: Tue, 17 Nov 2026 10:06:51 +0100 Subject: [PATCH 1/2] feat(W28): use local storage for UI filters --- src/main/webui/package-lock.json | 45 +++++--- src/main/webui/src/layout/HeaderMeta.vue | 8 +- .../webui/src/pages/impact/ImpactPage.spec.ts | 37 +++--- .../webui/src/pages/impact/ImpactPage.vue | 16 +-- .../pages/impact/components/FilterBar.spec.ts | 22 ++-- .../src/pages/impact/components/FilterBar.vue | 19 +--- .../impact/model/useDashboardQuery.spec.ts | 65 +++++++++-- .../pages/impact/model/useDashboardQuery.ts | 105 ++++++++++++------ src/main/webui/src/router.ts | 2 + 9 files changed, 201 insertions(+), 118 deletions(-) diff --git a/src/main/webui/package-lock.json b/src/main/webui/package-lock.json index d767f94..62da537 100644 --- a/src/main/webui/package-lock.json +++ b/src/main/webui/package-lock.json @@ -275,6 +275,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -291,6 +292,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -307,6 +309,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -323,6 +326,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -339,6 +343,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -355,6 +360,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -371,9 +377,7 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -390,9 +394,7 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -409,9 +411,7 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -428,9 +428,7 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -447,9 +445,7 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -466,9 +462,7 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -485,6 +479,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -501,6 +496,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -517,6 +513,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1216,6 +1213,7 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -1418,6 +1416,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1438,6 +1437,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1458,6 +1458,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1478,6 +1479,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1498,6 +1500,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1518,6 +1521,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1538,6 +1542,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1558,6 +1563,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1578,6 +1584,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1598,6 +1605,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ @@ -1618,6 +1626,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MPL-2.0", "optional": true, "os": [ diff --git a/src/main/webui/src/layout/HeaderMeta.vue b/src/main/webui/src/layout/HeaderMeta.vue index c37312b..e5c9520 100644 --- a/src/main/webui/src/layout/HeaderMeta.vue +++ b/src/main/webui/src/layout/HeaderMeta.vue @@ -3,19 +3,15 @@ import {computed} from 'vue' import {useRoute} from 'vue-router' import {useAppInfo} from '@/services/auth/session' import {computeTimeRange} from '@/pages/impact/model/timeRange' +import {dashboardSelection} from '@/pages/impact/model/useDashboardQuery' import {asIsoUtc, formatUtcDayRange} from '@/services/format/formatters' const route = useRoute() const {appInfo} = useAppInfo() -function queryValue(value: unknown): string | null { - if (Array.isArray(value)) return typeof value[0] === 'string' ? value[0] : null - return typeof value === 'string' ? value : null -} - const range = computed(() => { if (!appInfo.value || route.name !== 'impact') return null - return computeTimeRange(queryValue(route.query.from), queryValue(route.query.to), appInfo.value.ui.maxDateRange.millis) + return computeTimeRange(dashboardSelection.value.from, dashboardSelection.value.to, appInfo.value.ui.maxDateRange.millis) }) const start = computed(() => range.value ? asIsoUtc(range.value.start) : '') const end = computed(() => range.value ? asIsoUtc(range.value.end) : '') diff --git a/src/main/webui/src/pages/impact/ImpactPage.spec.ts b/src/main/webui/src/pages/impact/ImpactPage.spec.ts index 0db598c..0f4df91 100644 --- a/src/main/webui/src/pages/impact/ImpactPage.spec.ts +++ b/src/main/webui/src/pages/impact/ImpactPage.spec.ts @@ -5,6 +5,7 @@ import type { AssetImpact, TimelineResponse } from '@/domain/impact' import App from '@/App.vue' import { router } from '@/router' import { ApiError } from '@/services/api/client' +import { applyFilters, resetFilters } from '@/pages/impact/model/useDashboardQuery' const api = vi.hoisted(() => ({ fetchAppInfo: vi.fn(), @@ -142,9 +143,10 @@ describe('ImpactPage errors', () => { describe('ImpactPage API requests', () => { afterEach(() => { document.body.innerHTML = '' + resetFilters() }) - it('builds separate requests from route filters and reloads them after a route change', async () => { + it('builds separate requests from the selected filters and reloads them when they change', async () => { api.fetchAppInfo.mockReset().mockResolvedValue({ auth: { enabled: false }, user: { authenticated: false, name: null, roles: [], permissions: ['ui.dashboard.read'] }, @@ -164,15 +166,8 @@ describe('ImpactPage API requests', () => { series: [{ key: 'gwp', label: 'GWP', unit: 'kgCO2eq', buckets: [{ embedded: 1, use: 2 }] }], }) - await router.push({ - name: 'impact', - params: { environment: 'test' }, - query: { - from: '2026-03-01T12:15', - to: '2026-03-02T00:00', - services: ['test-api=cpu,queue', 'test-worker=database'], - }, - }) + applyFilters('test', '2026-03-01T12:15', '2026-03-02T00:00', ['test-api=cpu,queue', 'test-worker=database']) + await router.push({ name: 'impact', params: { environment: 'test' } }) await router.isReady() const wrapper = mount(App, { global: { plugins: [router], stubs: { ChartCanvas: { template: '' } } } }) await flushPromises() @@ -192,24 +187,26 @@ describe('ImpactPage API requests', () => { expect(wrapper.find('.chart-title').text()).toContain('Impact over time — day') expect(wrapper.find('.chart-wrap.timeline .skeleton-block').exists()).toBe(false) - await router.push({ - name: 'impact', - params: { environment: 'prod' }, - query: { - from: '2026-04-04T00:00', - to: '2026-04-05T00:00', - services: ['prod-db=postgres'], - }, + await router.push({ name: 'impact', params: { environment: 'prod' } }) + await flushPromises() + + expect(router.currentRoute.value.fullPath).toBe('/impact/prod') + expect(api.fetchImpact).toHaveBeenCalledTimes(2) + expect(api.fetchImpact).toHaveBeenLastCalledWith({ + sourceTimeRange: firstRange, + environments: [{ id: 'prod', assets: [{ id: 'prod-api' }, { id: 'prod-db' }] }], }) + + applyFilters('prod', '2026-04-04T00:00', '2026-04-05T00:00', ['prod-db=postgres']) await flushPromises() const updatedRange = { start: '2026-04-04T00:00:00Z', end: '2026-04-05T00:00:00Z' } - expect(api.fetchImpact).toHaveBeenCalledTimes(2) + expect(api.fetchImpact).toHaveBeenCalledTimes(3) expect(api.fetchImpact).toHaveBeenLastCalledWith({ sourceTimeRange: updatedRange, environments: [{ id: 'prod', assets: [{ id: 'prod-db' }] }], }) - expect(api.fetchTimeline).toHaveBeenCalledTimes(2) + expect(api.fetchTimeline).toHaveBeenCalledTimes(3) expect(api.fetchTimeline).toHaveBeenLastCalledWith({ sourceTimeRange: updatedRange, environments: [{ id: 'prod', assets: [{ id: 'prod-db', serviceIds: ['postgres'] }] }], diff --git a/src/main/webui/src/pages/impact/ImpactPage.vue b/src/main/webui/src/pages/impact/ImpactPage.vue index 0bb764d..87d888f 100644 --- a/src/main/webui/src/pages/impact/ImpactPage.vue +++ b/src/main/webui/src/pages/impact/ImpactPage.vue @@ -7,7 +7,7 @@ import { asLocalDateTime } from '@/services/format/formatters' import { ApiError } from '@/services/api/client' import { NO_DATA_REASON } from '@/services/api/impact' import { useAppInfo } from '@/services/auth/session' -import { filtersFromRoute } from '@/pages/impact/model/useDashboardQuery' +import { dashboardSelection, filtersFor, resetFilters } from '@/pages/impact/model/useDashboardQuery' import { aggregateDashboard, buildDashboardRequests, serviceOptions } from '@/pages/impact/model/dashboard' import { computeTimeRange } from '@/pages/impact/model/timeRange' import { useDashboardData } from '@/pages/impact/useDashboardData' @@ -27,7 +27,7 @@ const dashboard = useDashboardData() const environments = computed(() => dashboard.liveEnvironments.data.value ?? []) const requestedEnvironmentId = computed(() => String(route.params.environment ?? '')) const environment = computed(() => environments.value.find(candidate => candidate.id === requestedEnvironmentId.value) ?? environments.value[0] ?? null) -const currentFilters = computed(() => filtersFromRoute(requestedEnvironmentId.value, route.query)) +const currentFilters = computed(() => filtersFor(requestedEnvironmentId.value)) const maxSpanMs = computed(() => appInfo.value?.ui.maxDateRange.millis ?? DEFAULT_MAX_DATE_RANGE_MS) const range = computed(() => computeTimeRange(currentFilters.value.from, currentFilters.value.to, maxSpanMs.value)) const from = computed(() => asLocalDateTime(range.value.start)) @@ -53,9 +53,7 @@ const pickerAssets = computed(() => withOwners(environment.value?.assets ?? [], watch(() => [ route.params.environment, - route.query.from, - route.query.to, - route.query.services, + dashboardSelection, dashboard.liveEnvironments.data.value, appInfo.value?.ui.maxDateRange.millis, ], () => { @@ -65,20 +63,16 @@ watch(() => [ const selected = available.find(candidate => candidate.id === requestedId) ?? available[0] if (!selected) return if (selected.id !== requestedId) { - void router.replace({ name: 'impact', params: { environment: selected.id }, query: route.query }) + void router.replace({ name: 'impact', params: { environment: selected.id } }) return } - const filters = filtersFromRoute(selected.id, route.query) + const filters = filtersFor(selected.id) const selectedRange = computeTimeRange(filters.from, filters.to, maxSpanMs.value) const requests = buildDashboardRequests(selected.id, selected.assets, filters.services, selectedRange.start, selectedRange.end) dashboard.loadEvaluation(selected.id, requests) }, { immediate: true, deep: true }) onMounted(dashboard.loadEnvironments) - -function resetFilters(): void { - void router.push({ name: 'impact', params: { environment: requestedEnvironmentId.value } }) -}