Library Panels: Add name endpoint & unique name validation to AddLibraryPanelModal (#33987)

This commit is contained in:
kay delaney
2021-05-14 15:03:37 +01:00
committed by GitHub
parent d49deebefe
commit c778d6a4a2
8 changed files with 269 additions and 127 deletions
+22
View File
@@ -8,6 +8,28 @@ import (
"github.com/grafana/grafana/pkg/services/sqlstore"
)
type Pair struct {
key string
value interface{}
}
func selectLibraryElementByParam(params []Pair) (string, []interface{}) {
conditions := make([]string, 0, len(params))
values := make([]interface{}, 0, len(params))
for _, p := range params {
conditions = append(conditions, "le."+p.key+"=?")
values = append(values, p.value)
}
return ` WHERE ` + strings.Join(conditions, " AND "), values
}
func writeParamSelectorSQL(builder *sqlstore.SQLBuilder, params ...Pair) {
if len(params) > 0 {
conditionString, paramValues := selectLibraryElementByParam(params)
builder.Write(conditionString, paramValues...)
}
}
func writePerPageSQL(query searchLibraryElementsQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
if query.perPage != 0 {
offset := query.perPage * (query.page - 1)