fix(api): correctly handle empty sort params

This commit is contained in:
Łukasz Mierzwa
2019-08-08 16:29:46 +01:00
parent 1b3c15a8eb
commit 9f5a3bdfae
2 changed files with 6 additions and 4 deletions

View File

@@ -164,7 +164,7 @@ func sortAlertGroups(c *gin.Context, groupsMap map[string]models.APIAlertGroup)
groups := make([]models.APIAlertGroup, 0, len(groupsMap))
sortOrder, found := c.GetQuery("sortOrder")
if !found {
if !found || sortOrder == "" {
sortOrder = config.Config.Grid.Sorting.Order
}
@@ -178,7 +178,7 @@ func sortAlertGroups(c *gin.Context, groupsMap map[string]models.APIAlertGroup)
}
sortLabel, found := c.GetQuery("sortLabel")
if !found {
if !found || sortLabel == "" {
sortLabel = config.Config.Grid.Sorting.Label
}

View File

@@ -1156,7 +1156,7 @@ var sortTests = []sortTest{
sortLabel: "",
sortReverse: "0",
expectedLabel: "cluster",
expectedValues: []string{"dev", "prod", "staging", "dev", "staging", "prod"},
expectedValues: []string{"dev", "dev", "prod", "prod", "staging", "staging"},
},
{
filter: "q=@receiver=by-cluster-service",
@@ -1164,7 +1164,7 @@ var sortTests = []sortTest{
sortLabel: "",
sortReverse: "1",
expectedLabel: "cluster",
expectedValues: []string{"prod", "staging", "dev", "staging", "prod", "dev"},
expectedValues: []string{"staging", "staging", "prod", "prod", "dev", "dev"},
},
{
filter: "q=@receiver=by-cluster-service",
@@ -1186,6 +1186,8 @@ var sortTests = []sortTest{
func TestSortOrder(t *testing.T) {
mockConfig()
config.Config.Grid.Sorting.Order = "label"
config.Config.Grid.Sorting.Label = "cluster"
config.Config.Grid.Sorting.CustomValues.Labels = map[string]map[string]string{}
config.Config.Grid.Sorting.CustomValues.Labels["job"] = map[string]string{
"node_exporter": "1",