]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix table in order to view boolean values 21643/head
authorTatjana Dehler <tdehler@suse.com>
Thu, 3 May 2018 14:59:32 +0000 (16:59 +0200)
committerTatjana Dehler <tdehler@suse.com>
Tue, 8 May 2018 14:58:37 +0000 (16:58 +0200)
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 <tdehler@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

index 358a8cde5da2ff96908790fbcf8ef77958a9517f..5eb78f884e58db9a218064bac137560aa5cfb511 100644 (file)
@@ -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);
     });
   });
 });
index f2b03187e9997e48469ade359daaec0c75e860ac..4d587c08f526e9a24a6943d6cac66e4e3fc40f0c 100644 (file)
@@ -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;