From 6f31b7d02b888f3d23220934ab539da0d8c74d15 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Thu, 11 Mar 2021 17:01:52 +0000 Subject: [PATCH 1/5] Fix excluding more than two labels on issues list Fix #14840 Signed-off-by: Andrew Thornton --- web_src/js/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index cda08870a5f72..b5fa293947910 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3761,7 +3761,7 @@ function initIssueList() { const href = $(this).attr('href'); const id = $(this).data('label-id'); - const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`; + const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; const newStr = 'labels=$1-$2$3&'; window.location = href.replace(new RegExp(regStr), newStr); @@ -3779,7 +3779,7 @@ function initIssueList() { const href = item.attr('href'); const id = item.data('label-id'); - const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`; + const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; const newStr = 'labels=$1-$2$3&'; window.location = href.replace(new RegExp(regStr), newStr); From 4a40d7aa3621135e25b10ab53df8448a09f6e4c8 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 12 Mar 2021 07:03:54 +0100 Subject: [PATCH 2/5] refactor DRY --- web_src/js/index.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index b5fa293947910..3f1aeafaff30b 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3753,18 +3753,21 @@ function initIssueList() { fullTextSearch: true }); + function removeLabel (item) { + const href = $(item).attr('href'); + const id = $(item).data('label-id'); + + const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; + const newStr = 'labels=$1-$2$3&'; + + window.location = href.replace(new RegExp(regStr), newStr); + } + $('.menu a.label-filter-item').each(function () { $(this).on('click', function (e) { if (e.altKey) { e.preventDefault(); - - const href = $(this).attr('href'); - const id = $(this).data('label-id'); - - const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; - const newStr = 'labels=$1-$2$3&'; - - window.location = href.replace(new RegExp(regStr), newStr); + removeLabel(this); } }); }); @@ -3772,17 +3775,8 @@ function initIssueList() { $('.menu .ui.dropdown.label-filter').on('keydown', (e) => { if (e.altKey && e.keyCode === 13) { const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected'); - if (selectedItems.length > 0) { - const item = $(selectedItems[0]); - - const href = item.attr('href'); - const id = item.data('label-id'); - - const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; - const newStr = 'labels=$1-$2$3&'; - - window.location = href.replace(new RegExp(regStr), newStr); + removeLabel($(selectedItems[0])); } } }); From a6094f455271a98112bb28b9c7631704849e2f2b Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 12 Mar 2021 07:04:38 +0100 Subject: [PATCH 3/5] fix multiple-label filter on milestone issuelist --- templates/repo/issue/milestone_issues.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index c2c81682ff0ff..4f4a91b211c4d 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -54,7 +54,7 @@ {{.i18n.Tr "repo.issues.filter_label_exclude" | Safe}} {{.i18n.Tr "repo.issues.filter_label_no_select"}} {{range .Labels}} - {{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}} {{.Name | RenderEmoji}} + {{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}} {{.Name | RenderEmoji}} {{end}} From 83c38bb79d9dfa8405641955438186b132c089ca Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 12 Mar 2021 15:15:21 +0000 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: jaqra <48099350+jaqra@users.noreply.github.com> --- web_src/js/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 3f1aeafaff30b..4c7e6b059313a 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3753,7 +3753,7 @@ function initIssueList() { fullTextSearch: true }); - function removeLabel (item) { + function excludeLabel (item) { const href = $(item).attr('href'); const id = $(item).data('label-id'); @@ -3767,7 +3767,7 @@ function initIssueList() { $(this).on('click', function (e) { if (e.altKey) { e.preventDefault(); - removeLabel(this); + excludeLabel(this); } }); }); From bcf8870ac593b338b37479e23df100228c7d60be Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 12 Mar 2021 15:29:00 +0000 Subject: [PATCH 5/5] Update web_src/js/index.js --- web_src/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 4c7e6b059313a..ccd9276059151 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3776,7 +3776,7 @@ function initIssueList() { if (e.altKey && e.keyCode === 13) { const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected'); if (selectedItems.length > 0) { - removeLabel($(selectedItems[0])); + excludeLabel($(selectedItems[0])); } } });