Skip to content

Commit 00d2e2e

Browse files
authored
fix(resources): handle duplicate resource types #3135
Problem AWS Explorer "Resources" tree: duplicate type definitions are not handled. #3132 Solution Use the most recently-updated definition. The CloudControl service should clarify this behavior in their API documentation. Duplicated, undifferentiated type definitions is unexpected. This may be a bug with the service itself.
1 parent 8ff4119 commit 00d2e2e

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
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": "Duplicate resource type definitions break the \"Resources\" node (#3132)"
4+
}

src/dynamicResources/explorer/nodes/resourcesNode.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CloudFormationClient, DefaultCloudFormationClient } from '../../../shar
99
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
1010
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
1111
import { makeChildrenNodes } from '../../../shared/treeview/utils'
12-
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
12+
import { toArrayAsync, updateInPlace } from '../../../shared/utilities/collectionUtils'
1313
import { ResourceTypeNode } from './resourceTypeNode'
1414
import { CloudFormation } from 'aws-sdk'
1515
import { CloudControlClient, DefaultCloudControlClient } from '../../../shared/clients/cloudControlClient'
@@ -60,10 +60,17 @@ export class ResourcesNode extends AWSTreeNodeBase {
6060
const defaultResources = isCloud9() ? Array.from(resourceTypes.keys()) : []
6161
const enabledResources = this.settings.get('enabledResources', defaultResources)
6262

63-
const availableTypes: Map<string, CloudFormation.TypeSummary> = toMap(
64-
await toArrayAsync(this.cloudFormation.listTypes()),
65-
type => type.TypeName
66-
)
63+
// Use the most recently update type definition per-type
64+
const types = await toArrayAsync(this.cloudFormation.listTypes())
65+
types.sort((a, b) => (a.LastUpdated?.getTime() ?? 0) - (b.LastUpdated?.getTime() ?? 0))
66+
67+
const availableTypes: Map<string, CloudFormation.TypeSummary> = new Map()
68+
for (const type of types) {
69+
if (type.TypeName) {
70+
availableTypes.set(type.TypeName!, type)
71+
}
72+
}
73+
6774
updateInPlace(
6875
this.resourceTypeNodes,
6976
enabledResources,

src/test/dynamicResources/explorer/moreResourcesNode.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ describe('ResourcesNode', function () {
8989
assert.deepStrictEqual(actualChildOrder, sortedText, 'Unexpected child sort order')
9090
})
9191

92+
it('handles duplicate type entries without failing', async function () {
93+
prepareMock(['type1', 'type2', 'type1'])
94+
const childNodes = await testNode.getChildren()
95+
assert.strictEqual(childNodes.length, 2, 'Unexpected child count')
96+
})
97+
9298
async function setConfiguration(resourceTypes: string[]) {
9399
await settings.update('enabledResources', resourceTypes)
94100
}

0 commit comments

Comments
 (0)