diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 723f0b5f83c..8e76e855c07 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -1530,6 +1530,13 @@ func (dr *DashboardServiceImpl) FindDashboards(ctx context.Context, query *dashb finalResults := make([]dashboards.DashboardSearchProjection, len(response.Hits)) for i, hit := range response.Hits { + folderTitle := "" + folderID := int64(0) + if f, ok := folderNames[hit.Folder]; ok { + folderTitle = f.Title + folderID = f.ID + } + result := dashboards.DashboardSearchProjection{ ID: hit.Field.GetNestedInt64(resource.SEARCH_FIELD_LEGACY_ID), UID: hit.Name, @@ -1538,7 +1545,9 @@ func (dr *DashboardServiceImpl) FindDashboards(ctx context.Context, query *dashb Slug: slugify.Slugify(hit.Title), IsFolder: false, FolderUID: hit.Folder, - FolderTitle: folderNames[hit.Folder], + FolderTitle: folderTitle, + FolderID: folderID, + FolderSlug: slugify.Slugify(folderTitle), Tags: hit.Tags, } @@ -1563,7 +1572,12 @@ func (dr *DashboardServiceImpl) FindDashboards(ctx context.Context, query *dashb return dr.dashboardStore.FindDashboards(ctx, query) } -func (dr *DashboardServiceImpl) fetchFolderNames(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery, hits []dashboardv0.DashboardHit) (map[string]string, error) { +type folderRes struct { + Title string + ID int64 +} + +func (dr *DashboardServiceImpl) fetchFolderNames(ctx context.Context, query *dashboards.FindPersistedDashboardsQuery, hits []dashboardv0.DashboardHit) (map[string]folderRes, error) { // call this with elevated permissions so we can get folder names where user does not have access // some dashboards are shared directly with user, but the folder is not accessible via the folder permissions serviceCtx, serviceIdent := identity.WithServiceIdentity(ctx, query.OrgId) @@ -1578,9 +1592,12 @@ func (dr *DashboardServiceImpl) fetchFolderNames(ctx context.Context, query *das return nil, folder.ErrInternal.Errorf("failed to fetch parent folders: %w", err) } - folderNames := make(map[string]string) + folderNames := make(map[string]folderRes) for _, f := range folders { - folderNames[f.UID] = f.Title + folderNames[f.UID] = folderRes{ + Title: f.Title, + ID: f.ID, + } } return folderNames, nil } @@ -1660,7 +1677,7 @@ func makeQueryResult(query *dashboards.FindPersistedDashboardsQuery, res []dashb } // nolint:staticcheck - if item.FolderID > 0 { + if item.FolderID > 0 || item.FolderUID != "" { hit.FolderURL = dashboards.GetFolderURL(item.FolderUID, item.FolderSlug) } diff --git a/pkg/services/dashboards/service/dashboard_service_test.go b/pkg/services/dashboards/service/dashboard_service_test.go index 0f830e3d1df..83e6eca02a7 100644 --- a/pkg/services/dashboards/service/dashboard_service_test.go +++ b/pkg/services/dashboards/service/dashboard_service_test.go @@ -1585,6 +1585,8 @@ func TestSearchDashboards(t *testing.T) { }, FolderTitle: "testing-folder-1", FolderUID: "f1", + FolderID: 1, + FolderURL: "/dashboards/f/f1/testing-folder-1", }, { UID: "uid2", @@ -1596,6 +1598,8 @@ func TestSearchDashboards(t *testing.T) { Tags: []string{}, FolderTitle: "testing-folder-1", FolderUID: "f1", + FolderID: 1, + FolderURL: "/dashboards/f/f1/testing-folder-1", }, } query := dashboards.FindPersistedDashboardsQuery{ @@ -1611,7 +1615,9 @@ func TestSearchDashboards(t *testing.T) { Title: "Dashboard 1", Tags: []string{"tag1", "tag2"}, FolderTitle: "testing-folder-1", + FolderSlug: "testing-folder-1", FolderUID: "f1", + FolderID: 1, }, { UID: "uid2", @@ -1619,7 +1625,9 @@ func TestSearchDashboards(t *testing.T) { OrgID: 1, Title: "Dashboard 2", FolderTitle: "testing-folder-1", + FolderSlug: "testing-folder-1", FolderUID: "f1", + FolderID: 1, }, }, nil).Once() result, err := service.SearchDashboards(context.Background(), &query) @@ -1634,6 +1642,7 @@ func TestSearchDashboards(t *testing.T) { { UID: "f1", Title: "testing-folder-1", + ID: 1, }, } fakeFolders.ExpectedHitList = expectedFolders