(frontend) add "more than a year" modification date preset

Filter items last modified over a year ago, available wherever the
modification date filter is used.
This commit is contained in:
Nicolas Clerc
2026-06-29 15:42:59 +02:00
parent ae60204f14
commit 77b3156805
4 changed files with 20 additions and 1 deletions
@@ -15,6 +15,7 @@ const MODIFIED_PRESETS: DatePreset[] = [
"last_7_days",
"last_30_days",
"this_year",
"more_than_a_year",
];
const MODIFIED_CUSTOM = "custom";
@@ -31,6 +31,12 @@ describe("presetRange", () => {
updated_at_before: "2026-05-29",
});
});
it("caps at one year ago for the more than a year preset", () => {
expect(presetRange("more_than_a_year", today)).toEqual({
updated_at_before: "2025-05-29",
});
});
});
describe("toISODate", () => {
@@ -1,6 +1,11 @@
import { ItemFilters } from "@/features/drivers/Driver";
export type DatePreset = "today" | "last_7_days" | "last_30_days" | "this_year";
export type DatePreset =
| "today"
| "last_7_days"
| "last_30_days"
| "this_year"
| "more_than_a_year";
export type DateRange = Pick<
ItemFilters,
@@ -27,6 +32,11 @@ const addDays = (date: Date, days: number): Date => {
* bound. `today` is injectable for deterministic tests.
*/
export const presetRange = (preset: DatePreset, today: Date = new Date()): DateRange => {
if (preset === "more_than_a_year") {
const before = new Date(today.getFullYear() - 1, today.getMonth(), today.getDate());
return { updated_at_before: toISODate(before) };
}
let after: Date;
switch (preset) {
case "today":
@@ -289,6 +289,7 @@
"last_7_days": "Last 7 days",
"last_30_days": "Last 30 days",
"this_year": "This year",
"more_than_a_year": "More than a year",
"custom": "Custom range"
},
"start": "Start",
@@ -926,6 +927,7 @@
"last_7_days": "7 derniers jours",
"last_30_days": "30 derniers jours",
"this_year": "Cette année",
"more_than_a_year": "Il y a plus d'un an",
"custom": "Période personnalisée"
},
"start": "Début",