/** * 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 = `
Loading metrics...
`; return; } if (this.error) { this.innerHTML = `
Failed to load metrics: ${this.error}
`; return; } this.innerHTML = `

Design System Metrics

Track adoption, health, and usage of your design system

${this.renderMetricCard('Adoption Rate', `${this.metrics.adoptionRate}%`, '#4caf50', 'Percentage of team using DS')} ${this.renderMetricCard('Components in Use', this.metrics.componentsUsed, '#2196f3', `of ${this.metrics.totalComponents} total`)} ${this.renderMetricCard('Design Tokens', this.metrics.tokensCovered, '#ff9800', 'Total tokens managed')} ${this.renderMetricCard('Active Projects', this.metrics.teamsActive, '#9c27b0', 'Projects in system')}

Recent Activity

Component Library Updated 2 hours ago
Added 3 new components to Button family
Tokens Synchronized 6 hours ago
Synced 42 color tokens from Figma
Team Onboarded 1 day ago
Marketing team completed DS training

System Health

Component Coverage
69%
Token Coverage
85%
Documentation
92%
`; } renderMetricCard(title, value, color, subtitle) { return `
${title}
${value}
${subtitle}
`; } } customElements.define('ds-metrics-dashboard', MetricsDashboard);