From 7c566075828fc9a62efbf7f78603b66f3a9fd76a Mon Sep 17 00:00:00 2001 From: Nathnael Date: Wed, 19 Aug 2026 10:11:48 +0000 Subject: [PATCH] fix(filters): honor a date filter's own operator, not always "between" DateBody always initialized its op state to DEFAULT_OP.date ("between"), ignoring a def's `operators` restriction. A single-operator exact-date filter (e.g. `operators: ["before"]`) opened on the range UI with no way off it, since OperatorSelect hides itself when there's only one choice. Default to the def's first allowed operator instead. --- .../backoffice/src/components/filters/bodies/DateBody.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/edr-freight-web/backoffice/src/components/filters/bodies/DateBody.tsx b/apps/edr-freight-web/backoffice/src/components/filters/bodies/DateBody.tsx index b2032170d..32970abef 100644 --- a/apps/edr-freight-web/backoffice/src/components/filters/bodies/DateBody.tsx +++ b/apps/edr-freight-web/backoffice/src/components/filters/bodies/DateBody.tsx @@ -15,7 +15,11 @@ import type { FilterBodyProps } from "./TextBody"; // i18n.language !== "en" branch here when this body is first wired into a // record-management page (Phase 4 of the filter-bar rollout). export function DateBody({ def, value, onChange, onClose }: FilterBodyProps) { - const [op, setOp] = useState(value?.op ?? DEFAULT_OP.date); + // DEFAULT_OP.date is always "between" — a def restricted to a single + // non-default operator (e.g. `operators: ["before"]` for an exact-date + // filter) would otherwise open on the range UI with no way to switch off + // it, since OperatorSelect hides itself when there's only one choice. + const [op, setOp] = useState(value?.op ?? def.operators?.[0] ?? DEFAULT_OP.date); // Mantine 9's date inputs speak `YYYY-MM-DD` strings, not Date objects. const [from, setFrom] = useState(value?.v[0]?.slice(0, 10) ?? null); const [to, setTo] = useState(value?.v[1]?.slice(0, 10) ?? null);