Skip to main content

Gadget example: My dashboards

This gadget lists the dashboards the viewer owns, each one a link. Everyone sees their own list, so you can add one gadget to a shared dashboard.

Applies to: Script Master for Jira Β· Cloud. The editor's My dashboards template does the same job.

Set it up​

  1. Create a gadget from the My dashboards template, or paste the code below.
  2. Check the list in the preview.
  3. Turn on Enable and select Save.

Result: On a dashboard, the gadget lists the viewer's dashboards. Selecting one opens it.

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="dashboards" style="margin: 0px; display: none"></ul>

<script type="module">
const context = await view.getContext();
const response = await requestJira(`/rest/api/3/dashboard/search?accountId=${context.accountId}`, {
headers: { 'Accept': 'application/json' }
});
const data = await response.json();

// Build the links as elements: textContent shows a dashboard name as text, never as markup
const dashboardLink = (dashboardId, dashboardName) => {
const path = `/jira/dashboards/${dashboardId}`;
const link = document.createElement('a');
link.setAttribute('href', path);
link.textContent = dashboardName;
link.addEventListener('click', (e) => {
e.preventDefault();
router.open(path);
});
const item = document.createElement('li');
item.append(link);
return item;
};
for (const dashboard of data.values) {
document.getElementById('dashboards').append(dashboardLink(dashboard.id, dashboard.name));
}

document.querySelector('#loader').style.display = 'none';
document.querySelector('#dashboards').style.display = 'block';
</script>

The links use router.open, because a plain link would open inside the gadget's frame.

  • My filters: the same idea for the viewer's filters.
  • Gadgets: how gadgets work on dashboards.