-
Notifications
You must be signed in to change notification settings - Fork 713
feat(ui): decouple tree nodes from the UI representation #2783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ export function createPlaceholderItem(message: string): TreeNode { | |
return { | ||
id: 'placeholder', | ||
resource: message, | ||
treeItem: new vscode.TreeItem(message, vscode.TreeItemCollapsibleState.None), | ||
getTreeItem: () => new vscode.TreeItem(message, vscode.TreeItemCollapsibleState.None), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like turning otherwise constant things into functions but it was kind of necessary for this functionality. |
||
} | ||
} | ||
|
||
|
@@ -96,16 +96,43 @@ export function unboxTreeNode<T>(node: TreeNode, predicate: (resource: unknown) | |
* would be passed in as-is. | ||
*/ | ||
export class TreeShim extends AWSTreeNodeBase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The shim was updated to support this new functionality. It's not a perfect recreation because |
||
public constructor(public readonly node: TreeNode) { | ||
super(node.treeItem.label ?? '[No label]') | ||
assign(node.treeItem, this) | ||
private children?: AWSTreeNodeBase[] | ||
|
||
this.node.onDidChangeChildren?.(() => this.refresh()) | ||
public constructor(public readonly node: TreeNode) { | ||
super('Loading...') | ||
this.updateTreeItem() | ||
|
||
this.node.onDidChangeChildren?.(() => { | ||
this.children = undefined | ||
this.refresh() | ||
}) | ||
|
||
this.node.onDidChangeTreeItem?.(async () => { | ||
const { didRefresh } = await this.updateTreeItem() | ||
!didRefresh && this.refresh() | ||
}) | ||
} | ||
|
||
public override async getChildren(): Promise<AWSTreeNodeBase[]> { | ||
if (this.children) { | ||
return this.children | ||
} | ||
|
||
const children = (await this.node.getChildren?.()) ?? [] | ||
|
||
return children.map(n => new TreeShim(n)) | ||
return (this.children = children.map(n => new TreeShim(n))) | ||
} | ||
|
||
private async updateTreeItem(): Promise<{ readonly didRefresh: boolean }> { | ||
const item = this.node.getTreeItem() | ||
if (item instanceof Promise) { | ||
assign(await item, this) | ||
this.refresh() | ||
|
||
return { didRefresh: true } | ||
} | ||
|
||
assign(item, this) | ||
return { didRefresh: false } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metric was being recorded when the child node expanded rather than the parent (my bad).