mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search (SQL): support dashboardUID query parameter (#50121)
This commit is contained in:
@@ -964,8 +964,10 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
||||
filters = append(filters, searchstore.TagsFilter{Tags: query.Tags})
|
||||
}
|
||||
|
||||
if len(query.DashboardIds) > 0 {
|
||||
filters = append(filters, searchstore.DashboardFilter{IDs: query.DashboardIds})
|
||||
if len(query.DashboardUIDs) > 0 {
|
||||
filters = append(filters, searchstore.DashboardFilter{UIDs: query.DashboardUIDs})
|
||||
} else if len(query.DashboardIds) > 0 {
|
||||
filters = append(filters, searchstore.DashboardIDFilter{IDs: query.DashboardIds})
|
||||
}
|
||||
|
||||
if query.IsStarred {
|
||||
|
||||
@@ -27,18 +27,19 @@ func ProvideService(cfg *setting.Cfg, sqlstore *sqlstore.SQLStore, starService s
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Title string
|
||||
Tags []string
|
||||
OrgId int64
|
||||
SignedInUser *models.SignedInUser
|
||||
Limit int64
|
||||
Page int64
|
||||
IsStarred bool
|
||||
Type string
|
||||
DashboardIds []int64
|
||||
FolderIds []int64
|
||||
Permission models.PermissionType
|
||||
Sort string
|
||||
Title string
|
||||
Tags []string
|
||||
OrgId int64
|
||||
SignedInUser *models.SignedInUser
|
||||
Limit int64
|
||||
Page int64
|
||||
IsStarred bool
|
||||
Type string
|
||||
DashboardUIDs []string
|
||||
DashboardIds []int64
|
||||
FolderIds []int64
|
||||
Permission models.PermissionType
|
||||
Sort string
|
||||
|
||||
Result models.HitList
|
||||
}
|
||||
@@ -58,16 +59,17 @@ type SearchService struct {
|
||||
|
||||
func (s *SearchService) SearchHandler(ctx context.Context, query *Query) error {
|
||||
dashboardQuery := models.FindPersistedDashboardsQuery{
|
||||
Title: query.Title,
|
||||
SignedInUser: query.SignedInUser,
|
||||
IsStarred: query.IsStarred,
|
||||
DashboardIds: query.DashboardIds,
|
||||
Type: query.Type,
|
||||
FolderIds: query.FolderIds,
|
||||
Tags: query.Tags,
|
||||
Limit: query.Limit,
|
||||
Page: query.Page,
|
||||
Permission: query.Permission,
|
||||
Title: query.Title,
|
||||
SignedInUser: query.SignedInUser,
|
||||
IsStarred: query.IsStarred,
|
||||
DashboardUIDs: query.DashboardUIDs,
|
||||
DashboardIds: query.DashboardIds,
|
||||
Type: query.Type,
|
||||
FolderIds: query.FolderIds,
|
||||
Tags: query.Tags,
|
||||
Limit: query.Limit,
|
||||
Page: query.Page,
|
||||
Permission: query.Permission,
|
||||
}
|
||||
|
||||
if sortOpt, exists := s.sortOptions[query.Sort]; exists {
|
||||
|
||||
@@ -95,14 +95,22 @@ func (f FolderFilter) Where() (string, []interface{}) {
|
||||
return sqlIDin("dashboard.folder_id", f.IDs)
|
||||
}
|
||||
|
||||
type DashboardFilter struct {
|
||||
type DashboardIDFilter struct {
|
||||
IDs []int64
|
||||
}
|
||||
|
||||
func (f DashboardFilter) Where() (string, []interface{}) {
|
||||
func (f DashboardIDFilter) Where() (string, []interface{}) {
|
||||
return sqlIDin("dashboard.id", f.IDs)
|
||||
}
|
||||
|
||||
type DashboardFilter struct {
|
||||
UIDs []string
|
||||
}
|
||||
|
||||
func (f DashboardFilter) Where() (string, []interface{}) {
|
||||
return sqlUIDin("dashboard.uid", f.UIDs)
|
||||
}
|
||||
|
||||
type TagsFilter struct {
|
||||
Tags []string
|
||||
}
|
||||
@@ -150,6 +158,21 @@ func sqlIDin(column string, ids []int64) (string, []interface{}) {
|
||||
return fmt.Sprintf("%s IN %s", column, sqlArray), params
|
||||
}
|
||||
|
||||
func sqlUIDin(column string, uids []string) (string, []interface{}) {
|
||||
length := len(uids)
|
||||
if length < 1 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
sqlArray := "(?" + strings.Repeat(",?", length-1) + ")"
|
||||
|
||||
params := []interface{}{}
|
||||
for _, id := range uids {
|
||||
params = append(params, id)
|
||||
}
|
||||
return fmt.Sprintf("%s IN %s", column, sqlArray), params
|
||||
}
|
||||
|
||||
// FolderWithAlertsFilter applies a filter that makes the result contain only folders that contain alert rules
|
||||
type FolderWithAlertsFilter struct {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user