Skip to content

Commit 41af99f

Browse files
committed
fix: Strip comparator name prefixes
https://harperdb.atlassian.net/browse/STUDIO-451
1 parent 8058201 commit 41af99f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/features/instance/operations/queries/getSearchByConditions.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import {
77
import type { InstanceAttribute } from '@/lib/api.patch';
88
import { describe, expect, it } from 'vitest';
99

10-
function attr(type?: InstanceAttribute['type']): InstanceAttribute {
11-
return { attribute: 'col', type };
12-
}
13-
1410
describe('parseComparator', () => {
1511
it('understand greater than equal', () => {
1612
expect(parseComparator('>= 10')).toEqual({
@@ -170,6 +166,23 @@ describe('translateColumnFilterToSearchCondition', () => {
170166
});
171167
});
172168

169+
it('strips off redundant names', () => {
170+
expect(
171+
translateColumnFilterToSearchConditions('age', 'age > 1 & age < 10', attr('Int')),
172+
).toEqual([
173+
{
174+
search_attribute: 'age',
175+
search_type: 'greater_than',
176+
search_value: 1,
177+
},
178+
{
179+
search_attribute: 'age',
180+
search_type: 'less_than',
181+
search_value: 10,
182+
},
183+
]);
184+
});
185+
173186
it('parses booleans with accepted truthy values', () => {
174187
expect(
175188
translateColumnFilterToSearchCondition('active', 'Yes', attr('Boolean')),
@@ -231,4 +244,9 @@ describe('translateColumnFilterToSearchCondition', () => {
231244
search_value: 'value',
232245
});
233246
});
247+
248+
function attr(type?: InstanceAttribute['type']): InstanceAttribute {
249+
return { attribute: 'col', type };
250+
}
251+
234252
});

src/features/instance/operations/queries/getSearchByConditions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export function translateColumnFilterToSearchConditions(key: string, rawValues:
9090
}
9191

9292
export function translateColumnFilterToSearchCondition(key: string, rawValue: string, attribute: InstanceAttribute | undefined): SearchCondition {
93+
if (rawValue.startsWith(key)) {
94+
rawValue = rawValue.substring(key.length);
95+
}
9396
const { comparator, value } = parseComparator(rawValue);
9497
switch (attribute?.type) {
9598
case 'ID':
@@ -115,7 +118,6 @@ export function translateColumnFilterToSearchCondition(key: string, rawValue: st
115118
};
116119
}
117120
case 'Date': {
118-
const { comparator, value } = parseComparator(rawValue);
119121
const parsed = new Date(value).toISOString();
120122
return {
121123
search_attribute: key,

0 commit comments

Comments
 (0)