Skip to content

Commit c1a40a3

Browse files
committed
refactor: add abort controller support to getAppDetail and improve error handling in EAAppDetail component
1 parent c77d31a commit c1a40a3

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/components/external-apps/ExternalAppService.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { get, put, trash, ResponseType, AppType, getUrlWithSearchParams, getAPIOptionsWithTriggerTimeout } from '@devtron-labs/devtron-fe-common-lib'
17+
import {
18+
get,
19+
put,
20+
trash,
21+
ResponseType,
22+
AppType,
23+
getUrlWithSearchParams,
24+
getAPIOptionsWithTriggerTimeout,
25+
APIOptions,
26+
} from '@devtron-labs/devtron-fe-common-lib'
1827
import { Routes } from '../../config'
1928
import { HelmApp, AppEnvironmentDetail } from '../app/list-new/AppListType'
2029
import { ResourceTree } from '../v2/appDetails/appDetails.type'
@@ -132,9 +141,12 @@ export const getReleaseInfo = (appId: string): Promise<ReleaseInfoResponse> => {
132141
return get(url)
133142
}
134143

135-
export const getAppDetail = (appId: string): Promise<HelmAppDetailResponse> => {
144+
export const getAppDetail = async (
145+
appId: string,
146+
abortControllerRef?: APIOptions['abortControllerRef'],
147+
): Promise<HelmAppDetailResponse> => {
136148
const url = `${Routes.HELM_RELEASE_APP_DETAIL_API}?appId=${appId}`
137-
return get(url)
149+
return get(url, { abortControllerRef })
138150
}
139151

140152
export const getArgoAppDetail = (appName: string, clusterId: string, namespace: string) => {

src/components/v2/appDetails/ea/EAAppDetail.component.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useState, useEffect } from 'react'
17+
import { useState, useEffect, useRef } from 'react'
1818
import { useLocation, useHistory } from 'react-router-dom'
1919
import {
2020
showError,
2121
Progressing,
2222
ErrorScreenManager,
2323
ServerErrors,
2424
DeploymentAppTypes,
25+
getIsRequestAborted,
2526
} from '@devtron-labs/devtron-fe-common-lib'
2627
import moment from 'moment'
2728
import { sortOptionsByValue } from '../../../common'
@@ -49,13 +50,17 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
4950
})
5051
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(false)
5152

53+
const abortControllerRef = useRef<AbortController>(new AbortController())
54+
5255
let initTimer = null
5356
let isAPICallInProgress = false
5457

5558
// component load
5659
useEffect(() => {
5760
_init()
5861
return (): void => {
62+
abortControllerRef.current.abort()
63+
5964
if (initTimer) {
6065
clearTimeout(initTimer)
6166
}
@@ -120,7 +125,7 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
120125
const _getAndSetAppDetail = () => {
121126
isAPICallInProgress = true
122127
setIsReloadResourceTreeInProgress(true)
123-
getAppDetail(appId)
128+
getAppDetail(appId, abortControllerRef)
124129
.then((appDetailResponse: HelmAppDetailResponse) => {
125130
IndexStore.publishAppDetails(
126131
_convertToGenericAppDetailModel(appDetailResponse.result),
@@ -159,8 +164,11 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
159164
setErrorResponseCode(undefined)
160165
})
161166
.catch((errors: ServerErrors) => {
162-
showError(errors)
163-
setErrorResponseCode(errors.code)
167+
if (!getIsRequestAborted(errors)) {
168+
showError(errors)
169+
setErrorResponseCode(errors.code)
170+
}
171+
164172
setIsLoading(false)
165173
isAPICallInProgress = false
166174
})

0 commit comments

Comments
 (0)