From 20e6ac397ebb1c855d7c98a9fc2918477367bdfd Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Tue, 15 Nov 2022 13:16:03 +0100 Subject: [PATCH] Search: Fixes issue with Recent/Starred section always displaying "General" folder (#58746) --- .../page/components/FolderSection.test.tsx | 33 +++++++++++++++++-- .../search/page/components/FolderSection.tsx | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/public/app/features/search/page/components/FolderSection.test.tsx b/public/app/features/search/page/components/FolderSection.test.tsx index b77e5d1f216..9359618cc8e 100644 --- a/public/app/features/search/page/components/FolderSection.test.tsx +++ b/public/app/features/search/page/components/FolderSection.test.tsx @@ -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(); + + 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(); + }); + }); }); }); diff --git a/public/app/features/search/page/components/FolderSection.tsx b/public/app/features/search/page/components/FolderSection.tsx index 1ca6f74a29a..c1e4f89b00a 100644 --- a/public/app/features/search/page/components/FolderSection.tsx +++ b/public/app/features/search/page/components/FolderSection.tsx @@ -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]);