From d45df8799648a532f6b817d8a8c03faba9900793 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 28 Feb 2022 15:06:57 -0500 Subject: [PATCH] Fixes #1844 - pages autolinked issues properly --- CHANGELOG.md | 1 + src/views/nodes/autolinkedItemsNode.ts | 17 +++++++++++++++-- src/views/nodes/branchNode.ts | 6 +++--- src/views/nodes/common.ts | 31 ++++++++++++++++++++----------- src/views/nodes/resultsCommitsNode.ts | 20 +++++++++++++++----- src/views/nodes/tagNode.ts | 6 +++--- src/views/nodes/viewNode.ts | 2 +- src/views/viewBase.ts | 3 ++- 8 files changed, 60 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7fb6b1..856b2ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#1844](https://github.com/gitkraken/vscode-gitlens/issues/1844) - Autolinked issues aren't properly paged when there are too many commits - Fixes [#1843](https://github.com/gitkraken/vscode-gitlens/issues/1843) - Compare references doesn't work if you have multiple repos open ## [12.0.0] - 2022-02-28 diff --git a/src/views/nodes/autolinkedItemsNode.ts b/src/views/nodes/autolinkedItemsNode.ts index 578eb70..b7bd448 100644 --- a/src/views/nodes/autolinkedItemsNode.ts +++ b/src/views/nodes/autolinkedItemsNode.ts @@ -7,7 +7,7 @@ import { debug } from '../../system/decorators/log'; import { PromiseCancelledErrorWithId } from '../../system/promise'; import { ViewsWithCommits } from '../viewBase'; import { AutolinkedItemNode } from './autolinkedItemNode'; -import { MessageNode } from './common'; +import { LoadMoreNode, MessageNode } from './common'; import { PullRequestNode } from './pullRequestNode'; import { ContextValues, ViewNode } from './viewNode'; @@ -32,6 +32,7 @@ export class AutolinkedItemsNode extends ViewNode { public readonly repoPath: string, public readonly remote: GitRemote, public readonly log: GitLog, + private expand: boolean, ) { super(GitUri.fromRepoPath(repoPath), view, parent); this._instanceId = instanceId++; @@ -82,13 +83,25 @@ export class AutolinkedItemsNode extends ViewNode { children = [new MessageNode(this.view, this, 'No autolinked issues or pull requests could be found.')]; } + if (this.log.hasMore) { + children.push( + new LoadMoreNode(this.view, this.parent as any, children[children.length - 1], { + context: { expandAutolinks: true }, + message: 'Load more commits to search for autolinks', + }), + ); + } + this._children = children; } return this._children; } getTreeItem(): TreeItem { - const item = new TreeItem('Autolinked Issues and Pull Requests', TreeItemCollapsibleState.Collapsed); + const item = new TreeItem( + 'Autolinked Issues and Pull Requests', + this.expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed, + ); item.id = this.id; item.contextValue = ContextValues.AutolinkedItems; diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 968f56b..0e87353 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -267,9 +267,9 @@ export class BranchNode if (log.hasMore) { children.push( - new LoadMoreNode(this.view, this, children[children.length - 1], undefined, () => - this.view.container.git.getCommitCount(this.branch.repoPath, this.branch.name), - ), + new LoadMoreNode(this.view, this, children[children.length - 1], { + getCount: () => this.view.container.git.getCommitCount(this.branch.repoPath, this.branch.name), + }), ); } diff --git a/src/views/nodes/common.ts b/src/views/nodes/common.ts index 45a39a3..d315c25 100644 --- a/src/views/nodes/common.ts +++ b/src/views/nodes/common.ts @@ -146,26 +146,31 @@ export abstract class PagerNode extends ViewNode { parent: ViewNode & PageableViewNode, protected readonly message: string, protected readonly previousNode?: ViewNode, - protected readonly pageSize: number = Container.instance.config.views.pageItemLimit, - protected readonly countFn?: () => Promise, + protected readonly options?: { + context?: Record; + pageSize?: number; + getCount?: () => Promise; + }, // protected readonly pageSize: number = Container.instance.config.views.pageItemLimit, // protected readonly countFn?: () => Promise, // protected readonly context?: Record, // protected readonly beforeLoadCallback?: (mode: 'all' | 'more') => void, ) { super(GitUri.unknown, view, parent); } async loadAll() { - const count = (await this.countFn?.()) ?? 0; + const count = (await this.options?.getCount?.()) ?? 0; return this.view.loadMoreNodeChildren( this.parent! as ViewNode & PageableViewNode, count > 5000 ? 5000 : 0, this.previousNode, + this.options?.context, ); } loadMore() { return this.view.loadMoreNodeChildren( this.parent! as ViewNode & PageableViewNode, - this.pageSize, + this.options?.pageSize ?? Container.instance.config.views.pageItemLimit, this.previousNode, + this.options?.context, ); } @@ -194,18 +199,22 @@ export class LoadMoreNode extends PagerNode { view: View, parent: ViewNode & PageableViewNode, previousNode: ViewNode, - pageSize?: number, - countFn?: () => Promise, + options?: { + context?: Record; + getCount?: () => Promise; + message?: string; + pageSize?: number; + }, ) { super( view, parent, - pageSize === 0 - ? `Load all ${GlyphChars.Space}${GlyphChars.Dash}${GlyphChars.Space} this may take a while` - : 'Load more', + options?.message ?? + (options?.pageSize === 0 + ? `Load all ${GlyphChars.Space}${GlyphChars.Dash}${GlyphChars.Space} this may take a while` + : 'Load more'), previousNode, - pageSize, - countFn, + options, ); } } diff --git a/src/views/nodes/resultsCommitsNode.ts b/src/views/nodes/resultsCommitsNode.ts index 317001b..137d585 100644 --- a/src/views/nodes/resultsCommitsNode.ts +++ b/src/views/nodes/resultsCommitsNode.ts @@ -71,12 +71,18 @@ export class ResultsCommitsNode): Promise { const results = await this.getCommitsQueryResults(); if (results == null || !results.hasMore) return; + if (context != null && 'expandAutolinks' in context) { + this._expandAutolinks = Boolean(context.expandAutolinks); + } await results.more?.(limit ?? this.view.config.pageItemLimit); this.limit = results.log?.count; diff --git a/src/views/nodes/tagNode.ts b/src/views/nodes/tagNode.ts index bc83315..a3d5a7a 100644 --- a/src/views/nodes/tagNode.ts +++ b/src/views/nodes/tagNode.ts @@ -63,9 +63,9 @@ export class TagNode extends ViewRefNode - this.view.container.git.getCommitCount(this.tag.repoPath, this.tag.name), - ), + new LoadMoreNode(this.view, this, children[children.length - 1], { + getCount: () => this.view.container.git.getCommitCount(this.tag.repoPath, this.tag.name), + }), ); } return children; diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index 5434c2f..fe2c23e 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -177,7 +177,7 @@ export interface PageableViewNode { readonly id: string; limit?: number; readonly hasMore: boolean; - loadMore(limit?: number | { until?: string | undefined }): Promise; + loadMore(limit?: number | { until?: string | undefined }, context?: Record): Promise; } export namespace PageableViewNode { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 578e41c..013ed94 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -533,12 +533,13 @@ export abstract class ViewBase< node: ViewNode & PageableViewNode, limit: number | { until: string | undefined } | undefined, previousNode?: ViewNode, + context?: Record, ) { if (previousNode != null) { void (await this.reveal(previousNode, { select: true })); } - await node.loadMore(limit); + await node.loadMore(limit, context); this._lastKnownLimits.set(node.id, node.limit); }