From 19ca0394865495597a71df0bad9f93370af45092 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Thu, 17 Oct 2024 13:24:41 +0000 Subject: [PATCH] feat(ui): set your_repositories as the default filter for org dashboards (#5593) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5593 Reviewed-by: Michael Kriese Reviewed-by: Otto Reviewed-by: Shiny Nematoda --- routers/web/user/home.go | 24 +++++++++++++++++++----- tests/integration/issue_test.go | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 4b249e9696..c59dcf5c25 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -380,9 +380,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } var ( - viewType string - sortType = ctx.FormString("sort") - filterMode int + viewType string + sortType = ctx.FormString("sort") + filterMode int + defaultFilterMode int + defaultViewType string ) // Default to recently updated, unlike repository issues list @@ -403,6 +405,18 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // TODO: distinguish during routing + // Default to created_by on /pulls and /issues + // because it is most relevant to the user in the global context + if ctx.Org == nil || ctx.Org.Organization == nil { + defaultFilterMode = issues_model.FilterModeCreate + defaultViewType = "created_by" + } else { + // Default to your_repositories on /org/*/pulls and /org/*/issues + // because it is the most relevant to the user in the context of an org + defaultFilterMode = issues_model.FilterModeYourRepositories + defaultViewType = "your_repositories" + } + viewType = ctx.FormString("type") switch viewType { case "assigned": @@ -418,8 +432,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { case "created_by": fallthrough default: - filterMode = issues_model.FilterModeCreate - viewType = "created_by" + filterMode = defaultFilterMode + viewType = defaultViewType } // -------------------------------------------------------------------------- diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 781f9abd1a..4c0a64ad70 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -1302,6 +1302,23 @@ func TestIssueUserDashboard(t *testing.T) { } } +func TestIssueOrgDashboard(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + session := loginUser(t, user.Name) + + // assert 'your_repositories' is the default filter for org dashboards + const sel = ".dashboard .ui.list-header.dropdown .ui.menu a.active.item[href^='?type=your_repositories']" + + for _, path := range []string{"/org/org3/issues", "/org/org3/pulls"} { + req := NewRequest(t, "GET", path) + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + htmlDoc.AssertElement(t, sel, true) + } +} + func TestIssueCount(t *testing.T) { defer tests.PrepareTestEnv(t)()