Skip to content

Commit 0a2a05a

Browse files
authored
API Gateway nodes include their IDs (#1471)
Prevents duplicate nodes. Renders in a way familiar to console users with ID in parenthesis trailing the API name
1 parent e7df1c6 commit 0a2a05a

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
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": "List API Gateway names with their ID (so Toolkit can list APIs with identical names)"
4+
}

src/apigateway/explorer/apiGatewayNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
4646
this,
4747
localize('AWS.explorerNode.apigateway.noApis', '[No API Gateway REST APIs found]')
4848
),
49-
sort: (nodeA: RestApiNode, nodeB: RestApiNode) => nodeA.name.localeCompare(nodeB.name),
49+
sort: (nodeA: RestApiNode, nodeB: RestApiNode) => nodeA.label!.localeCompare(nodeB.label!),
5050
})
5151
}
5252

5353
public async updateChildren(): Promise<void> {
5454
const client: ApiGatewayClient = ext.toolkitClientBuilder.createApiGatewayClient(this.regionCode)
5555
const apis: Map<string, RestApi> = toMap(
5656
await toArrayAsync(client.listApis()),
57-
configuration => configuration.name
57+
configuration => `${configuration.name} (${configuration.id})`
5858
)
5959

6060
updateInPlace(

src/apigateway/explorer/apiNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class RestApiNode extends AWSTreeNodeBase implements AWSResourceNode {
2121

2222
public update(api: RestApi): void {
2323
this.api = api
24-
this.label = this.api.name || ''
24+
this.label = `${this.api.name} (${this.api.id})` || ''
2525
this.tooltip = this.api.description
2626
}
2727

src/test/apigateway/explorer/apiGatewayNodes.test.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,34 @@ import { RestApiNode } from '../../../apigateway/explorer/apiNodes'
1818

1919
const FAKE_PARTITION_ID = 'aws'
2020
const FAKE_REGION_CODE = 'someregioncode'
21-
const UNSORTED_TEXT = ['zebra', 'Antelope', 'aardvark', 'elephant']
22-
const SORTED_TEXT = ['aardvark', 'Antelope', 'elephant', 'zebra']
21+
const UNSORTED_TEXT = [
22+
{ name: 'zebra', id: "it's zee not zed" },
23+
{ name: 'zebra', id: "it's actually zed" },
24+
{ name: 'Antelope', id: 'anti-antelope' },
25+
{ name: 'aardvark', id: 'a-a-r-d-vark' },
26+
{ name: 'elephant', id: 'trunk capacity' },
27+
]
28+
const SORTED_TEXT = [
29+
'aardvark (a-a-r-d-vark)',
30+
'Antelope (anti-antelope)',
31+
'elephant (trunk capacity)',
32+
"zebra (it's actually zed)",
33+
"zebra (it's zee not zed)",
34+
]
2335

2436
describe('ApiGatewayNode', () => {
2537
let sandbox: sinon.SinonSandbox
2638
let testNode: ApiGatewayNode
2739

28-
let apiNames: string[]
40+
let apiNames: { name: string; id: string }[]
2941

3042
beforeEach(() => {
3143
sandbox = sinon.createSandbox()
3244

33-
apiNames = ['api1', 'api2']
45+
apiNames = [
46+
{ name: 'api1', id: '11111' },
47+
{ name: 'api2', id: '22222' },
48+
]
3449

3550
initializeClientBuilders()
3651

@@ -79,9 +94,10 @@ describe('ApiGatewayNode', () => {
7994
const apiGatewayClient = {
8095
listApis: sandbox.stub().callsFake(() => {
8196
return asyncGenerator<RestApi>(
82-
apiNames.map<RestApi>(name => {
97+
apiNames.map<RestApi>(({ name, id }) => {
8398
return {
84-
name: name,
99+
name,
100+
id,
85101
}
86102
})
87103
)

0 commit comments

Comments
 (0)