debian-mirror-gitlab/app/assets/javascripts/admin/users/tabs.js

33 lines
817 B
JavaScript
Raw Normal View History

2021-04-17 20:07:23 +05:30
import Api from '~/api';
2021-03-11 19:13:27 +05:30
import { historyPushState } from '~/lib/utils/common_utils';
import { mergeUrlParams } from '~/lib/utils/url_utility';
const COHORTS_PANE = 'cohorts';
2021-04-17 20:07:23 +05:30
const COHORTS_PANE_TAB_CLICK_EVENT = 'i_analytics_cohorts';
2021-03-11 19:13:27 +05:30
const tabClickHandler = (e) => {
const { hash } = e.currentTarget;
2021-04-17 20:07:23 +05:30
let tab = null;
if (hash === `#${COHORTS_PANE}`) {
tab = COHORTS_PANE;
Api.trackRedisHllUserEvent(COHORTS_PANE_TAB_CLICK_EVENT);
}
2021-03-11 19:13:27 +05:30
const newUrl = mergeUrlParams({ tab }, window.location.href);
historyPushState(newUrl);
};
const initTabs = () => {
const tabLinks = document.querySelectorAll('.js-users-tab-item a');
if (tabLinks.length) {
tabLinks.forEach((tabLink) => {
tabLink.addEventListener('click', (e) => tabClickHandler(e));
});
}
};
export default initTabs;