From: Stephan Müller Date: Thu, 19 Sep 2019 14:04:34 +0000 (+0200) Subject: mgr/dashboard: Searchable objects for table X-Git-Tag: v15.1.0~1024^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=31ea95946497afa6a46a6322ef48dea9729134d4;p=ceph-ci.git mgr/dashboard: Searchable objects for table The table can now search through objects, by default it won't search through them, but it won't fail like before. The RBD list page is now capable of searching through objects, which only exist on an RBD that was cloned from a snapshot. Fixes: https://tracker.ceph.com/issues/42480 Signed-off-by: Stephan Müller --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.html index af73500de78..ccd95925353 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.html @@ -7,6 +7,7 @@ columnMode="flex" [columns]="columns" identifier="id" + [searchableObjects]="true" forceIdentifier="true" selectionType="single" (updateSelection)="updateSelection($event)"> 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 3d5a8101f9f..46baec7e139 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 @@ -109,6 +109,33 @@ describe('TableComponent', () => { component.updateFilter(true); }; + describe('searchableObjects', () => { + const testObject = { + obj: { + min: 8, + max: 123 + } + }; + + beforeEach(() => { + component.data = [testObject]; + component.columns = [{ prop: 'obj', name: 'Object' }]; + }); + + it('should not search through objects as default case', () => { + expect(component.searchableObjects).toBe(false); + expectSearch('8', []); + }); + + it('should search through objects if searchableObjects is set to true', () => { + component.searchableObjects = true; + expectSearch('28', []); + expectSearch('8', [testObject]); + expectSearch('123', [testObject]); + expectSearch('max', [testObject]); + }); + }); + it('should find a particular number', () => { expectSearch('5', [{ a: 5, b: 50, c: true }]); expectSearch('9', [{ a: 9, b: 90, c: true }]); 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 bd00af4e7e6..feff197838a 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 @@ -106,6 +106,10 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O @Input() autoSave = true; + // Enable this in order to search through the JSON of any used object. + @Input() + searchableObjects = false; + // Only needed to set if the classAddingTpl is used @Input() customCss?: { [css: string]: number | string | ((any) => boolean) }; @@ -561,6 +565,15 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O } else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) { cellValue = cellValue.toString(); } + + if (_.isObjectLike(cellValue)) { + if (this.searchableObjects) { + cellValue = JSON.stringify(cellValue); + } else { + return false; + } + } + return cellValue.toLowerCase().indexOf(searchTerm) !== -1; }).length > 0 );