From 56616e69a1e78c2bfd035a028109af112f172eec Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Fri, 13 Sep 2024 13:51:08 +0200 Subject: [PATCH] scopes: sort scope dashboard bindings on dashboard title (#93305) Signed-off-by: bergquist --- pkg/registry/apis/scope/find_scope_dashboards.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/registry/apis/scope/find_scope_dashboards.go b/pkg/registry/apis/scope/find_scope_dashboards.go index bdaa55ef338..f4cace05c19 100644 --- a/pkg/registry/apis/scope/find_scope_dashboards.go +++ b/pkg/registry/apis/scope/find_scope_dashboards.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + "slices" + "strings" scope "github.com/grafana/grafana/pkg/apis/scope/v0alpha1" "k8s.io/apimachinery/pkg/api/errors" @@ -92,6 +94,11 @@ func (f *findScopeDashboardsREST) Connect(ctx context.Context, name string, opts } } + // sort the dashboard lists based on dashboard title. + slices.SortFunc(results.Items, func(i, j scope.ScopeDashboardBinding) int { + return strings.Compare(i.Status.DashboardTitle, j.Status.DashboardTitle) + }) + logger.FromContext(req.Context()).Debug("find scopedashboardbinding", "raw", len(all.Items), "filtered", len(results.Items)) responder.Object(200, results)