Skip to content

Commit

Permalink
Fix query restore date function detection
Browse files Browse the repository at this point in the history
When restoring query, fallback to "Manual Value" if the provided value is not a valid date. This handles date literals with variables since we do not yet support those in the UI.

resolves #1110
  • Loading branch information
paustint committed Dec 12, 2024
1 parent 2a8348e commit 310e899
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libs/features/query/src/utils/query-filter.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getFlattenedListItemsById,
getPicklistListItems,
} from '@jetstream/shared/ui-utils';
import { REGEX } from '@jetstream/shared/utils';
import {
ExpressionConditionHelpText,
ExpressionConditionRowSelectedItems,
Expand All @@ -18,6 +17,8 @@ import {
Maybe,
QueryFilterOperator,
} from '@jetstream/types';
import { isValid } from 'date-fns/isValid';
import { parseISO } from 'date-fns/parseISO';

// Used for GROUP BY and HAVING clause
export const QUERY_FIELD_DATE_FUNCTIONS: ListItem<string, QueryFilterOperator>[] = [
Expand Down Expand Up @@ -217,7 +218,8 @@ export function getTypeFromMetadata(type: FieldType, operator: Maybe<QueryFilter
// default to SELECT if value is a date literal (query restore would have a value)
if (Array.isArray(value) || DATE_LITERALS_SET.has(value || '')) {
return isListOperator(operator) ? 'SELECT-MULTI' : 'SELECT';
} else if (value && REGEX.NUMERIC.test(value)) {
// Set to manual value if text is not a valid date
} else if (value && !isValid(parseISO(value))) {
return 'TEXT';
}
return 'DATE';
Expand All @@ -226,7 +228,8 @@ export function getTypeFromMetadata(type: FieldType, operator: Maybe<QueryFilter
// default to SELECT (Relative Value) if no value or value is a date literal (query restore would have a value)
if (!value || Array.isArray(value) || DATE_LITERALS_SET.has(value)) {
return isListOperator(operator) ? 'SELECT-MULTI' : 'SELECT';
} else if (value && REGEX.NUMERIC.test(value)) {
// Set to manual value if text is not a valid date
} else if (value && !isValid(parseISO(value))) {
return 'TEXT';
}
return 'DATETIME';
Expand Down

0 comments on commit 310e899

Please sign in to comment.