From 50070550a8798dba2f1758d39923f0f4ef09acb5 Mon Sep 17 00:00:00 2001 From: puni9869 <80308335+puni9869@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:34:39 +0530 Subject: [PATCH] Hide archived labels when filtering by labels on the issue list (#27115) Followup https://github.com/go-gitea/gitea/pull/26820 ## Archived labels UI for issue filter and issue filter actions for issues/pull request pages. Changed: * Enhanced the Issue filter and Issue filter actions UI page to seamlessly incorporate a list of archived labels. * Pagination functionality is same as before. If archived label checkbox is checked then we are adding a query string`archived=true` in the url to save the state of page. * Issue filter actions menu is separated into different template. * Adding the archived flag in issue url labels. * Pull Request page is also work the same. Outsourced: * Defer the implementation of specialized handling for archived labels to upcoming pull requests. This step will be undertaken subsequent to the successful merge of this pull request. Screenshots ### Issue page image ### Issue page with label filter on archived label checkbox when not checked --> No archived label is there in list image ### Issue page with label filter on archived label checkbox when checked --> Show archived label in the list. image ### Issue page with label filter on issue action menu on archived label checkbox when checked --> Show archived label in the list. image ### Applied the archived=true in Issue labels when archived checkbox is checked. image --- Part of https://github.com/go-gitea/gitea/issues/25237 --------- Signed-off-by: puni9869 Co-authored-by: delvh Co-authored-by: Giteabot --- options/locale/locale_en-US.ini | 3 +- routers/web/repo/issue.go | 5 + templates/repo/issue/filter_actions.tmpl | 130 +++++++++++++++++++++++ templates/repo/issue/filters.tmpl | 79 +++++++++----- templates/repo/issue/list.tmpl | 127 +--------------------- templates/repo/issue/openclose.tmpl | 4 +- templates/shared/issuelist.tmpl | 2 +- web_src/css/repo.css | 6 +- web_src/css/repo/issue-list.css | 8 ++ web_src/js/features/repo-issue-list.js | 35 +++++- 10 files changed, 237 insertions(+), 162 deletions(-) create mode 100644 templates/repo/issue/filter_actions.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8667e77a89..3c8c322567 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1519,7 +1519,8 @@ issues.label_description = Description issues.label_color = Color issues.label_exclusive = Exclusive issues.label_archive = Archive Label -issues.label_archive_tooltip= Archived labels are excluded from the label search when applying labels to an issue. Existing labels on issues remain unaffected, allowing you to retire obsolete labels without losing information. +issues.label_archived_filter = Show archived labels +issues.label_archive_tooltip = Archived labels are excluded by default from the suggestions when searching by label. issues.label_exclusive_desc = Name the label scope/item to make it mutually exclusive with other scope/ labels. issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request. issues.label_count = %d labels diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 090d23301b..6394ee4198 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -442,6 +442,11 @@ 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") + + if ctx.FormBool("archived") { + ctx.Data["ShowArchivedLabels"] = true + pager.AddParam(ctx, "archived", "ShowArchivedLabels") + } ctx.Data["Page"] = pager } diff --git a/templates/repo/issue/filter_actions.tmpl b/templates/repo/issue/filter_actions.tmpl new file mode 100644 index 0000000000..f84a99ff7f --- /dev/null +++ b/templates/repo/issue/filter_actions.tmpl @@ -0,0 +1,130 @@ + + diff --git a/templates/repo/issue/filters.tmpl b/templates/repo/issue/filters.tmpl index dca2fb0dba..15a90869b0 100644 --- a/templates/repo/issue/filters.tmpl +++ b/templates/repo/issue/filters.tmpl @@ -18,10 +18,22 @@ {{svg "octicon-search" 16}} +
+ + +
{{ctx.Locale.Tr "repo.issues.filter_label_exclude" | Safe}}
- {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} + {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} {{$exclusiveScope := .ExclusiveScope}} @@ -29,7 +41,16 @@
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - {{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if .IsSelected}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} + + {{if .IsExcluded}} + {{svg "octicon-circle-slash"}} + {{else if .IsSelected}} + {{if $exclusiveScope}} + {{svg "octicon-dot-fill"}} + {{else}} + {{svg "octicon-check"}} + {{end}} + {{end}} {{RenderLabel $.Context .}}

{{template "repo/issue/labels/label_archived" .}}

@@ -50,13 +71,13 @@
- {{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} - {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} {{if .OpenMilestones}}
{{ctx.Locale.Tr "repo.issues.filter_milestone_open"}}
{{range .OpenMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -66,7 +87,7 @@
{{ctx.Locale.Tr "repo.issues.filter_milestone_closed"}}
{{range .ClosedMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -87,15 +108,15 @@ {{svg "octicon-search" 16}} - {{ctx.Locale.Tr "repo.issues.filter_project_all"}} - {{ctx.Locale.Tr "repo.issues.filter_project_none"}} + {{ctx.Locale.Tr "repo.issues.filter_project_all"}} + {{ctx.Locale.Tr "repo.issues.filter_project_none"}} {{if .OpenProjects}}
{{ctx.Locale.Tr "repo.issues.new.open_projects"}}
{{range .OpenProjects}} - + {{svg .IconName 18 "gt-mr-3 gt-shrink-0"}}{{.Title}} {{end}} @@ -106,7 +127,7 @@ {{ctx.Locale.Tr "repo.issues.new.closed_projects"}} {{range .ClosedProjects}} - + {{svg .IconName 18 "gt-mr-3"}}{{.Title}} {{end}} @@ -118,7 +139,7 @@ - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}}
{{range .Assignees}} - + {{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} {{end}} @@ -163,14 +184,14 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} {{end}} @@ -182,14 +203,14 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 75d4234324..038526f424 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -36,132 +36,7 @@ {{template "repo/issue/openclose" .}}
- + {{template "repo/issue/filter_actions" .}}
{{template "shared/issuelist" dict "." . "listType" "repo"}} diff --git a/templates/repo/issue/openclose.tmpl b/templates/repo/issue/openclose.tmpl index a215922afc..ad8de4013a 100644 --- a/templates/repo/issue/openclose.tmpl +++ b/templates/repo/issue/openclose.tmpl @@ -1,5 +1,5 @@ diff --git a/web_src/css/repo.css b/web_src/css/repo.css index d0d001bf52..562fb4a345 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -129,11 +129,13 @@ .repository .filter.menu.labels .label-filter .menu .info { display: inline-block; - padding: 0.5rem 0.25rem; + padding: 0.5rem 0; font-size: 12px; width: 100%; white-space: nowrap; - text-align: center; + margin-left: 10px; + margin-right: 8px; + text-align: left; } .repository .filter.menu.labels .label-filter .menu .info code { diff --git a/web_src/css/repo/issue-list.css b/web_src/css/repo/issue-list.css index 17ae6ea38f..d2f8e429f5 100644 --- a/web_src/css/repo/issue-list.css +++ b/web_src/css/repo/issue-list.css @@ -80,3 +80,11 @@ #issue-list .flex-item-body .checklist progress::-moz-progress-bar { background-color: var(--color-secondary-dark-4); } + +.archived-label-filter { + margin-left: 10px; + font-size: 12px; + display: flex !important; + margin-bottom: 8px; + min-width: fit-content; +} diff --git a/web_src/js/features/repo-issue-list.js b/web_src/js/features/repo-issue-list.js index af4586121e..a9a8628ba7 100644 --- a/web_src/js/features/repo-issue-list.js +++ b/web_src/js/features/repo-issue-list.js @@ -73,7 +73,7 @@ function initRepoIssueListCheckboxes() { url, action, issueIDs, - elementId + elementId, ).then(() => { window.location.reload(); }).catch((reason) => { @@ -185,9 +185,42 @@ async function initIssuePinSort() { }); } +function initArchivedLabelFilter() { + const archivedLabelEl = document.querySelector('#archived-filter-checkbox'); + if (!archivedLabelEl) { + return; + } + + const url = new URL(window.location.href); + const archivedLabels = document.querySelectorAll('[data-is-archived]'); + + const selectedLabels = (url.searchParams.get('labels') || '') + .split(',') + .map((id) => id < 0 ? `${~id + 1}` : id); // selectedLabels contains -ve ids, which are excluded so convert any -ve value id to +ve + + const archivedElToggle = () => { + for (const label of archivedLabels) { + const id = label.getAttribute('data-label-id'); + toggleElem(label, archivedLabelEl.checked || selectedLabels.includes(id)); + } + }; + + archivedElToggle(); + archivedLabelEl.addEventListener('change', () => { + archivedElToggle(); + if (archivedLabelEl.checked) { + url.searchParams.set('archived', 'true'); + } else { + url.searchParams.delete('archived'); + } + window.location.href = url.href; + }); +} + export function initRepoIssueList() { if (!document.querySelectorAll('.page-content.repository.issue-list, .page-content.repository.milestone-issue-list').length) return; initRepoIssueListCheckboxes(); initRepoIssueListAuthorDropdown(); initIssuePinSort(); + initArchivedLabelFilter(); }