/** * ds-metrics-dashboard.js * Metrics dashboard for design system adoption and health * Shows key metrics like component adoption rate, token usage, etc. */ import store from '../../stores/app-store.js'; export default class MetricsDashboard extends HTMLElement { constructor() { super(); this.isLoading = true; this.error = null; this.metrics = { adoptionRate: 0, componentsUsed: 0, totalComponents: 0, tokensCovered: 0, teamsActive: 0, averageUpdateFreq: 'N/A' }; } connectedCallback() { this.render(); this.loadMetrics(); } async loadMetrics() { this.isLoading = true; this.error = null; this.render(); try { const response = await fetch('/api/discovery/stats'); if (!response.ok) { throw new Error(`API Error: ${response.status}`); } const json = await response.json(); if (json.status === 'success' && json.data) { const stats = json.data; // Map backend field names to component properties this.metrics = { adoptionRate: stats.adoption_percentage || 0, componentsUsed: stats.components_in_use || 0, totalComponents: stats.total_components || 0, tokensCovered: stats.tokens_count || 0, teamsActive: stats.active_projects || 0, averageUpdateFreq: stats.avg_update_days ? `${stats.avg_update_days} days` : 'N/A' }; } else { throw new Error(json.message || 'Invalid response format'); } } catch (error) { console.error('Failed to load metrics:', error); this.error = error.message; } finally { this.isLoading = false; this.render(); } } render() { if (this.isLoading) { this.innerHTML = `
Track adoption, health, and usage of your design system