Skip to content

Commit af99189

Browse files
committed
Merge branch 'develop' into feat/app-clone-flow
2 parents 4a592e6 + 8a3cbd1 commit af99189

File tree

5 files changed

+109
-50
lines changed

5 files changed

+109
-50
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ const ExternalFluxAppDetails = () => {
6969
setAppDetailsError(null)
7070
}
7171

72+
/**
73+
* Throws error in case request is aborted
74+
*/
7275
const handleFetchExternalFluxCDAppDetails = () =>
7376
// NOTE: returning a promise so that we can trigger the next timeout after this api call completes
74-
new Promise<void>((resolve) => {
77+
new Promise<void>((resolve, reject) => {
7578
setIsReloadResourceTreeInProgress(true)
7679

7780
abortPreviousRequests(
@@ -87,6 +90,8 @@ const ExternalFluxAppDetails = () => {
8790
} else {
8891
setAppDetailsError(error)
8992
}
93+
} else {
94+
reject(error)
9095
}
9196
})
9297
.finally(() => {
@@ -107,7 +112,11 @@ const ExternalFluxAppDetails = () => {
107112
}
108113

109114
const handleReloadResourceTree = async () => {
110-
await handleFetchExternalFluxCDAppDetails()
115+
try {
116+
await handleFetchExternalFluxCDAppDetails()
117+
} catch {
118+
// do nothing
119+
}
111120
}
112121

113122
useEffect(() => {

src/components/cdPipeline/CDPipeline.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,13 @@ export default function CDPipeline({
356356
})
357357
sortObjectArrayAlphabetically(list, 'name')
358358
form.environments = list
359-
setFormData(form)
359+
setFormData((prevState) => {
360+
return {
361+
...form,
362+
// Can retain the release mode since this method is called only when creating a new pipeline
363+
releaseMode: prevState.releaseMode,
364+
}
365+
})
360366
setPageState(ViewType.FORM)
361367
setIsAdvanced(false)
362368
})
@@ -827,6 +833,9 @@ export default function CDPipeline({
827833
setSelectedTaskIndex(_formData[activeStageName].steps.length - 1)
828834
}
829835

836+
/**
837+
* @description This method is called only in case when we render basic view, i.e, CD creation first modal
838+
*/
830839
const handleStrategy = (value: string): void => {
831840
let newSelection
832841
newSelection = {}
@@ -838,10 +847,10 @@ export default function CDPipeline({
838847
newSelection['jsonStr'] = JSON.stringify(allStrategies.current[value], null, 4)
839848
newSelection['yamlStr'] = YAMLStringify(allStrategies.current[value])
840849

841-
const _form = { ...formData }
842-
_form.savedStrategies.push(newSelection)
843-
_form.savedStrategies = [newSelection]
844-
setFormData(_form)
850+
setFormData((prevState) => ({
851+
...prevState,
852+
savedStrategies: [newSelection],
853+
}))
845854
}
846855

847856
const handleValidateMandatoryPlugins: PipelineContext['handleValidateMandatoryPlugins'] = ({
@@ -1411,7 +1420,7 @@ export default function CDPipeline({
14111420
</button>
14121421
</div>
14131422

1414-
{!isAdvanced && (
1423+
{!isAdvanced && !isTemplateView && (
14151424
<div className="px-20">
14161425
<TabGroup
14171426
tabs={[
@@ -1425,18 +1434,16 @@ export default function CDPipeline({
14251434
'data-testid': 'new-deployment-tab',
14261435
},
14271436
},
1428-
...(isTemplateView
1429-
? []
1430-
: [{
1431-
tabType: 'button' as const,
1432-
active: formData.releaseMode === ReleaseMode.MIGRATE_EXTERNAL_APPS,
1433-
label: 'Migrate to Devtron',
1434-
id: ReleaseMode.MIGRATE_EXTERNAL_APPS,
1435-
props: {
1436-
onClick: handleSelectMigrateToDevtron,
1437-
'data-testid': 'migrate-to-devtron-tab',
1438-
},
1439-
}]),
1437+
{
1438+
tabType: 'button' as const,
1439+
active: formData.releaseMode === ReleaseMode.MIGRATE_EXTERNAL_APPS,
1440+
label: 'Migrate to Devtron',
1441+
id: ReleaseMode.MIGRATE_EXTERNAL_APPS,
1442+
props: {
1443+
onClick: handleSelectMigrateToDevtron,
1444+
'data-testid': 'migrate-to-devtron-tab',
1445+
},
1446+
},
14401447
]}
14411448
/>
14421449
</div>

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ import { AppDetails, AppType } from '../v2/appDetails/appDetails.type'
3232
import IndexStore from '../v2/appDetails/index.store'
3333
import { ExternalArgoAppDetailType } from './externalArgoApp.type'
3434

35+
let initTimer = null
36+
3537
const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }: ExternalArgoAppDetailType) => {
3638
const location = useLocation()
3739
const history = useHistory()
3840
const [isLoading, setIsLoading] = useState(true)
3941
const [isReloadResourceTreeInProgress, setIsReloadResourceTreeInProgress] = useState(false)
4042
const [errorResponseCode, setErrorResponseCode] = useState(undefined)
4143

42-
let initTimer = null
4344
let isAPICallInProgress = false
4445

4546
const abortControllerRef = useRef<AbortController>(new AbortController())
@@ -68,11 +69,21 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
6869

6970
const _init = () => {
7071
if (!isAPICallInProgress) {
71-
_getAndSetAppDetail(true)
72+
_getAndSetAppDetail()
7273
}
7374
}
7475

75-
const _getAndSetAppDetail = async (shouldTriggerPolling: boolean = false) => {
76+
const handleInitiatePolling = () => {
77+
if (initTimer) {
78+
clearTimeout(initTimer)
79+
}
80+
81+
initTimer = setTimeout(() => {
82+
_init()
83+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
84+
}
85+
86+
const _getAndSetAppDetail = async () => {
7687
isAPICallInProgress = true
7788
setIsReloadResourceTreeInProgress(true)
7889

@@ -85,25 +96,25 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
8596
...appDetailResponse.result,
8697
deploymentAppType: DeploymentAppTypes.GITOPS,
8798
}
99+
100+
isAPICallInProgress = false
101+
handleInitiatePolling()
102+
88103
IndexStore.publishAppDetails(genericAppDetail, AppType.EXTERNAL_ARGO_APP)
89104
setErrorResponseCode(undefined)
90105
})
91106
.catch((errors: ServerErrors) => {
92107
if (!getIsRequestAborted(errors)) {
93108
showError(errors)
94109
setErrorResponseCode(errors.code)
110+
isAPICallInProgress = false
111+
handleInitiatePolling()
95112
}
96113
})
97114
.finally(() => {
98115
setIsLoading(false)
99116
isAPICallInProgress = false
100117
setIsReloadResourceTreeInProgress(false)
101-
102-
if (shouldTriggerPolling) {
103-
initTimer = setTimeout(() => {
104-
_init()
105-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
106-
}
107118
})
108119
}
109120

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import { getExternalLinks } from '../../../externalLinks/ExternalLinks.service'
4040
import { ExternalLinkIdentifierType, ExternalLinksAndToolsType } from '../../../externalLinks/ExternalLinks.type'
4141
import { sortByUpdatedOn } from '../../../externalLinks/ExternalLinks.utils'
4242

43+
let initTimer = null
44+
4345
const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
4446
const location = useLocation()
4547
const history = useHistory()
@@ -53,7 +55,6 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
5355

5456
const abortControllerRef = useRef<AbortController>(new AbortController())
5557

56-
let initTimer = null
5758
let isAPICallInProgress = false
5859

5960
// component load
@@ -80,7 +81,7 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
8081

8182
const _init = () => {
8283
if (!isAPICallInProgress) {
83-
_getAndSetAppDetail(true)
84+
_getAndSetAppDetail()
8485
}
8586
}
8687

@@ -120,7 +121,17 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
120121
return genericAppDetail
121122
}
122123

123-
const _getAndSetAppDetail = (shouldTriggerPolling: boolean = false) => {
124+
const handleInitiatePolling = () => {
125+
if (initTimer) {
126+
clearTimeout(initTimer)
127+
}
128+
129+
initTimer = setTimeout(() => {
130+
_init()
131+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
132+
}
133+
134+
const _getAndSetAppDetail = () => {
124135
isAPICallInProgress = true
125136
setIsReloadResourceTreeInProgress(true)
126137

@@ -161,24 +172,21 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
161172
}
162173

163174
setErrorResponseCode(undefined)
175+
176+
handleInitiatePolling()
164177
})
165178
.catch((errors: ServerErrors) => {
179+
setIsLoading(false)
180+
isAPICallInProgress = false
181+
166182
if (!getIsRequestAborted(errors)) {
167183
showError(errors)
168184
setErrorResponseCode(errors.code)
185+
handleInitiatePolling()
169186
}
170-
171-
setIsLoading(false)
172-
isAPICallInProgress = false
173187
})
174188
.finally(() => {
175189
setIsReloadResourceTreeInProgress(false)
176-
177-
if (shouldTriggerPolling) {
178-
initTimer = setTimeout(() => {
179-
_init()
180-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
181-
}
182190
})
183191
}
184192

src/components/v2/index.tsx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const RouterComponent = () => {
110110
}, [location.search])
111111

112112
const _init = (fetchExternalLinks?: boolean) => {
113-
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks, true), abortControllerRef)
113+
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks), abortControllerRef)
114114
}
115115

116116
const handleAppDetailsCallError = (e: any) => {
@@ -135,41 +135,65 @@ const RouterComponent = () => {
135135
}
136136

137137
const handleInitiatePolling = () => {
138+
if (initTimer) {
139+
clearTimeout(initTimer)
140+
}
141+
138142
initTimer = setTimeout(() => {
139143
_init()
140144
}, window._env_.HELM_APP_DETAILS_POLLING_INTERVAL || 30000)
141145
}
142146

143-
const handleFetchAppDetails = async (fetchExternalLinks: boolean) => {
147+
const handleFetchAppDetails = async (fetchExternalLinks: boolean): Promise<{ isAborted: boolean }> => {
144148
try {
145149
const response = await getInstalledChartDetail(+params.appId, +params.envId, abortControllerRef)
146150
handlePublishAppDetails(response)
147151
isVirtualRef.current = response.result?.isVirtualEnvironment
148152
if (fetchExternalLinks) {
149153
getExternalLinksAndTools(response.result?.clusterId)
150154
}
155+
setLoadingDetails(false)
151156
} catch (error) {
152-
handleAppDetailsCallError(error)
153-
} finally {
157+
const isAborted = getIsRequestAborted(error)
158+
159+
if (!isAborted) {
160+
handleAppDetailsCallError(error)
161+
}
154162
setLoadingDetails(false)
163+
164+
return { isAborted }
155165
}
166+
167+
return { isAborted: false }
156168
}
157169

158170
const handleFetchResourceTree = async () => {
159171
try {
160172
const response = await getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef)
161173
handlePublishAppDetails(response)
174+
setLoadingResourceTree(false)
162175
} catch (error) {
163-
handleAppDetailsCallError(error)
164-
} finally {
176+
const isAborted = getIsRequestAborted(error)
177+
178+
if (!isAborted) {
179+
handleAppDetailsCallError(error)
180+
}
165181
setLoadingResourceTree(false)
182+
183+
return { isAborted }
166184
}
185+
186+
return { isAborted: false }
167187
}
168188

169-
const _getAndSetAppDetail = async (fetchExternalLinks: boolean, shouldTriggerPolling: boolean = false) => {
189+
const _getAndSetAppDetail = async (fetchExternalLinks: boolean) => {
170190
// Intentionally not setting await since it was not awaited earlier when in thens as well
171-
Promise.allSettled([handleFetchAppDetails(fetchExternalLinks), handleFetchResourceTree()]).finally(() => {
172-
if (shouldTriggerPolling) {
191+
Promise.allSettled([
192+
handleFetchAppDetails(fetchExternalLinks),
193+
handleFetchResourceTree(),
194+
]).then((results) => {
195+
const isAborted = results.some((result) => result.status === 'fulfilled' && result.value.isAborted)
196+
if (!isAborted) {
173197
handleInitiatePolling()
174198
}
175199
})

0 commit comments

Comments
 (0)