* 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>
27 lines
675 B
JavaScript
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();
|