From 31ea95946497afa6a46a6322ef48dea9729134d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Thu, 19 Sep 2019 16:04:34 +0200 Subject: [PATCH] mgr/dashboard: Searchable objects for table MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- .../block/rbd-list/rbd-list.component.html | 1 + .../datatable/table/table.component.spec.ts | 27 +++++++++++++++++++ .../shared/datatable/table/table.component.ts | 13 +++++++++ 3 files changed, 41 insertions(+) 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 af73500de788..ccd959253535 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 3d5a8101f9f8..46baec7e139c 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 bd00af4e7e69..feff197838a4 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 ); -- 2.47.3