Peter Sanchez: 1 Fixing missing query string options when paginating org links. 6 files changed, 35 insertions(+), 32 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/121/mbox | git am -3Learn more about email & git
Fixes: https://todo.code.netlandish.com/~netlandish/links/104 Signed-off-by: Peter Sanchez <peter@netlandish.com> --- admin/routes.go | 12 ++++++------ billing/routes.go | 4 ++-- core/routes.go | 6 +++--- helpers.go | 29 ++++++++++++++++------------- list/routes.go | 12 ++++++------ short/routes.go | 4 ++-- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/admin/routes.go b/admin/routes.go index 3184bb8..1e730b1 100644 --- a/admin/routes.go +++ b/admin/routes.go @@ -1165,11 +1165,11 @@ func (s *Service) DomainList(c echo.Context) error { return err } if result.Organizations.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.Organizations.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Organizations.PageInfo.Cursor, "next") } if result.Organizations.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.Organizations.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Organizations.PageInfo.Cursor, "prev") } gmap["domains"] = result.Organizations.Result return s.Render(c, http.StatusOK, "admin_domains_list.html", gmap) @@ -1242,11 +1242,11 @@ func (s *Service) OrgList(c echo.Context) error { return err } if result.Organizations.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.Organizations.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Organizations.PageInfo.Cursor, "next") } if result.Organizations.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.Organizations.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Organizations.PageInfo.Cursor, "prev") } gmap["orgs"] = result.Organizations.Result return s.Render(c, http.StatusOK, "admin_organization_list.html", gmap) @@ -1631,11 +1631,11 @@ func (s *Service) UserList(c echo.Context) error { return err } if result.GetUsers.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", query, result.GetUsers.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.GetUsers.PageInfo.Cursor, "next") } if result.GetUsers.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", query, result.GetUsers.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.GetUsers.PageInfo.Cursor, "prev") } gmap["users"] = result.GetUsers.Result return s.Render(c, http.StatusOK, "admin_user_list.html", gmap) diff --git a/billing/routes.go b/billing/routes.go index 9699849..5fd4e83 100644 --- a/billing/routes.go @@ -281,11 +281,11 @@ func (s *Service) SubscriptionHistory(c echo.Context) error { } if result.Payments.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Payments.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Payments.PageInfo.Cursor, "next") } if result.Payments.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Payments.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Payments.PageInfo.Cursor, "prev") } return s.Render(c, http.StatusOK, "billing_history.html", gmap) diff --git a/core/routes.go b/core/routes.go index 5d2995b..d6bdf55 100644 --- a/core/routes.go +++ b/core/routes.go @@ -2254,11 +2254,11 @@ func (s *Service) OrgLinksList(c echo.Context) error { } if result.OrgLinks.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", tag, search, result.OrgLinks.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.OrgLinks.PageInfo.Cursor, "next") } if result.OrgLinks.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", tag, search, result.OrgLinks.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.OrgLinks.PageInfo.Cursor, "prev") } if navFlag == "recent" { gmap["title"] = lt.Translate("Recent Links") @@ -3249,7 +3249,7 @@ func (s *Service) FollowToggle(c echo.Context) error { orgSlug := c.Param("slug") action := c.Param("action") var q string - result := make(map[string]interface{}) + result := make(map[string]any) switch action { case "follow": q = `mutation Follow($orgSlug: String!) { diff --git a/helpers.go b/helpers.go index 9f86203..4e944c0 100644 --- a/helpers.go +++ b/helpers.go @@ -480,16 +480,19 @@ func ParsePendingBaseURLs(ctx context.Context, userAgent string) error { } // GetPaginationParams returns the params needed for cursor pagination -func GetPaginationParams(pagination, tag, search, cursor string) template.URL { - queryParams := make(url.Values) - queryParams.Set(pagination, cursor) - if tag != "" { - queryParams.Set("tag", tag) +func GetPaginationParams(c echo.Context, pagvar, cursor string, exclude ...string) template.URL { + q := make(url.Values) + oldq := c.QueryParams() + for k, val := range oldq { + if k == pagvar || slices.Contains(exclude, k) { + continue + } + for _, v := range val { + q.Add(k, v) + } } - if search != "" { - queryParams.Set("q", search) - } - return template.URL(queryParams.Encode()) + q.Set(pagvar, cursor) + return template.URL(q.Encode()) } // Maps a list of domain by their levels (user, system, domain) @@ -784,7 +787,7 @@ func NewTagQuery(t, c string) *TagQuery { } } -func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []interface{}, error) { +func (t TagQuery) GetSubQuery(inputTag, inputExcludeTag *string) (string, []any, error) { var tags = make([]string, 0) if inputTag != nil && *inputTag != "" { tag := strings.Replace(*inputTag, " ", "", -1) @@ -942,7 +945,7 @@ func IsRegistrationEnabled(c echo.Context) bool { // Render is just a helper to always include base.html in our template // renderings. -func Render(c echo.Context, code int, name string, data interface{}) error { +func Render(c echo.Context, code int, name string, data any) error { gctx := c.(*server.Context) tmpl, err := gctx.NewTemplate( TemplateFS, @@ -1338,11 +1341,11 @@ func FetchAuditLogs(c echo.Context, userID int, "listId": listID, } if result.AuditLogs.PageInfo.HasPrevPage { - gmap["prevURL"] = GetPaginationParams("prev", "", "", result.AuditLogs.PageInfo.Cursor) + gmap["prevURL"] = GetPaginationParams(c, "prev", result.AuditLogs.PageInfo.Cursor, "next") } if result.AuditLogs.PageInfo.HasNextPage { - gmap["nextURL"] = GetPaginationParams("next", "", "", result.AuditLogs.PageInfo.Cursor) + gmap["nextURL"] = GetPaginationParams(c, "next", result.AuditLogs.PageInfo.Cursor, "prev") } return gmap, nil diff --git a/list/routes.go b/list/routes.go index 09af3f9..1271fbf 100644 --- a/list/routes.go +++ b/list/routes.go @@ -591,11 +591,11 @@ func (s *Service) ListingLinksManage(c echo.Context) error { "org": org, } if result.Listing.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Listing.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listing.PageInfo.Cursor, "next") } if result.Listing.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Listing.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listing.PageInfo.Cursor, "prev") } return s.Render(c, http.StatusOK, "listing_link_list.html", gmap) } @@ -1118,11 +1118,11 @@ func (s *Service) ListingList(c echo.Context) error { "autoCompleteOrgID": org.ID, } if result.Listings.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.Listings.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listings.PageInfo.Cursor, "next") } if result.Listings.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", tag, "", result.Listings.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listings.PageInfo.Cursor, "prev") } return s.Render(c, http.StatusOK, "listing_list.html", gmap) } @@ -1621,11 +1621,11 @@ func (r *DetailService) ListDetail(c echo.Context) error { "query": template.URL(query.Encode()), } if result.Listing.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", "", "", result.Listing.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.Listing.PageInfo.Cursor, "next") } if result.Listing.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", "", "", result.Listing.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.Listing.PageInfo.Cursor, "prev") } srv := gctx.Server req := c.Request() diff --git a/short/routes.go b/short/routes.go index 5fce7cd..96d1106 100644 --- a/short/routes.go +++ b/short/routes.go @@ -180,11 +180,11 @@ func (s *Service) LinkShortList(c echo.Context) error { } if result.LinkShorts.PageInfo.HasPrevPage { - gmap["prevURL"] = links.GetPaginationParams("prev", tag, "", result.LinkShorts.PageInfo.Cursor) + gmap["prevURL"] = links.GetPaginationParams(c, "prev", result.LinkShorts.PageInfo.Cursor, "next") } if result.LinkShorts.PageInfo.HasNextPage { - gmap["nextURL"] = links.GetPaginationParams("next", tag, "", result.LinkShorts.PageInfo.Cursor) + gmap["nextURL"] = links.GetPaginationParams(c, "next", result.LinkShorts.PageInfo.Cursor, "prev") } return s.Render(c, http.StatusOK, "link_short_list.html", gmap) } -- 2.47.2
Applied. To git@git.code.netlandish.com:~netlandish/links f712053..cbe9bed master -> master