From e25a8fa181b37e7815b08d6026833b6537c9079b Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Tue, 18 Jun 2019 08:47:57 -0700 Subject: [PATCH] fix: sorting label by description (#14148) * chore: labels test cleanup * fix: throwing error when value is empty string --- ui/cypress/e2e/labels.test.ts | 13 +++++--- ui/src/labels/components/LabelsTab.tsx | 2 +- ui/src/shared/components/Filter.test.tsx | 41 ++++++++++++++++++++++++ ui/src/shared/components/Filter.tsx | 6 +--- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/ui/cypress/e2e/labels.test.ts b/ui/cypress/e2e/labels.test.ts index 59c13c0582..2fe86aab08 100644 --- a/ui/cypress/e2e/labels.test.ts +++ b/ui/cypress/e2e/labels.test.ts @@ -188,7 +188,7 @@ describe('labels', () => { "(\u03944) J'entends par attribut ce que l'entendement perçoit d'une substance comme constituant son essence. " const newLabelColor = '#B0D0FF' - //create label + // create label cy.get('@org').then(({id}) => { cy.createLabel(oldLabelName, id, { @@ -197,14 +197,16 @@ describe('labels', () => { }) }) - //verify name, descr, color + // verify name, descr, color cy.getByTestID('label-card').should('have.length', 1) cy.getByTestID('label-card') .contains(oldLabelName) .should('be.visible') + cy.getByTestID('label-card') .contains(oldLabelDescription) .should('be.visible') + cy.getByTestID('label-card') .children('div.resource-list--name-meta') .children('div.label') @@ -219,12 +221,13 @@ describe('labels', () => { .children('div') .invoke('text') .should('equal', 'Edit Label') - //dissmiss + + // dismiss cy.getByTestID('overlay--header') .children('button') .click() - //modify + // modify cy.getByTestID('label-card') .contains(oldLabelName) .click() @@ -240,7 +243,7 @@ describe('labels', () => { .type(newLabelColor) cy.getByTestID('create-label-form--submit').click() - //verify name, descr, color + // verify name, descr, color cy.getByTestID('label-card').should('have.length', 1) cy.getByTestID('label-card') .contains(newLabelName) diff --git a/ui/src/labels/components/LabelsTab.tsx b/ui/src/labels/components/LabelsTab.tsx index e468c109a3..a6bdddf581 100644 --- a/ui/src/labels/components/LabelsTab.tsx +++ b/ui/src/labels/components/LabelsTab.tsx @@ -101,7 +101,7 @@ class Labels extends PureComponent { list={labels} - searchKeys={['name', 'description']} + searchKeys={['name', 'properties.description']} searchTerm={searchTerm} > {ls => ( diff --git a/ui/src/shared/components/Filter.test.tsx b/ui/src/shared/components/Filter.test.tsx index 2b9c8dd043..48230853ef 100644 --- a/ui/src/shared/components/Filter.test.tsx +++ b/ui/src/shared/components/Filter.test.tsx @@ -173,6 +173,47 @@ describe('FilterList', () => { expect(expected[2].textContent).toEqual(itemThree.name) }) + it('can filter nested objects', () => { + const itemOne = { + id: '1', + name: 'crackle', + properties: { + description: 'a', + }, + } + + const itemTwo = { + id: '2', + name: 'ports', + properties: { + description: 'b', + }, + } + + const itemThree = { + id: '3', + name: 'rando', + properties: { + description: 'z', + }, + } + + const list = [itemOne, itemTwo, itemThree] + + const searchTerm = 'Z' + const searchKeys = ['name', 'properties.description'] + const {getAllByTestId} = setup({ + list, + searchTerm, + searchKeys, + }) + + const expected = getAllByTestId('list-item') + + expect(expected.length).toEqual(1) + expect(expected[0].textContent).toEqual(itemThree.name) + }) + it('errors when searchKey value is an object', () => { const itemOne = { name: { diff --git a/ui/src/shared/components/Filter.tsx b/ui/src/shared/components/Filter.tsx index ea1522670b..3aad3346d1 100644 --- a/ui/src/shared/components/Filter.tsx +++ b/ui/src/shared/components/Filter.tsx @@ -56,7 +56,7 @@ export default class FilterList extends PureComponent> { if (!isStringArray && _.isObject(value)) { throw new Error( - `The value at key "${key}" is an object. Take a look at "searchKeys" and + `The value at key "${key}" is an object. Take a look at "searchKeys" and make sure you're indexing onto a primitive value` ) } @@ -66,10 +66,6 @@ export default class FilterList extends PureComponent> { return this.checkIndex(searchIndex, formattedSearchTerm) } - if (value === '') { - throw new Error(`${key} is undefined. Take a look at "searchKeys". `) - } - return String(value) .toLocaleLowerCase() .includes(formattedSearchTerm)