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

Commit d5780f2

Browse files
Merge pull request #2107 from github/fixes/team-explorer-button-visibility
Pull requests button disappears when changing from a non-GitHub to a GitHub repository
2 parents d2b35ab + a6ea7c1 commit d5780f2

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

src/GitHub.TeamFoundation.14/Base/EnsureLoggedInSection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async Task CheckLogin()
4545
if (ActiveRepo == null || ActiveRepoUri == null)
4646
return;
4747

48-
var isgithub = await IsAGitHubRepo();
48+
var isgithub = await IsAGitHubRepo(ActiveRepoUri);
4949
if (!isgithub)
5050
return;
5151

src/GitHub.TeamFoundation.14/Base/TeamExplorerNavigationItemBase.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
using System;
22
using System.Diagnostics;
33
using System.Drawing;
4+
using System.Threading.Tasks;
45
using GitHub.Api;
56
using GitHub.Extensions;
7+
using GitHub.Logging;
68
using GitHub.Services;
79
using GitHub.UI;
810
using GitHub.VisualStudio.Helpers;
911
using Microsoft.TeamFoundation.Controls;
1012
using Microsoft.VisualStudio.PlatformUI;
13+
using Serilog;
1114

1215
namespace GitHub.VisualStudio.Base
1316
{
1417
public class TeamExplorerNavigationItemBase : TeamExplorerItemBase, ITeamExplorerNavigationItem2
1518
{
19+
static readonly ILogger log = LogManager.ForContext<TeamExplorerNavigationItemBase>();
20+
1621
readonly Octicon octicon;
1722

1823
public TeamExplorerNavigationItemBase(IGitHubServiceProvider serviceProvider,
@@ -35,10 +40,23 @@ public TeamExplorerNavigationItemBase(IGitHubServiceProvider serviceProvider,
3540
SubscribeToRepoChanges();
3641
}
3742

38-
public override async void Invalidate()
43+
public override void Invalidate()
3944
{
4045
IsVisible = false;
41-
IsVisible = await IsAGitHubRepo();
46+
InvalidateAsync().Forget(log);
47+
}
48+
49+
async Task InvalidateAsync()
50+
{
51+
var uri = ActiveRepoUri;
52+
var isVisible = await IsAGitHubRepo(uri);
53+
if (ActiveRepoUri != uri)
54+
{
55+
log.Information("Not setting button visibility because repository changed from {BeforeUrl} to {AfterUrl}", uri, ActiveRepoUri);
56+
return;
57+
}
58+
59+
IsVisible = isVisible;
4260
}
4361

4462
void OnThemeChanged()

src/GitHub.TeamFoundation.14/Home/ForkNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public override async void Invalidate()
8686
{
8787
IsVisible = false;
8888

89-
if (await IsAGitHubDotComRepo())
89+
if (await IsAGitHubDotComRepo(ActiveRepoUri))
9090
{
9191
var connection = await ConnectionManager.GetConnection(ActiveRepo);
9292
IsVisible = connection?.IsLoggedIn ?? false;

src/GitHub.TeamFoundation.14/Home/GitHubHomeSection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected async override void RepoChanged()
6464

6565
base.RepoChanged();
6666

67-
IsVisible = await IsAGitHubRepo();
67+
IsVisible = await IsAGitHubRepo(ActiveRepoUri);
6868

6969
if (IsVisible)
7070
{
@@ -93,7 +93,7 @@ protected async override void RepoChanged()
9393

9494
public override async void Refresh()
9595
{
96-
IsVisible = await IsAGitHubRepo();
96+
IsVisible = await IsAGitHubRepo(ActiveRepoUri);
9797
if (IsVisible)
9898
{
9999
IsLoggedIn = await IsUserAuthenticated();

src/GitHub.TeamFoundation.14/Home/IssuesNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override async void Invalidate()
4040
{
4141
IsVisible = false;
4242

43-
var visible = await IsAGitHubRepo();
43+
var visible = await IsAGitHubRepo(ActiveRepoUri);
4444
if (visible)
4545
{
4646
var repo = await SimpleApiClient.GetRepository();

src/GitHub.TeamFoundation.14/Home/WikiNavigationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void Execute()
3838

3939
public override async void Invalidate()
4040
{
41-
var visible = await IsAGitHubRepo();
41+
var visible = await IsAGitHubRepo(ActiveRepoUri);
4242
if (visible)
4343
{
4444
var repo = await SimpleApiClient.GetRepository();

src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,8 @@ protected virtual void RepoChanged()
123123
}
124124
}
125125

126-
protected async Task<RepositoryOrigin> GetRepositoryOrigin()
126+
protected async Task<RepositoryOrigin> GetRepositoryOrigin(UriString uri)
127127
{
128-
if (ActiveRepo == null)
129-
return RepositoryOrigin.NonGitRepository;
130-
131-
var uri = ActiveRepoUri;
132128
if (uri == null)
133129
return RepositoryOrigin.Other;
134130

@@ -154,15 +150,15 @@ protected async Task<RepositoryOrigin> GetRepositoryOrigin()
154150
return RepositoryOrigin.Other;
155151
}
156152

157-
protected async Task<bool> IsAGitHubRepo()
153+
protected async Task<bool> IsAGitHubRepo(UriString uri)
158154
{
159-
var origin = await GetRepositoryOrigin();
155+
var origin = await GetRepositoryOrigin(uri);
160156
return origin == RepositoryOrigin.DotCom || origin == RepositoryOrigin.Enterprise;
161157
}
162158

163-
protected async Task<bool> IsAGitHubDotComRepo()
159+
protected async Task<bool> IsAGitHubDotComRepo(UriString uri)
164160
{
165-
var origin = await GetRepositoryOrigin();
161+
var origin = await GetRepositoryOrigin(uri);
166162
return origin == RepositoryOrigin.DotCom;
167163
}
168164

0 commit comments

Comments
 (0)