]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Prettier KV-table 22422/head
authorStephan Müller <smueller@suse.com>
Tue, 5 Jun 2018 14:15:36 +0000 (16:15 +0200)
committerStephan Müller <smueller@suse.com>
Tue, 12 Jun 2018 13:42:27 +0000 (15:42 +0200)
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-key-value/table-key-value.component.ts

index df54ca431084ab2221701fdc635cd6638f8cc50d..179bf3279fa53df7e7feb74d7ac99b0feb91020d 100644 (file)
@@ -25,11 +25,6 @@ describe('TableKeyValueComponent', () => {
 
   it('should create', () => {
     expect(component).toBeTruthy();
-    expect(component._convertValue).toBeTruthy();
-    expect(component._makePairs).toBeTruthy();
-    expect(component._makePairsFromObject).toBeTruthy();
-    expect(component._makePairsFromArray).toBeTruthy();
-    expect(component._insertFlattenObjects).toBeTruthy();
   });
 
   it('should make key value object pairs out of arrays with length two', () => {
@@ -127,17 +122,17 @@ describe('TableKeyValueComponent', () => {
       expect(component._convertValue(v(value)).value).toBe(result);
 
     it('should leave a string as it is', () => {
-      testConvertValue('something', 'something')
+      testConvertValue('something', 'something');
     });
 
     it('should leave an int as it is', () => {
-      testConvertValue(29, 29)
+      testConvertValue(29, 29);
     });
 
     it('should convert arrays with any type to string', () => {
-      testConvertValue([1, 2, 3], '1, 2, 3')
-      testConvertValue([{ sth: 'something' }], '{"sth":"something"}')
-      testConvertValue([1, 'two', { 3: 'three' }], '1, two, {"3":"three"}')
+      testConvertValue([1, 2, 3], '1, 2, 3');
+      testConvertValue([{ sth: 'something' }], '{"sth":"something"}');
+      testConvertValue([1, 'two', { 3: 'three' }], '1, two, {"3":"three"}');
     });
 
     it('should convert only allow objects if renderObjects is set to true', () => {
index 0c836648fb321e1216c81f2f8e1730055cbb6a47..a440bb1ffa693cbaf00a41d7caee798b36badc49 100644 (file)
@@ -19,7 +19,6 @@ import { CdTableColumn } from '../../models/cd-table-column';
   styleUrls: ['./table-key-value.component.scss']
 })
 export class TableKeyValueComponent implements OnInit, OnChanges {
-
   columns: Array<CdTableColumn> = [];
 
   @Input() data: any;
@@ -30,8 +29,8 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
   @Input() appendParentKey = true;
 
   tableData: {
-    key: string,
-    value: any
+    key: string;
+    value: any;
   }[];
 
   /**
@@ -39,7 +38,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
    */
   @Output() fetchData = new EventEmitter();
 
-  constructor() { }
+  constructor() {}
 
   ngOnInit() {
     this.columns = [
@@ -78,7 +77,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
     } else {
       throw new Error('Wrong data format');
     }
-    temp = temp.map((v) => this._convertValue(v)).filter(o => o); // Filters out undefined
+    temp = temp.map((v) => this._convertValue(v)).filter((o) => o); // Filters out undefined
     return this.renderObjects ? this._insertFlattenObjects(temp) : temp;
   }
 
@@ -94,7 +93,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
     } else {
       if (_.isArray(first)) {
         if (first.length === 2) {
-          temp = data.map(a => ({
+          temp = data.map((a) => ({
             key: a[0],
             value: a[1]
           }));
@@ -107,7 +106,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
   }
 
   _makePairsFromObject(data: object) {
-    return Object.keys(data).map(k => ({
+    return Object.keys(data).map((k) => ({
       key: k,
       value: data[k]
     }));
@@ -117,7 +116,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
     temp.forEach((v, i) => {
       if (_.isPlainObject(v.value)) {
         temp.splice(i, 1);
-        this._makePairs(v.value).forEach(item => {
+        this._makePairs(v.value).forEach((item) => {
           if (this.appendParentKey) {
             item.key = v.key + ' ' + item.key;
           }
@@ -131,7 +130,9 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
 
   _convertValue(v: any) {
     if (_.isArray(v.value)) {
-      v.value = v.value.map((v) => (_.isPlainObject(v) ? JSON.stringify(v) : v)).join(', ');
+      v.value = v.value
+        .map((item) => (_.isPlainObject(item) ? JSON.stringify(item) : item))
+        .join(', ');
     } else if (_.isPlainObject(v.value) && !this.renderObjects) {
       return;
     }