Skip to content

Commit bd58f9e

Browse files
authored
ec2: add icons as additional entrypoints to explorer. (#3656)
Problem: Explorer implementation feels non-interactive, and there is no way to search for a specific instance without opening command prompt. Solution: -terminal icons on EC2 instance nodes that function as entry point to `aws.ec2.openTerminal` (skipping selection). -terminal icon on EC2 parent node that functions as entry point to `aws.ec2.connectToInstance` without skipping selection.
1 parent 9c25c83 commit bd58f9e

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,11 @@
13171317
"group": "0@1",
13181318
"when": "viewItem == awsEc2Node"
13191319
},
1320+
{
1321+
"command": "aws.ec2.openTerminal",
1322+
"group": "inline@1",
1323+
"when": "viewItem == awsEc2Node"
1324+
},
13201325
{
13211326
"command": "aws.ecr.createRepository",
13221327
"when": "view == aws.explorer && viewItem == awsEcrNode",
@@ -2062,6 +2067,7 @@
20622067
{
20632068
"command": "aws.ec2.openTerminal",
20642069
"title": "%AWS.command.ec2.openTerminal%",
2070+
"icon": "$(terminal-view-icon)",
20652071
"category": "%AWS.title%",
20662072
"cloud9": {
20672073
"cn": {

src/ec2/activation.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@
55
import { ExtContext } from '../shared/extensions'
66
import { Commands } from '../shared/vscode/commands2'
77
import { telemetry } from '../shared/telemetry/telemetry'
8-
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
9-
import { promptUserForEc2Selection } from './prompter'
10-
import { Ec2ConnectionManager } from './model'
8+
import { Ec2Node } from './explorer/ec2ParentNode'
9+
import { openRemoteConnection, openTerminal } from './commands'
1110

1211
export async function activate(ctx: ExtContext): Promise<void> {
1312
ctx.extensionContext.subscriptions.push(
14-
Commands.register('aws.ec2.openTerminal', async (node?: Ec2InstanceNode) => {
13+
Commands.register('aws.ec2.openTerminal', async (node?: Ec2Node) => {
1514
await telemetry.ec2_connectToInstance.run(async span => {
1615
span.record({ ec2ConnectionType: 'ssm' })
17-
const selection = node ? node.toSelection() : await promptUserForEc2Selection()
18-
19-
const connectionManager = new Ec2ConnectionManager(selection.region)
20-
await connectionManager.attemptToOpenEc2Terminal(selection)
16+
await (node ? openTerminal(node) : openTerminal(node))
2117
})
2218
}),
2319

24-
Commands.register('aws.ec2.openRemoteConnection', async (node?: Ec2InstanceNode) => {
25-
const selection = node ? node.toSelection() : await promptUserForEc2Selection()
26-
//const connectionManager = new Ec2ConnectionManager(selection.region)
27-
console.log(selection)
20+
Commands.register('aws.ec2.openRemoteConnection', async (node?: Ec2Node) => {
21+
await (node ? openRemoteConnection(node) : openRemoteConnection(node))
2822
})
2923
)
3024
}

src/ec2/commands.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
7+
import { Ec2Node } from './explorer/ec2ParentNode'
8+
import { Ec2ConnectionManager } from './model'
9+
import { promptUserForEc2Selection } from './prompter'
10+
11+
export async function openTerminal(node?: Ec2Node) {
12+
const selection = node instanceof Ec2InstanceNode ? node.toSelection() : await promptUserForEc2Selection()
13+
14+
const connectionManager = new Ec2ConnectionManager(selection.region)
15+
await connectionManager.attemptToOpenEc2Terminal(selection)
16+
}
17+
18+
export async function openRemoteConnection(node?: Ec2Node) {
19+
const selection = node instanceof Ec2InstanceNode ? node.toSelection() : await promptUserForEc2Selection()
20+
//const connectionManager = new Ec2ConnectionManager(selection.region)
21+
console.log(selection)
22+
}

src/ec2/explorer/ec2ParentNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import { Ec2Client } from '../../shared/clients/ec2Client'
1111
import { updateInPlace } from '../../shared/utilities/collectionUtils'
1212

1313
export const contextValueEc2 = 'awsEc2Node'
14+
export type Ec2Node = Ec2InstanceNode | Ec2ParentNode
1415

1516
export class Ec2ParentNode extends AWSTreeNodeBase {
1617
protected readonly placeHolderMessage = '[No EC2 Instances Found]'
1718
protected readonly ec2InstanceNodes: Map<string, Ec2InstanceNode>
19+
public override readonly contextValue: string = contextValueEc2
1820

1921
public constructor(
2022
public override readonly regionCode: string,

src/ec2/prompter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function handleEc2ConnectPrompterResponse(response: RegionSubmenuResponse
3939
export function createEc2ConnectPrompter(): RegionSubmenu<string> {
4040
return new RegionSubmenu(
4141
async region => (await getInstancesFromRegion(region)).map(asQuickpickItem).promise(),
42-
{ title: 'Select EC2 Instance Id', matchOnDetail: true },
42+
{ title: 'Select EC2 Instance', matchOnDetail: true },
4343
{ title: 'Select Region for EC2 Instance' },
4444
'Instances'
4545
)

0 commit comments

Comments
 (0)