mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
dashboards: render correct link for folder when searching for dashboards (#10763)
Fixes #10761
This commit is contained in:
parent
20feb123c9
commit
a879dd8c0c
@ -21,8 +21,9 @@ type Hit struct {
|
|||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
IsStarred bool `json:"isStarred"`
|
IsStarred bool `json:"isStarred"`
|
||||||
FolderId int64 `json:"folderId,omitempty"`
|
FolderId int64 `json:"folderId,omitempty"`
|
||||||
|
FolderUid string `json:"folderUid,omitempty"`
|
||||||
FolderTitle string `json:"folderTitle,omitempty"`
|
FolderTitle string `json:"folderTitle,omitempty"`
|
||||||
FolderSlug string `json:"folderSlug,omitempty"`
|
FolderUrl string `json:"folderUrl,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HitList []*Hit
|
type HitList []*Hit
|
||||||
|
@ -245,6 +245,7 @@ type DashboardSearchProjection struct {
|
|||||||
Term string
|
Term string
|
||||||
IsFolder bool
|
IsFolder bool
|
||||||
FolderId int64
|
FolderId int64
|
||||||
|
FolderUid string
|
||||||
FolderSlug string
|
FolderSlug string
|
||||||
FolderTitle string
|
FolderTitle string
|
||||||
}
|
}
|
||||||
@ -323,11 +324,15 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard
|
|||||||
Url: m.GetDashboardFolderUrl(item.IsFolder, item.Uid, item.Slug),
|
Url: m.GetDashboardFolderUrl(item.IsFolder, item.Uid, item.Slug),
|
||||||
Type: getHitType(item),
|
Type: getHitType(item),
|
||||||
FolderId: item.FolderId,
|
FolderId: item.FolderId,
|
||||||
|
FolderUid: item.FolderUid,
|
||||||
FolderTitle: item.FolderTitle,
|
FolderTitle: item.FolderTitle,
|
||||||
FolderSlug: item.FolderSlug,
|
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.FolderId > 0 {
|
||||||
|
hit.FolderUrl = m.GetFolderUrl(item.FolderUid, item.FolderSlug)
|
||||||
|
}
|
||||||
|
|
||||||
query.Result = append(query.Result, hit)
|
query.Result = append(query.Result, hit)
|
||||||
hits[item.Id] = hit
|
hits[item.Id] = hit
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
hit := query.Result[0]
|
hit := query.Result[0]
|
||||||
So(hit.Type, ShouldEqual, search.DashHitFolder)
|
So(hit.Type, ShouldEqual, search.DashHitFolder)
|
||||||
So(hit.Url, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
So(hit.Url, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
||||||
|
So(hit.FolderTitle, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to search for a dashboard folder's children", func() {
|
Convey("Should be able to search for a dashboard folder's children", func() {
|
||||||
@ -163,6 +164,10 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
hit := query.Result[0]
|
hit := query.Result[0]
|
||||||
So(hit.Id, ShouldEqual, savedDash.Id)
|
So(hit.Id, ShouldEqual, savedDash.Id)
|
||||||
So(hit.Url, ShouldEqual, fmt.Sprintf("/d/%s/%s", savedDash.Uid, savedDash.Slug))
|
So(hit.Url, ShouldEqual, fmt.Sprintf("/d/%s/%s", savedDash.Uid, savedDash.Slug))
|
||||||
|
So(hit.FolderId, ShouldEqual, savedFolder.Id)
|
||||||
|
So(hit.FolderUid, ShouldEqual, savedFolder.Uid)
|
||||||
|
So(hit.FolderTitle, ShouldEqual, savedFolder.Title)
|
||||||
|
So(hit.FolderUrl, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to search for dashboard by dashboard ids", func() {
|
Convey("Should be able to search for dashboard by dashboard ids", func() {
|
||||||
|
@ -107,6 +107,7 @@ func (sb *SearchBuilder) buildSelect() {
|
|||||||
dashboard_tag.term,
|
dashboard_tag.term,
|
||||||
dashboard.is_folder,
|
dashboard.is_folder,
|
||||||
dashboard.folder_id,
|
dashboard.folder_id,
|
||||||
|
folder.uid as folder_uid,
|
||||||
folder.slug as folder_slug,
|
folder.slug as folder_slug,
|
||||||
folder.title as folder_title
|
folder.title as folder_title
|
||||||
FROM `)
|
FROM `)
|
||||||
|
@ -150,9 +150,9 @@ export class SearchSrv {
|
|||||||
if (hit.folderId) {
|
if (hit.folderId) {
|
||||||
section = {
|
section = {
|
||||||
id: hit.folderId,
|
id: hit.folderId,
|
||||||
uid: hit.uid,
|
uid: hit.folderUid,
|
||||||
title: hit.folderTitle,
|
title: hit.folderTitle,
|
||||||
url: hit.url,
|
url: hit.folderUrl,
|
||||||
items: [],
|
items: [],
|
||||||
icon: 'fa fa-folder-open',
|
icon: 'fa fa-folder-open',
|
||||||
toggle: this.toggleFolder.bind(this),
|
toggle: this.toggleFolder.bind(this),
|
||||||
|
@ -20,9 +20,6 @@ describe('ManageDashboards', () => {
|
|||||||
icon: 'fa fa-folder',
|
icon: 'fa fa-folder',
|
||||||
tags: [],
|
tags: [],
|
||||||
isStarred: false,
|
isStarred: false,
|
||||||
folderId: 410,
|
|
||||||
folderTitle: 'afolder',
|
|
||||||
folderSlug: 'afolder',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
tags: [],
|
tags: [],
|
||||||
@ -77,9 +74,6 @@ describe('ManageDashboards', () => {
|
|||||||
icon: 'fa fa-folder',
|
icon: 'fa fa-folder',
|
||||||
tags: [],
|
tags: [],
|
||||||
isStarred: false,
|
isStarred: false,
|
||||||
folderId: 410,
|
|
||||||
folderTitle: 'afolder',
|
|
||||||
folderSlug: 'afolder',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
tags: [],
|
tags: [],
|
||||||
@ -112,8 +106,9 @@ describe('ManageDashboards', () => {
|
|||||||
tags: [],
|
tags: [],
|
||||||
isStarred: false,
|
isStarred: false,
|
||||||
folderId: 410,
|
folderId: 410,
|
||||||
folderTitle: 'afolder',
|
folderUid: 'uid',
|
||||||
folderSlug: 'afolder',
|
folderTitle: 'Folder',
|
||||||
|
folderUrl: '/dashboards/f/uid/folder',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 500,
|
id: 500,
|
||||||
|
@ -190,7 +190,9 @@ describe('SearchSrv', () => {
|
|||||||
title: 'dash in folder1 1',
|
title: 'dash in folder1 1',
|
||||||
type: 'dash-db',
|
type: 'dash-db',
|
||||||
folderId: 1,
|
folderId: 1,
|
||||||
|
folderUid: 'uid',
|
||||||
folderTitle: 'folder1',
|
folderTitle: 'folder1',
|
||||||
|
folderUrl: '/dashboards/f/uid/folder1',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -206,6 +208,11 @@ describe('SearchSrv', () => {
|
|||||||
|
|
||||||
it('should group results by folder', () => {
|
it('should group results by folder', () => {
|
||||||
expect(results).toHaveLength(2);
|
expect(results).toHaveLength(2);
|
||||||
|
expect(results[0].id).toEqual(0);
|
||||||
|
expect(results[1].id).toEqual(1);
|
||||||
|
expect(results[1].uid).toEqual('uid');
|
||||||
|
expect(results[1].title).toEqual('folder1');
|
||||||
|
expect(results[1].url).toEqual('/dashboards/f/uid/folder1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user