Dashboards: Fix FindDashboards when kubernetesClientDashboardsFolders is disabled (#105974)
Dashboards: fix legacy FindDashboards
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user