Skip to content

Commit 72a7610

Browse files
committed
Fixes view node parents in Launchpad view
1 parent 77a463b commit 72a7610

File tree

4 files changed

+66
-47
lines changed

4 files changed

+66
-47
lines changed

src/views/draftsView.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ensurePlusFeaturesEnabled } from '../plus/gk/utils/-webview/plus.utils'
1111
import { executeCommand } from '../system/-webview/command';
1212
import { configuration } from '../system/-webview/configuration';
1313
import { gate } from '../system/decorators/-webview/gate';
14-
import { groupByFilterMap } from '../system/iterable';
14+
import { groupByFilterMap, map } from '../system/iterable';
1515
import { CacheableChildrenViewNode } from './nodes/abstract/cacheableChildrenViewNode';
1616
import type { ViewNode } from './nodes/abstract/viewNode';
1717
import { DraftNode } from './nodes/draftNode';
@@ -35,25 +35,29 @@ export class DraftsViewNode extends CacheableChildrenViewNode<'drafts', DraftsVi
3535
const drafts = await this.view.container.drafts.getDrafts();
3636
drafts?.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
3737

38-
const groups = groupByFilterMap(
39-
drafts,
40-
this.calcDraftGroupKey.bind(this),
41-
d => new DraftNode(this.uri, this.view, this, d),
42-
);
38+
const groups = groupByFilterMap(drafts, getDraftGroupKey, d => d);
4339

4440
const mine = groups.get('mine');
4541
const shared = groups.get('shared');
4642
const isFlat = mine?.length && !shared?.length;
4743

4844
if (!isFlat) {
4945
if (mine?.length) {
50-
children.push(new GroupingNode(this.view, 'Created by Me', mine));
46+
children.push(
47+
new GroupingNode(this.view, this, 'Created by Me', p =>
48+
mine.map(d => new DraftNode(this.uri, this.view, p, d)),
49+
),
50+
);
5151
}
5252
if (shared?.length) {
53-
children.push(new GroupingNode(this.view, 'Shared with Me', shared));
53+
children.push(
54+
new GroupingNode(this.view, this, 'Shared with Me', p =>
55+
shared.map(d => new DraftNode(this.uri, this.view, p, d)),
56+
),
57+
);
5458
}
5559
} else {
56-
children.push(...mine);
60+
children.push(...map(mine, d => new DraftNode(this.uri, this.view, this, d)));
5761
}
5862
} catch (ex) {
5963
if (!(ex instanceof AuthenticationRequiredError)) throw ex;
@@ -70,13 +74,6 @@ export class DraftsViewNode extends CacheableChildrenViewNode<'drafts', DraftsVi
7074
const item = new TreeItem('Drafts', TreeItemCollapsibleState.Expanded);
7175
return item;
7276
}
73-
74-
private calcDraftGroupKey(d: Draft): DraftGroupKey {
75-
if (d.type === 'suggested_pr_change') {
76-
return 'pr_suggestion';
77-
}
78-
return d.isMine ? 'mine' : 'shared';
79-
}
8077
}
8178

8279
type DraftGroupKey = 'pr_suggestion' | 'mine' | 'shared';
@@ -201,3 +198,9 @@ export class DraftsView extends ViewBase<'drafts', DraftsViewNode, DraftsViewCon
201198
return configuration.updateEffective(`views.${this.configKey}.avatars` as const, enabled);
202199
}
203200
}
201+
202+
function getDraftGroupKey(d: Draft): DraftGroupKey {
203+
if (d.type === 'suggested_pr_change') return 'pr_suggestion';
204+
205+
return d.isMine ? 'mine' : 'shared';
206+
}

src/views/launchpadView.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ export class LaunchpadViewNode extends CacheableChildrenViewNode<
163163
const children: (GroupingNode | LaunchpadItemNode)[] = [];
164164

165165
const hasIntegrations = await this.view.container.launchpad.hasConnectedIntegration();
166-
if (!hasIntegrations) {
167-
return [];
168-
}
166+
if (!hasIntegrations) return [];
169167

170168
try {
171169
const result = await this.view.container.launchpad.getCategorizedItems();
@@ -190,15 +188,17 @@ export class LaunchpadViewNode extends CacheableChildrenViewNode<
190188
children.push(
191189
new LaunchpadViewGroupingNode(
192190
this.view,
191+
this,
193192
launchpadGroupLabelMap.get(ui)!,
194193
ui,
195-
groupItems.map(i => new LaunchpadItemNode(this.view, this, ui, i)),
196-
ui === 'current-branch' || expanded.get(ui)
197-
? TreeItemCollapsibleState.Expanded
198-
: TreeItemCollapsibleState.Collapsed,
199-
undefined,
200-
undefined,
201-
new ThemeIcon(icon.substring(2, icon.length - 1)),
194+
p => groupItems.map(i => new LaunchpadItemNode(this.view, p, ui, i)),
195+
{
196+
collapsibleState:
197+
ui === 'current-branch' || expanded.get(ui)
198+
? TreeItemCollapsibleState.Expanded
199+
: TreeItemCollapsibleState.Collapsed,
200+
iconPath: new ThemeIcon(icon.substring(2, icon.length - 1)),
201+
},
202202
),
203203
);
204204
}

src/views/nodes/groupingNode.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,33 @@ import { ContextValues, ViewNode } from './abstract/viewNode';
66
export class GroupingNode<TChild extends ViewNode = ViewNode> extends ViewNode<'grouping'> {
77
constructor(
88
view: View,
9+
parent: ViewNode,
910
private readonly label: string,
10-
private readonly childrenOrFn: TChild[] | Promise<TChild[]> | (() => TChild[] | Promise<TChild[]>),
11-
private readonly collapsibleState: TreeItemCollapsibleState = TreeItemCollapsibleState.Expanded,
12-
private readonly description?: string,
13-
private readonly tooltip?: string,
14-
private readonly iconPath?: TreeItem['iconPath'],
15-
private readonly contextValue?: string,
11+
private readonly children: (parent: ViewNode) => TChild[] | Promise<TChild[]>,
12+
private readonly options?: {
13+
readonly collapsibleState?: TreeItemCollapsibleState;
14+
readonly contextValue?: ContextValues;
15+
readonly description?: string;
16+
readonly iconPath?: TreeItem['iconPath'];
17+
readonly tooltip?: string;
18+
},
1619
) {
17-
super('grouping', unknownGitUri, view);
20+
super('grouping', unknownGitUri, view, parent);
1821
}
1922

2023
getChildren(): ViewNode[] | Promise<ViewNode[]> {
21-
return typeof this.childrenOrFn === 'function' ? this.childrenOrFn() : this.childrenOrFn;
24+
return this.children(this);
2225
}
2326

2427
getTreeItem(): TreeItem {
25-
const item = new TreeItem(this.label, this.collapsibleState);
28+
const { collapsibleState, description, tooltip, iconPath, contextValue } = this.options ?? {};
29+
30+
const item = new TreeItem(this.label, collapsibleState ?? TreeItemCollapsibleState.Expanded);
2631
item.id = this.id;
27-
item.contextValue = this.contextValue ?? ContextValues.Grouping;
28-
item.description = this.description;
29-
item.tooltip = this.tooltip;
30-
item.iconPath = this.iconPath;
32+
item.contextValue = contextValue ?? ContextValues.Grouping;
33+
item.description = description;
34+
item.tooltip = tooltip;
35+
item.iconPath = iconPath;
3136
return item;
3237
}
3338
}

src/views/nodes/launchpadViewGroupingNode.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,45 @@ import type { TreeItem } from 'vscode';
22
import { Disposable, TreeItemCollapsibleState } from 'vscode';
33
import type { LaunchpadGroup } from '../../plus/launchpad/models/launchpad';
44
import type { TreeViewNodeCollapsibleStateChangeEvent, View } from '../viewBase';
5-
import type { ViewNode } from './abstract/viewNode';
5+
import type { ContextValues, ViewNode } from './abstract/viewNode';
6+
import { getViewNodeId } from './abstract/viewNode';
67
import { GroupingNode } from './groupingNode';
78

89
export class LaunchpadViewGroupingNode<TChild extends ViewNode = ViewNode> extends GroupingNode {
910
private disposable: Disposable;
1011

1112
constructor(
1213
view: View,
14+
parent: ViewNode,
1315
label: string,
1416
private readonly group: LaunchpadGroup,
15-
childrenOrFn: TChild[] | Promise<TChild[]> | (() => TChild[] | Promise<TChild[]>),
16-
collapsibleState: TreeItemCollapsibleState = TreeItemCollapsibleState.Expanded,
17-
description?: string,
18-
tooltip?: string,
19-
iconPath?: TreeItem['iconPath'],
20-
contextValue?: string,
17+
children: (parent: ViewNode) => TChild[] | Promise<TChild[]>,
18+
options?: {
19+
readonly collapsibleState?: TreeItemCollapsibleState;
20+
readonly contextValue?: ContextValues;
21+
readonly description?: string;
22+
readonly iconPath?: TreeItem['iconPath'];
23+
readonly tooltip?: string;
24+
},
2125
) {
22-
super(view, label, childrenOrFn, collapsibleState, description, tooltip, iconPath, contextValue);
26+
super(view, parent, label, children, options);
2327
this.disposable = Disposable.from(
2428
this.view.onDidChangeNodeCollapsibleState(this.onNodeCollapsibleStateChanged, this),
2529
);
30+
31+
this.updateContext({ launchpadGroup: group });
32+
this._uniqueId = getViewNodeId(this.type, this.context);
2633
}
2734

2835
override dispose(): void {
2936
super.dispose();
3037
this.disposable?.dispose();
3138
}
3239

40+
override get id(): string {
41+
return this._uniqueId;
42+
}
43+
3344
private onNodeCollapsibleStateChanged(e: TreeViewNodeCollapsibleStateChangeEvent<ViewNode>) {
3445
if (e.element === this) {
3546
const storedExpandedGroups = this.view.container.storage.get('launchpadView:groups:expanded') ?? [];

0 commit comments

Comments
 (0)