mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
3d51ca7377
commit
05dda7f0a1
@ -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
|
||||
}
|
||||
kind := strings.ToLower(doc.Kind)
|
||||
frame.AppendRow(kind, doc.UID, doc.Spec.Title, "", nil, doc.FolderID)
|
||||
func dashboardPageItemLink(doc *DashboardListDoc, subURL string) string {
|
||||
if doc.FolderID == "" {
|
||||
return fmt.Sprintf("%s/d/%s/%s", subURL, doc.Name, doc.Namespace)
|
||||
}
|
||||
response.Frames = append(response.Frames, frame)
|
||||
return response
|
||||
return fmt.Sprintf("%s/dashboards/f/%s/%s", subURL, doc.Name, doc.Namespace)
|
||||
}
|
||||
|
||||
type customMeta struct {
|
||||
|
Loading…
Reference in New Issue
Block a user