Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 6165f30

Browse files
committed
Fix UI for closed PRs.
1 parent d246ad2 commit 6165f30

File tree

12 files changed

+149
-61
lines changed

12 files changed

+149
-61
lines changed

src/GitHub.App/ViewModels/Documents/IIssueishCommentViewModel.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,41 @@ namespace GitHub.ViewModels.Documents
1111
public interface IIssueishCommentViewModel : ICommentViewModel
1212
{
1313
/// <summary>
14-
/// Gets a value indicating whether the comment will show a
15-
/// a button for <see cref="CloseIssueish"/>.
14+
/// Gets a value indicating whether the comment will show a button for
15+
/// <see cref="CloseOrReopen"/>.
1616
/// </summary>
17-
bool CanCloseIssueish { get; }
17+
bool CanCloseOrReopen { get; }
1818

1919
/// <summary>
20-
/// Gets a a caption for the <see cref="CloseIssueish"/> command.
20+
/// Gets a a caption for the <see cref="CloseOrReopen"/> command.
2121
/// </summary>
22-
string CloseIssueishCaption { get; }
22+
string CloseOrReopenCaption { get; }
2323

2424
/// <summary>
25-
/// Gets a command which when executed will close the issue or pull request.
25+
/// Gets a command which when executed will close the issue or pull request if it is open,
26+
/// or reopen it if it is closed.
2627
/// </summary>
27-
ReactiveCommand<Unit, Unit> CloseIssueish { get; }
28+
ReactiveCommand<Unit, Unit> CloseOrReopen { get; }
2829

2930
/// <summary>
3031
/// Initializes the view model with data.
3132
/// </summary>
3233
/// <param name="thread">The thread that the comment is a part of.</param>
3334
/// <param name="currentUser">The current user.</param>
3435
/// <param name="comment">The comment model. May be null.</param>
35-
/// <param name="closeCaption">
36-
/// The caption for the <see cref="CloseIssueish"/> command, or null if the user cannot
37-
/// close the issue/pr from this comment.
36+
/// <param name="isPullRequest">
37+
/// true if the comment is on a pull request, false if the comment is on an issue.
38+
/// </param>
39+
/// <param name="isOpen">Whether the issue or pull request is open.</param>
40+
/// <param name="canCloseOrReopen">
41+
/// Whether the user can close or reopen the pull request from this comment.
3842
/// </param>
3943
Task InitializeAsync(
4044
IIssueishCommentThreadViewModel thread,
4145
ActorModel currentUser,
4246
CommentModel comment,
43-
string closeCaption);
47+
bool isPullRequest,
48+
bool isOpen,
49+
bool canCloseOrReopen);
4450
}
4551
}

src/GitHub.App/ViewModels/Documents/IssueishCommentViewModel.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace GitHub.ViewModels.Documents
1616
[PartCreationPolicy(CreationPolicy.NonShared)]
1717
public class IssueishCommentViewModel : CommentViewModel, IIssueishCommentViewModel
1818
{
19-
ObservableAsPropertyHelper<string> closeIssueishCaption;
19+
ObservableAsPropertyHelper<string> closeOrReopenCaption;
2020

2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
@@ -26,26 +26,28 @@ public class IssueishCommentViewModel : CommentViewModel, IIssueishCommentViewMo
2626
public IssueishCommentViewModel(ICommentService commentService)
2727
: base(commentService)
2828
{
29-
CloseIssueish = ReactiveCommand.CreateFromTask(
30-
DoCloseIssueish,
31-
this.WhenAnyValue(x => x.CanCloseIssueish));
29+
CloseOrReopen = ReactiveCommand.CreateFromTask(
30+
DoCloseOrReopen,
31+
this.WhenAnyValue(x => x.CanCloseOrReopen));
3232
}
3333

3434
/// <inheritdoc/>
35-
public bool CanCloseIssueish { get; private set; }
35+
public bool CanCloseOrReopen { get; private set; }
3636

3737
/// <inheritdoc/>
38-
public string CloseIssueishCaption => closeIssueishCaption?.Value;
38+
public string CloseOrReopenCaption => closeOrReopenCaption?.Value;
3939

4040
/// <inheritdoc/>
41-
public ReactiveCommand<Unit, Unit> CloseIssueish { get; }
41+
public ReactiveCommand<Unit, Unit> CloseOrReopen { get; }
4242

4343
/// <inheritdoc/>
4444
public async Task InitializeAsync(
4545
IIssueishCommentThreadViewModel thread,
4646
ActorModel currentUser,
4747
CommentModel comment,
48-
string closeCaption)
48+
bool isPullRequest,
49+
bool isOpen,
50+
bool canCloseOrReopen)
4951
{
5052
await base.InitializeAsync(
5153
thread,
@@ -54,17 +56,26 @@ await base.InitializeAsync(
5456
comment == null ? CommentEditState.Editing : CommentEditState.None)
5557
.ConfigureAwait(true);
5658

57-
CanCloseIssueish = closeCaption != null;
59+
CanCloseOrReopen = canCloseOrReopen;
60+
closeOrReopenCaption?.Dispose();
5861

59-
if (closeCaption != null)
62+
if (canCloseOrReopen)
6063
{
61-
closeIssueishCaption = this.WhenAnyValue(x => x.Body)
62-
.Select(x => string.IsNullOrWhiteSpace(x) ? closeCaption : Resources.CloseAndComment)
63-
.ToProperty(this, x => x.CloseIssueishCaption);
64+
var caption = isPullRequest ?
65+
isOpen ?
66+
(Resources.ClosePullRequest, Resources.CloseAndComment) :
67+
(Resources.ReopenPullRequest, Resources.ReopenAndComment) :
68+
isOpen ?
69+
(Resources.CloseIssue, Resources.CloseAndComment) :
70+
(Resources.ReopenIssue, Resources.ReopenAndComment);
71+
72+
closeOrReopenCaption = this.WhenAnyValue(x => x.Body)
73+
.Select(x => string.IsNullOrWhiteSpace(x) ? caption.Item1 : caption.Item2)
74+
.ToProperty(this, x => x.CloseOrReopenCaption);
6475
}
6576
}
6677

67-
Task DoCloseIssueish()
78+
Task DoCloseOrReopen()
6879
{
6980
return Task.CompletedTask;
7081
}

src/GitHub.App/ViewModels/Documents/PullRequestPageViewModel.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ Task IIssueishCommentThreadViewModel.CloseIssueish(ICommentViewModel comment)
129129
async Task AddComment(CommentModel comment)
130130
{
131131
var vm = factory.CreateViewModel<IIssueishCommentViewModel>();
132-
await vm.InitializeAsync(this, currentUserModel, comment, null).ConfigureAwait(true);
132+
await vm.InitializeAsync(
133+
this,
134+
currentUserModel,
135+
comment,
136+
true,
137+
State == PullRequestState.Open,
138+
false).ConfigureAwait(true);
133139
timeline.Add(vm);
134140
}
135141

@@ -140,7 +146,9 @@ await placeholder.InitializeAsync(
140146
this,
141147
currentUserModel,
142148
null,
143-
Resources.ClosePullRequest).ConfigureAwait(true);
149+
true,
150+
State == PullRequestState.Open,
151+
true).ConfigureAwait(true);
144152
timeline.Add(placeholder);
145153
}
146154

src/GitHub.App/ViewModels/PullRequestViewModelBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected virtual async Task InitializeAsync(
5656

5757
var fork = model.BaseRepositoryOwner != model.HeadRepositoryOwner;
5858
LocalRepository = localRepository;
59+
State = model.State;
5960
SourceBranchDisplayName = GetBranchDisplayName(fork, model.HeadRepositoryOwner, model.HeadRefName);
6061
TargetBranchDisplayName = GetBranchDisplayName(fork, model.BaseRepositoryOwner, model.BaseRefName);
6162
}

src/GitHub.Resources/Resources.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Resources/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,13 @@ https://git-scm.com/download/win</value>
851851
<data name="CloseAndComment" xml:space="preserve">
852852
<value>Close and comment</value>
853853
</data>
854+
<data name="ReopenAndComment" xml:space="preserve">
855+
<value>Reopen and comment</value>
856+
</data>
857+
<data name="ReopenIssue" xml:space="preserve">
858+
<value>Reopen issue</value>
859+
</data>
860+
<data name="ReopenPullRequest" xml:space="preserve">
861+
<value>Reopen pull request</value>
862+
</data>
854863
</root>

src/GitHub.VisualStudio.UI/Views/CommentView.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@
221221
Content="{x:Static ghfvs:Resources.StartAReview}"
222222
Visibility="{Binding CanStartReview, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
223223
<Button Margin="4 0 0 0"
224-
Command="{Binding CloseIssueish}"
225-
Content="{Binding CloseIssueishCaption}"
226-
Visibility="{Binding CanCloseIssueish, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
224+
Command="{Binding CloseOrReopen}"
225+
Content="{Binding CloseOrReopenCaption}"
226+
Visibility="{Binding CanCloseOrReopen, Converter={ui:BooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
227227
<Button Margin="4 0 0 0"
228228
Command="{Binding CancelEdit}"
229229
Content="{x:Static ghfvs:Resources.Cancel}"

src/GitHub.VisualStudio.UI/Views/Documents/PullRequestPageView.xaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@
4949
<StackPanel Grid.Row="1" Orientation="Horizontal">
5050
<TextBlock >
5151
<InlineUIContainer BaselineAlignment="Bottom">
52-
<Border Background="#6CC644" CornerRadius="2" Padding="6,0,6,2" Margin="0,0,2,-2">
53-
<TextBlock FontWeight="Bold" Foreground="White" Text="{Binding State}"/>
54-
</Border>
52+
<v:IssueishStateBadge DataContext="{Binding State}" Margin="0,0,0,-2"/>
5553
</InlineUIContainer>
5654
<InlineUIContainer BaselineAlignment="TextBottom">
5755
<v:ActorAvatarView ViewModel="{Binding Author}" Width="14" Height="14"/>

src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestDetailView.xaml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,6 @@
4646
<Setter Property="Fill" Value="{DynamicResource GitHubHeaderSeparatorBrush}"/>
4747
</Style>
4848

49-
<!-- TODO Fix this: here we change the color of TextBlock depending on the label.
50-
It's a hack, it will break with localization -->
51-
<Style x:Key="StateIndicator" TargetType="TextBlock">
52-
<Style.Triggers>
53-
<Trigger Property="Text" Value="OPEN">
54-
<Setter Property="Foreground" Value="#6CC644"/>
55-
</Trigger>
56-
<Trigger Property="Text" Value="CLOSED">
57-
<Setter Property="Foreground" Value="#BD2C00"/>
58-
</Trigger>
59-
<Trigger Property="Text" Value="MERGED">
60-
<Setter Property="Foreground" Value="#6E5494"/>
61-
</Trigger>
62-
</Style.Triggers>
63-
</Style>
64-
6549
<Style x:Key="CheckoutMessage" TargetType="TextBlock">
6650
<Setter Property="Margin" Value="0 4"/>
6751
</Style>
@@ -91,10 +75,7 @@
9175

9276
<!-- State and branches -->
9377
<StackPanel Orientation="Horizontal">
94-
<TextBlock FontWeight="Bold"
95-
VerticalAlignment="Center"
96-
Text="{Binding Model.State, Converter={StaticResource AllCaps}}"
97-
Style="{StaticResource StateIndicator}"/>
78+
<v:IssueishStateBadge DataContext="{Binding Model.State}" VerticalAlignment="Center"/>
9879

9980
<Rectangle Margin="9 0" Width="1" Height="12" VerticalAlignment="Center" Style="{DynamicResource Separator}" />
10081

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<UserControl x:Class="GitHub.VisualStudio.Views.IssueishStateBadge"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:models="clr-namespace:GitHub.Models;assembly=GitHub.Exports"
7+
mc:Ignorable="d">
8+
<d:DesignData.DataContext>
9+
<models:PullRequestState>Open</models:PullRequestState>
10+
</d:DesignData.DataContext>
11+
12+
<Border CornerRadius="2" Padding="6,2">
13+
<Border.Style>
14+
<Style TargetType="Border">
15+
<Style.Triggers>
16+
<DataTrigger Binding="{Binding}" Value="Open">
17+
<Setter Property="Background" Value="#6CC644"/>
18+
</DataTrigger>
19+
<DataTrigger Binding="{Binding}" Value="Closed">
20+
<Setter Property="Background" Value="#BD2C00"/>
21+
</DataTrigger>
22+
<DataTrigger Binding="{Binding}" Value="Merged">
23+
<Setter Property="Background" Value="#6E5494"/>
24+
</DataTrigger>
25+
</Style.Triggers>
26+
</Style>
27+
</Border.Style>
28+
<TextBlock FontWeight="Bold"
29+
Foreground="White"
30+
Text="{Binding}"
31+
VerticalAlignment="Center"/>
32+
</Border>
33+
</UserControl>

0 commit comments

Comments
 (0)