From bb7410aa09ae1b89f87ca693a79959d8010c14f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Fern=C3=A1ndez?= Date: Tue, 17 Jan 2023 16:35:54 +0100 Subject: [PATCH] Search: Fix empty folder message showing when by starred dashboards (#61610) --- .../page/components/SearchView.test.tsx | 40 +++++++++++++++++++ .../search/page/components/SearchView.tsx | 2 +- .../search/state/SearchStateManager.ts | 4 ++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/public/app/features/search/page/components/SearchView.test.tsx b/public/app/features/search/page/components/SearchView.test.tsx index cb3f230c736..8c594887eca 100644 --- a/public/app/features/search/page/components/SearchView.test.tsx +++ b/public/app/features/search/page/components/SearchView.test.tsx @@ -105,6 +105,46 @@ describe('SearchView', () => { expect(screen.getByRole('button', { name: 'Clear search and filters' })).toBeInTheDocument(); }); + it('shows an empty state if no starred dashboard returned', async () => { + jest.spyOn(getGrafanaSearcher(), 'search').mockResolvedValue({ + ...mockSearchResult, + totalRows: 0, + view: new DataFrameView({ fields: [], length: 0 }), + }); + + setup(undefined, { starred: true }); + + await waitFor(() => expect(screen.queryByText('No results found for your query.')).toBeInTheDocument()); + expect(screen.getByRole('button', { name: 'Clear search and filters' })).toBeInTheDocument(); + }); + + it('shows empty folder cta for empty folder', async () => { + jest.spyOn(getGrafanaSearcher(), 'search').mockResolvedValue({ + ...mockSearchResult, + totalRows: 0, + view: new DataFrameView({ fields: [], length: 0 }), + }); + + setup( + { + folderDTO: { + id: 1, + uid: 'abc', + title: 'morning coffee', + url: '/morningcoffee', + version: 1, + canSave: true, + canEdit: true, + canAdmin: true, + canDelete: true, + }, + }, + undefined + ); + + await waitFor(() => expect(screen.queryByText("This folder doesn't have any dashboards yet")).toBeInTheDocument()); + }); + describe('include panels', () => { it('should be enabled when layout is list', async () => { config.featureToggles.panelTitleSearch = true; diff --git a/public/app/features/search/page/components/SearchView.tsx b/public/app/features/search/page/components/SearchView.tsx index 5a03908f1df..dbde3e3ad22 100644 --- a/public/app/features/search/page/components/SearchView.tsx +++ b/public/app/features/search/page/components/SearchView.tsx @@ -159,7 +159,7 @@ export const SearchView = ({ showManage, folderDTO, hidePseudoFolders, keyboardE ); }; - if (folderDTO && !state.loading && !state.result?.totalRows && !state.query.length) { + if (folderDTO && !state.loading && !state.result?.totalRows && !stateManager.hasSearchFilters()) { return ( { store.set(SEARCH_PANELS_LOCAL_STORAGE_KEY, includePanels); }; + hasSearchFilters() { + return this.state.query || this.state.tag.length || this.state.starred; + } + getSearchQuery() { const q: SearchQuery = { query: this.state.query,