Search: Fixes issue with Recent/Starred section always displaying "General" folder (#58746)

This commit is contained in:
Joao Silva 2022-11-15 13:16:03 +01:00 committed by GitHub
parent 028751a18a
commit 20e6ac397e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 4 deletions

View File

@ -26,7 +26,7 @@ describe('FolderSection', () => {
window.localStorage.clear();
});
describe('when where are no results', () => {
describe('when there are no results', () => {
const emptySearchData: DataFrame = {
fields: [
{ name: 'kind', type: FieldType.string, config: {}, values: new ArrayVector([]) },
@ -100,8 +100,19 @@ describe('FolderSection', () => {
{ name: 'uid', type: FieldType.string, config: {}, values: new ArrayVector(['my-dashboard-1']) },
{ name: 'url', type: FieldType.string, config: {}, values: new ArrayVector(['/my-dashboard-1']) },
{ name: 'tags', type: FieldType.other, config: {}, values: new ArrayVector([['foo', 'bar']]) },
{ name: 'location', type: FieldType.string, config: {}, values: new ArrayVector(['/my-dashboard-1']) },
{ name: 'location', type: FieldType.string, config: {}, values: new ArrayVector(['my-folder-1']) },
],
meta: {
custom: {
locationInfo: {
'my-folder-1': {
name: 'My folder 1',
kind: 'folder',
url: '/my-folder-1',
},
},
},
},
length: 1,
};
@ -205,5 +216,23 @@ describe('FolderSection', () => {
expect(mockSelectionToggle).toHaveBeenCalledWith('dashboard', 'my-dashboard-1');
});
});
describe('when in a pseudo-folder (i.e. Starred/Recent)', () => {
const mockRecentSection = {
kind: 'folder',
uid: '__recent',
title: 'Recent',
itemsUIDs: ['my-dashboard-1'],
};
it('shows the correct folder name next to the dashboard', async () => {
render(<FolderSection section={mockRecentSection} onTagSelected={mockOnTagSelected} />);
await userEvent.click(await screen.findByRole('button', { name: mockRecentSection.title }));
expect(getGrafanaSearcher().search).toHaveBeenCalled();
expect(await screen.findByText('My dashboard 1')).toBeInTheDocument();
expect(await screen.findByText('My folder 1')).toBeInTheDocument();
});
});
});
});

View File

@ -82,8 +82,8 @@ export const FolderSection = ({
id: 666, // do not use me!
isStarred: false,
tags: item.tags ?? [],
folderUid,
folderTitle,
folderUid: folderUid || item.location,
folderTitle: folderTitle || raw.view.dataFrame.meta?.custom?.locationInfo[item.location].name,
}));
return v;
}, [sectionExpanded, tags]);