77cfc90b4fb2166b9ae955ad40a067549d6d5881 max Tue Sep 15 05:29:56 2026 -0700 hgc share-a-link: force the enclosing superTrack to show The hgc details-page "Share a link" button strips the hgsid and links straight to the page, but a track nested in a superTrack draws nothing on a fresh load of that link since superTracks default to hide. Add tdbTopSuperTrack() so the per-track JSON carries the enclosing superTrack's name, and have the share dialog force =show onto the URL when there is one. diff --git src/hg/js/topLinks.js src/hg/js/topLinks.js index bb00e0e1438..002cef08ba3 100644 --- src/hg/js/topLinks.js +++ src/hg/js/topLinks.js @@ -330,51 +330,58 @@ nameInput.focus(); } // Return the current page URL with the hgsid query parameter removed (for hgTrackUi sharing). function stripHgsid(url) { try { var u = new URL(url); u.searchParams.delete("hgsid"); return u.toString(); } catch (e) { return url.replace(/([?&])hgsid=[^&]*/, "$1").replace(/[?&]$/, ""); } } // Add name=val to url if it isn't already present (used to keep db= after stripping hgsid). - function ensureParam(url, name, val) { + // With force=true, overwrite any existing value instead (used for superTrack=show, since the + // page's own hgsid-derived value would otherwise win instead of the value we need to send). + function ensureParam(url, name, val, force) { try { var u = new URL(url); - if (!u.searchParams.has(name)) + if (force || !u.searchParams.has(name)) u.searchParams.set(name, val); return u.toString(); } catch (e) { - if (new RegExp("[?&]" + name + "=").test(url)) - return url; + var re = new RegExp("([?&])" + name + "=[^&]*"); + if (re.test(url)) + return force ? url.replace(re, "$1" + name + "=" + encodeURIComponent(val)) : url; return url + (url.indexOf("?") >= 0 ? "&" : "?") + name + "=" + encodeURIComponent(val); } } // Open a simple "here is the link" dialog for an arbitrary URL, with the hgsid stripped. // Used by hgTrackUi (the current page) and by the hgc item-details popup in hgTracks.js. - // opts (optional): {ensureDb: to add db= if missing, pageNote: true to note it's page-only}. + // opts (optional): {ensureDb: to add db= if missing, pageNote: true to note it's page-only, + // superTrack: of an enclosing superTrack whose visibility must be forced to "show" so + // the linked track isn't hidden by the superTrack's own default}. function shareUrlDialog(url, opts) { opts = opts || {}; var clean = stripHgsid(url); if (opts.ensureDb) clean = ensureParam(clean, "db", opts.ensureDb); + if (opts.superTrack) + clean = ensureParam(clean, opts.superTrack, "show", true); var body = document.createElement("div"); showModal("Share a link", body, 720); showResult(body, clean, {pageNote: opts.pageNote, snapshot: opts.snapshot}); } function showShareDialog(link) { var mode = link.getAttribute("data-sharemode") || "session"; // hgTrackUi etc.: the shareable thing is just this page's URL without the hgsid. Note // that it opens the page, not the user's session/tracks (like the hgc popup link). if (mode === "url") { shareUrlDialog(window.location.href, {pageNote: true}); return; }