docbrown/app/javascript/packs/analyticsDashboard.js
Monica Mateiu dbdd24c729
add org analytics menu if user has organizations (#13995)
* add organizations menu to analytics page

* Update app/views/dashboards/analytics.erb

Co-authored-by: rhymes <github@rhymes.dev>

* replace querySelector with getElementsByClassName for better performance

* Update app/javascript/packs/analyticsDashboard.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Update app/views/dashboards/analytics.erb

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* refactor analytics view and add specs

* skip flakey analyticsNavigation spec

Co-authored-by: rhymes <github@rhymes.dev>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2021-06-23 14:35:23 +02:00

27 lines
675 B
JavaScript

import { initCharts } from '../analytics/dashboard';
function renderOrgData() {
const organizationsArray = Array.from(
document.getElementsByClassName('organization'),
);
const activeOrg = organizationsArray.find(
(org) => org.getAttribute('aria-current') === 'page',
);
const chartData = activeOrg.dataset.organizationId
? activeOrg.dataset.organizationId
: null;
initCharts({ organizationId: chartData });
}
function initDashboard() {
const organizationsMenu = document.getElementsByClassName('organization')[0];
if (!organizationsMenu) {
initCharts({ organizationId: null });
} else {
renderOrgData();
}
}
initDashboard();