Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search-by-TFM Bug Bash feedback #9366

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This btn-filter class is no longer used in the code.

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