Skip to content

Commit 2554022

Browse files
authored
util: add guessDefaultRegion (#2718)
## Problem Currently, there is not a strong default for what region the user is working with. Internally, it can be difficult to know what region to have defaulted in Wizards or other selections. ## Solution We can solve this by implementing a heuristic `guessDefaultRegion` function that tracks what regions the user is working with in the explorer and makes a guess on what region the user wants to continue to work with.
1 parent df69e75 commit 2554022

File tree

21 files changed

+143
-38
lines changed

21 files changed

+143
-38
lines changed

src/apigateway/explorer/apiGatewayNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import globals from '../../shared/extensionGlobals'
2323
export class ApiGatewayNode extends AWSTreeNodeBase {
2424
private readonly apiNodes: Map<string, RestApiNode>
2525

26-
public constructor(private readonly partitionId: string, private readonly regionCode: string) {
26+
public constructor(private readonly partitionId: string, public readonly regionCode: string) {
2727
super('API Gateway', vscode.TreeItemCollapsibleState.Collapsed)
2828
this.apiNodes = new Map<string, RestApiNode>()
2929
}

src/apprunner/commands/createService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function createAppRunnerService(node: AppRunnerNode): Promise<void>
1212
let source: telemetry.AppRunnerServiceSource | undefined = undefined
1313

1414
try {
15-
const wizard = new CreateAppRunnerServiceWizard(node.region)
15+
const wizard = new CreateAppRunnerServiceWizard(node.regionCode)
1616
const result = await wizard.run()
1717
if (result === undefined) {
1818
telemetryResult = 'Cancelled'

src/apprunner/explorer/apprunnerNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class AppRunnerNode extends AWSTreeNodeBase {
2121
private readonly pollingNodes: Set<string> = new Set()
2222
private pollTimer?: NodeJS.Timeout
2323

24-
public constructor(public readonly region: string, public readonly client: AppRunnerClient) {
24+
public constructor(public readonly regionCode: string, public readonly client: AppRunnerClient) {
2525
super('App Runner', vscode.TreeItemCollapsibleState.Collapsed)
2626
this.contextValue = 'awsAppRunnerNode'
2727
}

src/apprunner/explorer/apprunnerServiceNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AppRunnerServiceNode extends CloudWatchLogsBase implements AWSResou
4545
) {
4646
super(
4747
'App Runner Service',
48-
parent.region,
48+
parent.regionCode,
4949
localize('AWS.explorerNode.apprunner.nologs', '[No App Runner logs found]')
5050
)
5151
this.iconPath = getIcon('aws-apprunner-service')

src/awsexplorer/awsExplorer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
8181
}
8282

8383
public async getChildren(element?: AWSTreeNodeBase): Promise<AWSTreeNodeBase[]> {
84+
if (element) {
85+
this.awsContext.setLastTouchedRegion(element.regionCode)
86+
}
87+
8488
let childNodes: AWSTreeNodeBase[] = []
8589

8690
try {

src/awsexplorer/regionNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ import globals from '../shared/extensionGlobals'
3333
export class RegionNode extends AWSTreeNodeBase {
3434
private region: Region
3535
private readonly childNodes: AWSTreeNodeBase[] = []
36+
public readonly regionCode: string
3637

37-
public get regionCode(): string {
38-
return this.region.id
39-
}
4038
public get regionName(): string {
4139
return this.region.name
4240
}
@@ -45,6 +43,7 @@ export class RegionNode extends AWSTreeNodeBase {
4543
super(region.name, TreeItemCollapsibleState.Expanded)
4644
this.contextValue = 'awsRegionNode'
4745
this.region = region
46+
this.regionCode = region.id
4847
this.update(region)
4948

5049
// Services that are candidates to add to the region explorer.

src/cloudWatchLogs/explorer/cloudWatchLogsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export abstract class CloudWatchLogsBase extends AWSTreeNodeBase {
2323

2424
public constructor(
2525
label: string,
26-
protected readonly regionCode: string,
26+
public readonly regionCode: string,
2727
protected placeholderMessage: string = localize(
2828
'AWS.explorerNode.cloudWatchLogs.nologs',
2929
'[No log groups found]'

src/eventSchemas/explorer/registryItemNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { SchemaClient } from '../../shared/clients/schemaClient'
2222

2323
export class RegistryItemNode extends AWSTreeNodeBase {
2424
private readonly schemaNodes: Map<string, SchemaItemNode>
25+
public readonly regionCode: string = this.client.regionCode
2526

2627
public constructor(private registryItemOutput: Schemas.RegistrySummary, private readonly client: SchemaClient) {
2728
super('', vscode.TreeItemCollapsibleState.Collapsed)
@@ -32,10 +33,6 @@ export class RegistryItemNode extends AWSTreeNodeBase {
3233
this.iconPath = getIcon('aws-schemas-registry')
3334
}
3435

35-
public get regionCode() {
36-
return this.client.regionCode
37-
}
38-
3936
public get registryName(): string {
4037
return (
4138
this.registryItemOutput.RegistryName ||

src/eventSchemas/explorer/schemasNode.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ import { SchemaClient } from '../../shared/clients/schemaClient'
1818

1919
export class SchemasNode extends AWSTreeNodeBase {
2020
private readonly registryNodes: Map<string, RegistryItemNode>
21+
public readonly regionCode = this.client.regionCode
2122

2223
public constructor(private readonly client: SchemaClient) {
2324
super('Schemas', vscode.TreeItemCollapsibleState.Collapsed)
2425
this.registryNodes = new Map<string, RegistryItemNode>()
2526
this.contextValue = 'awsSchemasNode'
2627
}
2728

28-
public get regionCode() {
29-
return this.client.regionCode
30-
}
31-
3229
public async getChildren(): Promise<AWSTreeNodeBase[]> {
3330
return await makeChildrenNodes({
3431
getChildNodes: async () => {

src/integrationTest/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { runTestsInFolder } from '../test/testRunner'
6+
import { runTests } from '../test/testRunner'
77

88
export function run(): Promise<void> {
9-
return runTestsInFolder('src/integrationTest', ['src/integrationTest/globalSetup.test.ts'])
9+
return runTests('src/integrationTest', ['src/integrationTest/globalSetup.test.ts'])
1010
}

0 commit comments

Comments
 (0)