@@ -417,11 +417,84 @@ function postPluginGraphQL(gqlField, prefix, foreignKey, dtRequest, callback) {
417417 $(`#histCount_${prefix}`).text(0);
418418 }
419419 });
420+
421+ // Auto-hide tabs with zero results
422+ autoHideEmptyTabs(counts, prefixes);
423+
420424 } catch (err) {
421425 console.error('[plugins] badge prefetch failed:', err);
422426 }
423427}
424428
429+ // ---------------------------------------------------------------
430+ // Hide plugin tabs (left-nav + pane) where all three counts are 0.
431+ // Within visible plugins, hide inner sub-tabs whose count is 0.
432+ // If the active tab was hidden, activate the first visible one.
433+ function autoHideEmptyTabs(counts, prefixes) {
434+ prefixes.forEach(prefix => {
435+ const c = counts[prefix] || { objects: 0, events: 0, history: 0 };
436+ const total = c.objects + c.events + c.history;
437+ const $li = $(`#tabs-location li:has(a[href="#${prefix}"])`);
438+ const $pane = $(`#tabs-content-location > #${prefix}`);
439+
440+ if (total === 0) {
441+ // Hide the entire plugin tab
442+ $li.hide();
443+ $pane.removeClass('active').hide();
444+ } else {
445+ // Ensure visible (in case a previous filter hid it)
446+ $li.show();
447+ $pane.show();
448+
449+ // Hide inner sub-tabs with zero count
450+ const subTabs = [
451+ { href: `#objectsTarget_${prefix}`, count: c.objects },
452+ { href: `#eventsTarget_${prefix}`, count: c.events },
453+ { href: `#historyTarget_${prefix}`, count: c.history },
454+ ];
455+
456+ let activeSubHidden = false;
457+ subTabs.forEach(st => {
458+ const $subLi = $pane.find(`ul.nav-tabs li:has(a[href="${st.href}"])`);
459+ const $subPane = $pane.find(st.href);
460+ if (st.count === 0) {
461+ if ($subLi.hasClass('active')) activeSubHidden = true;
462+ $subLi.hide();
463+ $subPane.removeClass('active').hide();
464+ } else {
465+ $subLi.show();
466+ $subPane.show();
467+ }
468+ });
469+
470+ // If the active inner sub-tab was hidden, activate the first visible one
471+ if (activeSubHidden) {
472+ const $firstVisibleSubLi = $pane.find('ul.nav-tabs li:visible').first();
473+ if ($firstVisibleSubLi.length) {
474+ $firstVisibleSubLi.addClass('active');
475+ const target = $firstVisibleSubLi.find('a').attr('href');
476+ $pane.find(target).addClass('active');
477+ }
478+ }
479+ }
480+ });
481+
482+ // If the active left-nav tab was hidden, activate the first visible one
483+ const $activeLi = $(`#tabs-location li.active:visible`);
484+ if ($activeLi.length === 0) {
485+ const $firstVisibleLi = $(`#tabs-location li:visible`).first();
486+ if ($firstVisibleLi.length) {
487+ $firstVisibleLi.addClass('active');
488+ const targetPrefix = $firstVisibleLi.find('a').attr('href')?.replace('#', '');
489+ if (targetPrefix) {
490+ $(`#tabs-content-location > #${targetPrefix}`).addClass('active');
491+ // Trigger shown.bs.tab so deferred DataTables initialize
492+ $firstVisibleLi.find('a').tab('show');
493+ }
494+ }
495+ }
496+ }
497+
425498function generateTabs() {
426499
427500 // Reset the tabs by clearing previous headers and content
0 commit comments