]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Stringify object[] in KV-table
authorStephan Müller <smueller@suse.com>
Tue, 5 Jun 2018 14:11:12 +0000 (16:11 +0200)
committerStephan Müller <smueller@suse.com>
Tue, 12 Jun 2018 13:42:27 +0000 (15:42 +0200)
The problem was that object[] weren't handled in the key value table
before. Now they will be stringified to prevent an output like
'[Object object]'.

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 53e89e53f9296b0202d0aa2a53ef22508169f7bd..df54ca431084ab2221701fdc635cd6638f8cc50d 100644 (file)
@@ -121,13 +121,30 @@ describe('TableKeyValueComponent', () => {
     ]);
   });
 
-  it('tests _convertValue', () => {
+  describe('tests _convertValue', () => {
     const v = (value) => ({ key: 'sth', value: value });
-    expect(component._convertValue(v('something'))).toEqual(v('something'));
-    expect(component._convertValue(v([1, 2, 3]))).toEqual(v('1, 2, 3'));
-    expect(component._convertValue(v({ sth: 'something' }))).toBe(undefined);
-    component.renderObjects = true;
-    expect(component._convertValue(v({ sth: 'something' }))).toEqual(v({ sth: 'something' }));
+    const testConvertValue = (value, result) =>
+      expect(component._convertValue(v(value)).value).toBe(result);
+
+    it('should leave a string as it is', () => {
+      testConvertValue('something', 'something')
+    });
+
+    it('should leave an int as it is', () => {
+      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"}')
+    });
+
+    it('should convert only allow objects if renderObjects is set to true', () => {
+      expect(component._convertValue(v({ sth: 'something' }))).toBe(undefined);
+      component.renderObjects = true;
+      expect(component._convertValue(v({ sth: 'something' }))).toEqual(v({ sth: 'something' }));
+    });
   });
 
   it('tests _insertFlattenObjects', () => {
index a6ad738073e8b9266d6505d94781849b0f3371a8..0c836648fb321e1216c81f2f8e1730055cbb6a47 100644 (file)
@@ -131,7 +131,7 @@ export class TableKeyValueComponent implements OnInit, OnChanges {
 
   _convertValue(v: any) {
     if (_.isArray(v.value)) {
-      v.value = v.value.join(', ');
+      v.value = v.value.map((v) => (_.isPlainObject(v) ? JSON.stringify(v) : v)).join(', ');
     } else if (_.isPlainObject(v.value) && !this.renderObjects) {
       return;
     }