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-7086 Correctly cast package search results to show updated package info #15373

Merged
merged 3 commits into from
Jul 8, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,8 @@ private void PopulateMyPackages()
var pkgs = PackageManagerClientViewModel.CachedPackageList.Where(x => x.Maintainers != null && x.Maintainers.Contains(name)).ToList();
foreach(var pkg in pkgs)
{
var p = new PackageManagerSearchElementViewModel(pkg,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(pkg.Name));
var p = GetSearchElementViewModel(pkg, true);

p.RequestDownload += this.PackageOnExecuted;
p.RequestShowFileDialog += this.OnRequestShowFileDialog;
p.IsOnwer = true;
Expand Down Expand Up @@ -1353,9 +1352,7 @@ internal IEnumerable<PackageManagerSearchElementViewModel> GetAllPackages()

// Filter based on user preference
// A package has dependencies if the number of direct_dependency_ids is more than 1
var initialResults = LastSync?.Select(x => new PackageManagerSearchElementViewModel(x,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(x.Name), isEnabledForInstall));
var initialResults = LastSync?.Select(x => GetSearchElementViewModel(x));
list = ApplyNonHostFilters(initialResults);
list = ApplyHostFilters(list).ToList();

Expand Down Expand Up @@ -1491,14 +1488,29 @@ internal IEnumerable<PackageManagerSearchElementViewModel> Search(string searchT
/// <returns></returns>
private PackageManagerSearchElementViewModel GetViewModelForPackageSearchElement(string packageName)
{
var result = SearchResults.Where(e => e.Name.Equals(packageName));
var result = PackageManagerClientViewModel.CachedPackageList.Where(e => e.Name.Equals(packageName));

if (!result.Any())
{
return null;
}

return result.ElementAt(0);
return GetSearchElementViewModel(result.FirstOrDefault());
}

/// <summary>
/// Returns a new PackageManagerSearchElementViewModel for the given package, with updated properties.
/// </summary>
/// <param name="package">Package to cast</param>
/// <param name="bypassCustomPackageLocations">When true, will bypass the check for loading package from custom locations.</param>
/// <returns></returns>
private PackageManagerSearchElementViewModel GetSearchElementViewModel(PackageManagerSearchElement package, bool bypassCustomPackageLocations = false)
{
var isEnabledForInstall = bypassCustomPackageLocations || !(Preferences as IDisablePackageLoadingPreferences).DisableCustomPackageLocations;
return new PackageManagerSearchElementViewModel(package,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(package.Name),
isEnabledForInstall);
}

/// <summary>
Expand Down
Loading