Skip to content

Commit af08466

Browse files
authored
Sort CloudFormation Stack Resource nodes (#816)
* AWS Explorer now sorts the resources that belong to each CloudFormation Stack * Typo fix
1 parent d40367b commit af08466

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "AWS Explorer now sorts the resources that belong to each CloudFormation Stack"
4+
}

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"AWS.explorerNode.addRegion": "Add a region to view functions...",
5050
"AWS.explorerNode.addRegion.tooltip": "Click to add a region to view functions...",
5151
"AWS.explorerNode.lambda.noFunctions": "[No Functions found]",
52-
"AWS.explorerNode.cloudFormation.noFunctions": "[no functions in this CloudFormation]",
52+
"AWS.explorerNode.cloudFormation.noFunctions": "[Stack has no Lambda Functions]",
5353
"AWS.explorerNode.cloudformation.noStacks": "[No Stacks found]",
5454
"AWS.explorerNode.cloudFormation.error": "Error loading CloudFormation resources",
5555
"AWS.explorerNode.container.noItems": "[no items]",

src/lambda/explorer/cloudFormationNodes.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import * as vscode from 'vscode'
1212
import { CloudFormationClient } from '../../shared/clients/cloudFormationClient'
1313
import { LambdaClient } from '../../shared/clients/lambdaClient'
1414
import { ext } from '../../shared/extensionGlobals'
15-
import { AWSTreeErrorHandlerNode } from '../../shared/treeview/nodes/awsTreeErrorHandlerNode'
1615
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
1716
import { ErrorNode } from '../../shared/treeview/nodes/errorNode'
1817
import { PlaceholderNode } from '../../shared/treeview/nodes/placeholderNode'
@@ -64,7 +63,7 @@ export class CloudFormationNode extends AWSTreeNodeBase {
6463
}
6564
}
6665

67-
export class CloudFormationStackNode extends AWSTreeErrorHandlerNode {
66+
export class CloudFormationStackNode extends AWSTreeNodeBase {
6867
private readonly functionNodes: Map<string, LambdaFunctionNode>
6968

7069
public constructor(
@@ -91,26 +90,27 @@ export class CloudFormationStackNode extends AWSTreeErrorHandlerNode {
9190
return this.stackSummary.StackName
9291
}
9392

94-
public async getChildren(): Promise<(LambdaFunctionNode | PlaceholderNode)[]> {
95-
await this.handleErrorProneOperation(
96-
async () => this.updateChildren(),
97-
localize('AWS.explorerNode.cloudFormation.error', 'Error loading CloudFormation resources')
98-
)
99-
100-
if (!!this.errorNode) {
101-
return [this.errorNode]
102-
}
103-
104-
if (this.functionNodes.size > 0) {
105-
return [...this.functionNodes.values()]
106-
}
93+
public async getChildren(): Promise<AWSTreeNodeBase[]> {
94+
return await makeChildrenNodes({
95+
getChildNodes: async () => {
96+
await this.updateChildren()
10797

108-
return [
109-
new PlaceholderNode(
110-
this,
111-
localize('AWS.explorerNode.cloudFormation.noFunctions', '[no functions in this CloudFormation]')
112-
)
113-
]
98+
return [...this.functionNodes.values()]
99+
},
100+
getErrorNode: async (error: Error) =>
101+
new ErrorNode(
102+
this,
103+
error,
104+
localize('AWS.explorerNode.cloudFormation.error', 'Error loading CloudFormation resources')
105+
),
106+
getNoChildrenPlaceholderNode: async () =>
107+
new PlaceholderNode(
108+
this,
109+
localize('AWS.explorerNode.cloudFormation.noFunctions', '[Stack has no Lambda Functions]')
110+
),
111+
sort: (nodeA: LambdaFunctionNode, nodeB: LambdaFunctionNode) =>
112+
nodeA.functionName.localeCompare(nodeB.functionName)
113+
})
114114
}
115115

116116
public update(stackSummary: CloudFormation.StackSummary): void {

src/shared/treeview/treeNodeUtilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function makeChildrenNodes(parameters: {
2929
}
3030
} catch (err) {
3131
const error = err as Error
32-
getLogger().error(`Error whlie getting Child nodes: ${error.message}`)
32+
getLogger().error(`Error while getting Child nodes: ${error.message}`)
3333

3434
childNodes.push(await parameters.getErrorNode(error))
3535
}

src/test/lambda/explorer/cloudFormationNodes.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,15 @@ describe('CloudFormationStackNode', () => {
132132
)
133133
})
134134

135-
// TODO : CloudFormation Stack Nodes don't sort their child nodes
136-
// TODO : https://github.com/aws/aws-toolkit-vscode/issues/813
137-
// it('sorts child nodes', async () => {
138-
// lambdaFunctionNames = UNSORTED_TEXT
139-
// cloudFormationStacklambdaFunctionNames = UNSORTED_TEXT
135+
it('sorts child nodes', async () => {
136+
lambdaFunctionNames = UNSORTED_TEXT
137+
cloudFormationStacklambdaFunctionNames = UNSORTED_TEXT
140138

141-
// const childNodes = await testNode.getChildren()
139+
const childNodes = await testNode.getChildren()
142140

143-
// const actualChildOrder = childNodes.map(node => node.label)
144-
// assert.deepStrictEqual(actualChildOrder, SORTED_TEXT, 'Unexpected child sort order')
145-
// })
141+
const actualChildOrder = childNodes.map(node => node.label)
142+
assert.deepStrictEqual(actualChildOrder, SORTED_TEXT, 'Unexpected child sort order')
143+
})
146144

147145
it('has an error node for a child if an error happens during loading', async () => {
148146
const lambdaClient = {

0 commit comments

Comments
 (0)