Skip to content

Commit

Permalink
Filter using 'is_substring' rather than 'equal'
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjbauer committed Jan 9, 2019
1 parent 8895058 commit 8efb2fc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions frontend/mock-backend/mock-api-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,16 @@ export default (app: express.Application) => {
((filter && filter.predicates) || []).forEach(p => {
resources = resources.filter(r => {
switch(p.op) {
// case PredicateOp.CONTAINS
// return r.name!.toLocaleLowerCase().indexOf(
// decodeURIComponent(req.query.filter).toLocaleLowerCase()) > -1);
case PredicateOp.EQUALS:
if (p.key !== 'name') {
throw new Error(`Key: ${p.key} is not yet supported by the mock API server`);
}
return r.name!.toLocaleLowerCase() === (p.string_value || '').toLocaleLowerCase();
return r.name && r.name.toLocaleLowerCase() === (p.string_value || '').toLocaleLowerCase();
case PredicateOp.ISSUBSTRING:
if (p.key !== 'name') {
throw new Error(`Key: ${p.key} is not yet supported by the mock API server`);
}
return r.name && r.name.toLocaleLowerCase().includes((p.string_value || '').toLocaleLowerCase());
case PredicateOp.NOTEQUALS:
// Fall through
case PredicateOp.GREATERTHAN:
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/apis/filter/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ export enum PredicateOp {
GREATERTHANEQUALS = <any> 'GREATER_THAN_EQUALS',
LESSTHAN = <any> 'LESS_THAN',
LESSTHANEQUALS = <any> 'LESS_THAN_EQUALS',
IN = <any> 'IN'
IN = <any> 'IN',
ISSUBSTRING = <any> 'IS_SUBSTRING'
}


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CustomTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('CustomTable', () => {
const expectedEncodedFilter = encodeURIComponent(JSON.stringify({
predicates: [{
key: 'name',
op: PredicateOp.EQUALS,
op: PredicateOp.ISSUBSTRING,
string_value: 'test filter',
}]
}));
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/CustomTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ export default class CustomTable extends React.Component<CustomTableProps, Custo
predicates: [{
// TODO: remove this hardcoding once more sophisticated filtering is supported
key: 'name',
// TODO: change this to the substring match operator once it's supported
op: PredicateOp.EQUALS,
op: PredicateOp.ISSUBSTRING,
string_value: filterString,
}],
};
Expand Down

0 comments on commit 8efb2fc

Please sign in to comment.