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

DYN-6339, DYN-6322 - honours filters during search #14591

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,9 @@ internal void SearchAndUpdateResults(string query)
else
{
results = Search(query, true);
results = ApplyNonHostFilters(results);
results = ApplyHostFilters(results);

dnenov marked this conversation as resolved.
Show resolved Hide resolved
}

this.ClearSearchResults();
Expand Down Expand Up @@ -1317,7 +1320,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 @@ -1343,15 +1346,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 @@ -1366,6 +1365,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.Model.IsDeprecated : !x.Model.IsDeprecated)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageNew)).OnChecked ? IsNewPackage(x.Model) : true)
.Where(x => NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageManagerPackageUpdated)).OnChecked ? IsUpdatedPackage(x.Model) : true)
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterDependencies)).OnChecked ? true : PackageHasDependencies(x.Model))
.Where(x => !NonHostFilter.First(f => f.FilterName.Equals(Resources.PackageSearchViewContextMenuFilterNoDependencies)).OnChecked ? true : !PackageHasDependencies(x.Model))
.ToList();
}

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