Skip to content

Commit 6be7bed

Browse files
authored
Added null checks to mitigate exceptions on the '/profiles' pages (#9388)
* profiles page uses the same js script, but does not have a searchForm, so I added checks in the script * addressed feedback from PR
1 parent 9111502 commit 6be7bed

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

src/NuGetGallery/Scripts/gallery/page-list-packages.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ $(function() {
3636
framework.indeterminate = checkedCount !== 0;
3737
}
3838

39-
// Submit the form when a user changes the selected 'sortBy' option
40-
searchForm.sortby.addEventListener('change', (e) => {
41-
searchForm.sortby.value = e.target.value;
42-
submitSearchForm();
43-
});
44-
4539
// Accordion/collapsible logic
4640
const collapsibles = document.querySelectorAll('.collapsible');
4741

@@ -68,8 +62,7 @@ $(function() {
6862
}
6963
}
7064

71-
searchForm.addEventListener('submit', submitSearchForm);
72-
65+
// Update query params before submitting the form
7366
function submitSearchForm() {
7467
constructFilterParameter(searchForm.frameworks, allFrameworks);
7568
constructFilterParameter(searchForm.tfms, allTfms);
@@ -93,7 +86,6 @@ $(function() {
9386
// Initialize state for Framework and Tfm checkboxes
9487
// NOTE: We first click on all selected Framework checkboxes and then on the selected Tfm checkboxes, which
9588
// allows us to correctly handle cases where a Framework AND one of its child Tfms is present in the query
96-
initializeFrameworkAndTfmCheckboxes();
9789
function initializeFrameworkAndTfmCheckboxes() {
9890
var inputFrameworkFilters = searchForm.frameworks.value.split(',').map(f => f.trim()).filter(f => f);
9991
var inputTfmFilters = searchForm.tfms.value.split(',').map(f => f.trim()).filter(f => f);
@@ -110,4 +102,14 @@ $(function() {
110102
}
111103
});
112104
}
105+
106+
// The /profiles pages use this js file too, but some code needs to be applied only to the search page
107+
if (searchForm) {
108+
searchForm.sortby.addEventListener('change', (e) => {
109+
searchForm.sortby.value = e.target.value;
110+
submitSearchForm();
111+
});
112+
searchForm.addEventListener('submit', submitSearchForm);
113+
initializeFrameworkAndTfmCheckboxes();
114+
}
113115
});

src/NuGetGallery/Views/Shared/ListPackages.cshtml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
@AddRadioGroupOption("Package Type", "packagetype", optionName, optionValue, Model.PackageType, isDefault);
1313
}
1414

15-
@helper AddSortByOption(string optionName, string optionValue, bool isDefault = false)
16-
{
17-
@AddRadioGroupOption("Sort By", "sortby", optionName, optionValue, Model.SortBy, isDefault);
18-
}
19-
2015
@helper AddRadioGroupOption(string ariaSectionLabel, string radioGroupName, string optionName, string optionValue, string optionCompareValue, bool isDefault = false)
2116
{
2217
<div style="display: flex;">

0 commit comments

Comments
 (0)