Skip to content

Commit d824fd5

Browse files
committed
refactor: implement abortPreviousRequests in multiple components to enhance API call management and error handling
1 parent b1e4164 commit d824fd5

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

src/Pages/App/Details/ExternalFlux/ExternalFluxAppDetails.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useEffect, useRef, useState } from 'react'
1818
import { useParams } from 'react-router-dom'
1919

2020
import {
21+
abortPreviousRequests,
2122
AppType,
2223
DeploymentAppTypes,
2324
ERROR_STATUS_CODE,
@@ -73,7 +74,11 @@ const ExternalFluxAppDetails = () => {
7374
new Promise<void>((resolve) => {
7475
setIsReloadResourceTreeInProgress(true)
7576

76-
getExternalFluxCDAppDetails({ clusterId, namespace, appName, isKustomization, abortControllerRef })
77+
abortPreviousRequests(
78+
() =>
79+
getExternalFluxCDAppDetails({ clusterId, namespace, appName, isKustomization, abortControllerRef }),
80+
abortControllerRef,
81+
)
7782
.then(handleUpdateIndexStoreWithDetails)
7883
.catch((error) => {
7984
if (!getIsRequestAborted(error)) {

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ServerErrors,
2424
DeploymentAppTypes,
2525
getIsRequestAborted,
26+
abortPreviousRequests,
2627
} from '@devtron-labs/devtron-fe-common-lib'
2728
import { getArgoAppDetail } from '../external-apps/ExternalAppService'
2829
import { checkIfToRefetchData, deleteRefetchDataFromUrl } from '../util/URLUtil'
@@ -77,7 +78,11 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
7778
const _getAndSetAppDetail = async () => {
7879
isAPICallInProgress = true
7980
setIsReloadResourceTreeInProgress(true)
80-
getArgoAppDetail({ appName, clusterId, namespace, abortControllerRef })
81+
82+
abortPreviousRequests(
83+
() => getArgoAppDetail({ appName, clusterId, namespace, abortControllerRef }),
84+
abortControllerRef,
85+
)
8186
.then((appDetailResponse) => {
8287
const genericAppDetail: AppDetails = {
8388
...appDetailResponse.result,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ServerErrors,
2424
DeploymentAppTypes,
2525
getIsRequestAborted,
26+
abortPreviousRequests,
2627
} from '@devtron-labs/devtron-fe-common-lib'
2728
import moment from 'moment'
2829
import { sortOptionsByValue } from '../../../common'
@@ -125,7 +126,8 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
125126
const _getAndSetAppDetail = () => {
126127
isAPICallInProgress = true
127128
setIsReloadResourceTreeInProgress(true)
128-
getAppDetail(appId, abortControllerRef)
129+
130+
abortPreviousRequests(() => getAppDetail(appId, abortControllerRef), abortControllerRef)
129131
.then((appDetailResponse: HelmAppDetailResponse) => {
130132
IndexStore.publishAppDetails(
131133
_convertToGenericAppDetailModel(appDetailResponse.result),

src/components/v2/appDetails/sourceInfo/scaleWorkloads/ScaleWorkloadsModal.component.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DeploymentAppTypes,
2525
TabGroup,
2626
getIsRequestAborted,
27+
abortPreviousRequests,
2728
} from '@devtron-labs/devtron-fe-common-lib'
2829
import { ReactComponent as Info } from '../../../../../assets/icons/ic-info-filled.svg'
2930
import { ReactComponent as Close } from '../../../../../assets/icons/ic-close.svg'
@@ -126,11 +127,16 @@ export default function ScaleWorkloadsModal({ appId, onClose, history }: ScaleWo
126127
const _getAndSetAppDetail = async () => {
127128
try {
128129
if (appDetails?.deploymentAppType === DeploymentAppTypes.GITOPS && isHelmApp) {
129-
const response = await getInstalledChartDetailWithResourceTree(
130-
+appDetails.installedAppId,
131-
+appDetails.environmentId,
130+
const response = await abortPreviousRequests(
131+
() =>
132+
getInstalledChartDetailWithResourceTree(
133+
+appDetails.installedAppId,
134+
+appDetails.environmentId,
135+
abortControllerRef,
136+
),
132137
abortControllerRef,
133138
)
139+
134140
IndexStore.publishAppDetails(response.result, AppType.DEVTRON_HELM_CHART)
135141
}
136142
} catch (e) {
@@ -398,7 +404,7 @@ export default function ScaleWorkloadsModal({ appId, onClose, history }: ScaleWo
398404
</div>
399405
</Checkbox>
400406
</div>
401-
<div className="h-192 dc__overflow-auto">
407+
<div className="h-192 dc__overflow-auto">
402408
{Array.from(_workloadsList.values()).map((item) => (
403409
<div key={`${item.kind}/${item.name}`} className="check-single-workload">
404410
<Checkbox

src/components/v2/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Suspense, useEffect, useRef, useState } from 'react'
1818
import { Redirect, Route, Switch, useHistory, useLocation, useParams, useRouteMatch } from 'react-router-dom'
1919

2020
import {
21+
abortPreviousRequests,
2122
DetailsProgressing,
2223
ErrorScreenManager,
2324
getIsRequestAborted,
@@ -108,14 +109,14 @@ const RouterComponent = ({ envType }) => {
108109
useEffect(() => {
109110
if (checkIfToRefetchData(location)) {
110111
setTimeout(() => {
111-
_getAndSetAppDetail(true)
112+
abortPreviousRequests(() => _getAndSetAppDetail(true), abortControllerRef)
112113
deleteRefetchDataFromUrl(history, location)
113114
}, 5000)
114115
}
115116
}, [location.search])
116117

117118
const _init = (fetchExternalLinks?: boolean) => {
118-
_getAndSetAppDetail(fetchExternalLinks)
119+
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks), abortControllerRef)
119120
initTimer = setTimeout(() => {
120121
_init()
121122
}, window._env_.HELM_APP_DETAILS_POLLING_INTERVAL || 30000)
@@ -183,7 +184,10 @@ const RouterComponent = ({ envType }) => {
183184
const handleReloadResourceTree = () => {
184185
if (envType === EnvType.CHART) {
185186
setIsReloadResourceTreeInProgress(true)
186-
getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef)
187+
abortPreviousRequests(
188+
() => getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef),
189+
abortControllerRef,
190+
)
187191
.then(handlePublishAppDetails)
188192
.catch((err) => {
189193
if (!getIsRequestAborted(err)) {

0 commit comments

Comments
 (0)