Gadget example: My filters
This gadget lists the viewer's filters, each one a link to its search results. Everyone sees their own list, so you can add one gadget to a shared dashboard.
Applies to: Script Master for Jira Β· Cloud
Set it upβ
- Create a gadget and paste the code below into Frontend HTML + JavaScript.
- Check the list in the preview.
- Turn on Enable and select Save.
Result: On a dashboard, the gadget lists the viewer's filters. Selecting one opens its results.
The codeβ
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@atlaskit/css-reset@3.0.1/dist/bundle.css" />
<span id="loader">Loading...</span>
<ul id="filters" style="margin: 0px; display: none"></ul>
<script type="module">
const response = await requestJira('/rest/api/3/filter/my', {
headers: { 'Accept': 'application/json' }
});
const filters = await response.json();
// Build the links as elements: textContent shows a filter name as text, never as markup
const filterLink = (filterId, filterName) => {
const path = `/issues/?filter=${filterId}`;
const link = document.createElement('a');
link.setAttribute('href', path);
link.textContent = filterName;
link.addEventListener('click', (e) => {
e.preventDefault();
router.open(path);
});
const item = document.createElement('li');
item.append(link);
return item;
};
for (const filter of filters) {
document.getElementById('filters').append(filterLink(filter.id, filter.name));
}
document.querySelector('#loader').style.display = 'none';
document.querySelector('#filters').style.display = 'block';
</script>
Relatedβ
- My dashboards: the same idea for the viewer's dashboards.
- Gadgets: how gadgets work on dashboards.