Skip to content

Commit

Permalink
Hide archived labels by default from the suggestions when assigning l…
Browse files Browse the repository at this point in the history
…abels for an issue (go-gitea#27451)

Followup of go-gitea#27115
Finally closes go-gitea#25237

## Screenshots
### Issue Sidebar
<img width="513" alt="image"
src="https://github.com/go-gitea/gitea/assets/80308335/9f7fda2f-5a03-4684-8619-fd3498a95b41">

### PR sidebar
<img width="367" alt="image"
src="https://github.com/go-gitea/gitea/assets/80308335/53db9b64-faec-4a67-91d6-76945596a469">

### PR sidebar with archived labels shown
<img width="352" alt="image"
src="https://github.com/go-gitea/gitea/assets/80308335/9dc5050f-4e69-4f76-bb83-582480a2281e">

---------

Signed-off-by: puni9869 <punitinani1@hotmail.com>
Co-authored-by: silverwind <me@silverwind.io>
  • Loading branch information
puni9869 and silverwind committed Feb 20, 2024
1 parent e4bc8bb commit 70a59b7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
6 changes: 2 additions & 4 deletions templates/repo/issue/filter_actions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
<div class="divider"></div>
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
<div class="item issue-action gt-df gt-items-start" data-action="toggle" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/labels">
<div class="item issue-action gt-df gt-sb" data-action="toggle" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/labels">
{{if SliceUtils.Contains $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel $.Context .}}
{{if .IsArchived}}
<i data-tooltip-content={{ctx.Locale.Tr "archived"}}>{{svg "octicon-info"}}</i>
{{end}}
{{template "repo/issue/labels/label_archived" .}}
</div>
{{end}}
</div>
Expand Down
12 changes: 8 additions & 4 deletions templates/repo/issue/labels/labels_selector_field.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
<div class="divider"></div>
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}gt-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}gt-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
<p class="archived-label-hint">{{template "repo/issue/labels/label_archived" .}}</p>
</a>
{{end}}
<div class="divider"></div>
{{$previousExclusiveScope = "_no_scope"}}
Expand All @@ -32,8 +34,10 @@
<div class="divider"></div>
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}gt-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}gt-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
<p class="archived-label-hint">{{template "repo/issue/labels/label_archived" .}}</p>
</a>
{{end}}
{{else}}
<div class="disabled item">{{ctx.Locale.Tr "repo.issues.new.no_items"}}</div>
Expand Down
5 changes: 5 additions & 0 deletions web_src/css/repo/issue-label.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@
.label-operation .label {
height: fit-content;
}

.archived-label-hint {
float: right;
margin: -12px;
}
6 changes: 5 additions & 1 deletion web_src/js/features/repo-issue-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from 'jquery';
import {updateIssuesMeta} from './repo-issue.js';
import {toggleElem} from '../utils/dom.js';
import {toggleElem, hideElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';
Expand Down Expand Up @@ -194,6 +194,10 @@ function initArchivedLabelFilter() {
const url = new URL(window.location.href);
const archivedLabels = document.querySelectorAll('[data-is-archived]');

if (!archivedLabels.length) {
hideElem('.archived-label-filter');
return;
}
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
Expand Down
13 changes: 13 additions & 0 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,16 @@ export function initIssueTemplateCommentEditors($commentForm) {
initCombo($(el));
}
}

// This function used to show and hide archived label on issue/pr
// page in the sidebar where we select the labels
// If we have any archived label tagged to issue and pr. We will show that
// archived label with checked classed otherwise we will hide it
// with the help of this function.
// This function runs globally.
export function initArchivedLabelHandler() {
if (!document.querySelector('.archived-label-hint')) return;
for (const label of document.querySelectorAll('[data-is-archived]')) {
toggleElem(label, label.classList.contains('checked'));
}
}
3 changes: 2 additions & 1 deletion web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
initRepoIssueWipTitle,
initRepoPullRequestMergeInstruction,
initRepoPullRequestAllowMaintainerEdit,
initRepoPullRequestReview, initRepoIssueSidebarList
initRepoPullRequestReview, initRepoIssueSidebarList, initArchivedLabelHandler,
} from './features/repo-issue.js';
import {
initRepoEllipsisButton,
Expand Down Expand Up @@ -152,6 +152,7 @@ onDomReady(() => {
initRepoIssueDue();
initRepoIssueList();
initRepoIssueSidebarList();
initArchivedLabelHandler();
initRepoIssueReferenceRepositorySearch();
initRepoIssueTimeTracking();
initRepoIssueWipTitle();
Expand Down

0 comments on commit 70a59b7

Please sign in to comment.