search: dashboard list link (#95996)

search: dashboard list link
This commit is contained in:
Scott Lepper 2024-11-07 09:40:05 -05:00 committed by GitHub
parent 3d51ca7377
commit 05dda7f0a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
@ -173,6 +174,23 @@ func (s *StandardSearchService) doSearchQuery(ctx context.Context, qry Query, _
return response
}
frame := newSearchFrame(res)
for _, r := range res.Items {
doc, err := getDoc(r.Value)
if err != nil {
s.logger.Error("Failed to parse doc", "error", err)
response.Error = err
return response
}
kind := strings.ToLower(doc.Kind)
link := dashboardPageItemLink(doc, s.cfg.AppSubURL)
frame.AppendRow(kind, doc.UID, doc.Spec.Title, link, nil, doc.FolderID)
}
response.Frames = append(response.Frames, frame)
return response
}
func newSearchFrame(res *resource.SearchResponse) *data.Frame {
fScore := data.NewFieldFromFieldType(data.FieldTypeFloat64, 0)
fUID := data.NewFieldFromFieldType(data.FieldTypeString, 0)
fKind := data.NewFieldFromFieldType(data.FieldTypeString, 0)
@ -202,19 +220,14 @@ func (s *StandardSearchService) doSearchQuery(ctx context.Context, qry Query, _
Count: uint64(len(res.Items)),
},
})
return frame
}
for _, r := range res.Items {
doc, err := getDoc(r.Value)
if err != nil {
s.logger.Error("Failed to parse doc", "error", err)
response.Error = err
return response
func dashboardPageItemLink(doc *DashboardListDoc, subURL string) string {
if doc.FolderID == "" {
return fmt.Sprintf("%s/d/%s/%s", subURL, doc.Name, doc.Namespace)
}
kind := strings.ToLower(doc.Kind)
frame.AppendRow(kind, doc.UID, doc.Spec.Title, "", nil, doc.FolderID)
}
response.Frames = append(response.Frames, frame)
return response
return fmt.Sprintf("%s/dashboards/f/%s/%s", subURL, doc.Name, doc.Namespace)
}
type customMeta struct {