[Feat]Add link to show all Issues/PullRequests (#4125)

The Issue and PullRequest list has 3 states:
- open: This lists all open Issues/PullRequests
- closed: This lists all closed Issues/PullRequests
- all: This lists all open and closed Issues/PullRequests

If you want to get to the all state, you need to click Open while in open state or Closed while in closed state, which is very unintuitive. This PR adss a third button to get to this state.

![grafik](/attachments/4ff59e4c-e318-40f0-80ba-f921ce098919)

I'm not sure if the eye icon fits well, but I couldn't find a better one.

Tests will be added once #4124 is merged.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4125
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: JakobDev <jakobdev@gmx.de>
Co-committed-by: JakobDev <jakobdev@gmx.de>
This commit is contained in:
JakobDev 2024-10-09 04:56:40 +00:00 committed by Earl Warren
parent 80d41ee2e1
commit 1fc5e41592
7 changed files with 43 additions and 10 deletions

View file

@ -15,7 +15,7 @@ import (
// IssueStats represents issue statistic information. // IssueStats represents issue statistic information.
type IssueStats struct { type IssueStats struct {
OpenCount, ClosedCount int64 OpenCount, ClosedCount, AllCount int64
YourRepositoriesCount int64 YourRepositoriesCount int64
AssignCount int64 AssignCount int64
CreateCount int64 CreateCount int64
@ -104,6 +104,7 @@ func GetIssueStats(ctx context.Context, opts *IssuesOptions) (*IssueStats, error
} }
accum.OpenCount += stats.OpenCount accum.OpenCount += stats.OpenCount
accum.ClosedCount += stats.ClosedCount accum.ClosedCount += stats.ClosedCount
accum.AllCount += stats.AllCount
accum.YourRepositoriesCount += stats.YourRepositoriesCount accum.YourRepositoriesCount += stats.YourRepositoriesCount
accum.AssignCount += stats.AssignCount accum.AssignCount += stats.AssignCount
accum.CreateCount += stats.CreateCount accum.CreateCount += stats.CreateCount
@ -131,7 +132,13 @@ func getIssueStatsChunk(ctx context.Context, opts *IssuesOptions, issueIDs []int
stats.ClosedCount, err = applyIssuesOptions(sess, opts, issueIDs). stats.ClosedCount, err = applyIssuesOptions(sess, opts, issueIDs).
And("issue.is_closed = ?", true). And("issue.is_closed = ?", true).
Count(new(Issue)) Count(new(Issue))
if err != nil {
return stats, err return stats, err
}
stats.AllCount = stats.OpenCount + stats.ClosedCount
return stats, nil
} }
func applyIssuesOptions(sess *xorm.Session, opts *IssuesOptions, issueIDs []int64) *xorm.Session { func applyIssuesOptions(sess *xorm.Session, opts *IssuesOptions, issueIDs []int64) *xorm.Session {

View file

@ -25,6 +25,7 @@ func TestGetIssueStats(t *testing.T) {
assert.Equal(t, int64(4), stats.OpenCount) assert.Equal(t, int64(4), stats.OpenCount)
assert.Equal(t, int64(1), stats.ClosedCount) assert.Equal(t, int64(1), stats.ClosedCount)
assert.Equal(t, int64(5), stats.AllCount)
assert.Equal(t, int64(0), stats.YourRepositoriesCount) assert.Equal(t, int64(0), stats.YourRepositoriesCount)
assert.Equal(t, int64(0), stats.AssignCount) assert.Equal(t, int64(0), stats.AssignCount)
assert.Equal(t, int64(0), stats.CreateCount) assert.Equal(t, int64(0), stats.CreateCount)

View file

@ -1608,6 +1608,7 @@ issues.previous = Previous
issues.next = Next issues.next = Next
issues.open_title = Open issues.open_title = Open
issues.closed_title = Closed issues.closed_title = Closed
issues.all_title = All
issues.draft_title = Draft issues.draft_title = Draft
issues.num_comments_1 = %d comment issues.num_comments_1 = %d comment
issues.num_comments = %d comments issues.num_comments = %d comments

1
release-notes/4125.md Normal file
View file

@ -0,0 +1 @@
Added link to show all Issues/PullRequests

View file

@ -456,6 +456,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
ctx.Data["IssueStats"] = issueStats ctx.Data["IssueStats"] = issueStats
ctx.Data["OpenCount"] = issueStats.OpenCount ctx.Data["OpenCount"] = issueStats.OpenCount
ctx.Data["ClosedCount"] = issueStats.ClosedCount ctx.Data["ClosedCount"] = issueStats.ClosedCount
ctx.Data["AllCount"] = issueStats.AllCount
linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%t" linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%t"
ctx.Data["AllStatesLink"] = fmt.Sprintf(linkStr, ctx.Link, ctx.Data["AllStatesLink"] = fmt.Sprintf(linkStr, ctx.Link,
url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "all", url.QueryEscape(selectLabels), url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "all", url.QueryEscape(selectLabels),

View file

@ -1,5 +1,5 @@
<div class="small-menu-items ui compact tiny menu"> <div class="small-menu-items ui compact tiny menu">
<a class="{{if eq .State "open"}}active {{end}}item" href="{{if eq .State "open"}}{{.AllStatesLink}}{{else}}{{.OpenLink}}{{end}}"> <a class="{{if eq .State "open"}}active {{end}}item" href="{{.OpenLink}}" data-test-name="open-issue-count">
{{if .PageIsMilestones}} {{if .PageIsMilestones}}
{{svg "octicon-milestone" 16 "tw-mr-2"}} {{svg "octicon-milestone" 16 "tw-mr-2"}}
{{else if .PageIsPullList}} {{else if .PageIsPullList}}
@ -9,8 +9,12 @@
{{end}} {{end}}
{{ctx.Locale.PrettyNumber .OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}} {{ctx.Locale.PrettyNumber .OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
</a> </a>
<a class="{{if eq .State "closed"}}active {{end}}item" href="{{if eq .State "closed"}}{{.AllStatesLink}}{{else}}{{.ClosedLink}}{{end}}"> <a class="{{if eq .State "closed"}}active {{end}}item" href="{{.ClosedLink}}" data-test-name="closed-issue-count">
{{svg "octicon-check" 16 "tw-mr-2"}} {{svg "octicon-check" 16 "tw-mr-2"}}
{{ctx.Locale.PrettyNumber .ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}} {{ctx.Locale.PrettyNumber .ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
</a> </a>
<a class="{{if eq .State "all"}}active {{end}}item" href="{{.AllStatesLink}}" data-test-name="all-issue-count">
{{svg "octicon-eye" 16 "tw-mr-2"}}
{{ctx.Locale.PrettyNumber (.AllCount)}}&nbsp;{{ctx.Locale.Tr "repo.issues.all_title"}}
</a>
</div> </div>

View file

@ -1301,3 +1301,21 @@ func TestIssueUserDashboard(t *testing.T) {
htmlDoc.AssertElement(t, sel, true) htmlDoc.AssertElement(t, sel, true)
} }
} }
func TestIssueCount(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequest(t, "GET", "/user2/repo1/issues")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
openCount := htmlDoc.doc.Find("a[data-test-name='open-issue-count']").Text()
assert.Contains(t, openCount, "1\u00a0Open")
closedCount := htmlDoc.doc.Find("a[data-test-name='closed-issue-count']").Text()
assert.Contains(t, closedCount, "1\u00a0Closed")
allCount := htmlDoc.doc.Find("a[data-test-name='all-issue-count']").Text()
assert.Contains(t, allCount, "2\u00a0All")
}