Skip to content

Commit 577d967

Browse files
Hide Discussion/Issue GitHub buttons if the ProjectUrl isn't set for navigation
1 parent 9386cff commit 577d967

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@
113113
Margin="0,16,0,0"
114114
ColumnSpacing="8">
115115

116-
<StackPanel Orientation="Horizontal"
116+
<StackPanel x:Name="ButtonPanel"
117+
x:Load="{x:Bind renderer:ToolkitDocumentationRenderer.IsProjectPathValid()}"
118+
Orientation="Horizontal"
117119
Spacing="8">
118120
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.DiscussionId), Mode=OneWay}">
119121
<StackPanel Orientation="Horizontal">

common/CommunityToolkit.Labs.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#endif
1616
#endif
1717

18+
#nullable enable
19+
1820
namespace CommunityToolkit.Labs.Shared.Renderers;
1921

2022
/// <summary>
@@ -34,8 +36,6 @@ public ToolkitDocumentationRenderer()
3436
ProjectUrl = Assembly.GetExecutingAssembly()?.GetCustomAttribute<CommunityToolkit.Attributes.PackageProjectUrlAttribute>()?.PackageProjectUrl;
3537
}
3638

37-
// TODO: If ProjectUrl is null should we log an error?
38-
3939
this.InitializeComponent();
4040
}
4141

@@ -223,11 +223,13 @@ private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEvent
223223
}
224224
#endif
225225

226-
public static Uri ToGitHubUri(string path, int id) => new Uri($"{ProjectUrl}/{path}/{id}");
226+
public static Uri? ToGitHubUri(string path, int id) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/{path}/{id}") : null;
227227

228228
public static Visibility IsIdValid(int id) => id switch
229229
{
230230
<= 0 => Visibility.Collapsed,
231231
_ => Visibility.Visible,
232232
};
233+
234+
public static bool IsProjectPathValid() => !string.IsNullOrWhiteSpace(ProjectUrl);
233235
}

common/Labs.Head.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@
113113
<_Parameter1>CommitHash</_Parameter1>
114114
<_Parameter2>$(SourceRevisionId)</_Parameter2>
115115
</AssemblyAttributes>
116-
<AssemblyAttributes Include="CommunityToolkit.Attributes.PackageProjectUrlAttribute">
116+
<AssemblyAttributes Include="CommunityToolkit.Attributes.PackageProjectUrlAttribute" Condition="'$(PackageProjectUrl)' != ''">
117117
<_Parameter1>$(PackageProjectUrl)</_Parameter1>
118118
</AssemblyAttributes>
119+
<Warning Text="The PackageProjectUrl property was not set." Condition="'$(PackageProjectUrl)' == ''" />
119120
</ItemGroup>
120121

121122
<!-- Extra attributes specific to platforms -->

0 commit comments

Comments
 (0)