Search: Fix empty folder message showing when by starred dashboards (#61610)

This commit is contained in:
Laura Fernández 2023-01-17 16:35:54 +01:00 committed by GitHub
parent 4076933e66
commit bb7410aa09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -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<DashboardQueryResult>({ 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<DashboardQueryResult>({ 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;

View File

@ -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 (
<EmptyListCTA
title="This folder doesn't have any dashboards yet"

View File

@ -136,6 +136,10 @@ export class SearchStateManager extends StateManagerBase<SearchState> {
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,