From 881eac42eb9f4f73d619653e08530f6ed9bcae18 Mon Sep 17 00:00:00 2001 From: Tatjana Dehler Date: Thu, 3 May 2018 16:59:32 +0200 Subject: [PATCH] mgr/dashboard: fix table in order to view boolean values The table didn't handle boolean values correctly. If a table contained booleans it resulted in a TypeError because the value can't be converted to lower case. We need to convert the boolean value to string at first. Signed-off-by: Tatjana Dehler --- .../datatable/table/table.component.spec.ts | 49 ++++++++++++------- .../shared/datatable/table/table.component.ts | 2 +- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts index 358a8cde5da2f..5eb78f884e58d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts @@ -17,7 +17,8 @@ describe('TableComponent', () => { data.push({ a: i, b: i * i, - c: [-(i % 10), 'score' + (i % 16 + 6) ] + c: [-(i % 10), 'score' + (i % 16 + 6) ], + d: !(i % 2) }); } return data; @@ -50,7 +51,8 @@ describe('TableComponent', () => { component.columns = [ {prop: 'a', name: 'Index'}, {prop: 'b', name: 'Power ofA'}, - {prop: 'c', name: 'Poker array'} + {prop: 'c', name: 'Poker array'}, + {prop: 'd', name: 'Boolean value'} ]; }); @@ -77,11 +79,23 @@ describe('TableComponent', () => { }); it('should search for 13', () => { - doSearch('13', 9, {a: 7, b: 49, c: [ -7, 'score13'] }); + doSearch('13', 9, {a: 7, b: 49, c: [ -7, 'score13'], d: false}); expect(component.rows[1].a).toBe(13); expect(component.rows[8].a).toBe(87); }); + it('should search for true', () => { + doSearch('true', 50, {a: 0, b: 0, c: [ -0, 'score6'], d: true}); + expect(component.rows[0].d).toBe(true); + expect(component.rows[1].d).toBe(true); + }); + + it('should search for false', () => { + doSearch('false', 50, {a: 1, b: 1, c: [ -1, 'score7'], d: false}); + expect(component.rows[0].d).toBe(false); + expect(component.rows[1].d).toBe(false); + }); + it('should test search manipulation', () => { let searchTerms = []; spyOn(component, 'subSearch').and.callFake((d, search, c) => { @@ -100,28 +114,28 @@ describe('TableComponent', () => { }); it('should search for multiple values', () => { - doSearch('7 5 3', 5, {a: 57, b: 3249, c: [ -7, 'score15']}); + doSearch('7 5 3', 5, {a: 57, b: 3249, c: [ -7, 'score15'], d: false}); }); it('should search with column filter', () => { - doSearch('power:1369', 1, {a: 37, b: 1369, c: [ -7, 'score11']}); - doSearch('ndex:7 ofa:5 poker:3', 3, {a: 71, b: 5041, c: [-1, 'score13']}); + doSearch('power:1369', 1, {a: 37, b: 1369, c: [ -7, 'score11'], d: false}); + doSearch('ndex:7 ofa:5 poker:3', 3, {a: 71, b: 5041, c: [-1, 'score13'], d: false}); }); it('should search with through array', () => { - doSearch('array:score21', 6, {a: 15, b: 225, c: [-5, 'score21']}); + doSearch('array:score21', 6, {a: 15, b: 225, c: [-5, 'score21'], d: false}); }); it('should search with spaces', () => { - doSearch('\'poker array\':score21', 6, {a: 15, b: 225, c: [-5, 'score21']}); - doSearch('"poker array":score21', 6, {a: 15, b: 225, c: [-5, 'score21']}); - doSearch('poker+array:score21', 6, {a: 15, b: 225, c: [-5, 'score21']}); + doSearch('\'poker array\':score21', 6, {a: 15, b: 225, c: [-5, 'score21'], d: false}); + doSearch('"poker array":score21', 6, {a: 15, b: 225, c: [-5, 'score21'], d: false}); + doSearch('poker+array:score21', 6, {a: 15, b: 225, c: [-5, 'score21'], d: false}); }); it('should not search if column name is incomplete', () => { - doSearch('\'poker array\'', 100, {a: 0, b: 0, c: [-0, 'score6']}); - doSearch('pok', 100, {a: 0, b: 0, c: [-0, 'score6']}); - doSearch('pok:', 100, {a: 0, b: 0, c: [-0, 'score6']}); + doSearch('\'poker array\'', 100, {a: 0, b: 0, c: [-0, 'score6'], d: true}); + doSearch('pok', 100, {a: 0, b: 0, c: [-0, 'score6'], d: true}); + doSearch('pok:', 100, {a: 0, b: 0, c: [-0, 'score6'], d: true}); }); it('should restore full table after search', () => { @@ -165,7 +179,7 @@ describe('TableComponent', () => { }); it('should have table columns', () => { - expect(component.tableColumns.length).toBe(3); + expect(component.tableColumns.length).toBe(4); expect(component.tableColumns).toEqual(component.columns); }); @@ -178,14 +192,15 @@ describe('TableComponent', () => { it('should remove column "a"', () => { toggleColumn('a', false); expect(component.table.sorts[0].prop).toBe('b'); - expect(component.tableColumns.length).toBe(2); + expect(component.tableColumns.length).toBe(3); }); it('should not be able to remove all columns', () => { toggleColumn('a', false); toggleColumn('b', false); toggleColumn('c', false); - expect(component.table.sorts[0].prop).toBe('c'); + toggleColumn('d', false); + expect(component.table.sorts[0].prop).toBe('d'); expect(component.tableColumns.length).toBe(1); }); @@ -193,7 +208,7 @@ describe('TableComponent', () => { toggleColumn('a', false); toggleColumn('a', true); expect(component.table.sorts[0].prop).toBe('b'); - expect(component.tableColumns.length).toBe(3); + expect(component.tableColumns.length).toBe(4); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts index f2b03187e9997..4d587c08f526e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts @@ -352,7 +352,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O } if (_.isArray(cellValue)) { cellValue = cellValue.join(' '); - } else if (_.isNumber(cellValue)) { + } else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) { cellValue = cellValue.toString(); } return cellValue.toLowerCase().indexOf(searchTerm) !== -1; -- 2.39.5