Dashboards: Fix FindDashboards when kubernetesClientDashboardsFolders is disabled (#105974)

Dashboards: fix legacy FindDashboards
This commit is contained in:
Stephanie Hingtgen
2025-05-24 07:06:30 -06:00
committed by GitHub
parent a8fd34cec4
commit 5c0194955e
5 changed files with 95 additions and 113 deletions
+33 -1
View File
@@ -922,7 +922,39 @@ func (d *dashboardStore) FindDashboards(ctx context.Context, query *dashboards.F
return nil, err
}
return res, nil
if len(res) <= 1 {
return res, nil
}
// the search query above will return one row per dashboard tag, and dashboards
// can have multiple tags. we only want to return one row per dashboard, so dedup
// the results by id.
// note: we must preserve the order of the results as we dedup, as the query can be sorted
seen := make(map[int64]int)
uniqueRes := make([]dashboards.DashboardSearchProjection, 0, len(res))
for _, item := range res {
if idx, exists := seen[item.ID]; exists {
if item.Term != "" {
if uniqueRes[idx].Tags == nil {
uniqueRes[idx].Tags = make([]string, 0)
}
uniqueRes[idx].Tags = append(uniqueRes[idx].Tags, item.Term)
}
continue
}
if item.Tags == nil {
item.Tags = make([]string, 0)
}
if item.Term != "" {
item.Tags = append(item.Tags, item.Term)
}
seen[item.ID] = len(uniqueRes)
uniqueRes = append(uniqueRes, item)
}
return uniqueRes, nil
}
func (d *dashboardStore) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) ([]*dashboards.DashboardTagCloudItem, error) {