Skip to content

Commit 865ea75

Browse files
avoid Console warning for missing #metrics-loading element (#496)
* Fix CodeMirror layout spacing and update content textarea Signed-off-by: Nayana R Gowda <[email protected]> * avoid warning for missing #metrics-loading element Signed-off-by: Nayana R Gowda <[email protected]> --------- Signed-off-by: Nayana R Gowda <[email protected]>
1 parent 5c49036 commit 865ea75

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

mcpgateway/static/admin.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@
6161
.feedback:blank {
6262
display: none;
6363
}
64+
65+
66+
/* .hidden {
67+
display: none;
68+
} */

mcpgateway/static/admin.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ function fetchWithTimeout(url, options = {}, timeout = 30000) {
263263
}
264264

265265
// Safe element getter with logging
266-
function safeGetElement(id) {
266+
function safeGetElement(id, suppressWarning = false) {
267267
try {
268268
const element = document.getElementById(id);
269-
if (!element) {
269+
if (!element && !suppressWarning) {
270270
console.warn(`Element with id "${id}" not found`);
271271
}
272272
return element;
@@ -536,6 +536,12 @@ const METRICS_RETRY_DELAY = 2000; // Increased from 1500ms
536536
* Enhanced metrics loading with better race condition prevention
537537
*/
538538
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+
539545
// Cancel any existing request
540546
if (metricsRequestController) {
541547
console.log("Cancelling existing metrics request...");
@@ -550,10 +556,12 @@ async function loadAggregatedMetrics() {
550556
}
551557

552558
console.log("Starting new metrics request...");
559+
showMetricsLoading();
553560

554561
metricsRequestPromise = loadMetricsInternal().finally(() => {
555562
metricsRequestPromise = null;
556563
metricsRequestController = null;
564+
hideMetricsLoading();
557565
});
558566

559567
return metricsRequestPromise;
@@ -676,8 +684,11 @@ async function fetchWithTimeoutAndRetry(
676684
* Show loading state for metrics
677685
*/
678686
function showMetricsLoading() {
679-
const metricsPanel = safeGetElement("metrics-panel");
687+
const metricsPanel = safeGetElement("metrics-panel", true); // suppress warning
680688
if (metricsPanel) {
689+
const existingLoading = safeGetElement("metrics-loading", true);
690+
if (existingLoading) return;
691+
681692
const loadingDiv = document.createElement("div");
682693
loadingDiv.id = "metrics-loading";
683694
loadingDiv.className = "flex justify-center items-center p-8";
@@ -697,7 +708,7 @@ function showMetricsLoading() {
697708
* Hide loading state for metrics
698709
*/
699710
function hideMetricsLoading() {
700-
const loadingDiv = safeGetElement("metrics-loading");
711+
const loadingDiv = safeGetElement("metrics-loading", true);
701712
if (loadingDiv && loadingDiv.parentNode) {
702713
loadingDiv.parentNode.removeChild(loadingDiv);
703714
}
@@ -4560,6 +4571,20 @@ document.addEventListener("DOMContentLoaded", () => {
45604571
// 4. Handle initial tab/state
45614572
initializeTabState();
45624573

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+
45634588
// 5. Set up form validation
45644589
setupFormValidation();
45654590

mcpgateway/templates/admin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ <h3 class="text-lg font-bold mb-4 dark:text-gray-200">Add New Root</h3>
13081308
</div>
13091309
</div>
13101310

1311-
1311+
13121312

13131313
<!-- Metrics Panel -->
13141314
<div id="metrics-panel" class="tab-panel hidden">

0 commit comments

Comments
 (0)