debian-mirror-gitlab/app/assets/javascripts/milestones/milestone.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import createFlash from '~/flash';
import { sanitize } from '~/lib/dompurify';
import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale';
2022-08-13 15:12:31 +05:30
import { GlTabsBehavior, TAB_SHOWN_EVENT, HISTORY_TYPE_HASH } from '~/tabs';
2022-01-26 12:08:38 +05:30
export default class Milestone {
constructor() {
this.tabsEl = document.querySelector('.js-milestone-tabs');
this.loadedTabs = new WeakSet();
this.bindTabsSwitching();
2022-08-13 15:12:31 +05:30
// eslint-disable-next-line no-new
new GlTabsBehavior(this.tabsEl, { history: HISTORY_TYPE_HASH });
2022-01-26 12:08:38 +05:30
}
bindTabsSwitching() {
this.tabsEl.addEventListener(TAB_SHOWN_EVENT, (event) => {
const tab = event.target;
const { activeTabPanel } = event.detail;
this.loadTab(tab, activeTabPanel);
});
}
loadTab(tab, tabPanel) {
const { endpoint } = tab.dataset;
if (endpoint && !this.loadedTabs.has(tab)) {
axios
.get(endpoint)
.then(({ data }) => {
// eslint-disable-next-line no-param-reassign
tabPanel.innerHTML = sanitize(data.html);
this.loadedTabs.add(tab);
})
.catch(() =>
createFlash({
message: __('Error loading milestone tab'),
}),
);
}
}
}