From a639e3159a0920dc80d41737ed9a847818c4bad2 Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 9 Nov 2025 14:18:45 +0000 Subject: [PATCH] Fix discovery to protocol mapping integration - Fix global function references between discovery.js and protocol_mapping.js - Add 'Apply All as Protocol Signals' functionality to discovery results - Implement bulk signal creation from discovery results - Add proper CSS styling for discovery results and notifications - Expose key functions to global scope for cross-script communication - Improve modal auto-population with better timing and error handling Now discovery results properly: - Populate the signal form when clicking 'Use This Signal' - Create all signals at once when clicking 'Apply All as Protocol Signals' - Show clear notifications for success/failure - Refresh the protocol signals display automatically --- src/dashboard/templates.py | 81 ++++++++++++++++++++++++++++++++++++++ static/discovery.js | 63 ++++++++++++++++++++++++++++- static/protocol_mapping.js | 6 ++- 3 files changed, 147 insertions(+), 3 deletions(-) diff --git a/src/dashboard/templates.py b/src/dashboard/templates.py index fe8e734..0d68277 100644 --- a/src/dashboard/templates.py +++ b/src/dashboard/templates.py @@ -229,6 +229,87 @@ DASHBOARD_HTML = """ .log-entry.info { color: #007acc; } + + /* Discovery Results Styling */ + .discovery-result-card { + border: 1px solid #ddd; + border-radius: 6px; + padding: 15px; + margin-bottom: 10px; + background: #f8f9fa; + } + + .discovery-result-card .signal-info { + margin-bottom: 10px; + } + + .discovery-result-card .signal-tags { + margin: 5px 0; + } + + .discovery-result-card .signal-details { + display: flex; + gap: 15px; + font-size: 14px; + color: #666; + } + + .use-signal-btn { + background: #007acc; + color: white; + border: none; + padding: 8px 16px; + border-radius: 4px; + cursor: pointer; + font-weight: bold; + } + + .use-signal-btn:hover { + background: #005a9e; + } + + .apply-all-btn { + background: #28a745; + color: white; + border: none; + padding: 10px 20px; + border-radius: 4px; + cursor: pointer; + font-weight: bold; + margin-top: 15px; + } + + .apply-all-btn:hover { + background: #218838; + } + + .discovery-notification { + position: fixed; + top: 20px; + right: 20px; + padding: 15px; + border-radius: 4px; + z-index: 10000; + max-width: 300px; + } + + .discovery-notification.success { + background: #d4edda; + color: #155724; + border: 1px solid #c3e6cb; + } + + .discovery-notification.error { + background: #f8d7da; + color: #721c24; + border: 1px solid #f5c6cb; + } + + .discovery-notification.warning { + background: #fff3cd; + color: #856404; + border: 1px solid #ffeaa7; + } diff --git a/static/discovery.js b/static/discovery.js index 43fc20f..5f68096 100644 --- a/static/discovery.js +++ b/static/discovery.js @@ -115,8 +115,8 @@ class SimplifiedProtocolDiscovery { console.log('Auto-populating signal form with:', signalData); // Use the simplified protocol mapping function - if (typeof autoPopulateSignalForm === 'function') { - autoPopulateSignalForm(signalData); + if (typeof window.autoPopulateSignalForm === 'function') { + window.autoPopulateSignalForm(signalData); } else { console.error('Simplified protocol mapping functions not loaded'); this.showNotification('Protocol mapping system not available', 'error'); @@ -222,6 +222,65 @@ class SimplifiedProtocolDiscovery { this.autoPopulateSignalForm(signal); } }); + + // Add "Apply All" button + const applyAllButton = document.createElement('button'); + applyAllButton.className = 'apply-all-btn'; + applyAllButton.textContent = 'Apply All as Protocol Signals'; + applyAllButton.style.marginTop = '15px'; + applyAllButton.style.padding = '10px 20px'; + applyAllButton.style.background = '#28a745'; + applyAllButton.style.color = 'white'; + applyAllButton.style.border = 'none'; + applyAllButton.style.borderRadius = '4px'; + applyAllButton.style.cursor = 'pointer'; + applyAllButton.style.fontWeight = 'bold'; + + applyAllButton.onclick = () => { + this.applyAllAsProtocolSignals(suggestedSignals); + }; + + resultsContainer.appendChild(applyAllButton); + } + + // Apply all discovered signals as protocol signals + async applyAllAsProtocolSignals(signals) { + console.log('Applying all discovered signals as protocol signals:', signals); + + let successCount = 0; + let errorCount = 0; + + for (const signal of signals) { + try { + const response = await fetch('/api/v1/dashboard/protocol-signals', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(signal) + }); + + const data = await response.json(); + + if (data.success) { + successCount++; + console.log(`✓ Created signal: ${signal.signal_name}`); + } else { + errorCount++; + console.error(`✗ Failed to create signal: ${signal.signal_name}`, data.detail); + } + } catch (error) { + errorCount++; + console.error(`✗ Error creating signal: ${signal.signal_name}`, error); + } + } + + // Show results + const message = `Created ${successCount} signals successfully. ${errorCount > 0 ? `${errorCount} failed.` : ''}`; + this.showNotification(message, errorCount > 0 ? 'warning' : 'success'); + + // Refresh the protocol signals display + if (typeof window.loadAllSignals === 'function') { + window.loadAllSignals(); + } } // Tag-based signal search diff --git a/static/protocol_mapping.js b/static/protocol_mapping.js index 3016db6..72eafc8 100644 --- a/static/protocol_mapping.js +++ b/static/protocol_mapping.js @@ -354,4 +354,8 @@ document.addEventListener('DOMContentLoaded', function() { // Load initial data loadAllSignals(); -}); \ No newline at end of file +}); + +// Expose functions to global scope for discovery integration +window.autoPopulateSignalForm = autoPopulateSignalForm; +window.loadAllSignals = loadAllSignals; \ No newline at end of file