Skip to content

Commit 83bb3f0

Browse files
authored
Fix "load more" when there's a new PR (#6816)
* Fix "load more" when there's a new PR Fixes #6615 * Fix test
1 parent cebc1f3 commit 83bb3f0

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/github/notifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ export class NotificationProvider extends Disposable {
175175

176176
for (const catNode of catNodes) {
177177
if (catNode.id === 'All Open') {
178-
if (catNode.prs.length === 0) {
178+
if (catNode.prs.size === 0) {
179179
for (const prNode of await catNode.cachedChildren()) {
180180
if (prNode instanceof PRNode) {
181181
allPrs.push(prNode.pullRequestModel);
182182
}
183183
}
184184
}
185185
else {
186-
allPrs = catNode.prs;
186+
allPrs = Array.from(catNode.prs.values());
187187
}
188188

189189
}

src/test/view/prsTree.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ describe('GitHub Pull Requests view', function () {
141141
builder.pullRequest(pr => {
142142
pr.repository(r =>
143143
r.pullRequest(p => {
144+
p.databaseId(1111);
144145
p.number(1111);
145146
p.title('zero');
146147
p.author(a => a.login('me').avatarUrl('https://avatars.com/me.jpg').url('https://github.com/me'));
@@ -157,6 +158,7 @@ describe('GitHub Pull Requests view', function () {
157158
builder.pullRequest(pr => {
158159
pr.repository(r =>
159160
r.pullRequest(p => {
161+
p.databaseId(2222);
160162
p.number(2222);
161163
p.title('one');
162164
p.author(a => a.login('you').avatarUrl('https://avatars.com/you.jpg'));

src/view/treeNodes/categoryNode.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface PageInformation {
117117

118118
export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
119119
public collapsibleState: vscode.TreeItemCollapsibleState;
120-
public prs: PullRequestModel[];
120+
public prs: Map<number, PullRequestModel>;
121121
public fetchNextPage: boolean = false;
122122
public repositoryPageInformation: Map<string, PageInformation> = new Map<string, PageInformation>();
123123
public contextValue: string;
@@ -134,7 +134,7 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
134134
) {
135135
super(parent);
136136

137-
this.prs = [];
137+
this.prs = new Map();
138138

139139
switch (this.type) {
140140
case PRType.All:
@@ -322,7 +322,8 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
322322
this.fetchNextPage = false;
323323
if (this.type === PRType.LocalPullRequest) {
324324
try {
325-
this.prs = (await this._prsTreeModel.getLocalPullRequests(this._folderRepoManager)).items;
325+
this.prs.clear();
326+
(await this._prsTreeModel.getLocalPullRequests(this._folderRepoManager)).items.forEach(item => this.prs.set(item.id, item));
326327
} catch (e) {
327328
vscode.window.showErrorMessage(vscode.l10n.t('Fetching local pull requests failed: {0}', formatError(e)));
328329
needLogin = e instanceof AuthenticationError;
@@ -339,10 +340,9 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
339340
break;
340341
}
341342
if (!fetchNextPage) {
342-
this.prs = response.items;
343-
} else {
344-
this.prs = this.prs.concat(response.items);
343+
this.prs.clear();
345344
}
345+
response.items.forEach(item => this.prs.set(item.id, item));
346346
hasMorePages = response.hasMorePages;
347347
hasUnsearchedRepositories = response.hasUnsearchedRepositories;
348348
} catch (e) {
@@ -360,8 +360,8 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
360360
}
361361
}
362362

363-
if (this.prs && this.prs.length) {
364-
const nodes: (PRNode | PRCategoryActionNode)[] = this.prs.map(
363+
if (this.prs.size > 0) {
364+
const nodes: (PRNode | PRCategoryActionNode)[] = Array.from(this.prs.values()).map(
365365
prItem => new PRNode(this, this._folderRepoManager, prItem, this.type === PRType.LocalPullRequest, this._notificationProvider),
366366
);
367367
if (hasMorePages) {

0 commit comments

Comments
 (0)