@@ -263,10 +263,10 @@ function fetchWithTimeout(url, options = {}, timeout = 30000) {
263
263
}
264
264
265
265
// Safe element getter with logging
266
- function safeGetElement ( id ) {
266
+ function safeGetElement ( id , suppressWarning = false ) {
267
267
try {
268
268
const element = document . getElementById ( id ) ;
269
- if ( ! element ) {
269
+ if ( ! element && ! suppressWarning ) {
270
270
console . warn ( `Element with id "${ id } " not found` ) ;
271
271
}
272
272
return element ;
@@ -536,6 +536,12 @@ const METRICS_RETRY_DELAY = 2000; // Increased from 1500ms
536
536
* Enhanced metrics loading with better race condition prevention
537
537
*/
538
538
async function loadAggregatedMetrics ( ) {
539
+ const metricsPanel = safeGetElement ( "metrics-panel" , true ) ;
540
+ if ( ! metricsPanel || metricsPanel . closest ( '.tab-panel.hidden' ) ) {
541
+ console . log ( "Metrics panel not visible, skipping load" ) ;
542
+ return ;
543
+ }
544
+
539
545
// Cancel any existing request
540
546
if ( metricsRequestController ) {
541
547
console . log ( "Cancelling existing metrics request..." ) ;
@@ -550,10 +556,12 @@ async function loadAggregatedMetrics() {
550
556
}
551
557
552
558
console . log ( "Starting new metrics request..." ) ;
559
+ showMetricsLoading ( ) ;
553
560
554
561
metricsRequestPromise = loadMetricsInternal ( ) . finally ( ( ) => {
555
562
metricsRequestPromise = null ;
556
563
metricsRequestController = null ;
564
+ hideMetricsLoading ( ) ;
557
565
} ) ;
558
566
559
567
return metricsRequestPromise ;
@@ -676,8 +684,11 @@ async function fetchWithTimeoutAndRetry(
676
684
* Show loading state for metrics
677
685
*/
678
686
function showMetricsLoading ( ) {
679
- const metricsPanel = safeGetElement ( "metrics-panel" ) ;
687
+ const metricsPanel = safeGetElement ( "metrics-panel" , true ) ; // suppress warning
680
688
if ( metricsPanel ) {
689
+ const existingLoading = safeGetElement ( "metrics-loading" , true ) ;
690
+ if ( existingLoading ) return ;
691
+
681
692
const loadingDiv = document . createElement ( "div" ) ;
682
693
loadingDiv . id = "metrics-loading" ;
683
694
loadingDiv . className = "flex justify-center items-center p-8" ;
@@ -697,7 +708,7 @@ function showMetricsLoading() {
697
708
* Hide loading state for metrics
698
709
*/
699
710
function hideMetricsLoading ( ) {
700
- const loadingDiv = safeGetElement ( "metrics-loading" ) ;
711
+ const loadingDiv = safeGetElement ( "metrics-loading" , true ) ;
701
712
if ( loadingDiv && loadingDiv . parentNode ) {
702
713
loadingDiv . parentNode . removeChild ( loadingDiv ) ;
703
714
}
@@ -4560,6 +4571,20 @@ document.addEventListener("DOMContentLoaded", () => {
4560
4571
// 4. Handle initial tab/state
4561
4572
initializeTabState ( ) ;
4562
4573
4574
+ // // ✅ 4.1 Set up tab button click handlers
4575
+ // document.querySelectorAll('.tab-button').forEach(button => {
4576
+ // button.addEventListener('click', () => {
4577
+ // const tabId = button.getAttribute('data-tab');
4578
+
4579
+ // document.querySelectorAll('.tab-panel').forEach(panel => {
4580
+ // panel.classList.add('hidden');
4581
+ // });
4582
+
4583
+ // document.getElementById(tabId).classList.remove('hidden');
4584
+ // });
4585
+ // });
4586
+
4587
+
4563
4588
// 5. Set up form validation
4564
4589
setupFormValidation ( ) ;
4565
4590
0 commit comments