Skip to content

Commit adc78e6

Browse files
authored
Merge pull request #1578 from netalertx/next_release
feat(plugins): Implement auto-hide functionality for empty plugin tabs
2 parents 448e17c + 13e9173 commit adc78e6

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

front/pluginsCore.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 and strip active from both nav item and pane
442+
$li.removeClass('active').hide();
443+
$pane.removeClass('active').css('display', '');
444+
} else {
445+
// Ensure nav item visible (in case a previous filter hid it)
446+
$li.show();
447+
// Clear any inline display override so Bootstrap CSS controls pane visibility via .active
448+
$pane.css('display', '');
449+
450+
// Hide inner sub-tabs with zero count
451+
const subTabs = [
452+
{ href: `#objectsTarget_${prefix}`, count: c.objects },
453+
{ href: `#eventsTarget_${prefix}`, count: c.events },
454+
{ href: `#historyTarget_${prefix}`, count: c.history },
455+
];
456+
457+
let activeSubHidden = false;
458+
subTabs.forEach(st => {
459+
const $subLi = $pane.find(`ul.nav-tabs li:has(a[href="${st.href}"])`);
460+
const $subPane = $pane.find(st.href);
461+
if (st.count === 0) {
462+
if ($subLi.hasClass('active')) activeSubHidden = true;
463+
$subLi.hide();
464+
$subPane.removeClass('active').css('display', '');
465+
} else {
466+
$subLi.show();
467+
$subPane.css('display', '');
468+
}
469+
});
470+
471+
// If the active inner sub-tab was hidden, activate the first visible one
472+
// via Bootstrap's tab lifecycle so shown.bs.tab fires for deferred DataTable init
473+
if (activeSubHidden) {
474+
const $firstVisibleSubA = $pane.find('ul.nav-tabs li:visible:first a');
475+
if ($firstVisibleSubA.length) {
476+
$firstVisibleSubA.tab('show');
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+
425498
function generateTabs() {
426499

427500
// Reset the tabs by clearing previous headers and content

0 commit comments

Comments
 (0)