Skip to content

Commit

Permalink
Merge pull request #1111 from jetstreamapp/bug/1110-query-restore-dat…
Browse files Browse the repository at this point in the history
…e-literal

Fix query restore date function detection
  • Loading branch information
paustint authored Dec 18, 2024
2 parents 2a8348e + a56cc16 commit 489e904
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const QueryGroupByTitleSummary: FunctionComponent<QueryGroupByTitleSummar
<Badge key={groupBy.field} className="slds-m-left_x-small slds-truncate" title={groupBy.fieldLabel || undefined}>
{groupBy.function ? (
<>
{groupBy.field}({groupBy.function})
{groupBy.function}({groupBy.field})
</>
) : (
groupBy.field
Expand Down
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
4 changes: 4 additions & 0 deletions libs/features/query/src/utils/query-soql-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
WhereClause,
isOrderByField,
isValueCondition,
isValueFunctionCondition,
isWhereOrHavingClauseWithRightCondition,
} from '@jetstreamapp/soql-parser-js';
import isString from 'lodash/isString';
Expand Down Expand Up @@ -206,6 +207,9 @@ function getParsableFieldsFromFilter(where: Maybe<WhereClause>, fields: string[]
if (isValueCondition(where.left)) {
fields.push(where.left.field?.toLowerCase());
}
if (isValueFunctionCondition(where.left) && Array.isArray(where.left.fn.parameters) && isString(where.left.fn.parameters[0])) {
fields.push(where.left.fn.parameters[0].toLowerCase());
}
if (isWhereOrHavingClauseWithRightCondition(where)) {
getParsableFieldsFromFilter(where.right, fields);
}
Expand Down

0 comments on commit 489e904

Please sign in to comment.