-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
fix: keep runner list sorting across pages, make page size configurable #39161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
| "slices" | ||
|
|
||
| actions_model "gitea.dev/models/actions" | ||
| "gitea.dev/models/db" | ||
|
|
@@ -34,6 +35,11 @@ const ( | |
| tplUserRunnerEdit templates.TplName = "user/settings/runner_edit" | ||
| ) | ||
|
|
||
| // runnersPageSizes are the selectable "runners per page" values on the runner management page. | ||
| var runnersPageSizes = []int{25, 50, 100, 200} | ||
|
|
||
| const runnersDefaultPageSize = 100 | ||
|
Comment on lines
+38
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also comes a question: what benefits does the "selectable items per page" bring? Isn't it "the more the better" in most cases?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so what do you suggest? showing always all?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean maybe a default 50 or 100 is good enough? No need to make it "selectable". We never did so on other pages. If we'd really like to make the "limit" selectable, we need a plan to consider all pages.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just annoyed me yesterday as I have 102 runners 😂
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could agree 100 seems too many ... So reduce it to 50?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's too less...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I misunderstood. Maybe you mean you need a large limit to see all? From UI/UX perspective, I don't see why a list should show too many items, it exceeds human processing capabilities. When the list is large, usually it needs to support "search" or "filter". And, Gitea already has a lot of config options under So overall there are already many different approaches. If we don't have a plan, and the problem is trivial, I'd prefer to keep things simple until we a design which is universally applicable to most pages, instead of ad-hoc "improvements"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I also have a question: now you have 102 runners and would like to add "limit=200", then some days later, if you have 202 or 1002 runners, would you add "limit=300/500/2000" then?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree - maybe instead of having a lot of config options for pagination we could add one global which triggers for all. |
||
|
|
||
| type runnersCtx struct { | ||
| OwnerID int64 | ||
| RepoID int64 | ||
|
|
@@ -111,10 +117,15 @@ func Runners(ctx *context.Context) { | |
|
|
||
| page := max(ctx.FormInt("page"), 1) | ||
|
|
||
| pageSize := ctx.FormInt("limit") | ||
| if !slices.Contains(runnersPageSizes, pageSize) { | ||
| pageSize = runnersDefaultPageSize | ||
| } | ||
|
|
||
| opts := actions_model.FindRunnerOptions{ | ||
| ListOptions: db.ListOptions{ | ||
| Page: page, | ||
| PageSize: 100, | ||
| PageSize: pageSize, | ||
| }, | ||
| Sort: ctx.Req.URL.Query().Get("sort"), | ||
| Filter: ctx.Req.URL.Query().Get("q"), | ||
|
|
@@ -160,8 +171,11 @@ func Runners(ctx *context.Context) { | |
| ctx.Data["RunnerRepoID"] = opts.RepoID | ||
| ctx.Data["SortType"] = opts.Sort | ||
| ctx.Data["AllowBulkActions"] = rCtx.IsAdmin | ||
| ctx.Data["PageSize"] = pageSize | ||
| ctx.Data["PageSizes"] = runnersPageSizes | ||
|
|
||
| pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) | ||
| pager.AddParamFromRequest(ctx.Req) | ||
|
|
||
| ctx.Data["Page"] = pager | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,44 @@ import ( | |
| "gitea.dev/modules/base" | ||
| "gitea.dev/tests" | ||
|
|
||
| "github.com/PuerkitoBio/goquery" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestActionsRunnerListPagination(t *testing.T) { | ||
| defer tests.PrepareTestEnv(t)() | ||
|
|
||
| ctx := t.Context() | ||
| require.NoError(t, db.DeleteAllRecords("action_runner")) | ||
| for i := range 26 { | ||
| require.NoError(t, actions_model.CreateRunner(ctx, &actions_model.ActionRunner{ | ||
| Name: fmt.Sprintf("global-runner-%02d", i), | ||
| TokenHash: fmt.Sprintf("h%d", i), | ||
| UUID: fmt.Sprintf("h%d", i), | ||
| })) | ||
| } | ||
|
|
||
| session := loginUser(t, "user1") | ||
| req := NewRequest(t, "GET", "/-/admin/actions/runners?sort=newest&limit=25") | ||
| resp := session.MakeRequest(t, req, http.StatusOK) | ||
| htmlDoc := NewHTMLParser(t, resp.Body) | ||
|
|
||
| // the chosen page size is reflected in the per-page selector | ||
| assert.Positive(t, htmlDoc.Find(`.dropdown .menu a.item.active[href*="limit=25"]`).Length()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First, the Second, I really doubt about the value of such
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we need this first: refactor: pagination/pager - #39162 Then the page links are always correct. It doesn't make sense to keep testing all the links again and again for all pages. |
||
|
|
||
| // pagination links carry both the sort and the page size across pages | ||
| var pagerHrefs []string | ||
| htmlDoc.Find(".page.buttons a[href]").Each(func(_ int, s *goquery.Selection) { | ||
| pagerHrefs = append(pagerHrefs, s.AttrOr("href", "")) | ||
| }) | ||
| require.NotEmpty(t, pagerHrefs) | ||
| for _, href := range pagerHrefs { | ||
| assert.Contains(t, href, "sort=newest", "pagination link must keep the sort: %s", href) | ||
| assert.Contains(t, href, "limit=25", "pagination link must keep the page size: %s", href) | ||
| } | ||
| } | ||
|
|
||
| func TestActionsRunnerModify(t *testing.T) { | ||
| defer tests.PrepareTestEnv(t)() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would make this a more generic
num_per_page