Skip to content

Commit

Permalink
DYN-6339, DYN-6322 - honours filters during search (#14591)
Browse files Browse the repository at this point in the history
* honors filters during search

- now honors active filters while searching

* remove extra line

* fix

---------

Co-authored-by: reddyashish <[email protected]>
  • Loading branch information
dnenov and reddyashish authored Nov 14, 2023
1 parent 8af516c commit 8490918
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ internal void SearchAndUpdateResults(string query)
else
{
results = Search(query, true);
results = ApplyNonHostFilters(results);
results = ApplyHostFilters(results);
}

this.ClearSearchResults();
Expand Down Expand Up @@ -1326,7 +1328,7 @@ internal void SearchAndUpdateResults()
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
internal IEnumerable<PackageManagerSearchElementViewModel> Filter(IEnumerable<PackageManagerSearchElementViewModel> list)
internal IEnumerable<PackageManagerSearchElementViewModel> ApplyHostFilters(IEnumerable<PackageManagerSearchElementViewModel> list)
{
// No need to filter by host if nothing selected
if (SelectedHosts.Count == 0) return list;
Expand All @@ -1352,15 +1354,11 @@ internal IEnumerable<PackageManagerSearchElementViewModel> GetAllPackages()

// Filter based on user preference
// A package has depndencies if the number of direct_dependency_ids is more than 1
list = Filter(LastSync.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterDeprecated)).OnChecked ? x.IsDeprecated : !x.IsDeprecated)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageNew)).OnChecked ? IsNewPackage(x) : true)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageUpdated)).OnChecked ? IsUpdatedPackage(x) : true)
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterDependencies)).OnChecked ? true : PackageHasDependencies(x))
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterNoDependencies)).OnChecked ? true : !PackageHasDependencies(x))
?.Select(x => new PackageManagerSearchElementViewModel(x,
var initialResults = LastSync?.Select(x => new PackageManagerSearchElementViewModel(x,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(x.Name), isEnabledForInstall)))
.ToList();
CanInstallPackage(x.Name), isEnabledForInstall));
list = ApplyNonHostFilters(initialResults);
list = ApplyHostFilters(list).ToList();

Sort(list, this.SortingKey);

Expand All @@ -1375,6 +1373,21 @@ internal IEnumerable<PackageManagerSearchElementViewModel> GetAllPackages()
return list;
}

/// <summary>
/// Applies non-host filters to a list of PackageManagerSearchElementViewModel
/// </summary>
/// <param name="list">The list to filter</param>
/// <returns></returns>
private List<PackageManagerSearchElementViewModel> ApplyNonHostFilters(IEnumerable<PackageManagerSearchElementViewModel> list)
{
return list.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterDeprecated)).OnChecked ? x.SearchElementModel.IsDeprecated : !x.SearchElementModel.IsDeprecated)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageNew)).OnChecked ? IsNewPackage(x.SearchElementModel) : true)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageUpdated)).OnChecked ? IsUpdatedPackage(x.SearchElementModel) : true)
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterDependencies)).OnChecked ? true : PackageHasDependencies(x.SearchElementModel))
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterNoDependencies)).OnChecked ? true : !PackageHasDependencies(x.SearchElementModel))
.ToList();
}

/// <summary>
/// Checks if a package has any dependencies (will always have at least itself as 1 dependency)
/// </summary>
Expand Down

0 comments on commit 8490918

Please sign in to comment.