7912833b68798e9a29c06efc6bd4df497108aaa6
chmalee
  Thu Mar 21 11:40:17 2024 -0700
Refactor duplicate assignments in if else clauses after code review, good call Jonathan, refs #33254

diff --git src/hg/js/hgSearch.js src/hg/js/hgSearch.js
index 281ecb0..6001dbf 100644
--- src/hg/js/hgSearch.js
+++ src/hg/js/hgSearch.js
@@ -852,95 +852,81 @@
                     // helper decoder to change the html encoded entities in
                     // uiState.positionMatches.posName to what is actually rendered
                     // in matchStr
                     return $("<textarea/>").html(str).text();
                 };
                 let geneSymbol; // a potentially fake geneSymbol for the autoComplete
                 if (trackName === "trackDb") {
                     match = matchList.matches.find((elem) => {
                         let posSplit = elem.posName.split(":");
                         geneSymbol = decoder(posSplit[1] + " - " + posSplit[2]);
                         id = "hgTrackUi?db=" + uiState.db + "&g=" + posSplit[0];
                         return geneSymbol === matchStr;
                     });
                     callbackData.label = geneSymbol;
                     callbackData.value = geneSymbol;
-                    if (typeof match.description !== "undefined") {
-                        callbackData.label += " " + match.description;
-                        // hack to remove the bolding from the item values in the autocomplete
-                        callbackData.value = $("<div>" + match.description + "</div>").text();
-                    }
                     callbackData.id = id;
                     callbackData.geneSymbol = geneSymbol;
                     callbackData.internalId = "";
                 } else if (trackName === "publicHubs") {
                     match = matchList.matches.find((elem) => {
                         let posSplit = elem.posName.split(":");
                         geneSymbol = decoder(posSplit[4] + " - " + trackHubSkipHubName(posSplit[3]));
                         id = "hgTrackUi?hubUrl=" + posSplit[0] + ":" + posSplit[1] + "&g=" + posSplit[3] + "&db=" + posSplit[3];
                         return decoder(posSplit[4]) === matchStr;
                     });
                     callbackData.label = geneSymbol;
                     callbackData.value = geneSymbol;
-                    if (typeof match.description !== "undefined") {
-                        callbackData.label += " " + match.description;
-                        // hack to remove the bolding from the item values in the autocomplete
-                        callbackData.value = $("<div>" + match.description + "</div>").text();
-                    }
                     callbackData.id = id;
                     callbackData.geneSymbol = geneSymbol;
                     callbackData.internalId = "";
                 } else if (trackName === "helpDocs") {
                     match = matchList.matches.find((elem) => {
                         let posSplit = elem.posName.split(":");
                         geneSymbol = decoder(posSplit[1].replaceAll("_", " "));
                         return geneSymbol === matchStr;
                     });
                     callbackData.label = geneSymbol;
                     callbackData.value = geneSymbol;
-                    if (typeof match.description !== "undefined") {
-                        callbackData.label += " " + match.description;
-                        // hack to remove the bolding from the item values in the autocomplete
-                        callbackData.value = $("<div>" + match.description + "</div>").text();
-                    }
                     callbackData.id = match.position.split(":")[0];
                     callbackData.geneSymbol = geneSymbol;
                     callbackData.internalId = "";
                 } else { // regular track item  search result click
                     match = matchList.matches.find((elem) => {
                         geneSymbol = elem.posName.replace(/ .*$/,"");
                         return decoder(elem.posName) === matchStr;
                     });
                     callbackData.label = geneSymbol;
                     callbackData.value = geneSymbol;
-                    if (typeof match.description !== "undefined") {
-                        callbackData.label += " " + match.description;
-                        // hack to remove the bolding from the item values in the autocomplete
-                        callbackData.value = $("<div>" + match.description + "</div>").text();
-                    }
                     // special case the genbank searches that are supposed to go to hgc
                     // and not hgTracks
                     let parentTitle = i.parentNode.parentNode.parentNode.childNodes[2];
                     if (["all_mrna", "all_est", "xenoMrna", "xenoEst", "intronEst"].includes(trackName) && parentTitle.textContent.includes("Unaligned")) {
                         id = "hgc?db=" + db + "&g=" + trackName+ "&i=" + match.position + "&c=0&o=0&l=0&r=0" ;
                     } else {
                         id = match.position;
                     }
                     callbackData.id = id;
                     callbackData.geneSymbol = geneSymbol;
                     callbackData.internalId = match.hgFindMatches;
                 }
+                // the value text is the same for all the types, and needs this
+                // hack to remove the bolding from the item values in the autocomplete
+                if (match && typeof match.description !== "undefined") {
+                    callbackData.label += " " + match.description;
+                    callbackData.value = $("<div>" + match.description + "</div>").text();
+                }
                 // type for autocomplete select to know where to navigate to
                 callbackData.type = trackName;
                 addRecentSearch(db, callbackData.geneSymbol, callbackData);
                 window.location = i.href;
             });
         });
     }
 
     function init() {
         cart.setCgi('hgSearch');
         cart.debug(debugCartJson);
         // If a user clicks search before the page has finished loading
         // start processing it now:
         $("#searchBarSearchButton").click(sendUserSearch);
         if (typeof cartJson !== "undefined") {