Skip to content

Commit 1db117d

Browse files
committed
(WIP) Adds new view ids
1 parent 097c74f commit 1db117d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+108
-158
lines changed

src/views/launchpadView.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ export class LaunchpadItemNode extends CacheableChildrenViewNode<'launchpad-item
4646
this.repoPath = repoPath;
4747
}
4848

49-
override get id(): string {
50-
return this._uniqueId;
51-
}
52-
5349
override toClipboard(type?: ClipboardType): string {
5450
const url = this.getUrl();
5551
switch (type) {

src/views/nodes/UncommittedFilesNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export class UncommittedFilesNode extends ViewNode<'uncommitted-files', ViewsWit
3131
this._uniqueId = getViewNodeId(this.type, this.context);
3232
}
3333

34-
override get id(): string {
35-
return this._uniqueId;
36-
}
37-
3834
get repoPath(): string {
3935
return this.status.repoPath;
4036
}

src/views/nodes/abstract/repositoryFolderNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export abstract class RepositoryFolderNode<
4949
this.child = undefined;
5050
}
5151

52-
override get id(): string {
53-
return this._uniqueId;
54-
}
55-
5652
override toClipboard(): string {
5753
return this.repo.path;
5854
}

src/views/nodes/abstract/viewNode.ts

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,29 @@ export interface AmbientContext {
154154
readonly worktreesByBranch?: Map<string, GitWorktree>;
155155
}
156156

157-
export function getViewNodeId(type: string, context: AmbientContext): string {
157+
export function getViewNodeId(
158+
type: TreeViewNodeTypes | `${TreeViewNodeTypes}+${string}`,
159+
context: AmbientContext,
160+
): string {
161+
switch (type) {
162+
case 'branch':
163+
return `${type}(${context.branch?.id})`;
164+
165+
case 'commit':
166+
return `${type}(${context.commit?.repoPath}|${context.commit?.sha})`;
167+
168+
case 'pullrequest':
169+
return `${type}(${context.pullRequest?.url})`;
170+
171+
case 'commit-file':
172+
return `${type}:(${
173+
context.repository?.path ?? context.branch?.repoPath ?? context.commit?.repoPath
174+
}|${context.file?.path}+${context.file?.status})`;
175+
176+
// case 'results-file':
177+
// return `${type}(${context.file?.path}+${context.file?.status})`;
178+
}
179+
158180
let uniqueness = '';
159181
if (context.root) {
160182
uniqueness += '/root';
@@ -252,8 +274,22 @@ export abstract class ViewNode<
252274
return types.includes(this.type as unknown as T[number]);
253275
}
254276

277+
public childrenIds = new Set<string>();
278+
public childrenCount = 0;
255279
protected _uniqueId!: string;
256-
splatted = false;
280+
281+
private _splatted: boolean;
282+
//** Indicates if this node is only shown as its children, not itself */
283+
get splatted(): boolean {
284+
return this._splatted;
285+
}
286+
set splatted(value: boolean) {
287+
if (this._splatted === value) return;
288+
289+
this._splatted = value;
290+
// this.setId();
291+
}
292+
257293
// NOTE: @eamodio uncomment to track node leaks
258294
// readonly uuid = uuid();
259295

@@ -266,7 +302,10 @@ export abstract class ViewNode<
266302
//** Indicates if this node is only shown as its children, not itself */
267303
splatted?: boolean,
268304
) {
269-
this.splatted = splatted ?? false;
305+
this._splatted = splatted ?? false;
306+
(parent ?? this).childrenCount++;
307+
308+
// this.setId();
270309

271310
// NOTE: @eamodio uncomment to track node leaks
272311
// queueMicrotask(() => this.view.registerNode(this));
@@ -281,9 +320,38 @@ export abstract class ViewNode<
281320
// NOTE: @eamodio uncomment to track node leaks
282321
// this.view.unregisterNode(this);
283322
}
323+
private _id!: string;
324+
get id(): string {
325+
if (this._id == null) {
326+
// if (!this.splatted) {
327+
this._id = this._uniqueId ?? `${(this.parent ?? this).childrenCount}:${this.type}`;
328+
// }
329+
}
330+
return this._id;
331+
}
332+
333+
get parentId(): string {
334+
return this.parent?.treeId ?? '~';
335+
}
336+
337+
get treeId(): string {
338+
return this.splatted ? this.parentId : `${this.parentId}/${this.id}`;
339+
}
284340

285-
get id(): string | undefined {
286-
return this._uniqueId;
341+
private setId() {
342+
// if (this.splatted) {
343+
// this._id = undefined!; //this.parent?.id ?? '~';
344+
// } else {
345+
// const { parent } = this;
346+
// const { childrenIds } = parent ?? this;
347+
// this._id = this._uniqueId ?? `${childrenIds.size ?? 0}:${this.type}`;
348+
// if (childrenIds.has(this._id)) {
349+
// debugger;
350+
// // this._id = `${this._id}-${this._uniqueCounter++}`;
351+
// }
352+
// childrenIds.add(this._id);
353+
// }
354+
// console.log('#######', this.type, this.splatted, this._id);
287355
}
288356

289357
private _context: AmbientContext | undefined;

src/views/nodes/autolinkedItemNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export class AutolinkedItemNode extends ViewNode<'autolink', ViewsWithCommits> {
2222
this._uniqueId = getViewNodeId(`${this.type}+${item.id}`, this.context);
2323
}
2424

25-
override get id(): string {
26-
return this._uniqueId;
27-
}
28-
2925
override async toClipboard(type?: ClipboardType): Promise<string> {
3026
const enriched = await this.maybeEnriched;
3127
switch (type) {

src/views/nodes/autolinkedItemsNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export class AutolinkedItemsNode extends CacheableChildrenViewNode<'autolinks',
3030
this._uniqueId = getViewNodeId(this.type, this.context);
3131
}
3232

33-
override get id(): string {
34-
return this._uniqueId;
35-
}
36-
3733
async getChildren(): Promise<ViewNode[]> {
3834
if (this.children == null) {
3935
const commits = [...this.log.commits.values()];

src/views/nodes/branchNode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export class BranchNode
8383
super('branch', uri, view, parent, root);
8484

8585
this.updateContext({ repository: repo, branch: branch, root: root });
86-
this._uniqueId = getViewNodeId(this.type, this.context);
86+
// this._uniqueId = getViewNodeId(this.type, this.context);
87+
this._uniqueId = `${this.type}(${this.branch.id})`;
88+
8789
this.limit = this.view.getNodeLastKnownLimit(this);
8890

8991
this.options = {
@@ -106,10 +108,6 @@ export class BranchNode
106108
this.children = undefined;
107109
}
108110

109-
override get id(): string {
110-
return this._uniqueId;
111-
}
112-
113111
override toClipboard(): string {
114112
return this.branch.name;
115113
}

src/views/nodes/branchOrTagFolderNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
2222
this._uniqueId = getViewNodeId(`${this.type}+${folderType}+${relativePath ?? folderName}`, this.context);
2323
}
2424

25-
override get id(): string {
26-
return this._uniqueId;
27-
}
28-
2925
override toClipboard(): string {
3026
return this.folderName;
3127
}

src/views/nodes/branchTrackingStatusNode.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,10 @@ export class BranchTrackingStatusNode
5656
branchStatusUpstreamType: upstreamType,
5757
root: root,
5858
});
59-
this._uniqueId = getViewNodeId(this.type, this.context);
59+
// this._uniqueId = getViewNodeId(this.type, this.context);
6060
this.limit = this.view.getNodeLastKnownLimit(this);
6161
}
6262

63-
override get id(): string {
64-
return this._uniqueId;
65-
}
66-
6763
get repoPath(): string {
6864
return this.uri.repoPath!;
6965
}

src/views/nodes/branchesNode.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
2525
this._uniqueId = getViewNodeId(this.type, this.context);
2626
}
2727

28-
override get id(): string {
29-
return this._uniqueId;
30-
}
31-
3228
get repoPath(): string {
3329
return this.repo.path;
3430
}

0 commit comments

Comments
 (0)