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

Commit 22c8345

Browse files
committed
Don't add current page to current page.
When the page to be navigated to in the GitHub pane is the current page, do nothing.
1 parent e7c4ef0 commit 22c8345

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public GitHubPaneViewModel(
122122
.Subscribe(x => NavigateTo(x).Forget());
123123

124124
this.WhenAnyValue(x => x.SearchQuery)
125-
.Where(x => navigator.Content != null)
125+
.Where(x => navigator.Content is ISearchablePageViewModel)
126126
.ObserveOn(RxApp.MainThreadScheduler)
127127
.Subscribe(x => ((ISearchablePageViewModel)navigator.Content).SearchQuery = x);
128128
}
@@ -280,7 +280,7 @@ OleMenuCommand BindNavigatorCommand<T>(IServiceProvider paneServiceProvider, int
280280
}
281281

282282
async Task NavigateTo<TViewModel>(Func<TViewModel, Task> initialize, Func<TViewModel, bool> match = null)
283-
where TViewModel : IPanePageViewModel
283+
where TViewModel : class, IPanePageViewModel
284284
{
285285
Guard.ArgumentNotNull(initialize, nameof(initialize));
286286

@@ -299,7 +299,7 @@ async Task NavigateTo<TViewModel>(Func<TViewModel, Task> initialize, Func<TViewM
299299
navigator.NavigateTo(viewModel);
300300
await initialize(viewModel);
301301
}
302-
else
302+
else if (navigator.Content != viewModel)
303303
{
304304
navigator.NavigateTo(viewModel);
305305
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ public async Task HasNoEffectWhenUserLoggedOut()
148148

149149
viewModelFactory.DidNotReceive().CreateViewModel<IPullRequestListViewModel>();
150150
}
151+
152+
[Fact]
153+
public async Task HasNoEffectWhenAlreadyCurrentPage()
154+
{
155+
var te = CreateTeamExplorerServiceHolder(ValidGitHubRepo);
156+
var cm = CreateConnectionManager(ValidGitHubRepo);
157+
var nav = new NavigationViewModel();
158+
var target = CreateTarget(
159+
teServiceHolder: te,
160+
connectionManager: cm,
161+
navigator: nav);
162+
163+
await Initialize(target);
164+
Assert.Same(nav, target.Content);
165+
Assert.IsAssignableFrom<IPullRequestListViewModel>(nav.Content);
166+
167+
await target.ShowPullRequests();
168+
169+
Assert.Equal(1, nav.History.Count);
170+
}
151171
}
152172

153173
static GitHubPaneViewModel CreateTarget(

0 commit comments

Comments
 (0)