Skip to content

Commit 32c1ca0

Browse files
alexr00RMacfarlane
andauthored
Make PRs and Issues views have same commands (microsoft#1760)
* Make PRs and Issues views have same commands Fixes microsoft#1744 * Properly reset credential store state Co-authored-by: RMacfarlane <ramacfar@microsoft.com>
1 parent 946ad1b commit 32c1ca0

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@
702702
"command": "issue.userCompletion",
703703
"title": "User Completion Chosen"
704704
},
705+
{
706+
"command": "issue.signinAndRefreshList",
707+
"title": "Sign in and Refresh",
708+
"category": "GitHub Issues"
709+
},
705710
{
706711
"command": "github.publish",
707712
"title": "Publish to GitHub"
@@ -929,6 +934,10 @@
929934
"command": "issue.userCompletion",
930935
"when": "false"
931936
},
937+
{
938+
"command": "issue.signinAndRefreshList",
939+
"when": "false"
940+
},
932941
{
933942
"command": "github.publish",
934943
"when": "false"
@@ -942,7 +951,7 @@
942951
},
943952
{
944953
"command": "pr.configurePRViewlet",
945-
"when": "gitOpenRepositoryCount != 0 && github:initialized && view =~ /pr:/",
954+
"when": "gitOpenRepositoryCount != 0 && github:initialized && view =~ /(pr|issues):/",
946955
"group": "navigation"
947956
},
948957
{
@@ -1257,4 +1266,4 @@
12571266
"webpack/**/tar": "^4.4.2"
12581267
},
12591268
"license": "MIT"
1260-
}
1269+
}

src/github/credentials.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export class CredentialStore {
5454
}
5555
}
5656

57-
public reset() {
57+
public async reset() {
5858
this._githubAPI = undefined;
59+
await this.initialize();
5960
}
6061

6162
public isAuthenticated(): boolean {

src/github/pullRequestManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export class PullRequestManager implements vscode.Disposable {
430430
}
431431

432432
async clearCredentialCache(): Promise<void> {
433-
this._credentialStore.reset();
433+
await this._credentialStore.reset();
434434
this.state = PRManagerState.Initializing;
435435
}
436436

src/issues/issueFeatureRegistrar.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
3434

3535
async initialize() {
3636
this.registerCompletionProviders();
37-
await this._stateManager.tryInitializeAndWait();
37+
this.context.subscriptions.push(vscode.window.createTreeView('issues:github', { showCollapseAll: true, treeDataProvider: new IssuesTreeData(this._stateManager, this.manager, this.context) }));
3838
this.context.subscriptions.push(vscode.commands.registerCommand('issue.createIssueFromSelection', (newIssue?: NewIssue, issueBody?: string) => {
3939
/* __GDPR__
4040
"issue.createIssueFromSelection" : {}
@@ -173,11 +173,15 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
173173
*/
174174
this.telemetry.sendTelemetryEvent('issue.userCompletion');
175175
}));
176-
this.context.subscriptions.push(vscode.languages.registerHoverProvider('*', new IssueHoverProvider(this.manager, this._stateManager, this.context, this.telemetry)));
177-
this.context.subscriptions.push(vscode.languages.registerHoverProvider('*', new UserHoverProvider(this.manager, this.telemetry)));
178-
this.context.subscriptions.push(vscode.languages.registerCodeActionsProvider('*', new IssueTodoProvider(this.context)));
179-
this.context.subscriptions.push(vscode.window.registerTreeDataProvider('issues:github', new IssuesTreeData(this._stateManager, this.context)));
180-
this.context.subscriptions.push(vscode.workspace.registerFileSystemProvider('newIssue', new IssueFileSystemProvider()));
176+
this.context.subscriptions.push(vscode.commands.registerCommand('issue.signinAndRefreshList', async () => {
177+
return this.manager.authenticate();
178+
}));
179+
return this._stateManager.tryInitializeAndWait().then(() => {
180+
this.context.subscriptions.push(vscode.languages.registerHoverProvider('*', new IssueHoverProvider(this.manager, this._stateManager, this.context, this.telemetry)));
181+
this.context.subscriptions.push(vscode.languages.registerHoverProvider('*', new UserHoverProvider(this.manager, this.telemetry)));
182+
this.context.subscriptions.push(vscode.languages.registerCodeActionsProvider('*', new IssueTodoProvider(this.context)));
183+
this.context.subscriptions.push(vscode.workspace.registerFileSystemProvider('newIssue', new IssueFileSystemProvider()));
184+
});
181185
}
182186

183187
dispose() { }

src/issues/issuesView.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import { IssueModel } from '../github/issueModel';
88
import { MilestoneModel } from '../github/milestoneModel';
99
import { StateManager } from './stateManager';
1010
import { Resource } from '../common/resources';
11+
import { PullRequestManager, PRManagerState } from '../github/pullRequestManager';
1112

1213
export class IssuesTreeData implements vscode.TreeDataProvider<IssueModel | MilestoneModel | vscode.TreeItem> {
1314
private _onDidChangeTreeData: vscode.EventEmitter<IssueModel | MilestoneModel | null | undefined | void> = new vscode.EventEmitter();
1415
public onDidChangeTreeData: vscode.Event<IssueModel | MilestoneModel | null | undefined | void> = this._onDidChangeTreeData.event;
15-
private firstLabel: string | undefined;
1616

17-
constructor(private stateManager: StateManager, context: vscode.ExtensionContext) {
17+
constructor(private stateManager: StateManager, private manager: PullRequestManager, context: vscode.ExtensionContext) {
18+
context.subscriptions.push(this.manager.onDidChangeState(() => {
19+
this._onDidChangeTreeData.fire();
20+
}));
1821
context.subscriptions.push(this.stateManager.onDidChangeIssueData(() => {
1922
this._onDidChangeTreeData.fire();
2023
}));
@@ -28,7 +31,6 @@ export class IssuesTreeData implements vscode.TreeDataProvider<IssueModel | Mile
2831
let treeItem: vscode.TreeItem;
2932
if (element instanceof vscode.TreeItem) {
3033
treeItem = element;
31-
treeItem.collapsibleState = element.label === this.firstLabel ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed;
3234
} else if (!(element instanceof IssueModel)) {
3335
treeItem = new vscode.TreeItem(element.milestone.title, element.issues.length > 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None);
3436
} else {
@@ -54,16 +56,39 @@ export class IssuesTreeData implements vscode.TreeDataProvider<IssueModel | Mile
5456
}
5557

5658
getChildren(element: IssueModel | MilestoneModel | vscode.TreeItem | undefined): Promise<(IssueModel | MilestoneModel)[]> | IssueModel[] | vscode.TreeItem[] {
59+
if (element === undefined && this.manager.state !== PRManagerState.RepositoriesLoaded) {
60+
return this.getStateChildren();
61+
} else {
62+
return this.getIssuesChildren(element);
63+
}
64+
}
65+
66+
getStateChildren(): vscode.TreeItem[] {
67+
if (this.manager.state === PRManagerState.NeedsAuthentication) {
68+
const item = new vscode.TreeItem('Sign in');
69+
item.command = {
70+
title: 'Sign in',
71+
command: 'issue.signinAndRefreshList',
72+
arguments: []
73+
};
74+
return [item];
75+
} else {
76+
return [new vscode.TreeItem('Loading...')];
77+
}
78+
}
79+
80+
getIssuesChildren(element: IssueModel | MilestoneModel | vscode.TreeItem | undefined): Promise<(IssueModel | MilestoneModel)[]> | IssueModel[] | vscode.TreeItem[] {
5781
if (element === undefined) {
5882
// If there's only one query, don't display a title for it
5983
if (this.stateManager.issueCollection.size === 1) {
6084
return Array.from(this.stateManager.issueCollection.values())[0];
6185
}
6286
const queryLabels = Array.from(this.stateManager.issueCollection.keys());
63-
this.firstLabel = queryLabels[0];
87+
const firstLabel = queryLabels[0];
6488
return queryLabels.map(label => {
6589
const item = new vscode.TreeItem(label);
6690
item.contextValue = 'query';
91+
item.collapsibleState = label === firstLabel ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed;
6792
return item;
6893
});
6994
} else if (element instanceof vscode.TreeItem) {

0 commit comments

Comments
 (0)