2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2022-01-26 12:08:38 +05:30
|
|
|
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(() =>
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2022-01-26 12:08:38 +05:30
|
|
|
message: __('Error loading milestone tab'),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|