All files / src/browser/cia dashboard-init.ts

0% Statements 0/43
0% Branches 0/16
0% Functions 0/2
0% Lines 0/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                                                                                                                                                                                                           
/**
 * @module CIA/DashboardInit
 * @category Intelligence Platform - System Orchestration
 *
 * @description
 * Dashboard Initialization Module – Intelligence Platform Orchestration Layer.
 * Coordinates the bootstrap sequence for multi-layered data integration,
 * visualization rendering, and interactive intelligence presentation. Manages
 * component lifecycle, dependency resolution, error recovery, and state
 * coordination across distributed rendering engines and data transformation
 * pipelines.
 *
 * @author Hack23 AB - Intelligence Platforms
 * @license Apache-2.0
 * @version 1.0.0
 * @since 2024-01-15
 
 *
 * @intelligence Intelligence Platform Orchestration Layer — coordinates bootstrap sequence for multi-layered data integration, visualization rendering, and interactive intelligence presentation. Manages component lifecycle, dependency resolution, error recovery, and state coordination across rendering engines and data pipelines.
 *
 * @business Platform reliability SLA foundation — initialization resilience directly impacts uptime metrics and user trust. Error recovery ensures graceful degradation, maintaining partial functionality during outages. SLA commitments for enterprise clients depend on robust initialization.
 *
 * @marketing First-load experience quality — dashboard initialization speed and reliability determine first-impression quality for new users. Time to Interactive (< 3s target) is critical for conversion from landing page visitor to engaged user. Loading state UX affects bounce rate.
 * */
 
import { CIADataLoader } from './data-loader.js';
import { CIADashboardRenderer } from './visualizations.js';
import { Election2026Predictions } from './election-predictions.js';
import { t } from './i18n-translations.js';
 
import type { CIADataPayload } from './data-loader.js';
import type { RendererData } from './visualizations.js';
 
/* ------------------------------------------------------------------ */
/*  Dashboard initialization                                          */
/* ------------------------------------------------------------------ */
 
async function initDashboard(): Promise<void> {
  const loader = new CIADataLoader();
 
  // Update loading text with i18n
  const loadingText = document.querySelector('#loading-state p') as HTMLElement | null;
  if (loadingText) {
    loadingText.textContent = t('loadingData');
  }
 
  try {
    // Load all CIA exports using the loadAll method
    const data: CIADataPayload = await loader.loadAll();
    const { overview, election, partyPerf, top10, committees, votingPatterns } = data;
 
    // Hide loading state
    const loadingState = document.getElementById('loading-state');
    if (loadingState) loadingState.classList.add('hidden');
    const dashboardContent = document.getElementById('dashboard-content');
    if (dashboardContent) dashboardContent.classList.remove('hidden');
 
    // Initialize renderers
    const rendererData: RendererData = {
      overview,
      partyPerf,
      top10,
      committees,
      votingPatterns
    };
    const renderer = new CIADashboardRenderer(rendererData);
 
    const electionRenderer = new Election2026Predictions(election);
 
    // Render all sections
    renderer.renderKeyMetrics();
    renderer.renderPartyPerformance();
    renderer.renderTop10Rankings();
    renderer.renderVotingPatterns();
    renderer.renderCommitteeNetwork();
 
    electionRenderer.renderSeatPredictions();
    electionRenderer.renderCoalitionScenarios();
    electionRenderer.renderKeyFactors();
  } catch (error: unknown) {
    console.error('Dashboard initialization error:', error);
 
    const loadingState = document.getElementById('loading-state');
    if (loadingState) loadingState.classList.add('hidden');
    const errorState = document.getElementById('error-state');
    if (errorState) errorState.classList.remove('hidden');
 
    // Use i18n for user-facing error message, log technical details to console
    const errorMessage = t('errorLoadingData');
    const errorMessageEl = document.getElementById('error-message');
    if (errorMessageEl) errorMessageEl.textContent = errorMessage;
 
    // Retry button with i18n text
    const retryButton = document.getElementById('retry-button') as HTMLButtonElement | null;
    if (retryButton) {
      retryButton.textContent = t('retryButton');
      retryButton.addEventListener('click', () => {
        location.reload();
      });
    }
  }
}
 
// Initialize on DOM ready
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', initDashboard);
} else {
  initDashboard();
}