/** * ds-quick-wins.js * Identifies low-effort, high-impact opportunities for design system adoption * UI Team Tool #5 */ import { ComponentHelpers } from '../../utils/component-helpers.js'; import contextStore from '../../stores/context-store.js'; import toolBridge from '../../services/tool-bridge.js'; class DSQuickWins extends HTMLElement { constructor() { super(); this.quickWins = null; this.isAnalyzing = false; } async connectedCallback() { this.render(); this.setupEventListeners(); await this.loadCachedResults(); } async loadCachedResults() { try { const context = contextStore.getMCPContext(); if (!context.project_id) return; const cached = localStorage.getItem(`quickwins_${context.project_id}`); if (cached) { this.quickWins = JSON.parse(cached); this.renderResults(); } } catch (error) { console.error('[DSQuickWins] Failed to load cached results:', error); } } setupEventListeners() { const analyzeBtn = this.querySelector('#analyze-quick-wins-btn'); const pathInput = this.querySelector('#project-path-input'); if (analyzeBtn) { analyzeBtn.addEventListener('click', () => this.analyzeQuickWins()); } if (pathInput) { pathInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') { this.analyzeQuickWins(); } }); } } async analyzeQuickWins() { const pathInput = this.querySelector('#project-path-input'); const projectPath = pathInput?.value.trim() || ''; if (!projectPath) { ComponentHelpers.showToast?.('Please enter a project path', 'error'); return; } this.isAnalyzing = true; this.updateLoadingState(); try { // Call dss_find_quick_wins MCP tool const result = await toolBridge.executeTool('dss_find_quick_wins', { path: projectPath }); this.quickWins = result; // Cache results const context = contextStore.getMCPContext(); if (context.project_id) { localStorage.setItem(`quickwins_${context.project_id}`, JSON.stringify(result)); } this.renderResults(); ComponentHelpers.showToast?.('Quick wins analysis complete', 'success'); } catch (error) { console.error('[DSQuickWins] Analysis failed:', error); ComponentHelpers.showToast?.(`Analysis failed: ${error.message}`, 'error'); const resultsContainer = this.querySelector('#results-container'); if (resultsContainer) { resultsContainer.innerHTML = ComponentHelpers.renderError('Quick wins analysis failed', error); } } finally { this.isAnalyzing = false; this.updateLoadingState(); } } updateLoadingState() { const analyzeBtn = this.querySelector('#analyze-quick-wins-btn'); const resultsContainer = this.querySelector('#results-container'); if (!analyzeBtn || !resultsContainer) return; if (this.isAnalyzing) { analyzeBtn.disabled = true; analyzeBtn.textContent = '⏳ Analyzing...'; resultsContainer.innerHTML = ComponentHelpers.renderLoading('Identifying quick win opportunities...'); } else { analyzeBtn.disabled = false; analyzeBtn.textContent = '⚡ Find Quick Wins'; } } renderResults() { const resultsContainer = this.querySelector('#results-container'); if (!resultsContainer || !this.quickWins) return; const opportunities = this.quickWins.opportunities || []; const totalImpact = opportunities.reduce((sum, opp) => sum + (opp.impact || 0), 0); const avgEffort = opportunities.length > 0 ? (opportunities.reduce((sum, opp) => sum + (opp.effort || 0), 0) / opportunities.length).toFixed(1) : 0; resultsContainer.innerHTML = `
${ComponentHelpers.escapeHtml(opp.description)}
Enter your project path above to identify low-effort, high-impact improvements