From 72900d81d8d5e51b203028f66664f3188c7ec603 Mon Sep 17 00:00:00 2001
From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com>
Date: Tue, 15 Nov 2022 08:26:01 -0500
Subject: [PATCH] [v9.2.x] Search: Fixes issue with Recent/Starred section
always displaying "General" folder (#58749)
---
.../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 c9af99428b3..600a3873829 100644
--- a/public/app/features/search/page/components/FolderSection.tsx
+++ b/public/app/features/search/page/components/FolderSection.tsx
@@ -77,8 +77,8 @@ export const FolderSection: FC = ({
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]);