diff --git a/pkg/appview/src/js/repository.js b/pkg/appview/src/js/repository.js index 23f9548..a2d9934 100644 --- a/pkg/appview/src/js/repository.js +++ b/pkg/appview/src/js/repository.js @@ -299,11 +299,38 @@ function initTabController() { const selector = document.getElementById('tag-selector'); if (!content || !selector || !to) return; const currentTag = selector.value; + // Backstop: syncDiffMenu() hides the current tag's entry, but keep the + // guard in case it's reached some other way (keyboard, stale DOM). if (!currentTag || to === currentTag) return; window.location.href = '/diff/' + content.dataset.owner + '/' + content.dataset.repo + '?from=' + encodeURIComponent(currentTag) + '&to=' + encodeURIComponent(to); }; + // Hide the currently-selected tag from the "Diff" menu — diffing a tag + // against itself is a no-op (see the guard in diffToTag above), so the + // entry is dead weight in the menu. + // + // This has to live in JS, not the template: #diff-dropdown sits OUTSIDE + // #tag-content and is never re-rendered, so a template-side filter would + // be right on first paint and stale after the first htmx tag swap. Called + // from initTabs(), which runs on load and again on every tag swap. + // + // The template guards the whole dropdown with {{ if gt (len .AllTags) 1 }} + // and tags are unique per repo (tags PK is did+repository+tag), so hiding + // exactly one entry always leaves at least one behind — never an empty menu. + function syncDiffMenu() { + const selector = document.getElementById('tag-selector'); + const menu = document.getElementById('diff-dropdown'); + if (!selector || !menu) return; + const currentTag = selector.value; + menu.querySelectorAll('[data-action="diff-to"]').forEach(btn => { + const item = btn.closest('li') || btn; + // Inline style, matching filterTags() above: beats the daisyUI + // menu's own display rules without a specificity fight. + item.style.display = (btn.dataset.diffTo === currentTag) ? 'none' : ''; + }); + } + window.switchRepoTab = function(tabId) { window._activeRepoTab = tabId; const section = document.getElementById('tag-content'); @@ -338,6 +365,8 @@ function initTabController() { function initTabs() { loaded = {}; + syncDiffMenu(); + const prefetch = [ ['artifacts-tab-btn', 'artifacts-content', tagsUrl], ['layers-tab-btn', 'layers-content', () => contentUrl('layers')],