Skip to content

Commit f0bde22

Browse files
committed
Improves updating view state
1 parent d3983d2 commit f0bde22

File tree

8 files changed

+47
-112
lines changed

8 files changed

+47
-112
lines changed

src/views/branchesView.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class BranchesRepositoryNode extends RepositoryFolderNode<BranchesView, B
4848

4949
export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView, BranchesRepositoryNode> {
5050
async getChildren(): Promise<ViewNode[]> {
51+
this.view.description = this.getViewDescription();
52+
this.view.message = undefined;
53+
5154
if (this.children == null) {
5255
let grouped: Map<Repository, Map<string, Repository>> | undefined;
5356

@@ -65,8 +68,6 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
6568
return [];
6669
}
6770

68-
this.view.message = undefined;
69-
7071
// Get all the worktree branches (and track if they are opened) to pass along downstream, e.g. in the BranchNode to display an indicator
7172
const worktreesByBranch = await getWorktreesByBranch(repositories, { includeDefault: true });
7273
this.updateContext({
@@ -85,30 +86,16 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
8586
const branches = await child.repo.git.getBranches({ filter: b => !b.remote });
8687
if (branches.values.length === 0) {
8788
this.view.message = 'No branches could be found.';
88-
if (!this.view.grouped) {
89-
this.view.description = undefined;
90-
}
91-
9289
void child.ensureSubscription();
9390

9491
return [];
9592
}
9693

97-
this.view.message = undefined;
98-
99-
if (this.view.grouped) {
100-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${branches.values.length})`;
101-
} else {
102-
this.view.description = `(${branches.values.length})`;
103-
}
94+
this.view.description = this.getViewDescription(branches.values.length);
10495

10596
return child.getChildren();
10697
}
10798

108-
if (!this.view.grouped) {
109-
this.view.description = undefined;
110-
}
111-
11299
return this.children;
113100
}
114101

src/views/commitsView.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
121121
export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView, CommitsRepositoryNode> {
122122
async getChildren(): Promise<ViewNode[]> {
123123
if (this.children == null) {
124+
this.view.description = this.getViewDescription();
125+
this.view.message = undefined;
126+
124127
const repositories = this.view.container.git.openRepositories;
125128
if (repositories.length === 0) {
126129
this.view.message = this.view.container.git.isDiscoveringRepositories
@@ -130,8 +133,6 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView,
130133
return [];
131134
}
132135

133-
this.view.message = undefined;
134-
135136
const splat = repositories.length === 1;
136137
this.children = repositories.map(
137138
r =>
@@ -180,9 +181,9 @@ export class CommitsViewNode extends RepositoriesSubscribeableNode<CommitsView,
180181
descParts.push(status);
181182
}
182183

183-
this.view.description = `${this.view.grouped ? 'commits: ' : ''}${descParts.join(
184-
` ${GlyphChars.Dot} `,
185-
)}`;
184+
this.view.description = `${
185+
this.view.grouped ? `${this.view.name.toLocaleLowerCase()}: ` : ''
186+
}${descParts.join(` ${GlyphChars.Dot} `)}`;
186187
}
187188

188189
children.push(...(await child.getChildren()));

src/views/contributorsView.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export class ContributorsRepositoryNode extends RepositoryFolderNode<Contributor
5353

5454
export class ContributorsViewNode extends RepositoriesSubscribeableNode<ContributorsView, ContributorsRepositoryNode> {
5555
async getChildren(): Promise<ViewNode[]> {
56+
this.view.description = this.getViewDescription();
57+
this.view.message = undefined;
58+
5659
if (this.children == null) {
5760
let repositories = this.view.container.git.openRepositories;
5861
if (
@@ -71,8 +74,6 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
7174
return [];
7275
}
7376

74-
this.view.message = undefined;
75-
7677
const splat = repositories.length === 1;
7778
this.children = repositories.map(
7879
r => new ContributorsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
@@ -100,30 +101,16 @@ export class ContributorsViewNode extends RepositoriesSubscribeableNode<Contribu
100101
// const contributors = await child.repo.getContributors({ all: all, ref: ref });
101102
if (children.length === 0) {
102103
this.view.message = 'No contributors could be found.';
103-
if (!this.view.grouped) {
104-
this.view.description = undefined;
105-
}
106-
107104
void child.ensureSubscription();
108105

109106
return [];
110107
}
111108

112-
this.view.message = undefined;
113-
114-
if (this.view.grouped) {
115-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${children.length})`;
116-
} else {
117-
this.view.description = `(${children.length})`;
118-
}
109+
this.view.description = this.getViewDescription(children.length);
119110

120111
return children;
121112
}
122113

123-
if (!this.view.grouped) {
124-
this.view.description = undefined;
125-
}
126-
127114
return this.children;
128115
}
129116

src/views/nodes/abstract/repositoriesSubscribeableNode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export abstract class RepositoriesSubscribeableNode<
3131
return szudzikPairing(this.view.container.git.etag, this.view.container.subscription.etag);
3232
}
3333

34+
protected getViewDescription(count?: number) {
35+
return `${this.view.grouped ? `${this.view.name.toLocaleLowerCase()} ` : ''}${
36+
count != null ? `(${count})` : ''
37+
}`;
38+
}
39+
3440
@debug()
3541
protected subscribe(): Disposable | Promise<Disposable> {
3642
return Disposable.from(

src/views/remotesView.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class RemotesRepositoryNode extends RepositoryFolderNode<RemotesView, Rem
4848

4949
export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView, RemotesRepositoryNode> {
5050
async getChildren(): Promise<ViewNode[]> {
51+
this.view.description = this.getViewDescription();
52+
this.view.message = undefined;
53+
5154
if (this.children == null) {
5255
let repositories = this.view.container.git.openRepositories;
5356
if (configuration.get('views.collapseWorktreesWhenPossible')) {
@@ -63,8 +66,6 @@ export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView,
6366
return [];
6467
}
6568

66-
this.view.message = undefined;
67-
6869
const splat = repositories.length === 1;
6970
this.children = repositories.map(
7071
r => new RemotesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
@@ -77,28 +78,16 @@ export class RemotesViewNode extends RepositoriesSubscribeableNode<RemotesView,
7778
const remotes = await child.repo.git.getRemotes();
7879
if (remotes.length === 0) {
7980
this.view.message = 'No remotes could be found.';
80-
if (!this.view.grouped) {
81-
this.view.description = undefined;
82-
}
83-
8481
void child.ensureSubscription();
8582

8683
return [];
8784
}
8885

89-
if (this.view.grouped) {
90-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${remotes.length})`;
91-
} else {
92-
this.view.description = `(${remotes.length})`;
93-
}
86+
this.view.description = this.getViewDescription(remotes.length);
9487

9588
return child.getChildren();
9689
}
9790

98-
if (!this.view.grouped) {
99-
this.view.description = undefined;
100-
}
101-
10291
return this.children;
10392
}
10493

src/views/stashesView.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class StashesRepositoryNode extends RepositoryFolderNode<StashesView, Sta
3434

3535
export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView, StashesRepositoryNode> {
3636
async getChildren(): Promise<ViewNode[]> {
37+
this.view.description = this.getViewDescription();
38+
this.view.message = undefined;
39+
3740
if (this.children == null) {
3841
let repositories = this.view.container.git.openRepositories;
3942
if (configuration.get('views.collapseWorktreesWhenPossible')) {
@@ -49,8 +52,6 @@ export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView,
4952
return [];
5053
}
5154

52-
this.view.message = undefined;
53-
5455
const splat = repositories.length === 1;
5556
this.children = repositories.map(
5657
r => new StashesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
@@ -61,31 +62,18 @@ export class StashesViewNode extends RepositoriesSubscribeableNode<StashesView,
6162
const [child] = this.children;
6263

6364
const stash = await child.repo.git.getStash();
64-
if (stash == null || stash.commits.size === 0) {
65+
if (!stash?.commits.size) {
6566
this.view.message = 'No stashes could be found.';
66-
if (!this.view.grouped) {
67-
this.view.description = undefined;
68-
}
69-
7067
void child.ensureSubscription();
7168

7269
return [];
7370
}
7471

75-
this.view.message = undefined;
76-
if (this.view.grouped) {
77-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${stash.commits.size})`;
78-
} else {
79-
this.view.description = `(${stash.commits.size})`;
80-
}
72+
this.view.description = this.getViewDescription(stash.commits.size);
8173

8274
return child.getChildren();
8375
}
8476

85-
if (!this.view.grouped) {
86-
this.view.description = undefined;
87-
}
88-
8977
return this.children;
9078
}
9179

src/views/tagsView.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export class TagsRepositoryNode extends RepositoryFolderNode<TagsView, TagsNode>
3535

3636
export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRepositoryNode> {
3737
async getChildren(): Promise<ViewNode[]> {
38+
this.view.description = this.getViewDescription();
39+
this.view.message = undefined;
40+
3841
if (this.children == null) {
3942
let repositories = this.view.container.git.openRepositories;
4043
if (configuration.get('views.collapseWorktreesWhenPossible')) {
@@ -50,8 +53,6 @@ export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRe
5053
return [];
5154
}
5255

53-
this.view.message = undefined;
54-
5556
const splat = repositories.length === 1;
5657
this.children = repositories.map(
5758
r => new TagsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
@@ -64,29 +65,16 @@ export class TagsViewNode extends RepositoriesSubscribeableNode<TagsView, TagsRe
6465
const tags = await child.repo.git.getTags();
6566
if (tags.values.length === 0) {
6667
this.view.message = 'No tags could be found.';
67-
if (!this.view.grouped) {
68-
this.view.description = undefined;
69-
}
70-
7168
void child.ensureSubscription();
7269

7370
return [];
7471
}
7572

76-
this.view.message = undefined;
77-
if (this.view.grouped) {
78-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${tags.values.length})`;
79-
} else {
80-
this.view.description = `(${tags.values.length})`;
81-
}
73+
this.view.description = this.getViewDescription(tags.values.length);
8274

8375
return child.getChildren();
8476
}
8577

86-
if (!this.view.grouped) {
87-
this.view.description = undefined;
88-
}
89-
9078
return this.children;
9179
}
9280

src/views/worktreesView.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ export class WorktreesRepositoryNode extends RepositoryFolderNode<WorktreesView,
4141
}
4242

4343
export class WorktreesViewNode extends RepositoriesSubscribeableNode<WorktreesView, WorktreesRepositoryNode> {
44+
protected override getViewDescription(count?: number): string {
45+
const description = super.getViewDescription(count);
46+
return description ? `${description} \u00a0\u2022\u00a0 ${proBadge}` : proBadge;
47+
}
48+
4449
async getChildren(): Promise<ViewNode[]> {
45-
const access = await this.view.container.git.access(PlusFeatures.Worktrees);
46-
if (access.allowed === false) return [];
50+
this.view.description = this.getViewDescription();
51+
this.view.message = undefined;
4752

4853
if (this.children == null) {
54+
const access = await this.view.container.git.access(PlusFeatures.Worktrees);
55+
if (access.allowed === false) return [];
56+
4957
let repositories = this.view.container.git.openRepositories;
5058
if (configuration.get('views.collapseWorktreesWhenPossible')) {
5159
const grouped = await groupRepositories(repositories);
@@ -60,8 +68,6 @@ export class WorktreesViewNode extends RepositoriesSubscribeableNode<WorktreesVi
6068
return [];
6169
}
6270

63-
this.view.message = undefined;
64-
6571
const splat = repositories.length === 1;
6672
this.children = repositories.map(
6773
r => new WorktreesRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
@@ -71,33 +77,16 @@ export class WorktreesViewNode extends RepositoriesSubscribeableNode<WorktreesVi
7177
if (this.children.length === 1) {
7278
const [child] = this.children;
7379

74-
const children = await child.getChildren();
75-
if (children.length <= 1) {
76-
this.view.message = undefined;
77-
if (!this.view.grouped) {
78-
this.view.description = proBadge;
79-
}
80-
80+
const grandChildren = await child.getChildren();
81+
if (grandChildren.length <= 1) {
8182
void child.ensureSubscription();
8283

8384
return [];
8485
}
8586

86-
this.view.message = undefined;
87-
88-
if (this.view.grouped) {
89-
this.view.description = `${this.view.name.toLocaleLowerCase()} (${
90-
children.length
91-
}) \u00a0\u2022\u00a0 ${proBadge}`;
92-
} else {
93-
this.view.description = `(${children.length}) \u00a0\u2022\u00a0 ${proBadge}`;
94-
}
95-
96-
return children;
97-
}
87+
this.view.description = this.getViewDescription(grandChildren.length);
9888

99-
if (!this.view.grouped) {
100-
this.view.description = proBadge;
89+
return grandChildren;
10190
}
10291

10392
return this.children;

0 commit comments

Comments
 (0)