{"size": 1408, "ext": "js", "max_stars_repo_path": "ee/app/assets/javascripts/pages/projects/pipelines/show/codequality_report.js", "max_stars_repo_name": "mehulagg/gitlab-codesanbox", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ee/app/assets/javascripts/pages/projects/pipelines/show/codequality_report.js", "max_issues_repo_name": "mehulagg/gitlab-codesanbox", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ee/app/assets/javascripts/pages/projects/pipelines/show/codequality_report.js", "max_forks_repo_name": "mehulagg/gitlab-codesanbox", "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:30:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:30:08.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 31.2888888889, "max_line_length": 85, "alphanum_fraction": 0.6889204545}
import Vue from 'vue';
import CodequalityReportApp from 'ee/codequality_report/codequality_report.vue';
import createStore from 'ee/codequality_report/store';
import Translate from '~/vue_shared/translate';

Vue.use(Translate);

export default () => {
  const tabsElement = document.querySelector('.pipelines-tabs');
  const codequalityTab = document.getElementById('js-pipeline-codequality-report');

  if (tabsElement && codequalityTab) {
    const fetchReportAction = 'fetchReport';
    const { codequalityReportDownloadPath, blobPath } = codequalityTab.dataset;
    const store = createStore({ endpoint: codequalityReportDownloadPath, blobPath });

    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
    new Vue({
      el: codequalityTab,
      components: {
        CodequalityReportApp,
      },
      store,
      render: createElement => createElement('codequality-report-app'),
    });
  }
};
