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.
This commit is contained in:
Nathnael
2026-08-19 10:11:48 +00:00
parent dd6df306f2
commit 7c56607582

View File

@@ -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<DateFilterDef>) {
const [op, setOp] = useState<Operator>(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<Operator>(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<string | null>(value?.v[0]?.slice(0, 10) ?? null);
const [to, setTo] = useState<string | null>(value?.v[1]?.slice(0, 10) ?? null);