Skip to content

Improve the list header in milestone page #27302

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

Merged
merged 16 commits into from
Oct 18, 2023
16 changes: 12 additions & 4 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
isShowClosed = true
}

archived := ctx.FormBool("archived")
showArchivedLabels := "false"
if archived {
showArchivedLabels = "true"
}

Copy link
Member

@puni9869 puni9869 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little optimization.
Could you check what will be the value of ctx.FormBool("archived") if you don't pass into query params,

I guess you don't need showArchivedLabels varable extra to save the state . You can use archived variable. directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is "false", type is bool.
improved in 8508daf

Copy link
Member

@puni9869 puni9869 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use strings package . strings.FormatBool.

This change was already done.

page := ctx.FormInt("page")
if page <= 1 {
page = 1
Expand Down Expand Up @@ -417,6 +423,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
ctx.Data["PinnedIssues"] = pinned
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.Doer.IsAdmin)
ctx.Data["IssueStats"] = issueStats
ctx.Data["OpenCount"] = issueStats.OpenCount
ctx.Data["ClosedCount"] = issueStats.ClosedCount
ctx.Data["OpenLink"] = fmt.Sprintf("%s?q=%s&type=%s&sort=%s&state=open&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%s", ctx.Link, keyword, viewType, sortType, selectLabels, mentionedID, projectID, assigneeID, posterID, showArchivedLabels)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move this into the template? This solution seems not good enough. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move this into the template? This solution seems not good enough. 🤔

Lets move this in separat pr because there are many places where we can reduce and refactor this dedicately.

I don't want to over burder this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that there are too many similar links in different places of these templates.
If they can be a shared one, it can be more maintainable.

Copy link
Member

@silverwind silverwind Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of endlessly extending these query param lists, we should instead add a template helper that just merges the specified pairs into the current query params that the backend sees: #27192 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make a proof of concept of this helper soon.

Copy link
Member

@puni9869 puni9869 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker.
could you format this some how may be multiple line concate or a function formCloseLinkURL. for better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Does this look good for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for keeping you reiterating
#27302 (comment)

ctx.Data["ClosedLink"] = fmt.Sprintf("%s?q=%s&type=%s&sort=%s&state=closed&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%s", ctx.Link, keyword, viewType, sortType, selectLabels, mentionedID, projectID, assigneeID, posterID, showArchivedLabels)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Member

@puni9869 puni9869 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be use can use

queryStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%s";
// take state in expression "close/open"
ctx.Data["OpenLink"]  = fmt.Sprintf(queryStr,  "open",all the args here);
ctx.Data["CloseLink"]  = fmt.Sprintf(queryStr,  "close", all the args here);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ctx.Data["SelLabelIDs"] = labelIDs
ctx.Data["SelectLabels"] = selectLabels
ctx.Data["ViewType"] = viewType
Expand All @@ -432,6 +442,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
} else {
ctx.Data["State"] = "open"
}
ctx.Data["ShowArchivedLabels"] = archived

pager.AddParam(ctx, "q", "Keyword")
pager.AddParam(ctx, "type", "ViewType")
Expand All @@ -442,11 +453,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
pager.AddParam(ctx, "project", "ProjectID")
pager.AddParam(ctx, "assignee", "AssigneeID")
pager.AddParam(ctx, "poster", "PosterID")
pager.AddParam(ctx, "archived", "ShowArchivedLabels")

if ctx.FormBool("archived") {
ctx.Data["ShowArchivedLabels"] = true
pager.AddParam(ctx, "archived", "ShowArchivedLabels")
}
ctx.Data["Page"] = pager
}

Expand Down
3 changes: 3 additions & 0 deletions routers/web/repo/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package repo

import (
"fmt"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -72,6 +73,8 @@ func Milestones(ctx *context.Context) {
}
ctx.Data["OpenCount"] = stats.OpenCount
ctx.Data["ClosedCount"] = stats.ClosedCount
ctx.Data["OpenLink"] = fmt.Sprintf("%s/milestones?state=open&q=%s", ctx.Repo.RepoLink, keyword)
ctx.Data["ClosedLink"] = fmt.Sprintf("%s/milestones?state=closed&q=%s", ctx.Repo.RepoLink, keyword)

if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
if err := miles.LoadTotalTrackedTimes(ctx); err != nil {
Expand Down
206 changes: 206 additions & 0 deletions templates/repo/issue/filter_list.tmpl

Large diffs are not rendered by default.

209 changes: 4 additions & 205 deletions templates/repo/issue/filters.tmpl

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions templates/repo/issue/milestone/filter_list.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Sort -->
<div class="list-header-sort ui small dropdown type jump item">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active {{end}}item" href="{{$.Link}}?sort=closestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.earliest_due_data"}}</a>
<a class="{{if eq .SortType "furthestduedate"}}active {{end}}item" href="{{$.Link}}?sort=furthestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.latest_due_date"}}</a>
<a class="{{if eq .SortType "leastcomplete"}}active {{end}}item" href="{{$.Link}}?sort=leastcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_complete"}}</a>
<a class="{{if eq .SortType "mostcomplete"}}active {{end}}item" href="{{$.Link}}?sort=mostcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_complete"}}</a>
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="{{$.Link}}?sort=mostissues&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="{{$.Link}}?sort=leastissues&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
</div>
</div>
46 changes: 5 additions & 41 deletions templates/repo/issue/milestones.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,17 @@
<div role="main" aria-label="{{.Title}}" class="page-content repository milestones">
{{template "repo/header" .}}
<div class="ui container">
<div class="navbar gt-mb-4">
{{template "base/alert" .}}

<div class="list-header">
{{template "repo/issue/navbar" .}}
{{template "repo/issue/search" .}}
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
<a class="ui small primary button" href="{{$.Link}}/new">{{ctx.Locale.Tr "repo.milestones.new"}}</a>
{{end}}
</div>
{{template "base/alert" .}}

<div class="list-header">
<div class="small-menu-items ui compact tiny menu list-header-toggle">
<a class="item{{if not .IsShowClosed}} active{{end}}" href="{{.RepoLink}}/milestones?state=open&q={{$.Keyword}}">
{{svg "octicon-milestone" 16 "gt-mr-3"}}
{{ctx.Locale.PrettyNumber .OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
</a>
<a class="item{{if .IsShowClosed}} active{{end}}" href="{{.RepoLink}}/milestones?state=closed&q={{$.Keyword}}">
{{svg "octicon-check" 16 "gt-mr-3"}}
{{ctx.Locale.PrettyNumber .ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
</a>
</div>

<!-- Search -->
<form class="list-header-search ui form ignore-dirty">
<div class="ui small search fluid action input">
<input type="hidden" name="state" value="{{$.State}}">
{{template "shared/searchinput" dict "Value" .Keyword}}
<button class="ui small icon button" type="submit" aria-label="{{ctx.Locale.Tr "explore.search"}}">
{{svg "octicon-search"}}
</button>
</div>
</form>

<!-- Sort -->
<div class="list-header-sort ui small dropdown type jump item">
<span class="text">
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active {{end}}item" href="{{$.Link}}?sort=closestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.earliest_due_data"}}</a>
<a class="{{if eq .SortType "furthestduedate"}}active {{end}}item" href="{{$.Link}}?sort=furthestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.latest_due_date"}}</a>
<a class="{{if eq .SortType "leastcomplete"}}active {{end}}item" href="{{$.Link}}?sort=leastcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_complete"}}</a>
<a class="{{if eq .SortType "mostcomplete"}}active {{end}}item" href="{{$.Link}}?sort=mostcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_complete"}}</a>
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="{{$.Link}}?sort=mostissues&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="{{$.Link}}?sort=leastissues&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
</div>
</div>
</div>
{{template "repo/issue/filters" .}}

<!-- milestone list -->
<div class="milestone-list">
Expand Down
12 changes: 7 additions & 5 deletions templates/repo/issue/openclose.tmpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<div class="small-menu-items ui compact tiny menu">
<a class="{{if not .IsShowClosed}}active {{end}}item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state=open&labels={{.SelectLabels}}&milestone={{.MilestoneID}}&project={{.ProjectID}}&assignee={{.AssigneeID}}&poster={{.PosterID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">
{{if .PageIsPullList}}
<a class="{{if not .IsShowClosed}}active {{end}}item" href="{{.OpenLink}}">
{{if .PageIsMilestones}}
{{svg "octicon-milestone" 16 "gt-mr-3"}}
{{else if .PageIsPullList}}
{{svg "octicon-git-pull-request" 16 "gt-mr-3"}}
{{else}}
{{svg "octicon-issue-opened" 16 "gt-mr-3"}}
{{end}}
{{ctx.Locale.PrettyNumber .IssueStats.OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
{{ctx.Locale.PrettyNumber .OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
</a>
<a class="{{if .IsShowClosed}}active {{end}}item" href="{{$.Link}}?q={{$.Keyword}}&type={{.ViewType}}&sort={{$.SortType}}&state=closed&labels={{.SelectLabels}}&milestone={{.MilestoneID}}&project={{.ProjectID}}&assignee={{.AssigneeID}}&poster={{.PosterID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">
<a class="{{if .IsShowClosed}}active {{end}}item" href="{{.ClosedLink}}">
{{svg "octicon-check" 16 "gt-mr-3"}}
{{ctx.Locale.PrettyNumber .IssueStats.ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
{{ctx.Locale.PrettyNumber .ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
</a>
</div>
14 changes: 8 additions & 6 deletions templates/repo/issue/search.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<form class="list-header-search ui form ignore-dirty issue-list-search">
<div class="ui small search fluid action input">
<input type="hidden" name="type" value="{{$.ViewType}}">
<input type="hidden" name="state" value="{{$.State}}">
<input type="hidden" name="labels" value="{{.SelectLabels}}">
<input type="hidden" name="milestone" value="{{$.MilestoneID}}">
<input type="hidden" name="project" value="{{$.ProjectID}}">
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
<input type="hidden" name="poster" value="{{$.PosterID}}">
{{if not .PageIsMilestones}}
<input type="hidden" name="type" value="{{$.ViewType}}">
<input type="hidden" name="labels" value="{{.SelectLabels}}">
<input type="hidden" name="milestone" value="{{$.MilestoneID}}">
<input type="hidden" name="project" value="{{$.ProjectID}}">
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
<input type="hidden" name="poster" value="{{$.PosterID}}">
{{end}}
{{template "shared/searchinput" dict "Value" .Keyword}}
{{if .PageIsIssueList}}
<button id="issue-list-quick-goto" class="ui small icon button gt-hidden" data-tooltip-content="{{ctx.Locale.Tr "explore.go_to"}}" data-repo-link="{{.RepoLink}}">{{svg "octicon-hash"}}</button>
Expand Down