Skip to content

Commit

Permalink
Search-by-TFM Bug Bash feedback (#9366)
Browse files Browse the repository at this point in the history
* fixed a UI issue

* fixed multiple bugs from bug bash

* whitespace

* Search bar only removed from search page, not others (like the profiles page) + no search bar flicker on rendering
  • Loading branch information
advay26 authored Feb 8, 2023
1 parent 3f692c3 commit 4e5f90d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 51 deletions.
15 changes: 2 additions & 13 deletions src/Bootstrap/dist/css/bootstrap-theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 2 additions & 15 deletions src/Bootstrap/less/theme/page-list-packages.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@
margin: 0 !important;
}

.btn-filter {
margin-top: 33px;
margin-bottom: 33px;
width: 90px;
height: 45px;
font-weight: 500;
font-size: medium;
background-color: transparent;
border: none;
}

.btn-filter:hover {
background-color: #f4f4f4;
}

@media (max-width: @screen-md) {
.btn-filter {
text-align: left;
Expand Down Expand Up @@ -118,6 +103,7 @@
.collapsible {
color: rgb(73, 73, 73);
background-color: @alert-info-bg;
position: relative;
padding-top: 0px;
padding-bottom: 0px;
border: none;
Expand All @@ -131,6 +117,7 @@

.collapsible:focus {
outline: solid;
z-index: 1;
}

.tfmTab {
Expand Down
50 changes: 30 additions & 20 deletions src/NuGetGallery/Scripts/gallery/page-list-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ $(function() {
const allFrameworks = document.querySelectorAll('.framework');
const allTfms = document.querySelectorAll('.tfm');

// Hide the default search bar in the page header
const defaultSearchBarHeader = document.getElementById("search-bar-header");
defaultSearchBarHeader.parentNode.removeChild(defaultSearchBarHeader);

// Checkbox logic for Framework and Tfm filters
for (const framework of allFrameworks) {
framework.addEventListener('click', clickFrameworkCheckbox);
Expand All @@ -23,12 +19,10 @@ $(function() {

function clickFrameworkCheckbox() {
this.indeterminate = false;
updateFrameworkFilters(searchForm.frameworks, this.id, this.checked);

const tfms = document.querySelectorAll('[parent=' + this.id + ']');
tfms.forEach((tfm) => {
tfm.checked = false;
updateFrameworkFilters(searchForm.tfms, tfm.id, false);
});
}

Expand All @@ -40,25 +34,12 @@ $(function() {

framework.checked = false;
framework.indeterminate = checkedCount !== 0;
updateFrameworkFilters(searchForm.frameworks, framework.id, false);

updateFrameworkFilters(searchForm.tfms, this.id, this.checked);
}

// Update the query string with the selected Frameworks and Tfms
function updateFrameworkFilters(searchField, frameworkName, add) {
if (add) {
searchField.value += frameworkName + ",";
}
else {
searchField.value = searchField.value.replace(frameworkName + ",", "")
}
}

// Submit the form when a user changes the selected 'sortBy' option
searchForm.sortby.addEventListener('change', (e) => {
searchForm.sortby.value = e.target.value;
searchForm.submit();
submitSearchForm();
});

// Accordion/collapsible logic
Expand Down Expand Up @@ -95,6 +76,28 @@ $(function() {
}
}

searchForm.addEventListener('submit', submitSearchForm);

function submitSearchForm() {
constructFilterParameter(searchForm.frameworks, allFrameworks);
constructFilterParameter(searchForm.tfms, allTfms);
searchForm.submit();
}

// Update the query string with the selected frameworks and tfms
function constructFilterParameter(searchField, checkboxList) {
searchField.value = "";

checkboxList.forEach((framework) => {
if (framework.checked) {
searchField.value += framework.id + ",";
}
});

// trim trailing commas
searchField.value = searchField.value.replace(/,+$/, '');
}

// Initialize state for Framework and Tfm checkboxes
// NOTE: We first click on all selected Framework checkboxes and then on the selected Tfm checkboxes, which
// allows us to correctly handle cases where a Framework AND one of its child Tfms is present in the query
Expand All @@ -107,5 +110,12 @@ $(function() {

inputFrameworkFilters.map(id => document.getElementById(id)).forEach(checkbox => checkbox.click());
inputTfmFilters.map(id => document.getElementById(id)).forEach(checkbox => checkbox.click());

// expand TFM section if a TFM from that generation has been selected
allFrameworks.forEach((checkbox) => {
if (checkbox.indeterminate) {
document.querySelector('[tab=' + checkbox.id + ']').click();
}
});
}
});
7 changes: 4 additions & 3 deletions src/NuGetGallery/Views/Shared/ListPackages.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ViewBag.SortText = String.IsNullOrWhiteSpace(Model.SearchTerm) ? "recent installs" : "relevance";
ViewBag.Tab = "Packages";
ViewBag.BlockSearchEngineIndexing = !String.IsNullOrWhiteSpace(Model.SearchTerm) || Model.PageIndex != 0;
ViewBag.ShowSearchInNavbar = false;
}

@helper AddPackageFilterOption(string optionName, string optionValue, bool isDefault = false)
Expand Down Expand Up @@ -76,6 +77,8 @@
@if (Model.IsAdvancedSearchFlightEnabled)
{
<div class="row clearfix advanced-search-panel" id="advancedSearchPanel">
<input type="text" hidden id="frameworks" name="frameworks" value="@Model.Frameworks">
<input type="text" hidden id="tfms" name="tfms" value="@Model.Tfms">
@if (Model.IsFrameworkFilteringEnabled)
{
<div>
Expand Down Expand Up @@ -133,9 +136,7 @@
</div>

</div>
<input type="text" hidden id="frameworks" name="frameworks" value="@Model.Frameworks">
<input type="text" hidden id="tfms" name="tfms" value="@Model.Tfms">
<input type="hidden" id="prerel" name="prerel" value="@Model.IncludePrerelease.ToString()">
<input type="hidden" id="prerel" name="prerel" value="@Model.IncludePrerelease.ToString().ToLower()">
</div>
}
</div>
Expand Down

0 comments on commit 4e5f90d

Please sign in to comment.