fix: handle relative date filter values without amount for THIS direction

https://sonarly.com/issue/22312?type=bug

The relative date filter stringified parser fails on the value "THIS_QUARTER" because the regex requires a `DIRECTION_DIGITS_UNIT` three-segment format (e.g., `THIS_1_QUARTER`), but the stored filter value lacks the amount segment. This crashes the opportunities table view for the affected user.
This commit is contained in:
Sonarly Claude Code
2026-04-07 06:36:45 +00:00
parent aec43da1e2
commit b255d3481e
2 changed files with 7 additions and 7 deletions
@@ -3,7 +3,7 @@ import { isNonEmptyArray } from '@sniptt/guards';
import z from 'zod';
const REGEX_FOR_RELATIVE_DATE_FILTER_STRINGIFIED_PARSING =
/((?:THIS)|(?:PAST)|(?:NEXT))_(\d*)_(DAY|MONTH|YEAR|WEEK|QUARTER|HOUR|MINUTE|SECOND)(?:(?:;;([^;;]*);;)?(?:(MONDAY|SUNDAY|SATURDAY);;)?)?/;
/((?:THIS)|(?:PAST)|(?:NEXT))_(?:(\d+)_)?(DAY|MONTH|YEAR|WEEK|QUARTER|HOUR|MINUTE|SECOND)(?:(?:;;([^;;]*);;)?(?:(MONDAY|SUNDAY|SATURDAY);;)?)?/;
export const relativeDateFilterStringifiedSchema = z
.string()
@@ -305,12 +305,6 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
? resolvedFilterValue
: null;
if (!isDefined(parsedRelativeDateFilterValue)) {
throw new Error(
`Cannot parse relative date filter : "${recordFilter.value}"`,
);
}
const defaultDateRange = resolveDateTimeFilter({
value: `PAST_1_DAY;;${filterValueDependencies.timeZone}`,
operand: RecordFilterOperand.IS_RELATIVE,
@@ -323,6 +317,12 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
throw new Error('Failed to resolve default date range');
}
if (!isDefined(parsedRelativeDateFilterValue)) {
console.warn(
`Cannot parse relative date filter : "${recordFilter.value}", falling back to default range`,
);
}
const start =
parsedRelativeDateFilterValue?.start ?? defaultDateRange.start;