Monorepo for Tangled tangled.org

appview/pulls: add pagination to pull requests listing #957

merged opened by boltless.me targeting master from sl/vmtzuqllzunn
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mcjfwc4w6o22
+26 -5
Diff #0
+2
appview/pages/pages.go
··· 1069 1069 Stacks map[string]models.Stack 1070 1070 Pipelines map[string]models.Pipeline 1071 1071 LabelDefs map[string]*models.LabelDefinition 1072 + Page pagination.Page 1073 + PullCount int 1072 1074 } 1073 1075 1074 1076 func (p *Pages) RepoPulls(w io.Writer, params RepoPullsParams) error {
+8
appview/pages/templates/repo/pulls/pulls.html
··· 170 170 </div> 171 171 {{ end }} 172 172 </div> 173 + {{if gt .PullCount .Page.Limit }} 174 + {{ template "fragments/pagination" (dict 175 + "Page" .Page 176 + "TotalCount" .PullCount 177 + "BasePath" (printf "/%s/pulls" .RepoInfo.FullName) 178 + "QueryParams" (printf "state=%s&q=%s" .FilteringBy.String .FilterQuery) 179 + ) }} 180 + {{ end }} 173 181 {{ end }} 174 182 175 183 {{ define "stackedPullList" }}
+15 -4
appview/pulls/pulls.go
··· 567 567 state = models.PullMerged 568 568 } 569 569 570 + page := pagination.FromContext(r.Context()) 571 + 570 572 f, err := s.repoResolver.Resolve(r) 571 573 if err != nil { 572 574 log.Println("failed to get repo and knot", err) 573 575 return 574 576 } 575 577 576 - keyword := params.Get("q") 577 - 578 - page := pagination.Page{ 579 - Limit: 99999, 578 + var totalPulls int 579 + switch state { 580 + case models.PullOpen: 581 + totalPulls = f.RepoStats.PullCount.Open 582 + case models.PullMerged: 583 + totalPulls = f.RepoStats.PullCount.Merged 584 + case models.PullClosed: 585 + totalPulls = f.RepoStats.PullCount.Closed 580 586 } 581 587 588 + keyword := params.Get("q") 589 + 582 590 var pulls []*models.Pull 583 591 searchOpts := models.PullSearchOptions{ 584 592 Keyword: keyword, ··· 593 601 l.Error("failed to search for pulls", "err", err) 594 602 return 595 603 } 604 + totalPulls = int(res.Total) 596 605 l.Debug("searched pulls with indexer", "count", len(res.Hits)) 597 606 598 607 pulls, err = db.GetPulls( ··· 700 709 FilterQuery: keyword, 701 710 Stacks: stacks, 702 711 Pipelines: m, 712 + Page: page, 713 + PullCount: totalPulls, 703 714 }) 704 715 } 705 716
+1 -1
appview/pulls/router.go
··· 9 9 10 10 func (s *Pulls) Router(mw *middleware.Middleware) http.Handler { 11 11 r := chi.NewRouter() 12 - r.Get("/", s.RepoPulls) 12 + r.With(middleware.Paginate).Get("/", s.RepoPulls) 13 13 r.With(middleware.AuthMiddleware(s.oauth)).Route("/new", func(r chi.Router) { 14 14 r.Get("/", s.NewPull) 15 15 r.Get("/patch-upload", s.PatchUploadFragment)

History

2 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview/pulls: add pagination to pull requests listing
3/3 success
expand
expand 1 comment

lgtm, works nicely! might be a good time to improve the styling of the pagination component.

pull request successfully merged
boltless.me submitted #0
1 commit
expand
appview/pulls: add pagination to pull requests listing
3/3 success
expand
expand 0 comments