update like to wrap between % if no wildcard is given

This commit is contained in:
Stephanie Yang 2021-06-07 12:41:00 -05:00
parent af83e61101
commit 732040dc80
2 changed files with 17 additions and 2 deletions

View file

@ -103,7 +103,18 @@ describe('set types', () => {
}])).toEqual({ error: false, query: 'Not(Union(Row(fieldName="one"), Row(fieldName="two")))' })
});
it('stringifies like operator', () => {
it('stringifies like operator with a wildcard', () => {
expect(stringifyRowData([{
row: [{
"field": "fieldName",
"rowOperator": "like",
"value": "value%",
"type": "set"
}]
}])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="value%"))' })
});
it('stringifies like operator without a wildcard', () => {
expect(stringifyRowData([{
row: [{
"field": "fieldName",

View file

@ -30,7 +30,11 @@ export const stringifyRowData = (rowData: RowGrouping[], operator?: Operator) =>
return { error: true, query: error.message };
}
} else if (rowOperator === 'like') {
rowString = `UnionRows(Rows(field=${field}, like="%${value}%"))`;
if (value.includes('%')) {
rowString = `UnionRows(Rows(field=${field}, like="${value}"))`;
} else {
rowString = `UnionRows(Rows(field=${field}, like="%${value}%"))`;
}
} else {
rowString = ['set', 'timestamp'].includes(type)
? `Row(${field}${operator}"${value}")`