store sortable columns in map

llb-desktop-client-sort-backup
Emilia Grant 4 months ago committed by Sepehr
parent d58009e87a
commit a68efbfe97

@ -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
}

Loading…
Cancel
Save