Commit 7a776100 authored by mfluharty's avatar mfluharty

Only load codequality report when tab is active

Pattern copied from JUnit test reports tab
parent 49e72259
...@@ -6,13 +6,30 @@ import createStore from 'ee/codequality_report/store'; ...@@ -6,13 +6,30 @@ import createStore from 'ee/codequality_report/store';
Vue.use(Translate); Vue.use(Translate);
export default () => { export default () => {
const tabsElement = document.querySelector('.pipelines-tabs');
const codequalityTab = document.getElementById('js-pipeline-codequality-report'); const codequalityTab = document.getElementById('js-pipeline-codequality-report');
if (codequalityTab) { if (tabsElement && codequalityTab) {
const fetchReportAction = 'fetchReport';
const { codequalityReportDownloadPath, blobPath } = codequalityTab.dataset; const { codequalityReportDownloadPath, blobPath } = codequalityTab.dataset;
const store = createStore({ endpoint: codequalityReportDownloadPath, blobPath }); const store = createStore({ endpoint: codequalityReportDownloadPath, blobPath });
store.dispatch('fetchReport');
const isCodequalityTabActive = Boolean(
document.querySelector('.pipelines-tabs > li > a.codequality-tab.active'),
);
if (isCodequalityTabActive) {
store.dispatch(fetchReportAction);
} else {
const tabClickHandler = e => {
if (e.target.className === 'codequality-tab') {
store.dispatch(fetchReportAction);
tabsElement.removeEventListener('click', tabClickHandler);
}
};
tabsElement.addEventListener('click', tabClickHandler);
}
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment