Skip to content

Commit

Permalink
Add package links to Package details view (#12877)
Browse files Browse the repository at this point in the history
* add package links
  • Loading branch information
zeusongit authored May 13, 2022
1 parent 90a83bd commit a1e1301
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,7 @@
<Resource Include="UI\Images\folder-hover-16px.png" />
<Resource Include="UI\Images\up_16_16.png" />
<Resource Include="UI\Images\up-hover-16px.png" />
<Resource Include="UI\Images\link-16px.png" />
<EmbeddedResource Include="Controls\Docs\NodeAutocompleteDocumentation.html" />
<Content Include="sharpdx_direct3d11_effects_x64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3144,4 +3144,10 @@ To install the latest version of a package, click Install. \n
<data name="OnboardingGuideRunGraphTitle" xml:space="preserve">
<value>Run the graph</value>
</data>
<data name="PackageRepositoryLabel" xml:space="preserve">
<value>Repository</value>
</data>
<data name="PackageWebsiteLabel" xml:space="preserve">
<value>Website</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3131,4 +3131,10 @@ To install the latest version of a package, click Install. \n
<data name="OnboardingGuideRunGraphTitle" xml:space="preserve">
<value>Run the graph</value>
</data>
<data name="PackageRepositoryLabel" xml:space="preserve">
<value>Repository</value>
</data>
<data name="PackageWebsiteLabel" xml:space="preserve">
<value>Website</value>
</data>
</root>
26 changes: 26 additions & 0 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public object ConvertBack(object value, Type targetType, object parameter,
}
}

/// <summary>
/// If the given string is empty, collapsed visibility enum is returned, otherwise visible enum is returned.
/// </summary>
public class EmptyStringToCollapsedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
Expand All @@ -378,6 +381,29 @@ public object ConvertBack(object value, Type targetType, object parameter,
}
}

/// <summary>
/// If the given string is empty, hidden visibility enum is returned, otherwise visible enum is returned.
/// </summary>
public class EmptyStringToHiddenConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value is string && !string.IsNullOrEmpty(value as string))
{
return Visibility.Visible;
}

return Visibility.Hidden;
}

public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return null;
}
}

/// <summary>
/// Converts any numbers below 0 to 0, otherwise returns the original number.
/// For example, used to display the number of votes each package has received in the package manager.
Expand Down
Binary file added src/DynamoCoreWpf/UI/Images/link-16px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/PackageDetailsViewExtension/PackageDetailsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<controls:NegativeIntToZeroConverter x:Key="NegativeIntToZeroConverter" />
<controls:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<controls:PrettyDateConverter x:Key="PrettyDateConverter" />
<controls:EmptyStringToHiddenConverter x:Key="EmptyStringToHiddenConverter" />
<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementBold}" />
<Setter Property="FontWeight" Value="Bold" />
Expand All @@ -39,6 +40,16 @@
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
<Style x:Key="BodyLinkStyle" TargetType="Hyperlink">
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="14px" />
<Setter Property="Foreground" Value="{StaticResource Blue300Brush}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{StaticResource Blue400Brush}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="BorderStyle" TargetType="Border">
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Margin" Value="0,0,11,0" />
Expand Down Expand Up @@ -434,6 +445,52 @@
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<!-- Links -->
<StackPanel MinWidth="200"
Margin="0,10,0,10"
Orientation="Horizontal"
Visibility="{Binding PackageSiteURL, Converter={StaticResource EmptyStringToHiddenConverter}}">
<Rectangle Name="PackageLinkIcon"
Width="16px"
Height="16px">
<Rectangle.Fill>
<ImageBrush ImageSource="/DynamoCoreWpf;component/UI/Images/link-16px.png" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Name="PackageWebsiteLinkText"
Margin="8,0,0,0">
<Hyperlink Name="PackageWebsiteLink"
NavigateUri="{Binding PackageSiteURL}"
RequestNavigate="Hyperlink_RequestNavigate"
TextDecorations="None"
Style="{StaticResource BodyLinkStyle}">
<TextBlock Text="{x:Static p:Resources.PackageWebsiteLabel}" />
</Hyperlink>
</TextBlock>

</StackPanel>
<StackPanel MinWidth="200"
Margin="0,0,0,10"
Orientation="Horizontal"
Visibility="{Binding PackageRepositoryURL, Converter={StaticResource EmptyStringToHiddenConverter}}">
<Rectangle Name="RepositoryLinkIcon"
Width="16px"
Height="16px">
<Rectangle.Fill>
<ImageBrush ImageSource="/DynamoCoreWpf;component/UI/Images/link-16px.png" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Name="PackageRepositoryLinkText"
Margin="8,0,0,0">
<Hyperlink Name="PackageRepositoryLink"
NavigateUri="{Binding PackageRepositoryURL}"
RequestNavigate="Hyperlink_RequestNavigate"
TextDecorations="None"
Style="{StaticResource BodyLinkStyle}">
<TextBlock Text="{x:Static p:Resources.PackageRepositoryLabel}" />
</Hyperlink>
</TextBlock>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
Expand Down
7 changes: 7 additions & 0 deletions src/PackageDetailsViewExtension/PackageDetailsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;

namespace Dynamo.PackageDetails
{
Expand Down Expand Up @@ -34,5 +35,11 @@ private void FrameworkElement_OnDataContextChanged(object sender, DependencyProp
{
MainScrollViewer.ScrollToTop();
}

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
System.Diagnostics.Process.Start(e.Uri.ToString());
e.Handled = true;
}
}
}
14 changes: 13 additions & 1 deletion src/PackageDetailsViewExtension/PackageDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public string License
/// </summary>
public bool IsPackageDeprecated { get; }

/// <summary>
/// The site URL of the package whose details are being inspected.
/// </summary>
public string PackageSiteURL { get; }

/// <summary>
/// The repository URL of the package whose details are being inspected.
/// </summary>
public string PackageRepositoryURL { get; }

/// <summary>
/// A reference to the ViewExtension.
/// </summary>
Expand Down Expand Up @@ -199,8 +209,10 @@ PackageManagerSearchElement packageManagerSearchElement
IsPackageDeprecated = packageManagerSearchElement.IsDeprecated;
PackageDetailsViewExtension = packageDetailsViewExtension;
License = packageManagerSearchElement.Header.license;
PackageSiteURL = packageManagerSearchElement.SiteUrl;
PackageRepositoryURL = packageManagerSearchElement.RepositoryUrl;

if(!Models.DynamoModel.IsTestMode)
if (!Models.DynamoModel.IsTestMode)
{
packageLoader.PackageAdded += PackageLoaderOnPackageAdded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,56 @@ public void TestVersionsDisplayedInView()
Assert.AreEqual(PackageVersions.Count, packageDetailsViewModel.PackageDetailItems.Count);
}

/// <summary>
/// Tests whether the PackageDetailsViewModel displays the package links properly.
/// </summary>
[Test]
public void TestLinksDisplayedInView()
{
// Arrange
string someLink = "somelink";
PackageHeader packageHeader = new PackageHeader
{
_id = null,
name = string.Empty,
versions = PackageVersions,
latest_version_update = System.DateTime.Now,
num_versions = PackageVersions.Count,
comments = null,
num_comments = 0,
latest_comment = null,
votes = 0,
downloads = 0,
repository_url = someLink,
site_url = someLink,
banned = false,
deprecated = false,
@group = null,
engine = null,
license = null,
used_by = null,
host_dependencies = Hosts,
num_dependents = 0,
description = null,
maintainers = UsersList,
keywords = null
};
PackageManagerSearchElement packageManagerSearchElement = new PackageManagerSearchElement(packageHeader);

// Act
PackageDetailsViewExtension.OpenPackageDetails(packageManagerSearchElement);
PackageDetailsView packageDetailsView = PackageDetailsViewExtension.PackageDetailsView;

// Assert
Assert.IsNotNull(packageDetailsView.PackageWebsiteLink);
Assert.IsNotNull(packageDetailsView.PackageRepositoryLink);
Assert.IsInstanceOf<PackageDetailsViewModel>(packageDetailsView.DataContext);

PackageDetailsViewModel packageDetailsViewModel = packageDetailsView.DataContext as PackageDetailsViewModel;
Assert.AreEqual(someLink, packageDetailsViewModel.PackageRepositoryURL);
Assert.AreEqual(someLink, packageDetailsViewModel.PackageSiteURL);
}

/// <summary>
/// Tests whether OpenDependencyDetails method works.
/// This is fired when the user clicks a link to another dependency package.
Expand Down

0 comments on commit a1e1301

Please sign in to comment.