internal/httpd/filters.go
30 lines · 707 bytes
1package httpd
2
3import "net/url"
4
5// listFilter is one active narrowing on a list page, with the URL that
6// drops it and keeps the rest.
7type listFilter struct {
8 Key string
9 Value string
10 Clear string
11}
12
13// activeFilters turns the non-empty (key, value) pairs into the chips a
14// list page shows above its rows.
15func activeFilters(state string, pairs [][2]string) []listFilter {
16 var out []listFilter
17 for i, kv := range pairs {
18 if kv[1] == "" {
19 continue
20 }
21 q := url.Values{"state": {state}}
22 for j, other := range pairs {
23 if j != i && other[1] != "" {
24 q.Set(other[0], other[1])
25 }
26 }
27 out = append(out, listFilter{Key: kv[0], Value: kv[1], Clear: "?" + q.Encode()})
28 }
29 return out
30}