Skip to content

Commit

Permalink
HARMONY-1892: toggleLabelNavVisibility based on number of jobs selected
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyinverso committed Nov 13, 2024
1 parent cdd40e7 commit 7711d23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{{^isAdminRoute}}
{{#jobs.length}}
{{#labels.length}}
<li id="label-nav-item" class="nav-item dropstart">
<li id="label-nav-item" class="nav-item dropstart d-none">
<a id="label-dropdown-a" class="nav-link dropdown-toggle py-0 px-2" data-bs-toggle="dropdown" data-bs-auto-close="outside" href="#" role="button" aria-expanded="false">label</a>
<ul class="dropdown-menu mt-2">
<li class="mx-2 mb-2">
Expand Down
19 changes: 19 additions & 0 deletions services/harmony/public/js/workflow-ui/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PubSub from '../pub-sub.js';
let bsDropdown;
let labelLinks;
let labelDropdown;
let labelNavItem;

/**
* Responds to a submit link click event by adding or removing
Expand Down Expand Up @@ -158,6 +159,18 @@ function setLabelLinksEnabled(labelItemLinks) {
}
}

/**
* Hide/show labels dropdown based on the number of jobs selected.
* @param {number} selectedJobsCount - count of selected jobs
*/
function toggleLabelNavVisibility(selectedJobsCount) {
if (selectedJobsCount === 0) {
labelNavItem.classList.add('d-none');
} else {
labelNavItem.classList.remove('d-none');
}
}

/**
* Bind event handlers to their respective elements.
*/
Expand Down Expand Up @@ -201,10 +214,15 @@ export default {
labelLinks = Array.from(document.querySelectorAll('#labels-list .label-li a'));
// the dropdown that contains label list items
labelDropdown = document.getElementById('label-dropdown-a');
labelNavItem = document.getElementById('label-nav-item');
if (labelDropdown) {
bsDropdown = new bootstrap.Dropdown(labelDropdown);
}
bindEventListeners();
PubSub.subscribe(
'job-selected',
() => this.toggleLabelNavVisibility(jobsTable.getJobIds().length),
);
},
promoteLabels,
demoteLabels,
Expand All @@ -213,4 +231,5 @@ export default {
setLabelLinksEnabled,
filterLabelsList,
showAllLabels,
toggleLabelNavVisibility,
};

0 comments on commit 7711d23

Please sign in to comment.