Skip to content

Commit 3885c68

Browse files
authored
Update AWS Explorer text and behaviors (#910)
* Clean getChildren method - make error based fallback node text more general than lamda-centric (old code) - tidy up the "sign in" node tooltip * Clean up Region Node behavior - tidy up the "Add Region" node text - region nodes are now sorted by friendly name
1 parent 59c1166 commit 3885c68

File tree

3 files changed

+73
-52
lines changed

3 files changed

+73
-52
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "AWS Explorer now sorts region nodes by the region name"
4+
}

package.nls.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@
6363
"AWS.error.no.error.code": "No error code",
6464
"AWS.error.sam.local.package_json_not_found": "Unable to find package.json related to {0}",
6565
"AWS.error.check.logs": "Check the logs for more information by running the \"{0}\" command from the Command Palette.",
66-
"AWS.explorerNode.addRegion": "Add a region to view functions...",
67-
"AWS.explorerNode.addRegion.tooltip": "Click to add a region to view functions...",
66+
"AWS.explorerNode.addRegion": "Add a region to AWS Explorer...",
67+
"AWS.explorerNode.addRegion.tooltip": "Click here to add a region to AWS Explorer.",
6868
"AWS.explorerNode.lambda.noFunctions": "[No Functions found]",
6969
"AWS.explorerNode.cloudFormation.noFunctions": "[Stack has no Lambda Functions]",
7070
"AWS.explorerNode.cloudformation.noStacks": "[No Stacks found]",
7171
"AWS.explorerNode.cloudFormation.error": "Error loading CloudFormation resources",
7272
"AWS.explorerNode.container.noItems": "[no items]",
73-
"AWS.explorerNode.lambda.retry": "Unable to load Lambda Functions, click here to retry",
73+
"AWS.explorerNode.error.retry": "Unable to get child nodes, click here to retry",
7474
"AWS.explorerNode.lambda.error": "Error loading Lambda resources",
7575
"AWS.explorerNode.schemas.error": "Error loading Schemas resources",
7676
"AWS.explorerNode.schemas.noRegistry": "[No Schema Registries]",
7777
"AWS.explorerNode.registry.error": "Error loading registry schema items",
7878
"AWS.explorerNode.registry.noSchemas": "[No Registry Schemas]",
7979
"AWS.explorerNode.registry.registryName.Not.Found": "Registry name not found",
8080
"AWS.explorerNode.signIn": "Connect to AWS...",
81-
"AWS.explorerNode.signIn.tooltip": "Connect to AWS using a credential profile",
81+
"AWS.explorerNode.signIn.tooltip": "Click here to select credentials for the AWS Toolkit",
8282
"AWS.lambda.explorerTitle": "Explorer",
8383
"AWS.lambda.configure.error.fieldtype": "Your templates.json file has an issue. {0} was detected as {1} instead of one of the following: [{2}]. Please change or remove this field, and try again.",
8484
"AWS.lambda.debug.node.launchConfig.name": "Lambda: Debug {0} locally",

src/awsexplorer/awsExplorer.ts

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,27 @@ import { RegionProvider } from '../shared/regions/regionProvider'
1010
import { RefreshableAwsTreeProvider } from '../shared/treeview/awsTreeProvider'
1111
import { AWSCommandTreeNode } from '../shared/treeview/nodes/awsCommandTreeNode'
1212
import { AWSTreeNodeBase } from '../shared/treeview/nodes/awsTreeNodeBase'
13+
import { makeChildrenNodes } from '../shared/treeview/treeNodeUtilities'
1314
import { intersection, toMap, updateInPlace } from '../shared/utilities/collectionUtils'
1415
import { localize } from '../shared/utilities/vsCodeUtils'
1516
import { RegionNode } from './regionNode'
1617

18+
const ROOT_NODE_SIGN_IN = new AWSCommandTreeNode(
19+
undefined,
20+
localize('AWS.explorerNode.signIn', 'Connect to AWS...'),
21+
'aws.login',
22+
undefined,
23+
localize('AWS.explorerNode.signIn.tooltip', 'Click here to select credentials for the AWS Toolkit')
24+
)
25+
26+
const ROOT_NODE_ADD_REGION = new AWSCommandTreeNode(
27+
undefined,
28+
localize('AWS.explorerNode.addRegion', 'Add a region to AWS Explorer...'),
29+
'aws.showRegion',
30+
undefined,
31+
localize('AWS.explorerNode.addRegion.tooltip', 'Click here to add a region to AWS Explorer.')
32+
)
33+
1734
export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, RefreshableAwsTreeProvider {
1835
public viewProviderId: string = 'aws.explorer'
1936
public readonly onDidChangeTreeData: vscode.Event<AWSTreeNodeBase | undefined>
@@ -37,60 +54,32 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
3754
}
3855

3956
public async getChildren(element?: AWSTreeNodeBase): Promise<AWSTreeNodeBase[]> {
40-
if (!!element) {
41-
try {
42-
return await element.getChildren()
43-
} catch (error) {
44-
return [
45-
new AWSCommandTreeNode(
46-
element,
47-
localize(
48-
'AWS.explorerNode.lambda.retry',
49-
'Unable to load Lambda Functions, click here to retry'
50-
),
51-
'aws.refreshAwsExplorerNode',
52-
[this, element]
53-
)
54-
]
57+
let childNodes: AWSTreeNodeBase[] = []
58+
59+
try {
60+
if (element) {
61+
childNodes = childNodes.concat(await element.getChildren())
62+
} else {
63+
childNodes = childNodes.concat(await this.getRootNodes())
5564
}
56-
}
65+
} catch (err) {
66+
const error = err as Error
67+
this.logger.error(`Error getting children for node ${element?.label ?? 'Root Node'}`, error)
5768

58-
const profileName = this.awsContext.getCredentialProfileName()
59-
if (!profileName) {
60-
return [
69+
childNodes.splice(
70+
0,
71+
childNodes.length,
6172
new AWSCommandTreeNode(
62-
undefined,
63-
localize('AWS.explorerNode.signIn', 'Connect to AWS...'),
64-
'aws.login',
65-
undefined,
66-
localize('AWS.explorerNode.signIn.tooltip', 'Connect to AWS using a credential profile')
73+
element,
74+
localize('AWS.explorerNode.error.retry', 'Unable to get child nodes, click here to retry'),
75+
'aws.refreshAwsExplorerNode',
76+
[this, element],
77+
error.message
6778
)
68-
]
79+
)
6980
}
7081

71-
const explorerRegionCodes = await this.awsContext.getExplorerRegions()
72-
const regionMap = toMap(await this.regionProvider.getRegionData(), r => r.regionCode)
73-
74-
updateInPlace(
75-
this.regionNodes,
76-
intersection(regionMap.keys(), explorerRegionCodes),
77-
key => this.regionNodes.get(key)!.update(regionMap.get(key)!),
78-
key => new RegionNode(regionMap.get(key)!, this.regionProvider)
79-
)
80-
81-
if (this.regionNodes.size > 0) {
82-
return [...this.regionNodes.values()]
83-
} else {
84-
return [
85-
new AWSCommandTreeNode(
86-
undefined,
87-
localize('AWS.explorerNode.addRegion', 'Click to add a region to view functions...'),
88-
'aws.showRegion',
89-
undefined,
90-
localize('AWS.explorerNode.addRegion.tooltip', 'Configure a region to show available functions')
91-
)
92-
]
93-
}
82+
return childNodes
9483
}
9584

9685
public getRegionNodesSize() {
@@ -100,4 +89,32 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
10089
public refresh(node?: AWSTreeNodeBase) {
10190
this._onDidChangeTreeData.fire(node)
10291
}
92+
93+
private async getRootNodes(): Promise<AWSTreeNodeBase[]> {
94+
if (!(await this.awsContext.getCredentials())) {
95+
return [ROOT_NODE_SIGN_IN]
96+
}
97+
98+
const userVisibleRegionCodes = await this.awsContext.getExplorerRegions()
99+
const regionMap = toMap(await this.regionProvider.getRegionData(), r => r.regionCode)
100+
101+
return await makeChildrenNodes({
102+
getChildNodes: async () => {
103+
updateInPlace(
104+
this.regionNodes,
105+
intersection(regionMap.keys(), userVisibleRegionCodes),
106+
key => this.regionNodes.get(key)!.update(regionMap.get(key)!),
107+
key => new RegionNode(regionMap.get(key)!, this.regionProvider)
108+
)
109+
110+
return [...this.regionNodes.values()]
111+
},
112+
getErrorNode: async (error: Error) => {
113+
// Let the calling function handle the error
114+
throw error
115+
},
116+
getNoChildrenPlaceholderNode: async () => ROOT_NODE_ADD_REGION,
117+
sort: (nodeA: RegionNode, nodeB: RegionNode) => nodeA.regionName.localeCompare(nodeB.regionName)
118+
})
119+
}
103120
}

0 commit comments

Comments
 (0)