Repository navigation
Datahub Collected filter labels rolling windows as This week, This month and This year #1785
Description
The datahub's "Collected" filter offers "This week", "This month" and "This year", but these apply rolling windows: the past 7 days, the past month and the past 12 months (presetMinDate subtracts 7 days, 1 month and 1 year from now). Read as calendar periods, the labels select the wrong subjects. On 7 October, "This month" also includes subjects last seen on 8–30 September, and on 5 January "This year" includes most of the previous year. The other options are worded as spans ("3 months", "6 months", "2 years"), and the subject Graph and Table tabs label the same computation "Past Month" / "Past Year" (datahub.visualization.timeframeOptions). A user narrowing a cohort to "this month" for a monthly report gets a different set of subjects than they asked for, with nothing to show the window is rolling.
Where
apps/web/src/routes/_app/datahub/subjects/index.tsx:249-256:
<option value="all">{t({ en: 'Any time', es: 'Cualquier fecha', fr: 'Toute période' })}</option>
<option value="pastWeek">{t({ en: 'This week', es: 'Esta semana', fr: 'Cette semaine' })}</option>
<option value="pastMonth">{t({ en: 'This month', es: 'Este mes', fr: 'Ce mois-ci' })}</option>
<option value="pastThreeMonths">{t({ en: '3 months', es: '3 meses', fr: '3 mois' })}</option>
<option value="pastSixMonths">{t({ en: '6 months', es: '6 meses', fr: '6 mois' })}</option>
<option value="pastYear">{t({ en: 'This year', es: 'Este año', fr: 'Cette année' })}</option>and the windows they map to, index.tsx:61-80:
case 'pastMonth':
return monthsAgo(1);
// ...
case 'pastWeek':
return new Date(new Date(now).setDate(now.getDate() - 7));
case 'pastYear':
return yearsAgo(1);Reproduce
- Have a subject whose last record was collected on 20 September and another on 3 October.
- On 7 October, open Datahub → Subjects → Filters and set Collected to "This month".
Actual: both subjects are listed.
Expected: only the subject collected in October is listed, or, if the rolling window is intended, the option reads "Past month" (and "Past week", "Past year") like the subject graph's timeframe menu.
Tests
apps/web/src/routes/_app/datahub/subjects/__tests__/index.test.tsx:it('should label the rolling collected windows as past periods, so they are not read as calendar months'), or, if calendar periods are chosen,it('should start the This month window on the first of the month')with fake timers.testing/src/specs/datahub.spec.ts: select the month preset and assert the option text matches the window applied.
Suggested fix
Relabel the three options "Past week", "Past month", "Past year" (es: "Última semana", "Último mes", "Último año"; fr: "Semaine écoulée", "Mois écoulé", "Année écoulée", matching datahub.json), so all presets describe spans. Alternatively, keep the labels and compute calendar boundaries in presetMinDate.
Activity