dmitri.shuralyov.com/app/changes

Adjust state filter for changes.
dmitshur committed 7 years ago commit 05de2ccfa6bc82155c0cdf45f5a71fab2bf275f1
Showing partial commit. Full Commit
Collapse all
main.go
@@ -188,19 +188,19 @@ func (h *handler) ChangesHandler(w http.ResponseWriter, req *http.Request) error
	}
	filter, err := stateFilter(req.URL.Query())
	if err != nil {
		return httperror.BadRequest{Err: err}
	}
	is, err := h.is.List(req.Context(), state.RepoSpec, changes.ListOptions{State: filter})
	is, err := h.is.List(req.Context(), state.RepoSpec, changes.ListOptions{Filter: filter})
	if err != nil {
		return err
	}
	openCount, err := h.is.Count(req.Context(), state.RepoSpec, changes.ListOptions{State: changes.StateFilter(changes.OpenState)})
	openCount, err := h.is.Count(req.Context(), state.RepoSpec, changes.ListOptions{Filter: changes.FilterOpen})
	if err != nil {
		return fmt.Errorf("changes.Count(open): %v", err)
	}
	closedCount, err := h.is.Count(req.Context(), state.RepoSpec, changes.ListOptions{State: changes.StateFilter(changes.ClosedState)})
	closedCount, err := h.is.Count(req.Context(), state.RepoSpec, changes.ListOptions{Filter: changes.FilterClosedMerged})
	if err != nil {
		return fmt.Errorf("changes.Count(closed): %v", err)
	}
	var es []component.ChangeEntry
	for _, i := range is {
@@ -235,15 +235,15 @@ const (
// returning an error if the value is unsupported.
func stateFilter(query url.Values) (changes.StateFilter, error) {
	selectedTabName := query.Get(stateQueryKey)
	switch selectedTabName {
	case "":
		return changes.StateFilter(changes.OpenState), nil
		return changes.FilterOpen, nil
	case "closed":
		return changes.StateFilter(changes.ClosedState), nil
		return changes.FilterClosedMerged, nil
	case "all":
		return changes.AllStates, nil
		return changes.FilterAll, nil
	default:
		return "", fmt.Errorf("unsupported state filter value: %q", selectedTabName)
	}
}