Search: Fixes issue with Recent/Starred section always displaying "General" folder (#58746)
This commit is contained in:
@@ -26,7 +26,7 @@ describe('FolderSection', () => {
|
|||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when where are no results', () => {
|
describe('when there are no results', () => {
|
||||||
const emptySearchData: DataFrame = {
|
const emptySearchData: DataFrame = {
|
||||||
fields: [
|
fields: [
|
||||||
{ name: 'kind', type: FieldType.string, config: {}, values: new ArrayVector([]) },
|
{ 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: 'uid', type: FieldType.string, config: {}, values: new ArrayVector(['my-dashboard-1']) },
|
||||||
{ name: 'url', 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: '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,
|
length: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,5 +216,23 @@ describe('FolderSection', () => {
|
|||||||
expect(mockSelectionToggle).toHaveBeenCalledWith('dashboard', 'my-dashboard-1');
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ export const FolderSection = ({
|
|||||||
id: 666, // do not use me!
|
id: 666, // do not use me!
|
||||||
isStarred: false,
|
isStarred: false,
|
||||||
tags: item.tags ?? [],
|
tags: item.tags ?? [],
|
||||||
folderUid,
|
folderUid: folderUid || item.location,
|
||||||
folderTitle,
|
folderTitle: folderTitle || raw.view.dataFrame.meta?.custom?.locationInfo[item.location].name,
|
||||||
}));
|
}));
|
||||||
return v;
|
return v;
|
||||||
}, [sectionExpanded, tags]);
|
}, [sectionExpanded, tags]);
|
||||||
|
|||||||
Reference in New Issue
Block a user