internal/httpd/filters.go

1c20fc5c9fa1ffecea9369a20d6937c70188bca1
gitbay/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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form