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

Commit be71fff

Browse files
Merge branch 'master' into fixes/1683-pr-authoring-wrong-fork
2 parents eac6b57 + ab7ec8b commit be71fff

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

src/GitHub.App/ViewModels/GitHubPane/IssueListViewModelBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reactive.Disposables;
88
using System.Reactive.Linq;
99
using System.Threading.Tasks;
10+
using System.Windows.Threading;
1011
using GitHub.Collections;
1112
using GitHub.Extensions;
1213
using GitHub.Extensions.Reactive;
@@ -209,6 +210,7 @@ public override Task Refresh()
209210
this.WhenAnyValue(x => x.SelectedState),
210211
this.WhenAnyValue(x => x.AuthorFilter.Selected),
211212
(loading, count, _, __, ___) => Tuple.Create(loading, count))
213+
.ObserveOn(RxApp.MainThreadScheduler)
212214
.Subscribe(x => UpdateState(x.Item1, x.Item2)));
213215
dispose.Add(
214216
Observable.FromEventPattern<ErrorEventArgs>(

src/GitHub.App/ViewModels/GitHubPane/PullRequestFilesViewModel.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using System.Reactive.Disposables;
88
using System.Reactive.Linq;
99
using System.Reactive.Subjects;
10+
using System.Reactive.Threading.Tasks;
1011
using System.Threading.Tasks;
12+
using System.Windows.Input;
1113
using GitHub.Extensions;
1214
using GitHub.Models;
1315
using GitHub.Services;
@@ -50,7 +52,7 @@ public PullRequestFilesViewModel(
5052
DiffFileWithWorkingDirectory = ReactiveCommand.CreateAsyncTask(
5153
isBranchCheckedOut,
5254
x => (Task)editorService.OpenDiff(pullRequestSession, ((IPullRequestFileNode)x).RelativePath));
53-
OpenFileInWorkingDirectory = ReactiveCommand.CreateAsyncTask(
55+
OpenFileInWorkingDirectory = new NonDeletedFileCommand(
5456
isBranchCheckedOut,
5557
x => (Task)editorService.OpenFile(pullRequestSession, ((IPullRequestFileNode)x).RelativePath, true));
5658

@@ -198,5 +200,37 @@ async Task<IInlineCommentThreadModel> GetFirstCommentThread(IPullRequestFileNode
198200

199201
return threads.FirstOrDefault();
200202
}
203+
204+
/// <summary>
205+
/// Implements the <see cref="OpenFileInWorkingDirectory"/> command.
206+
/// </summary>
207+
/// <remarks>
208+
/// We need to "Open File in Solution" when the parameter passed to the command parameter
209+
/// represents a deleted file. ReactiveCommand doesn't allow us to change the CanExecute
210+
/// state depending on the parameter, so we override
211+
/// <see cref="ICommand.CanExecute(object)"/> to do this ourselves.
212+
/// </remarks>
213+
class NonDeletedFileCommand : ReactiveCommand<Unit>, ICommand
214+
{
215+
public NonDeletedFileCommand(
216+
IObservable<bool> canExecute,
217+
Func<object, Task> executeAsync)
218+
: base(canExecute, x => executeAsync(x).ToObservable())
219+
{
220+
}
221+
222+
bool ICommand.CanExecute(object parameter)
223+
{
224+
if (parameter is IPullRequestFileNode node)
225+
{
226+
if (node.Status == PullRequestFileStatus.Removed)
227+
{
228+
return false;
229+
}
230+
}
231+
232+
return CanExecute(parameter);
233+
}
234+
}
201235
}
202236
}

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static int ToPriority(PullRequestReviewState state)
9090
{
9191
case PullRequestReviewState.Approved:
9292
case PullRequestReviewState.ChangesRequested:
93+
case PullRequestReviewState.Dismissed:
9394
return 1;
9495
case PullRequestReviewState.Pending:
9596
return 2;

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestFilesView.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ void ApplyContextMenuBinding<TItem>(object sender, ContextMenuEventArgs e) where
6161

6262
if (fileNode != null)
6363
{
64-
container.ContextMenu.DataContext = this.DataContext;
65-
6664
foreach (var menuItem in container.ContextMenu.Items.OfType<MenuItem>())
6765
{
6866
menuItem.CommandParameter = fileNode;
6967
}
7068

69+
// HACK: MenuItem doesn't re-query ICommand.CanExecute when CommandParameter changes. Force
70+
// this to happen by resetting its DataContext to null and then to the correct value.
71+
container.ContextMenu.DataContext = null;
72+
container.ContextMenu.DataContext = this.DataContext;
7173
e.Handled = false;
7274
}
7375
}

test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestDetailViewModelTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ public async Task ShouldNotShowPendingReviewForOtherUserAsync()
137137
Assert.That(target.Reviews[0].Id, Is.Null);
138138
}
139139

140+
[Test]
141+
public async Task ShouldNotShowChangesRequestedAfterDismissed()
142+
{
143+
var dateTimeOffset = DateTimeOffset.Now;
144+
145+
var target = CreateTarget();
146+
var model = CreatePullRequestModel(
147+
CreatePullRequestReviewModel("1", "shana", PullRequestReviewState.ChangesRequested, dateTimeOffset.AddMinutes(1)),
148+
CreatePullRequestReviewModel("2", "shana", PullRequestReviewState.Dismissed, dateTimeOffset.AddMinutes(2)));
149+
150+
await target.Load(model);
151+
152+
Assert.That(target.Reviews, Has.Count.EqualTo(2));
153+
Assert.That(target.Reviews[0].User.Login, Is.EqualTo("shana"));
154+
Assert.That(target.Reviews[0].State, Is.EqualTo(PullRequestReviewState.Dismissed));
155+
Assert.That(target.Reviews[1].User.Login, Is.EqualTo("grokys"));
156+
}
157+
140158
static PullRequestDetailModel CreatePullRequestModel(
141159
params PullRequestReviewModel[] reviews)
142160
{

0 commit comments

Comments
 (0)