@@ -116,10 +116,7 @@ const RouterComponent = ({ envType }) => {
116
116
} , [ location . search ] )
117
117
118
118
const _init = ( fetchExternalLinks ?: boolean ) => {
119
- abortPreviousRequests ( ( ) => _getAndSetAppDetail ( fetchExternalLinks ) , abortControllerRef )
120
- initTimer = setTimeout ( ( ) => {
121
- _init ( )
122
- } , window . _env_ . HELM_APP_DETAILS_POLLING_INTERVAL || 30000 )
119
+ abortPreviousRequests ( ( ) => _getAndSetAppDetail ( fetchExternalLinks , true ) , abortControllerRef )
123
120
}
124
121
125
122
const handleAppDetailsCallError = ( e : any ) => {
@@ -143,30 +140,50 @@ const RouterComponent = ({ envType }) => {
143
140
setErrorResponseCode ( undefined )
144
141
}
145
142
146
- const _getAndSetAppDetail = async ( fetchExternalLinks : boolean ) => {
147
- if ( envType === EnvType . CHART ) {
148
- // Get App Details
149
- getInstalledChartDetail ( + params . appId , + params . envId , abortControllerRef )
150
- . then ( ( response ) => {
151
- handlePublishAppDetails ( response )
152
- isVirtualRef . current = response . result ?. isVirtualEnvironment
153
- setHelmAppPackageName ( response . result ?. helmPackageName )
154
- if ( fetchExternalLinks ) {
155
- getExternalLinksAndTools ( response . result ?. clusterId )
156
- }
157
- } )
158
- . catch ( handleAppDetailsCallError )
159
- . finally ( ( ) => {
160
- setLoadingDetails ( false )
161
- } )
143
+ const handleInitiatePolling = ( ) => {
144
+ initTimer = setTimeout ( ( ) => {
145
+ _init ( )
146
+ } , window . _env_ . HELM_APP_DETAILS_POLLING_INTERVAL || 30000 )
147
+ }
162
148
163
- // Get App Resource Tree
164
- getInstalledChartResourceTree ( + params . appId , + params . envId , abortControllerRef )
165
- . then ( handlePublishAppDetails )
166
- . catch ( handleAppDetailsCallError )
167
- . finally ( ( ) => {
168
- setLoadingResourceTree ( false )
169
- } )
149
+ const handleFetchAppDetails = async ( fetchExternalLinks : boolean ) => {
150
+ try {
151
+ const response = await getInstalledChartDetail ( + params . appId , + params . envId , abortControllerRef )
152
+ handlePublishAppDetails ( response )
153
+ isVirtualRef . current = response . result ?. isVirtualEnvironment
154
+ setHelmAppPackageName ( response . result ?. helmPackageName )
155
+ if ( fetchExternalLinks ) {
156
+ getExternalLinksAndTools ( response . result ?. clusterId )
157
+ }
158
+ } catch ( error ) {
159
+ handleAppDetailsCallError ( error )
160
+ } finally {
161
+ setLoadingDetails ( false )
162
+ }
163
+ }
164
+
165
+ const handleFetchResourceTree = async ( ) => {
166
+ try {
167
+ const response = await getInstalledChartResourceTree ( + params . appId , + params . envId , abortControllerRef )
168
+ handlePublishAppDetails ( response )
169
+ } catch ( error ) {
170
+ handleAppDetailsCallError ( error )
171
+ } finally {
172
+ setLoadingResourceTree ( false )
173
+ }
174
+ }
175
+
176
+ const _getAndSetAppDetail = async ( fetchExternalLinks : boolean , shouldTriggerPolling : boolean = false ) => {
177
+ if ( envType === EnvType . CHART ) {
178
+ // Intentionally not setting await since it was not awaited earlier when in thens as well
179
+ Promise . allSettled ( [
180
+ handleFetchAppDetails ( fetchExternalLinks ) ,
181
+ handleFetchResourceTree ( ) ,
182
+ ] ) . finally ( ( ) => {
183
+ if ( shouldTriggerPolling ) {
184
+ handleInitiatePolling ( )
185
+ }
186
+ } )
170
187
} else {
171
188
try {
172
189
// Revisit this flow
@@ -177,6 +194,10 @@ const RouterComponent = ({ envType }) => {
177
194
if ( e . code ) {
178
195
setErrorResponseCode ( e . code )
179
196
}
197
+ } finally {
198
+ if ( shouldTriggerPolling ) {
199
+ handleInitiatePolling ( )
200
+ }
180
201
}
181
202
}
182
203
}
0 commit comments