Fixed relative date filter initalization (#12811)

This PR fixes problems with date filter : 
- Filter chip shows the label with plural, ex : `This weeks` 
- Using a relative filter now initializes to `This day`
- Switching between the different relative sub-operands (This, Past,
Next) now initializes with a value so we're never in an "empty" state.
This commit is contained in:
Lucas Bordeau
2025-06-24 13:57:05 +02:00
committed by GitHub
parent 5c3550a2ee
commit 81d70e6fa3
3 changed files with 39 additions and 6 deletions

View File

@ -7,4 +7,14 @@ export const computeVariableDateViewFilterValue = (
direction: VariableDateViewFilterValueDirection,
amount: number | undefined,
unit: VariableDateViewFilterValueUnit,
) => `${direction}_${amount?.toString()}_${unit}`;
) => {
if (direction === 'THIS') {
return `THIS_1_${unit}`;
} else if (amount === undefined || amount <= 0) {
throw new Error(
'Amount must be defined and greater than 0 for relative date filters',
);
}
return `${direction}_${amount.toString()}_${unit}`;
};