From 85bad364724f0e1d967ef659c97b986c996ba909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Malka=20Lacombe?= Date: Wed, 18 Nov 2026 10:42:38 +0100 Subject: [PATCH 1/2] fix(W28): datepicker --- .../pages/impact/components/FilterBar.spec.ts | 26 +++++++++++++++++++ .../src/pages/impact/components/FilterBar.vue | 18 ++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/webui/src/pages/impact/components/FilterBar.spec.ts b/src/main/webui/src/pages/impact/components/FilterBar.spec.ts index 9febf2f..40da9ea 100644 --- a/src/main/webui/src/pages/impact/components/FilterBar.spec.ts +++ b/src/main/webui/src/pages/impact/components/FilterBar.spec.ts @@ -2,6 +2,7 @@ import {afterEach, describe, expect, it} from 'vitest' import {flushPromises, mount} from '@vue/test-utils' import {createMemoryHistory, createRouter} from 'vue-router' import FilterBar from '@/pages/impact/components/FilterBar.vue' +import DateRangePicker from '@/components/DateRangePicker.vue' import type {AssetInfo, LiveEnvironment} from '@/domain/environment' import {resetServices, servicesState} from '@/pages/impact/model/useDashboardQuery' @@ -51,6 +52,31 @@ describe('FilterBar selection', () => { wrapper.unmount() }) + it('applies a picked date range immediately, keeping the stored services', async () => { + const {router, wrapper} = await mountFilter(new Map([['a', []]])) + const picker = wrapper.findComponent(DateRangePicker) + picker.vm.$emit('update:from', '2026-11-01T00:00') + picker.vm.$emit('update:to', '2026-11-08T00:00') + await flushPromises() + + expect(router.currentRoute.value.path).toBe('/impact/env') + expect(router.currentRoute.value.query).toEqual({from: '2026-11-01T00:00', to: '2026-11-08T00:00'}) + expect(servicesState.value.services).toEqual([]) + wrapper.unmount() + }) + + it('does not navigate when the picked range is the current one', async () => { + const {router, wrapper} = await mountFilter() + const before = router.currentRoute.value.fullPath + const picker = wrapper.findComponent(DateRangePicker) + picker.vm.$emit('update:from', from) + picker.vm.$emit('update:to', to) + await flushPromises() + + expect(router.currentRoute.value.fullPath).toBe(before) + wrapper.unmount() + }) + it('applies checked assets immediately and global service IDs to each selected asset', async () => { const {router, wrapper} = await mountFilter(new Map([['a', []], ['b', []]])) const asset = wrapper.get('input[name="assets"][value="b"]') diff --git a/src/main/webui/src/pages/impact/components/FilterBar.vue b/src/main/webui/src/pages/impact/components/FilterBar.vue index b55b1d5..79553a7 100644 --- a/src/main/webui/src/pages/impact/components/FilterBar.vue +++ b/src/main/webui/src/pages/impact/components/FilterBar.vue @@ -56,13 +56,23 @@ function selectEnvironment(values: string[]): void { void router.push({name: 'impact', params: {environment: selected}, query: datesQuery(from.value, to.value)}) } -/** Stores the services and puts the picked dates in the URL, skipping the navigation when they did not change. */ -function applySelection(services: string[]): void { - applyServices(environmentId.value, services) +/** Puts the picked dates in the URL, skipping the navigation when they did not change. */ +function applyDates(): void { if (from.value !== props.from || to.value !== props.to) void router.push({name: 'impact', params: {environment: environmentId.value}, query: datesQuery(from.value, to.value)}) } +/** The picker emits `from` then `to`, so the range is complete, and applied right away, once `to` arrives. */ +function selectDates(value: string): void { + to.value = value + applyDates() +} + +function applySelection(services: string[]): void { + applyServices(environmentId.value, services) + applyDates() +} + function selectAssets(values: string[]): void { assetIds.value = values applySelection(values) @@ -79,7 +89,7 @@ function apply(): void {
Date range - +
Environment From 0d2175bda4090af083a348432e7a91975471424f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Malka=20Lacombe?= Date: Wed, 18 Nov 2026 11:02:08 +0100 Subject: [PATCH 2/2] fix(W28): highlight selected preset --- .../src/components/DateRangePicker.spec.ts | 44 +++++++++++++++++-- .../webui/src/components/DateRangePicker.vue | 21 ++++++++- .../src/layout/styles/easepick-theme.css | 5 +++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/main/webui/src/components/DateRangePicker.spec.ts b/src/main/webui/src/components/DateRangePicker.spec.ts index 990e943..5242431 100644 --- a/src/main/webui/src/components/DateRangePicker.spec.ts +++ b/src/main/webui/src/components/DateRangePicker.spec.ts @@ -15,12 +15,17 @@ vi.mock('@easepick/bundle', () => { toJSDate(): Date { return this.date } + + getTime(): number { + return this.date.getTime() + } } class Picker { private readonly listeners = new Map void>() setDateRange = vi.fn() destroy = vi.fn() + ui = {container: document.createElement('div')} constructor(options: any) { if (easepick.shouldThrow) throw new Error('Picker unavailable') @@ -36,6 +41,21 @@ vi.mock('@easepick/bundle', () => { select(detail: any): void { this.listeners.get('select')?.({detail}) } + + /** Renders the preset buttons the way PresetPlugin does: timestamps of the range in data attributes. */ + renderPresets(): HTMLElement[] { + const presets = easepick.options.at(-1).PresetPlugin.customPreset as Record number}>> + return Object.entries(presets).map(([label, [start, end]]) => { + const button = document.createElement('button') + button.className = 'preset-button unit' + button.textContent = label + button.dataset.start = String(start.getTime()) + button.dataset.end = String(end.getTime()) + this.ui.container.appendChild(button) + this.listeners.get('view')?.({detail: {view: 'PresetPluginButton', target: button}}) + return button + }) + } } return {create: Picker, DateTime, LockPlugin: {}, PresetPlugin: {}, RangePlugin: {}} @@ -49,12 +69,16 @@ function dateLabel(value: {toJSDate: () => Date}): string { return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` } -function mountPicker(maxDays = 7) { +function mountPicker(maxDays = 7, from = '2025-01-01T00:00', to = '2025-01-08T00:00') { return mount(DateRangePicker, { - props: {from: '2025-01-01T00:00', to: '2025-01-08T00:00', maxSpanMs: maxDays * DAY_MS}, + props: {from, to, maxSpanMs: maxDays * DAY_MS}, }) } +function activePresets(buttons: HTMLElement[]): string[] { + return buttons.filter(button => button.classList.contains('active')).map(button => button.textContent ?? '') +} + describe('DateRangePicker', () => { beforeEach(() => { easepick.shouldThrow = false @@ -105,4 +129,18 @@ describe('DateRangePicker', () => { expect(wrapper.emitted('update:to')).toEqual([['2025-01-31T00:00']]) wrapper.unmount() }) -}) \ No newline at end of file + + it('highlights the preset matching the current range, and none for a custom one', async () => { + const wrapper = mountPicker(400, '2025-03-25T00:00', '2025-04-01T00:00') + const buttons: HTMLElement[] = easepick.instances[0].renderPresets() + expect(activePresets(buttons)).toEqual(['Last 7 days']) + expect(buttons.find(button => button.textContent === 'Last 7 days')?.getAttribute('aria-pressed')).toBe('true') + + await wrapper.setProps({from: '2025-03-31T00:00', to: '2025-04-01T00:00'}) + expect(activePresets(buttons)).toEqual(['Today']) + + await wrapper.setProps({from: '2025-03-20T00:00', to: '2025-03-27T00:00'}) + expect(activePresets(buttons)).toEqual([]) + wrapper.unmount() + }) +}) diff --git a/src/main/webui/src/components/DateRangePicker.vue b/src/main/webui/src/components/DateRangePicker.vue index 259fe7b..afc565b 100644 --- a/src/main/webui/src/components/DateRangePicker.vue +++ b/src/main/webui/src/components/DateRangePicker.vue @@ -59,6 +59,19 @@ function syncPicker(): void { if (start && end) picker.setDateRange(pickerDate(start), pickerDate(end)) } +/** A preset button is highlighted only when the current range is exactly its own, never for a custom one. */ +function highlightPreset(button: HTMLElement): void { + const active = !!props.from && !!props.to + && Number(button.dataset.start) === pickerDate(props.from.slice(0, 10)).getTime() + && Number(button.dataset.end) === pickerDate(endDay(props.to)).getTime() + button.classList.toggle('active', active) + button.setAttribute('aria-pressed', String(active)) +} + +function highlightPresets(): void { + picker?.ui.container.querySelectorAll('.preset-button').forEach(highlightPreset) +} + function monthStartBack(months: number, end: Date): Date { const month = end.getUTCMonth() - months const lastDay = new Date(Date.UTC(end.getUTCFullYear(), month + 1, 0)).getUTCDate() @@ -105,6 +118,9 @@ function initialize(): void { }, }, setup: (instance) => { + instance.on('view', (event: { detail: { view: string; target: HTMLElement } }) => { + if (event.detail.view === 'PresetPluginButton') highlightPreset(event.detail.target) + }) instance.on('select', (event: { detail: { start?: { toJSDate: () => Date }; end?: { toJSDate: () => Date } } }) => { const {start, end} = event.detail if (start && end) emitRange(pickerDay(start.toJSDate()), pickerDay(end.toJSDate())) @@ -119,7 +135,10 @@ function initialize(): void { } onMounted(initialize) -watch(() => [props.from, props.to], syncPicker) +watch(() => [props.from, props.to], () => { + syncPicker() + highlightPresets() +}) onBeforeUnmount(() => picker?.destroy()) diff --git a/src/main/webui/src/layout/styles/easepick-theme.css b/src/main/webui/src/layout/styles/easepick-theme.css index 16ec995..49549c0 100644 --- a/src/main/webui/src/layout/styles/easepick-theme.css +++ b/src/main/webui/src/layout/styles/easepick-theme.css @@ -72,6 +72,11 @@ .preset-button:active { transform: scale(0.97); } +/* Preset matching the current range; a custom range highlights none */ +.preset-button.active { + box-shadow: inset 0 0 0 1.5px var(--color-bg-primary); + font-weight: 600; +} /* ── Header (month nav arrows) ── */ .header .button-previous-month,