Skip to content

Commit ccfb205

Browse files
zeripathnoerwjaqra
authored
Fix excluding more than two labels on issues list (#14962)
* Fix excluding more than two labels on issues list Fix #14840 Signed-off-by: Andrew Thornton <[email protected]> * refactor DRY * fix multiple-label filter on milestone issuelist * Apply suggestions from code review Co-authored-by: jaqra <[email protected]> * Update web_src/js/index.js Co-authored-by: Norwin Roosen <[email protected]> Co-authored-by: jaqra <[email protected]>
1 parent 855a4f4 commit ccfb205

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

templates/repo/issue/milestone_issues.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<span class="info">{{.i18n.Tr "repo.issues.filter_label_exclude" | Safe}}</span>
5555
<a class="item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_label_no_select"}}</a>
5656
{{range .Labels}}
57-
<a class="item label-filter-item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.ID}}&assignee={{$.AssigneeID}}" data-label-id="{{.ID}}">{{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}}<span class="label color" style="background-color: {{.Color}}"></span> {{.Name | RenderEmoji}}</a>
57+
<a class="item label-filter-item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{.QueryString}}&assignee={{$.AssigneeID}}" data-label-id="{{.ID}}">{{if .IsExcluded}}{{svg "octicon-circle-slash"}}{{else if contain $.SelLabelIDs .ID}}{{svg "octicon-check"}}{{end}}<span class="label color" style="background-color: {{.Color}}"></span> {{.Name | RenderEmoji}}</a>
5858
{{end}}
5959
</div>
6060
</div>

web_src/js/index.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,36 +3753,30 @@ function initIssueList() {
37533753
fullTextSearch: true
37543754
});
37553755

3756+
function excludeLabel (item) {
3757+
const href = $(item).attr('href');
3758+
const id = $(item).data('label-id');
3759+
3760+
const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`;
3761+
const newStr = 'labels=$1-$2$3&';
3762+
3763+
window.location = href.replace(new RegExp(regStr), newStr);
3764+
}
3765+
37563766
$('.menu a.label-filter-item').each(function () {
37573767
$(this).on('click', function (e) {
37583768
if (e.altKey) {
37593769
e.preventDefault();
3760-
3761-
const href = $(this).attr('href');
3762-
const id = $(this).data('label-id');
3763-
3764-
const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
3765-
const newStr = 'labels=$1-$2$3&';
3766-
3767-
window.location = href.replace(new RegExp(regStr), newStr);
3770+
excludeLabel(this);
37683771
}
37693772
});
37703773
});
37713774

37723775
$('.menu .ui.dropdown.label-filter').on('keydown', (e) => {
37733776
if (e.altKey && e.keyCode === 13) {
37743777
const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected');
3775-
37763778
if (selectedItems.length > 0) {
3777-
const item = $(selectedItems[0]);
3778-
3779-
const href = item.attr('href');
3780-
const id = item.data('label-id');
3781-
3782-
const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
3783-
const newStr = 'labels=$1-$2$3&';
3784-
3785-
window.location = href.replace(new RegExp(regStr), newStr);
3779+
excludeLabel($(selectedItems[0]));
37863780
}
37873781
}
37883782
});

0 commit comments

Comments
 (0)