From a68efbfe978386974fd74549bd302191414a3e34 Mon Sep 17 00:00:00 2001 From: Emilia Grant Date: Fri, 16 Jan 2026 12:19:54 -0500 Subject: [PATCH] store sortable columns in map --- .../internal/daemon/search_handler.go | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/clientcache/internal/daemon/search_handler.go b/internal/clientcache/internal/daemon/search_handler.go index 30f244ef60..0ba90981d9 100644 --- a/internal/clientcache/internal/daemon/search_handler.go +++ b/internal/clientcache/internal/daemon/search_handler.go @@ -9,6 +9,7 @@ import ( stderrors "errors" "fmt" "net/http" + "slices" "strconv" "strings" @@ -62,6 +63,13 @@ const ( sortDirectionKey = "sort_direction" ) +var ( + sortableColumnsForResource = map[cache.SearchableResource][]cache.SortBy{ + cache.Targets: []cache.SortBy{cache.SortByName}, + cache.Sessions: []cache.SortBy{cache.SortByCreatedAt}, + } +) + func newSearchHandlerFunc(ctx context.Context, repo *cache.Repository, refreshService *cache.RefreshService, logger hclog.Logger) (http.HandlerFunc, error) { const op = "daemon.newSearchHandlerFunc" switch { @@ -285,18 +293,9 @@ func parseSortBy(sb string, sr cache.SearchableResource) (cache.SortBy, bool) { return cache.SortByDefault, true } - switch sr { - case cache.Targets: - if by != cache.SortByName { - return cache.SortByDefault, false - } - return by, true - case cache.Sessions: - if by != cache.SortByCreatedAt { - return cache.SortByDefault, false - } - return by, true - default: + sortableBys, ok := sortableColumnsForResource[sr] + if !ok || !slices.Contains(sortableBys, by) { return cache.SortByDefault, false } + return by, true }