From 8efb2fcff9f666ba5b101647e909dc9c6889cecb Mon Sep 17 00:00:00 2001 From: Riley Bauer Date: Tue, 8 Jan 2019 10:58:56 -0800 Subject: [PATCH] Filter using 'is_substring' rather than 'equal' --- frontend/mock-backend/mock-api-middleware.ts | 10 ++++++---- frontend/src/apis/filter/api.ts | 3 ++- frontend/src/components/CustomTable.test.tsx | 2 +- frontend/src/components/CustomTable.tsx | 3 +-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/mock-backend/mock-api-middleware.ts b/frontend/mock-backend/mock-api-middleware.ts index 3e0ed791ac55..09762aecbb92 100644 --- a/frontend/mock-backend/mock-api-middleware.ts +++ b/frontend/mock-backend/mock-api-middleware.ts @@ -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: diff --git a/frontend/src/apis/filter/api.ts b/frontend/src/apis/filter/api.ts index 5b7a7ceae12e..36c95227760c 100644 --- a/frontend/src/apis/filter/api.ts +++ b/frontend/src/apis/filter/api.ts @@ -209,7 +209,8 @@ export enum PredicateOp { GREATERTHANEQUALS = 'GREATER_THAN_EQUALS', LESSTHAN = 'LESS_THAN', LESSTHANEQUALS = 'LESS_THAN_EQUALS', - IN = 'IN' + IN = 'IN', + ISSUBSTRING = 'IS_SUBSTRING' } diff --git a/frontend/src/components/CustomTable.test.tsx b/frontend/src/components/CustomTable.test.tsx index f376e4b97116..acd2e4aed519 100644 --- a/frontend/src/components/CustomTable.test.tsx +++ b/frontend/src/components/CustomTable.test.tsx @@ -553,7 +553,7 @@ describe('CustomTable', () => { const expectedEncodedFilter = encodeURIComponent(JSON.stringify({ predicates: [{ key: 'name', - op: PredicateOp.EQUALS, + op: PredicateOp.ISSUBSTRING, string_value: 'test filter', }] })); diff --git a/frontend/src/components/CustomTable.tsx b/frontend/src/components/CustomTable.tsx index d4c4cb30141c..420385c766e8 100644 --- a/frontend/src/components/CustomTable.tsx +++ b/frontend/src/components/CustomTable.tsx @@ -480,8 +480,7 @@ export default class CustomTable extends React.Component