@@ -28,77 +28,97 @@ import { DefaultSchemaClient } from '../shared/clients/schemaClient'
28
28
import { getEcsRootNode } from '../ecs/model'
29
29
import { TreeShim } from '../shared/treeview/utils'
30
30
31
+ const serviceCandidates = [
32
+ {
33
+ serviceId : 'apigateway' ,
34
+ createFn : ( regionCode : string , partitionId : string ) => new ApiGatewayNode ( partitionId , regionCode ) ,
35
+ } ,
36
+ {
37
+ serviceId : 'apprunner' ,
38
+ createFn : ( regionCode : string ) => new AppRunnerNode ( regionCode , new DefaultAppRunnerClient ( regionCode ) ) ,
39
+ } ,
40
+ {
41
+ serviceId : 'cloudformation' ,
42
+ createFn : ( regionCode : string ) => new CloudFormationNode ( regionCode ) ,
43
+ } ,
44
+ {
45
+ serviceId : 'logs' ,
46
+ createFn : ( regionCode : string ) => new CloudWatchLogsNode ( regionCode ) ,
47
+ } ,
48
+ {
49
+ serviceId : 'ecr' ,
50
+ createFn : ( regionCode : string ) => new EcrNode ( new DefaultEcrClient ( regionCode ) ) ,
51
+ } ,
52
+ {
53
+ serviceId : 'ecs' ,
54
+ createFn : ( regionCode : string ) => new TreeShim ( getEcsRootNode ( regionCode ) ) ,
55
+ } ,
56
+ {
57
+ serviceId : 'iot' ,
58
+ createFn : ( regionCode : string ) => new IotNode ( new DefaultIotClient ( regionCode ) ) ,
59
+ } ,
60
+ {
61
+ serviceId : 'lambda' ,
62
+ createFn : ( regionCode : string ) => new LambdaNode ( regionCode ) ,
63
+ } ,
64
+ {
65
+ serviceId : 's3' ,
66
+ createFn : ( regionCode : string ) => new S3Node ( new DefaultS3Client ( regionCode ) ) ,
67
+ } ,
68
+ {
69
+ serviceId : 'schemas' ,
70
+ createFn : ( regionCode : string ) =>
71
+ ! isCloud9 ( ) ? new SchemasNode ( new DefaultSchemaClient ( regionCode ) ) : undefined ,
72
+ } ,
73
+ {
74
+ serviceId : 'states' ,
75
+ createFn : ( regionCode : string ) => new StepFunctionsNode ( regionCode ) ,
76
+ } ,
77
+ {
78
+ serviceId : 'ssm' ,
79
+ createFn : ( regionCode : string ) => new SsmDocumentNode ( regionCode ) ,
80
+ } ,
81
+ ]
82
+
31
83
/**
32
84
* An AWS Explorer node representing a region.
33
85
* Contains resource types as child nodes (for example, nodes representing
34
86
* an account's Lambda Functions and CloudFormation stacks for this region)
35
87
*/
36
88
export class RegionNode extends AWSTreeNodeBase {
37
89
private region : Region
38
- private readonly childNodes : AWSTreeNodeBase [ ] = [ ]
39
90
public readonly regionCode : string
40
91
41
92
public get regionName ( ) : string {
42
93
return this . region . name
43
94
}
44
95
45
- public constructor ( region : Region , regionProvider : RegionProvider ) {
96
+ public constructor ( region : Region , private readonly regionProvider : RegionProvider ) {
46
97
super ( region . name , TreeItemCollapsibleState . Expanded )
47
98
this . contextValue = 'awsRegionNode'
48
99
this . region = region
49
100
this . regionCode = region . id
50
101
this . update ( region )
102
+ }
51
103
104
+ public async getChildren ( ) : Promise < AWSTreeNodeBase [ ] > {
52
105
// Services that are candidates to add to the region explorer.
53
106
// `serviceId`s are checked against ~/resources/endpoints.json to see whether or not the service is available in the given region.
54
107
// If the service is available, we use the `createFn` to generate the node for the region.
55
108
// This interface exists so we can add additional nodes to the array (otherwise Typescript types the array to what's already in the array at creation)
56
- const partitionId = regionProvider . getPartitionId ( this . regionCode ) ?? DEFAULT_PARTITION
57
- const serviceCandidates = [
58
- { serviceId : 'apigateway' , createFn : ( ) => new ApiGatewayNode ( partitionId , this . regionCode ) } ,
59
- {
60
- serviceId : 'apprunner' ,
61
- createFn : ( ) => new AppRunnerNode ( this . regionCode , new DefaultAppRunnerClient ( this . regionCode ) ) ,
62
- } ,
63
- { serviceId : 'cloudformation' , createFn : ( ) => new CloudFormationNode ( this . regionCode ) } ,
64
- { serviceId : 'logs' , createFn : ( ) => new CloudWatchLogsNode ( this . regionCode ) } ,
65
- {
66
- serviceId : 'ecr' ,
67
- createFn : ( ) => new EcrNode ( new DefaultEcrClient ( this . regionCode ) ) ,
68
- } ,
69
- {
70
- serviceId : 'ecs' ,
71
- createFn : ( ) => new TreeShim ( getEcsRootNode ( this . regionCode ) ) ,
72
- } ,
73
- {
74
- serviceId : 'iot' ,
75
- createFn : ( ) => new IotNode ( new DefaultIotClient ( this . regionCode ) ) ,
76
- } ,
77
- { serviceId : 'lambda' , createFn : ( ) => new LambdaNode ( this . regionCode ) } ,
78
- {
79
- serviceId : 's3' ,
80
- createFn : ( ) => new S3Node ( new DefaultS3Client ( this . regionCode ) ) ,
81
- } ,
82
- ...( isCloud9 ( )
83
- ? [ ]
84
- : [
85
- {
86
- serviceId : 'schemas' ,
87
- createFn : ( ) => new SchemasNode ( new DefaultSchemaClient ( this . regionCode ) ) ,
88
- } ,
89
- ] ) ,
90
- { serviceId : 'states' , createFn : ( ) => new StepFunctionsNode ( this . regionCode ) } ,
91
- { serviceId : 'ssm' , createFn : ( ) => new SsmDocumentNode ( this . regionCode ) } ,
92
- ]
93
-
94
- for ( const serviceCandidate of serviceCandidates ) {
95
- this . addChildNodeIfInRegion ( serviceCandidate . serviceId , regionProvider , serviceCandidate . createFn )
109
+ const partitionId = this . regionProvider . getPartitionId ( this . regionCode ) ?? DEFAULT_PARTITION
110
+ const childNodes : AWSTreeNodeBase [ ] = [ ]
111
+ for ( const { serviceId, createFn } of serviceCandidates ) {
112
+ if ( this . regionProvider . isServiceInRegion ( serviceId , this . regionCode ) ) {
113
+ const node = createFn ( this . regionCode , partitionId )
114
+ if ( node !== undefined ) {
115
+ childNodes . push ( node )
116
+ }
117
+ }
96
118
}
97
- this . childNodes . push ( new ResourcesNode ( this . regionCode ) )
98
- }
119
+ childNodes . push ( new ResourcesNode ( this . regionCode ) )
99
120
100
- public async getChildren ( ) : Promise < AWSTreeNodeBase [ ] > {
101
- return this . sortNodes ( this . childNodes )
121
+ return this . sortNodes ( childNodes )
102
122
}
103
123
104
124
private sortNodes ( nodes : AWSTreeNodeBase [ ] ) {
@@ -116,14 +136,4 @@ export class RegionNode extends AWSTreeNodeBase {
116
136
this . label = this . regionName
117
137
this . tooltip = `${ this . regionName } [${ this . regionCode } ]`
118
138
}
119
-
120
- private addChildNodeIfInRegion (
121
- serviceId : string ,
122
- regionProvider : RegionProvider ,
123
- childNodeProducer : ( ) => AWSTreeNodeBase
124
- ) {
125
- if ( regionProvider . isServiceInRegion ( serviceId , this . regionCode ) ) {
126
- this . childNodes . push ( childNodeProducer ( ) )
127
- }
128
- }
129
139
}
0 commit comments