Skip to content

Commit

Permalink
Fix null conditionals in toListWorkflowFilters and account for is and…
Browse files Browse the repository at this point in the history
… is null values
  • Loading branch information
laurakwhit committed Nov 27, 2024
1 parent fff0bcb commit 2a48b5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
34 changes: 30 additions & 4 deletions src/lib/utilities/query/to-list-workflow-filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ describe('combineFilters', () => {
conditional: 'is',
operator: '',
parenthesis: '',
value: 'null',
value: null,
},
];
expect(result).toEqual(expectedFilters);
Expand All @@ -1191,7 +1191,7 @@ describe('combineFilters', () => {
conditional: 'IS NOT',
operator: '',
parenthesis: '',
value: 'NULL',
value: null,
},
];
expect(result).toEqual(expectedFilters);
Expand All @@ -1209,15 +1209,41 @@ describe('combineFilters', () => {
conditional: 'is',
operator: 'AND',
parenthesis: '',
value: 'null',
value: null,
},
{
attribute: 'StartTime',
type: 'Datetime',
conditional: 'IS NOT',
operator: '',
parenthesis: '',
value: 'NULL',
value: null,
},
];
expect(result).toEqual(expectedFilters);
});

it('should parse a query with "is" and "is not" as a value', () => {
const result = toListWorkflowFilters(
'`WorkflowId`="is" AND `WorkflowType`="is not"',
attributes,
);
const expectedFilters = [
{
attribute: 'WorkflowId',
type: 'Keyword',
conditional: '=',
operator: 'AND',
parenthesis: '',
value: 'is',
},
{
attribute: 'WorkflowType',
type: 'Keyword',
conditional: '=',
operator: '',
parenthesis: '',
value: 'is not',
},
];
expect(result).toEqual(expectedFilters);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/utilities/query/to-list-workflow-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ export const toListWorkflowFilters = (

if (isNullConditional(nextToken)) {
const combinedTokens = `${nextToken} ${tokenTwoAhead}`;
filter.value = isNullConditional(combinedTokens)
const value = isNullConditional(combinedTokens)
? getThreeAhead(tokens, index)
: tokenTwoAhead;
filter.value = value.toLocaleLowerCase() === 'null' ? null : value;
} else if (isDatetimeStatement(attributes[token])) {
const start = tokenTwoAhead;
const hasValidStartTime = isValidDate(start);
Expand Down Expand Up @@ -125,7 +126,7 @@ export const toListWorkflowFilters = (
}
}

if (isConditional(token)) {
if (!filter.conditional && isConditional(token)) {
const combinedTokens = `${token} ${nextToken}`;
if (isNullConditional(combinedTokens)) {
filter.conditional = combinedTokens;
Expand Down

0 comments on commit 2a48b5b

Please sign in to comment.