From 28784935b8b6b6f733601193a2aeeeeceed64dd2 Mon Sep 17 00:00:00 2001 From: Jason Stangroome Date: Fri, 20 Aug 2021 06:49:14 +1000 Subject: [PATCH] Sort notification channels alphabetically (#37426) Even without the ability to control the sort order or to filter, this notably improves usability for long lists of notification channels. Partially fixes #20067. --- pkg/services/sqlstore/alert_notification.go | 2 +- pkg/services/sqlstore/alert_notification_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go index 118fc4aca5b..1f37efca75f 100644 --- a/pkg/services/sqlstore/alert_notification.go +++ b/pkg/services/sqlstore/alert_notification.go @@ -112,7 +112,7 @@ func GetAlertNotificationsWithUid(query *models.GetAlertNotificationsWithUidQuer func GetAllAlertNotifications(query *models.GetAllAlertNotificationsQuery) error { results := make([]*models.AlertNotification, 0) - if err := x.Where("org_id = ?", query.OrgId).Find(&results); err != nil { + if err := x.Where("org_id = ?", query.OrgId).Asc("name").Find(&results); err != nil { return err } diff --git a/pkg/services/sqlstore/alert_notification_test.go b/pkg/services/sqlstore/alert_notification_test.go index 5b35416dcef..bde1ad2c4cf 100644 --- a/pkg/services/sqlstore/alert_notification_test.go +++ b/pkg/services/sqlstore/alert_notification_test.go @@ -325,6 +325,10 @@ func TestAlertNotificationSQLAccess(t *testing.T) { err := GetAllAlertNotifications(query) So(err, ShouldBeNil) So(len(query.Result), ShouldEqual, 4) + So(query.Result[0].Name, ShouldEqual, cmd4.Name) + So(query.Result[1].Name, ShouldEqual, cmd1.Name) + So(query.Result[2].Name, ShouldEqual, cmd3.Name) + So(query.Result[3].Name, ShouldEqual, cmd2.Name) }) })