3
3
showError ,
4
4
Progressing ,
5
5
ConfirmationDialog ,
6
- Host ,
7
6
noop ,
8
7
stopPropagation ,
9
8
multiSelectStyles ,
@@ -24,7 +23,7 @@ import {
24
23
HELM_DEPLOYMENT_STATUS_TEXT ,
25
24
RESOURCES_NOT_FOUND ,
26
25
} from '../../../../config'
27
- import { NavigationArrow , useAppContext , useEventSource , FragmentHOC , ScanDetailsModal } from '../../../common'
26
+ import { NavigationArrow , useAppContext , FragmentHOC , ScanDetailsModal } from '../../../common'
28
27
import { CustomValueContainer , groupHeaderStyle , GroupHeading , Option } from './../../../v2/common/ReactSelect.utils'
29
28
import {
30
29
getAppConfigStatus ,
@@ -139,8 +138,10 @@ export default function AppDetail({ filteredEnvIds }: { filteredEnvIds?: string
139
138
140
139
// Set the URL and push to navigation stack
141
140
if ( selectedEnvId ) {
142
- const newUrl = getAppDetailsURL ( params . appId , selectedEnvId )
143
- push ( newUrl )
141
+ if ( String ( selectedEnvId ) !== String ( params . envId ) ) {
142
+ const newUrl = getAppDetailsURL ( params . appId , selectedEnvId )
143
+ push ( newUrl )
144
+ }
144
145
} else {
145
146
setEnvironmentId ( null )
146
147
}
@@ -224,7 +225,8 @@ export const Details: React.FC<DetailsType> = ({
224
225
} ) => {
225
226
const params = useParams < { appId : string ; envId : string } > ( )
226
227
const location = useLocation ( )
227
- const [ streamData , setStreamData ] = useState < AppStreamData > ( null )
228
+ // fixme: the state is not being set anywhere and just being drilled down
229
+ const [ streamData ] = useState < AppStreamData > ( null )
228
230
const [ detailedStatus , toggleDetailedStatus ] = useState < boolean > ( false )
229
231
const [ resourceTreeFetchTimeOut , setResourceTreeFetchTimeOut ] = useState < boolean > ( false )
230
232
const [ urlInfo , setUrlInfo ] = useState < boolean > ( false )
@@ -246,13 +248,15 @@ export const Details: React.FC<DetailsType> = ({
246
248
} )
247
249
const [ loadingDetails , setLoadingDetails ] = useState ( true )
248
250
const [ loadingResourceTree , setLoadingResourceTree ] = useState ( true )
251
+ // State to track the loading state for the timeline data when the detailed status modal opens
252
+ const [ isInitialTimelineDataLoading , setIsInitialTimelineDataLoading ] = useState ( true )
249
253
const [ errorsList , setErrorsList ] = useState < ErrorItem [ ] > ( [ ] )
250
254
const appDetailsRef = useRef ( null )
251
255
const appDetailsRequestRef = useRef ( null )
252
- const deploymentModalShownRef = useRef ( false )
253
256
const { envId } = useParams < { appId : string ; envId ?: string } > ( )
254
257
const pollResourceTreeRef = useRef ( true )
255
258
const appDetailsAbortRef = useRef ( null )
259
+ const shouldFetchTimelineRef = useRef ( false )
256
260
257
261
const [ deploymentStatusDetailsBreakdownData , setDeploymentStatusDetailsBreakdownData ] =
258
262
useState < DeploymentStatusDetailsBreakdownDataType > ( {
@@ -267,26 +271,18 @@ export const Details: React.FC<DetailsType> = ({
267
271
const interval = window . _env_ . DEVTRON_APP_DETAILS_POLLING_INTERVAL || 30000
268
272
appDetailsRequestRef . current = appDetails ?. deploymentAppDeleteRequest
269
273
270
- const syncSSE = useEventSource (
271
- `${ Host } /api/v1/applications/stream?name=${ appDetails ?. appName } -${ appDetails ?. environmentName } ` ,
272
- [ params . appId , params . envId ] ,
273
- appDetails &&
274
- ! ! appDetails . appName &&
275
- ! ! appDetails . environmentName &&
276
- appDetails . deploymentAppType !== DeploymentAppTypes . HELM ,
277
- ( event ) => setStreamData ( JSON . parse ( event . data ) ) ,
278
- )
279
-
280
274
const aggregatedNodes : AggregatedNodes = useMemo ( ( ) => {
281
275
return aggregateNodes ( appDetails ?. resourceTree ?. nodes || [ ] , appDetails ?. resourceTree ?. podMetadata || [ ] )
282
276
} , [ appDetails ] )
283
277
284
278
useEffect ( ( ) => {
285
- if ( location . search . includes ( DEPLOYMENT_STATUS_QUERY_PARAM ) ) {
286
- deploymentModalShownRef . current = true
287
- } else {
288
- deploymentModalShownRef . current = false
279
+ const isModalOpen = location . search . includes ( DEPLOYMENT_STATUS_QUERY_PARAM )
280
+ // Reset the loading state when the modal is closed
281
+ if ( shouldFetchTimelineRef . current && ! isModalOpen ) {
282
+ setIsInitialTimelineDataLoading ( true )
289
283
}
284
+ // The timeline should be fetched by default if the modal is open
285
+ shouldFetchTimelineRef . current = isModalOpen
290
286
} , [ location . search ] )
291
287
292
288
const clearDeploymentStatusTimer = useCallback ( ( ) : void => {
@@ -304,15 +300,6 @@ export const Details: React.FC<DetailsType> = ({
304
300
305
301
clearDeploymentStatusTimer ( )
306
302
307
- if (
308
- processedDeploymentStatusDetailsData . deploymentStatus === DEPLOYMENT_STATUS . HEALTHY ||
309
- processedDeploymentStatusDetailsData . deploymentStatus === DEPLOYMENT_STATUS . TIMED_OUT ||
310
- processedDeploymentStatusDetailsData . deploymentStatus === DEPLOYMENT_STATUS . SUPERSEDED ||
311
- processedDeploymentStatusDetailsData . deploymentStatus === DEPLOYMENT_STATUS . SUCCEEDED
312
- ) {
313
- deploymentModalShownRef . current = false
314
- }
315
-
316
303
if ( processedDeploymentStatusDetailsData . deploymentStatus === DEPLOYMENT_STATUS . INPROGRESS ) {
317
304
deploymentStatusTimer = setTimeout ( ( ) => {
318
305
getDeploymentDetailStepsData ( )
@@ -327,24 +314,29 @@ export const Details: React.FC<DetailsType> = ({
327
314
processDeploymentStatusDetailsData ,
328
315
clearDeploymentStatusTimer ,
329
316
DEPLOYMENT_STATUS ,
330
- deploymentModalShownRef ,
331
317
setDeploymentStatusDetailsBreakdownData ,
332
318
] ,
333
319
)
334
320
335
321
const getDeploymentDetailStepsData = useCallback (
336
322
( showTimeline ?: boolean ) : void => {
323
+ const shouldFetchTimeline = showTimeline ?? shouldFetchTimelineRef . current
324
+
337
325
// Deployments status details for Devtron apps
338
- getDeploymentStatusDetail ( params . appId , params . envId , showTimeline ?? deploymentModalShownRef . current ) . then (
326
+ getDeploymentStatusDetail ( params . appId , params . envId , shouldFetchTimeline ) . then (
339
327
( deploymentStatusDetailRes ) => {
340
328
processDeploymentStatusData ( deploymentStatusDetailRes . result )
329
+ // Update the loading status if the modal is open
330
+ if ( shouldFetchTimeline ) {
331
+ setIsInitialTimelineDataLoading ( false )
332
+ }
341
333
} ,
342
334
)
343
335
} ,
344
336
[
345
337
params . appId ,
346
338
params . envId ,
347
- deploymentModalShownRef . current ,
339
+ shouldFetchTimelineRef . current ,
348
340
getDeploymentStatusDetail ,
349
341
processDeploymentStatusData ,
350
342
] ,
@@ -437,7 +429,9 @@ export const Details: React.FC<DetailsType> = ({
437
429
}
438
430
439
431
function _getDeploymentStatusDetail ( deploymentAppType : DeploymentAppTypes ) {
440
- getDeploymentStatusDetail ( params . appId , params . envId , deploymentModalShownRef . current )
432
+ const shouldFetchTimeline = shouldFetchTimelineRef . current
433
+
434
+ getDeploymentStatusDetail ( params . appId , params . envId , shouldFetchTimeline )
441
435
. then ( ( deploymentStatusDetailRes ) => {
442
436
if ( deploymentStatusDetailRes . result ) {
443
437
if ( deploymentAppType === DeploymentAppTypes . HELM ) {
@@ -456,6 +450,9 @@ export const Details: React.FC<DetailsType> = ({
456
450
} else {
457
451
processDeploymentStatusData ( deploymentStatusDetailRes . result )
458
452
}
453
+ if ( shouldFetchTimeline ) {
454
+ setIsInitialTimelineDataLoading ( false )
455
+ }
459
456
}
460
457
} )
461
458
. catch ( noop )
@@ -687,6 +684,7 @@ export const Details: React.FC<DetailsType> = ({
687
684
streamData = { streamData }
688
685
deploymentStatusDetailsBreakdownData = { deploymentStatusDetailsBreakdownData }
689
686
isVirtualEnvironment = { isVirtualEnvRef . current }
687
+ isLoading = { isInitialTimelineDataLoading }
690
688
/>
691
689
) }
692
690
{ showScanDetailsModal && (
0 commit comments