diff --git a/public/app/core/services/search_srv.ts b/public/app/core/services/search_srv.ts index 3d85cb20005..64843c5a6c0 100644 --- a/public/app/core/services/search_srv.ts +++ b/public/app/core/services/search_srv.ts @@ -8,8 +8,10 @@ export class SearchSrv { } browse() { + const rootFolderId = 0; + let query = { - folderIds: [0] + folderIds: [rootFolderId] }; return this.backendSrv.search(query).then(results => { @@ -52,7 +54,9 @@ export class SearchSrv { } search(options) { - if (!options.query && !options.tag) { + if (!options.query && + (!options.tag || options.tag.length === 0) && + !options.starred) { return this.browse(); } diff --git a/public/app/core/specs/search_srv.jest.ts b/public/app/core/specs/search_srv.jest.ts index 0e14aad8dae..f27a7fd8c21 100644 --- a/public/app/core/specs/search_srv.jest.ts +++ b/public/app/core/specs/search_srv.jest.ts @@ -90,4 +90,30 @@ describe('SearchSrv', () => { }); + describe("with tags", () => { + beforeEach(() => { + backendSrvMock.search = jest.fn(); + backendSrvMock.search.mockReturnValue(Promise.resolve([])); + + return searchSrv.search({tag: ['atag']}).then(() => {}); + }); + + it("should send tags query to backend search", () => { + expect(backendSrvMock.search.mock.calls[0][0].tag).toHaveLength(1); + }); + }); + + describe("with starred", () => { + beforeEach(() => { + backendSrvMock.search = jest.fn(); + backendSrvMock.search.mockReturnValue(Promise.resolve([])); + + return searchSrv.search({starred: true}).then(() => {}); + }); + + it("should send starred query to backend search", () => { + expect(backendSrvMock.search.mock.calls[0][0].starred).toEqual(true); + }); + }); + }); diff --git a/public/app/features/dashboard/dashboard_list_ctrl.ts b/public/app/features/dashboard/dashboard_list_ctrl.ts index ace7d8065a7..57b692833d8 100644 --- a/public/app/features/dashboard/dashboard_list_ctrl.ts +++ b/public/app/features/dashboard/dashboard_list_ctrl.ts @@ -4,17 +4,20 @@ import { SearchSrv } from 'app/core/services/search_srv'; export class DashboardListCtrl { public sections: any []; - tags: any []; + tagFilterOptions: any []; selectedTagFilter: any; query: any; navModel: any; canDelete = false; canMove = false; + starredFilterOptions = [{text: 'Filter by Starred', disabled: true}, {text: 'Yes'}, {text: 'No'}]; + selectedStarredFilter: any; /** @ngInject */ constructor(private backendSrv, navModelSrv, private $q, private searchSrv: SearchSrv) { this.navModel = navModelSrv.getNav('dashboards', 'dashboards'); this.query = {query: '', mode: 'tree', tag: []}; + this.selectedStarredFilter = this.starredFilterOptions[0]; this.getDashboards().then(() => { this.getTags(); @@ -22,7 +25,9 @@ export class DashboardListCtrl { } getDashboards() { - if (this.query.query.length === 0 && this.query.tag.length === 0) { + if (this.query.query.length === 0 && + this.query.tag.length === 0 && + !this.query.starred) { return this.searchSrv.browse().then((result) => { return this.initDashboardList(result); }); @@ -139,24 +144,25 @@ export class DashboardListCtrl { getTags() { return this.searchSrv.getDashboardTags().then((results) => { - this.tags = [{ term: 'Filter By Tag', disabled: true }].concat(results); - this.selectedTagFilter = this.tags[0]; + this.tagFilterOptions = [{ term: 'Filter By Tag', disabled: true }].concat(results); + this.selectedTagFilter = this.tagFilterOptions[0]; }); } filterByTag(tag, evt) { this.query.tag.push(tag); - this.getDashboards(); if (evt) { evt.stopPropagation(); evt.preventDefault(); } + + return this.getDashboards(); } - filterChange() { + onTagFilterChange() { this.query.tag.push(this.selectedTagFilter.term); - this.selectedTagFilter = this.tags[0]; - this.getDashboards(); + this.selectedTagFilter = this.tagFilterOptions[0]; + return this.getDashboards(); } removeTag(tag, evt) { @@ -167,4 +173,9 @@ export class DashboardListCtrl { evt.preventDefault(); } } + + onStarredFilterChange() { + this.query.starred = this.selectedStarredFilter.text === 'Yes'; + return this.getDashboards(); + } } diff --git a/public/app/features/dashboard/partials/dashboardList.html b/public/app/features/dashboard/partials/dashboardList.html index b5f0fabeef4..0ab7aa28175 100644 --- a/public/app/features/dashboard/partials/dashboardList.html +++ b/public/app/features/dashboard/partials/dashboardList.html @@ -52,16 +52,22 @@