Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions src/main/webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/main/webui/src/layout/AppHeader.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script setup lang="ts">
import { RouterLink } from 'vue-router'
import { useTheme } from '@/layout/theme/useTheme'
import { lastDashboardLocation } from '@/pages/impact/model/useDashboardQuery'

const { isDark, toggleTheme } = useTheme()
</script>

<template>
<div class="header">
<a class="header-home" href="/" title="Back to the report">
<RouterLink class="header-home" :to="lastDashboardLocation" title="Back to the report">
<img src="/icons/wombat-large-mask.png" alt="Wombat" class="header-logo" />
<h1>Wombat — <span>Environmental Impact</span></h1>
</a>
</RouterLink>
<slot name="nav" />
<slot name="headerExtra" />
<slot name="userMenu" />
Expand Down
9 changes: 3 additions & 6 deletions src/main/webui/src/layout/HeaderMeta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ import {computed} from 'vue'
import {useRoute} from 'vue-router'
import {useAppInfo} from '@/services/auth/session'
import {computeTimeRange} from '@/pages/impact/model/timeRange'
import {filtersFor} 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)
const {from, to} = filtersFor(String(route.params.environment ?? ''), route.query)
return computeTimeRange(from, to, appInfo.value.ui.maxDateRange.millis)
})
const start = computed(() => range.value ? asIsoUtc(range.value.start) : '')
const end = computed(() => range.value ? asIsoUtc(range.value.end) : '')
Expand Down
3 changes: 2 additions & 1 deletion src/main/webui/src/layout/HeaderNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RouterLink, useRoute } from 'vue-router'
import { settingsLinks } from '@/services/auth/permissions'
import { useAppInfo } from '@/services/auth/session'
import { useDropdown } from '@/layout/useDropdown'
import { lastDashboardLocation } from '@/pages/impact/model/useDashboardQuery'

const { appInfo } = useAppInfo()
const route = useRoute()
Expand All @@ -15,7 +16,7 @@ const { open, root } = useDropdown()

<template>
<nav v-if="links.length > 0" class="header-nav" aria-label="Main">
<RouterLink class="header-nav-link" to="/" :aria-current="onReport ? 'page' : undefined">Report</RouterLink>
<RouterLink class="header-nav-link" :to="lastDashboardLocation" :aria-current="onReport ? 'page' : undefined">Report</RouterLink>
<div ref="root" class="header-nav-menu" :class="{ open }" id="settingsMenu">
<button
class="header-nav-link header-nav-trigger"
Expand Down
58 changes: 38 additions & 20 deletions src/main/webui/src/pages/impact/ImpactPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { applyServices, resetServices } from '@/pages/impact/model/useDashboardQuery'

const api = vi.hoisted(() => ({
fetchAppInfo: vi.fn(),
Expand Down Expand Up @@ -142,9 +143,10 @@ describe('ImpactPage errors', () => {
describe('ImpactPage API requests', () => {
afterEach(() => {
document.body.innerHTML = ''
resetServices()
})

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'] },
Expand All @@ -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'],
},
})
applyServices('test', ['test-api=cpu,queue', 'test-worker=database'])
await router.push({ name: 'impact', params: { environment: 'test' }, query: { from: '2026-03-01T12:15', to: '2026-03-02T00:00' } })
await router.isReady()
const wrapper = mount(App, { global: { plugins: [router], stubs: { ChartCanvas: { template: '<canvas />' } } } })
await flushPromises()
Expand All @@ -192,29 +187,52 @@ 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' }, query: { from: '2026-04-04T00:00', to: '2026-04-05T00:00' } })
await flushPromises()

const updatedRange = { start: '2026-04-04T00:00:00Z', end: '2026-04-05T00:00:00Z' }
expect(api.fetchImpact).toHaveBeenCalledTimes(2)
expect(api.fetchImpact).toHaveBeenLastCalledWith({
sourceTimeRange: updatedRange,
environments: [{ id: 'prod', assets: [{ id: 'prod-api' }, { id: 'prod-db' }] }],
})

applyServices('prod', ['prod-db=postgres'])
await flushPromises()

expect(router.currentRoute.value.query).toEqual({ from: '2026-04-04T00:00', to: '2026-04-05T00:00' })
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'] }] }],
})
expect(wrapper.find('.chart-title').text()).toContain('Impact over time — day')
wrapper.unmount()
})

it('writes the default date range into the URL', async () => {
vi.useFakeTimers({ toFake: ['Date'], now: new Date(Date.UTC(2026, 5, 10, 8, 30)) })
api.fetchImpact.mockClear()
try {
await router.push({ name: 'impact', params: { environment: 'test' } })
await router.isReady()
const wrapper = mount(App, { global: { plugins: [router], stubs: { ChartCanvas: { template: '<canvas />' } } } })
await flushPromises()

expect(router.currentRoute.value.query).toEqual({ from: '2026-03-13T00:00', to: '2026-06-11T00:00' })
expect(api.fetchImpact).toHaveBeenCalledTimes(1)
expect(api.fetchImpact).toHaveBeenLastCalledWith({
sourceTimeRange: { start: '2026-03-13T00:00:00Z', end: '2026-06-11T00:00:00Z' },
environments: [{ id: 'test', assets: [{ id: 'test-api' }, { id: 'test-worker' }] }],
})
wrapper.unmount()
} finally {
vi.useRealTimers()
}
})
})
Loading
Loading