Skip to content

Commit f9747c1

Browse files
committed
refactor: update API calls in ExternalFlux and ExternalArgo components to use structured parameters and enhance type safety
1 parent 60fbcec commit f9747c1

File tree

7 files changed

+54
-37
lines changed

7 files changed

+54
-37
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const ExternalFluxAppDetails = () => {
7373
new Promise<void>((resolve) => {
7474
setIsReloadResourceTreeInProgress(true)
7575

76-
getExternalFluxCDAppDetails(clusterId, namespace, appName, isKustomization, abortControllerRef)
76+
getExternalFluxCDAppDetails({ clusterId, namespace, appName, isKustomization, abortControllerRef })
7777
.then(handleUpdateIndexStoreWithDetails)
7878
.catch((error) => {
7979
if (!getIsRequestAborted(error)) {

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

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

17-
import { APIOptions, get, getUrlWithSearchParams } from '@devtron-labs/devtron-fe-common-lib'
17+
import { get, getUrlWithSearchParams } from '@devtron-labs/devtron-fe-common-lib'
1818

1919
import { Routes } from '../../../../config'
20+
import { GetExternalFluxCDAppDetailsParamsType } from './types'
2021

21-
export const getExternalFluxCDAppDetails = async (
22+
export const getExternalFluxCDAppDetails = async ({
2223
clusterId,
2324
namespace,
2425
appName,
2526
isKustomization,
26-
abortControllerRef?: APIOptions['abortControllerRef'],
27-
) => {
27+
abortControllerRef,
28+
}: GetExternalFluxCDAppDetailsParamsType) => {
2829
const appId = `${clusterId}|${namespace}|${appName}|${isKustomization}`
2930
const baseurl = `${Routes.FLUX_APPS}/${Routes.APP}`
3031
const params = {

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

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

17+
import { APIOptions } from '@devtron-labs/devtron-fe-common-lib'
18+
1719
export interface ExternalFluxAppDetailParams {
1820
clusterId: string
1921
appName: string
@@ -25,3 +27,9 @@ export enum EXTERNAL_FLUX_APP_STATUS {
2527
READY = 'Ready',
2628
NOT_READY = 'Not Ready',
2729
}
30+
31+
export interface GetExternalFluxCDAppDetailsParamsType
32+
extends Pick<ExternalFluxAppDetailParams, 'clusterId' | 'namespace' | 'appName'>,
33+
Pick<APIOptions, 'abortControllerRef'> {
34+
isKustomization: boolean
35+
}

src/components/external-apps/ExternalAppService.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Routes } from '../../config'
2828
import { HelmApp, AppEnvironmentDetail } from '../app/list-new/AppListType'
2929
import { ResourceTree } from '../v2/appDetails/appDetails.type'
3030
import { getK8sResourcePayloadAppType } from '@Components/v2/appDetails/k8Resource/nodeDetail/nodeDetail.util'
31+
import { GetArgoAppDetailParamsType } from './types'
3132

3233
export interface ReleaseInfoResponse extends ResponseType {
3334
result?: ReleaseAndInstalledAppInfo
@@ -144,17 +145,14 @@ export const getReleaseInfo = (appId: string): Promise<ReleaseInfoResponse> => {
144145
export const getAppDetail = async (
145146
appId: string,
146147
abortControllerRef?: APIOptions['abortControllerRef'],
147-
): Promise<HelmAppDetailResponse> => {
148-
const url = `${Routes.HELM_RELEASE_APP_DETAIL_API}?appId=${appId}`
149-
return get(url, { abortControllerRef })
150-
}
151-
152-
export const getArgoAppDetail = async (
153-
appName: string,
154-
clusterId: string,
155-
namespace: string,
156-
abortControllerRef?: APIOptions['abortControllerRef'],
157-
) =>
148+
): Promise<HelmAppDetailResponse> => get(`${Routes.HELM_RELEASE_APP_DETAIL_API}?appId=${appId}`, { abortControllerRef })
149+
150+
export const getArgoAppDetail = async ({
151+
appName,
152+
clusterId,
153+
namespace,
154+
abortControllerRef,
155+
}: GetArgoAppDetailParamsType) =>
158156
get(`${Routes.ARGO_APPLICATION}?name=${appName}&clusterId=${clusterId}&namespace=${namespace}`, {
159157
abortControllerRef,
160158
})

src/components/external-apps/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { APIOptions } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
export interface GetArgoAppDetailParamsType extends Pick<APIOptions, 'abortControllerRef'> {
4+
appName: string
5+
clusterId: string
6+
namespace: string
7+
}

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
7777
const _getAndSetAppDetail = async () => {
7878
isAPICallInProgress = true
7979
setIsReloadResourceTreeInProgress(true)
80-
getArgoAppDetail(appName, clusterId, namespace, abortControllerRef)
80+
getArgoAppDetail({ appName, clusterId, namespace, abortControllerRef })
8181
.then((appDetailResponse) => {
8282
const genericAppDetail: AppDetails = {
8383
...appDetailResponse.result,

src/components/v2/index.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
*/
1616

1717
import { Suspense, useEffect, useRef, useState } from 'react'
18-
import { useRouteMatch, useParams, Redirect, useLocation, useHistory, Switch, Route } from 'react-router-dom'
18+
import { Redirect, Route, Switch, useHistory, useLocation, useParams, useRouteMatch } from 'react-router-dom'
19+
1920
import {
20-
ErrorScreenManager,
2121
DetailsProgressing,
22-
showError,
22+
ErrorScreenManager,
2323
getIsRequestAborted,
24+
showError,
2425
} from '@devtron-labs/devtron-fe-common-lib'
26+
2527
import { URLS } from '../../config'
2628
import { sortOptionsByValue } from '../common'
27-
import ValuesComponent from './values/ChartValues.component'
28-
import AppHeaderComponent from './headers/AppHeader.component'
29-
import ChartHeaderComponent from './headers/ChartHeader.component'
29+
import { AppDetailsEmptyState } from '../common/AppDetailsEmptyState'
30+
import { getExternalLinks } from '../externalLinks/ExternalLinks.service'
31+
import { ExternalLinkIdentifierType, ExternalLinksAndToolsType } from '../externalLinks/ExternalLinks.type'
32+
import { sortByUpdatedOn } from '../externalLinks/ExternalLinks.utils'
33+
import { checkIfToRefetchData, deleteRefetchDataFromUrl } from '../util/URLUtil'
3034
import {
3135
getInstalledAppDetail,
3236
getInstalledChartDetail,
@@ -35,13 +39,11 @@ import {
3539
import AppDetailsComponent from './appDetails/AppDetails.component'
3640
import { AppDetails, AppType, EnvType } from './appDetails/appDetails.type'
3741
import IndexStore from './appDetails/index.store'
38-
import { checkIfToRefetchData, deleteRefetchDataFromUrl } from '../util/URLUtil'
3942
import ChartDeploymentHistory from './chartDeploymentHistory/ChartDeploymentHistory.component'
40-
import { ExternalLinkIdentifierType, ExternalLinksAndToolsType } from '../externalLinks/ExternalLinks.type'
41-
import { getExternalLinks } from '../externalLinks/ExternalLinks.service'
42-
import { sortByUpdatedOn } from '../externalLinks/ExternalLinks.utils'
43-
import { AppDetailsEmptyState } from '../common/AppDetailsEmptyState'
43+
import AppHeaderComponent from './headers/AppHeader.component'
44+
import ChartHeaderComponent from './headers/ChartHeader.component'
4445
import { HelmAppOverview } from './HelmAppOverview/HelmAppOverview'
46+
import ValuesComponent from './values/ChartValues.component'
4547

4648
let initTimer = null
4749

@@ -85,21 +87,23 @@ const RouterComponent = ({ envType }) => {
8587
}
8688
}, [params.appId, params.envId])
8789

88-
useEffect(() => {
89-
return () => {
90+
useEffect(
91+
() => () => {
9092
abortControllerRef.current.abort()
91-
}
92-
}, [])
93+
},
94+
[],
95+
)
9396

9497
// clearing the timer on component unmount
95-
useEffect(() => {
96-
return (): void => {
98+
useEffect(
99+
() => (): void => {
97100
if (initTimer) {
98101
clearTimeout(initTimer)
99102
}
100103
IndexStore.clearAppDetails() // Cleared out the data on unmount
101-
}
102-
}, [])
104+
},
105+
[],
106+
)
103107

104108
useEffect(() => {
105109
if (checkIfToRefetchData(location)) {
@@ -119,7 +123,6 @@ const RouterComponent = ({ envType }) => {
119123

120124
const handleAppDetailsCallError = (e: any) => {
121125
if (getIsRequestAborted(e)) {
122-
// FIXME: initTimer
123126
return
124127
}
125128

0 commit comments

Comments
 (0)