Skip to content

Filter project boards based on labels #21963

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
{{if or .Labels .Assignees}}
<div class="extra content labels-list p-0 pt-2">
{{range .Labels}}
<a class="ui label" target="_blank" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}};" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
<a class="ui label" target="_blank" href="{{$.RepoLink}}/issues?labels={{.ID}}" data-label-id="{{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}};" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
{{end}}
<div class="right floated">
{{range .Assignees}}
Expand Down
34 changes: 33 additions & 1 deletion web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@ function moveIssue({item, from, to, oldIndex}) {
});
}

async function initRepoProjectLabelFilter() {
// FIXME: Per design document, this should be moved to filter server side once sorting is partial ajax send
// There is a risk of flash of unfiltered content with this approach

// check if labels query string is set
const urlParams = new URLSearchParams(window.location.search);
const labels = urlParams.get('labels');
if (!labels) return;

// split labels query string into array
const labelsArray = labels.split(',');

// loop through all cards and check if they have the label
const cards = document.querySelectorAll('.board-card[data-issue]');
for (const card of cards) {
const labels = card.querySelectorAll('[data-label-id]');
let hasLabel = false;
for (const label of labels) {
const label_id = $(label).data('label-id');

if (labelsArray.includes(label_id.toString())) {
hasLabel = true;
break;
}
}
if (!hasLabel) {
card.style.display = 'none';
}
}
}

async function initRepoProjectSortable() {
const els = document.querySelectorAll('#project-board > .board');
if (!els.length) return;
Expand Down Expand Up @@ -89,7 +120,8 @@ export function initRepoProject() {
return;
}

const _promise = initRepoProjectSortable();
const _promise1 = initRepoProjectSortable();
const _promise2 = initRepoProjectLabelFilter();

$('.edit-project-board').each(function () {
const projectHeader = $(this).closest('.board-column-header');
Expand Down