diff --git a/pkg/registry/apis/dashboard/legacysearcher/search_client.go b/pkg/registry/apis/dashboard/legacysearcher/search_client.go index 71501c3fdcd..c108814a553 100644 --- a/pkg/registry/apis/dashboard/legacysearcher/search_client.go +++ b/pkg/registry/apis/dashboard/legacysearcher/search_client.go @@ -89,6 +89,36 @@ func (c *DashboardSearchClient) Search(ctx context.Context, req *resource.Resour } } } + + // if searching for tags, get those instead of the dashboards or folders + for facet, _ := range req.Facet { + if facet == resource.SEARCH_FIELD_TAGS { + tags, err := c.dashboardStore.GetDashboardTags(ctx, &dashboards.GetDashboardTagsQuery{ + OrgID: user.GetOrgID(), + }) + if err != nil { + return nil, err + } + list := &resource.ResourceSearchResponse{ + Results: &resource.ResourceTable{}, + Facet: map[string]*resource.ResourceSearchResponse_Facet{ + "tags": &resource.ResourceSearchResponse_Facet{ + Terms: []*resource.ResourceSearchResponse_TermFacet{}, + }, + }, + } + + for _, tag := range tags { + list.Facet["tags"].Terms = append(list.Facet["tags"].Terms, &resource.ResourceSearchResponse_TermFacet{ + Term: tag.Term, + Count: int64(tag.Count), + }) + } + + return list, nil + } + } + // handle deprecated dashboardIds query param for _, field := range req.Options.Labels { if field.Key == utils.LabelKeyDeprecatedInternalID { diff --git a/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go b/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go index 14dc870bbd4..76afb49f70b 100644 --- a/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go +++ b/pkg/registry/apis/dashboard/legacysearcher/search_client_test.go @@ -92,6 +92,46 @@ func TestDashboardSearchClient_Search(t *testing.T) { mockStore.AssertExpectations(t) }) + t.Run("Query for tags should return facet properly", func(t *testing.T) { + mockStore.On("GetDashboardTags", mock.Anything, &dashboards.GetDashboardTagsQuery{OrgID: 2}).Return([]*dashboards.DashboardTagCloudItem{ + {Term: "tag1", Count: 1}, + {Term: "tag2", Count: 5}, + }, nil).Once() + + req := &resource.ResourceSearchRequest{ + Facet: map[string]*resource.ResourceSearchRequest_Facet{ + "tags": { + Field: "tags", + }, + }, + Options: &resource.ListOptions{ + Key: dashboardKey, + }, + } + resp, err := client.Search(ctx, req) + + require.NoError(t, err) + require.NotNil(t, resp) + require.Equal(t, &resource.ResourceSearchResponse{ + Results: &resource.ResourceTable{}, + Facet: map[string]*resource.ResourceSearchResponse_Facet{ + "tags": &resource.ResourceSearchResponse_Facet{ + Terms: []*resource.ResourceSearchResponse_TermFacet{ + { + Term: "tag1", + Count: 1, + }, + { + Term: "tag2", + Count: 5, + }, + }, + }, + }, + }, resp) + mockStore.AssertExpectations(t) + }) + t.Run("Query should be set as the title, and * should be removed", func(t *testing.T) { mockStore.On("FindDashboards", mock.Anything, &dashboards.FindPersistedDashboardsQuery{ Title: "test",