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

link to nugettrends.com #9737

Merged
merged 3 commits into from
Apr 15, 2024
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
5 changes: 4 additions & 1 deletion src/AccountDeleter/EmptyFeatureFlagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public bool IsDisplayNuGetPackageExplorerLinkEnabled()
{
throw new NotImplementedException();
}

public bool IsDisplayNuGetTrendsLinksEnabled()
{
throw new NotImplementedException();
}
public bool IsDisplayTargetFrameworkEnabled(User user)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public bool IsDisplayFuGetLinksEnabled()
throw new NotImplementedException();
}

public bool IsDisplayNuGetTrendsLinksEnabled()
{
throw new NotImplementedException();
}

public bool IsDisplayVulnerabilitiesEnabled()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -309,4 +314,4 @@ public bool IsFrameworkFilteringEnabled(User user) {
throw new NotImplementedException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class FeatureFlagService : IFeatureFlagService
private const string ManagePackagesVulnerabilitiesFeatureName = GalleryPrefix + "ManagePackagesVulnerabilities";
private const string DisplayFuGetLinksFeatureName = GalleryPrefix + "DisplayFuGetLinks";
private const string DisplayNuGetPackageExplorerLinkFeatureName = GalleryPrefix + "DisplayNuGetPackageExplorerLink";
private const string DisplayNuGetTrendsLinkFeatureName = GalleryPrefix + "DisplayNuGetTrendsLink";
private const string ODataReadOnlyDatabaseFeatureName = GalleryPrefix + "ODataReadOnlyDatabase";
private const string PackagesAtomFeedFeatureName = GalleryPrefix + "PackagesAtomFeed";
private const string SearchSideBySideFlightName = GalleryPrefix + "SearchSideBySide";
Expand Down Expand Up @@ -170,6 +171,11 @@ public bool IsDisplayNuGetPackageExplorerLinkEnabled()
return _client.IsEnabled(DisplayNuGetPackageExplorerLinkFeatureName, defaultValue: false);
}

public bool IsDisplayNuGetTrendsLinksEnabled()
{
return _client.IsEnabled(DisplayNuGetTrendsLinkFeatureName, defaultValue: false);
}

public bool AreEmbeddedIconsEnabled(User user)
{
return _client.IsEnabled(EmbeddedIconFlightName, user, defaultValue: false);
Expand Down Expand Up @@ -404,4 +410,4 @@ public bool IsFrameworkFilteringEnabled(User user) {
return _client.IsEnabled(FrameworkFilteringFeatureName, user, defaultValue: false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public interface IFeatureFlagService
/// </summary>
bool IsDisplayFuGetLinksEnabled();

/// <summary>
/// Whether or not a nugettrends.com link is visible on a package's details page.
/// </summary>
bool IsDisplayNuGetTrendsLinksEnabled();

/// <summary>
/// Whether or not a nuget.info (NuGet Package Explorer) link is visible on a package's details page.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetGallery/App_Data/Files/Content/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"NuGetGallery.ManagePackagesVulnerabilities": "Enabled",
"NuGetGallery.DisplayFuGetLinks": "Enabled",
"NuGetGallery.DisplayNuGetPackageExplorerLink": "Enabled",
"NuGetGallery.DisplayNuGetTrendsLink": "Enabled",
"NuGetGallery.PatternSetTfmHeuristics": "Enabled",
"NuGetGallery.EmbeddedIcons": "Enabled",
"NuGetGallery.MarkdigMdRendering": "Enabled",
Expand Down Expand Up @@ -134,4 +135,4 @@
"Domains": []
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/NuGetGallery/Content/gallery/img/nuget-trends.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
model.IsPackageVulnerabilitiesEnabled = isPackageVulnerabilitiesEnabled;
model.IsFuGetLinksEnabled = _featureFlagService.IsDisplayFuGetLinksEnabled();
model.IsNuGetPackageExplorerLinkEnabled = _featureFlagService.IsDisplayNuGetPackageExplorerLinkEnabled();
model.IsNuGetTrendsLinksEnabled = _featureFlagService.IsDisplayNuGetTrendsLinksEnabled();
model.IsPackageRenamesEnabled = _featureFlagService.IsPackageRenamesEnabled(currentUser);
model.IsPackageDependentsEnabled = _featureFlagService.IsPackageDependentsEnabled(currentUser);
model.IsRecentPackagesNoIndexEnabled = _featureFlagService.IsRecentPackagesNoIndexEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ private DisplayPackageViewModel SetupCommon(
viewModel.NuGetPackageExplorerUrl = nugetPackageExplorerReadyUrl;
}

var nugetTrendsUrl = $"https://nugettrends.com/packages?ids={package.Id}";
if (PackageHelper.TryPrepareUrlForRendering(nugetTrendsUrl, out string nugetTrendsReadyUrl))
{
viewModel.NuGetTrendsUrl = nugetTrendsReadyUrl;
}

viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType;
viewModel.LicenseExpression = package.LicenseExpression;

Expand Down Expand Up @@ -264,4 +270,4 @@ private static string GetPushedBy(Package package, User currentUser, Dictionary<
return pushedByCache[userPushedBy];
}
}
}
}
9 changes: 8 additions & 1 deletion src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class DisplayPackageViewModel : ListPackageItemViewModel
public bool IsPackageDeprecationEnabled { get; set; }
public bool IsPackageVulnerabilitiesEnabled { get; set; }
public bool IsFuGetLinksEnabled { get; set; }
public bool IsNuGetTrendsLinksEnabled { get; set; }
public bool IsNuGetPackageExplorerLinkEnabled { get; set; }
public bool IsPackageRenamesEnabled { get; set; }
public bool IsGitHubUsageEnabled { get; set; }
Expand Down Expand Up @@ -88,6 +89,7 @@ public bool HasNewerRelease
public string ProjectUrl { get; set; }
public string LicenseUrl { get; set; }
public string FuGetUrl { get; set; }
public string NuGetTrendsUrl { get; set; }
public string NuGetPackageExplorerUrl { get; set; }
public IReadOnlyCollection<string> LicenseNames { get; set; }
public string LicenseExpression { get; set; }
Expand Down Expand Up @@ -146,6 +148,11 @@ public bool CanDisplayFuGetLink()
return IsFuGetLinksEnabled && !string.IsNullOrEmpty(FuGetUrl) && Available;
}

public bool CanDisplayNuGetTrendsLink()
{
return IsNuGetTrendsLinksEnabled && !string.IsNullOrEmpty(NuGetTrendsUrl) && Available;
}

public bool CanDisplayTargetFrameworks()
{
return IsDisplayTargetFrameworkEnabled && !Deleted && !IsDotnetNewTemplatePackageType;
Expand All @@ -166,4 +173,4 @@ public enum RepositoryKind
GitHub,
}
}
}
}
17 changes: 17 additions & 0 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,23 @@
</li>
}

@if (Model.CanDisplayNuGetTrendsLink() && Model.ShowDetailsAndLinks)
{
var disclaimer = "nugettrends.com is a 3rd party website, not controlled by Microsoft. This link is made available to you per the NuGet Terms of Use.";

<li>
<img class="icon"
aria-label="@disclaimer" title="@disclaimer"
src="@Url.Absolute("~/Content/gallery/img/nuget-trends.svg")"
@ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/nuget-trends-32x32.png")) />
<a href="@Model.NuGetTrendsUrl" data-track="outbound-nuget-trends-url"
aria-label="open in nugetrends.com"
title="Explore download trends on nugettrends.com" target="_blank" rel="nofollow noreferrer">
Open in NuGet Trends
</a>
</li>
}

@if (!Model.CanReportAsOwner && Model.Available && Model.ShowDetailsAndLinks)
{
<li class="report-link">
Expand Down
2 changes: 2 additions & 0 deletions src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class FakeFeatureFlagService : IFeatureFlagService

public bool IsDisplayNuGetPackageExplorerLinkEnabled() => throw new NotImplementedException();

public bool IsDisplayNuGetTrendsLinksEnabled() => throw new NotImplementedException();

public bool IsDisplayTargetFrameworkEnabled(User user) => throw new NotImplementedException();

public bool IsComputeTargetFrameworkEnabled() => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,76 @@ public void CannotDisplayFuGetLinkWhenInvalid(bool isEnabled, string url, bool i
Assert.False(model.CanDisplayFuGetLink());
}

[Fact]
public void ItInitializesNuGetTrendsUrl()
{
var package = new Package
{
Version = "1.0.0",
NormalizedVersion = "1.0.0",
PackageRegistration = new PackageRegistration
{
Id = "foo",
Owners = Enumerable.Empty<User>().ToList(),
Packages = Enumerable.Empty<Package>().ToList()
}
};

var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);
Assert.Equal("https://nugettrends.com/packages?ids=foo", model.NuGetTrendsUrl);
}

[Fact]
public void CanDisplayNuGetTrendsLinkWhenValid()
{
var package = new Package
{
Version = "1.0.0",
NormalizedVersion = "1.0.0",
PackageRegistration = new PackageRegistration
{
Id = "foo",
Owners = Enumerable.Empty<User>().ToList(),
Packages = Enumerable.Empty<Package>().ToList()
}
};

var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);

model.IsNuGetTrendsLinksEnabled = true;
model.Available = true;

Assert.True(model.CanDisplayNuGetTrendsLink());
}

[Theory]
[InlineData(false, "https://nugettrends.com/packages?ids=foo", true)]
[InlineData(true, "", true)]
[InlineData(true, null, true)]
[InlineData(true, "https://nugettrends.com/packages?ids=foo", false)]
public void CannotDisplayNuGetTrendsLinkWhenInvalid(bool isEnabled, string url, bool isAvailable)
{
var package = new Package
{
Version = "1.0.0",
NormalizedVersion = "1.0.0",
PackageRegistration = new PackageRegistration
{
Id = "foo",
Owners = Enumerable.Empty<User>().ToList(),
Packages = Enumerable.Empty<Package>().ToList()
}
};

var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);

model.IsNuGetTrendsLinksEnabled = isEnabled;
model.NuGetTrendsUrl = url;
model.Available = isAvailable;

Assert.False(model.CanDisplayNuGetTrendsLink());
}

[Theory]
[InlineData(true, true, true)]
[InlineData(false, true, true)]
Expand Down Expand Up @@ -1195,4 +1265,4 @@ private static DisplayPackageViewModel CreateDisplayPackageViewModel(
readmeResult: new RenderedMarkdownResult { Content = readmeHtml });
}
}
}
}