@@ -8,28 +8,28 @@ import { GenericEmptyState } from '@Common/EmptyState'
8
8
import { handleUTCTime , stopPropagation , useAsync } from '@Common/Helper'
9
9
import { DeploymentAppTypes } from '@Common/Types'
10
10
import { ComponentSizeType } from '@Shared/constants'
11
+ import { AppType } from '@Shared/types'
11
12
12
13
import { APIResponseHandler } from '../APIResponseHandler'
13
14
import { Button , ButtonComponentType , ButtonStyleType , ButtonVariantType } from '../Button'
15
+ import { PROGRESSING_DEPLOYMENT_STATUS } from '../DeploymentStatusBreakdown'
14
16
import { Icon } from '../Icon'
15
17
import { DeploymentStatus } from '../StatusComponent'
16
18
import { AppStatusBody } from './AppStatusBody'
17
19
import AppStatusModalTabList from './AppStatusModalTabList'
18
- import { getAppDetails } from './service'
20
+ import { getAppDetails , getDeploymentStatusWithTimeline } from './service'
19
21
import { AppStatusModalProps , AppStatusModalTabType } from './types'
20
22
import { getEmptyViewImageFromHelmDeploymentStatus , getShowDeploymentStatusModal } from './utils'
21
23
22
24
import './AppStatusModal.scss'
23
25
24
- // TODO: Need to handleTabChange for appDetails view since polling is external
25
26
const AppStatusModal = ( {
26
27
titleSegments,
27
28
handleClose,
28
29
type,
29
- isDeploymentTimelineLoading,
30
30
appDetails : appDetailsProp ,
31
- deploymentStatusDetailsBreakdownData : deploymentStatusDetailsBreakdownDataProps ,
32
31
processVirtualEnvironmentDeploymentData,
32
+ handleUpdateDeploymentStatusDetailsBreakdownData,
33
33
isConfigDriftEnabled,
34
34
configDriftModal : ConfigDriftModal ,
35
35
appId,
@@ -39,21 +39,19 @@ const AppStatusModal = ({
39
39
const [ showConfigDriftModal , setShowConfigDriftModal ] = useState ( false )
40
40
const [ selectedTab , setSelectedTab ] = useState < AppStatusModalTabType > ( initialTab || null )
41
41
42
- const abortControllerRef = useRef < AbortController > ( new AbortController ( ) )
43
- const pollingTimeoutRef = useRef < ReturnType < typeof setTimeout > | null > ( null )
42
+ const appDetailsAbortControllerRef = useRef < AbortController > ( new AbortController ( ) )
43
+ const appDetailsPollingTimeoutRef = useRef < ReturnType < typeof setTimeout > | null > ( null )
44
44
45
45
const getAppDetailsWrapper = async ( ) => {
46
46
const response = await abortPreviousRequests (
47
47
( ) =>
48
48
getAppDetails ( {
49
49
appId,
50
50
envId,
51
- abortControllerRef,
52
- deploymentStatusConfig : { showTimeline : false , processVirtualEnvironmentDeploymentData } ,
51
+ abortControllerRef : appDetailsAbortControllerRef ,
53
52
} ) ,
54
- abortControllerRef ,
53
+ appDetailsAbortControllerRef ,
55
54
)
56
-
57
55
return response
58
56
}
59
57
@@ -65,56 +63,140 @@ const AppStatusModal = ({
65
63
setFetchedAppDetails ,
66
64
] = useAsync ( getAppDetailsWrapper , [ appId , envId ] , type === 'release' )
67
65
68
- const handleExternalSync = async ( ) => {
69
- try {
70
- pollingTimeoutRef . current = setTimeout (
71
- async ( ) => {
66
+ const appDetails = type === 'release' ? fetchedAppDetails : appDetailsProp
67
+
68
+ const showDeploymentStatusModal = getShowDeploymentStatusModal ( { type, appDetails } )
69
+ const deploymentStatusAbortControllerRef = useRef < AbortController > ( new AbortController ( ) )
70
+ const deploymentStatusPollingTimeoutRef = useRef < ReturnType < typeof setTimeout > | null > ( null )
71
+
72
+ const getDeploymentStatusWrapper = async ( ) => {
73
+ const response = await abortPreviousRequests (
74
+ ( ) =>
75
+ getDeploymentStatusWithTimeline ( {
76
+ abortControllerRef : deploymentStatusAbortControllerRef ,
77
+ appId :
78
+ appDetails . appType === AppType . DEVTRON_HELM_CHART
79
+ ? appDetails . installedAppId
80
+ : appDetails . appId ,
81
+ envId : appDetails . environmentId ,
82
+ showTimeline : selectedTab === AppStatusModalTabType . DEPLOYMENT_STATUS ,
83
+ virtualEnvironmentConfig : appDetails . isVirtualEnvironment
84
+ ? {
85
+ processVirtualEnvironmentDeploymentData,
86
+ wfrId : appDetails . resourceTree ?. wfrId ,
87
+ }
88
+ : null ,
89
+ isHelmApp : appDetails . appType === AppType . DEVTRON_HELM_CHART ,
90
+ } ) ,
91
+ deploymentStatusAbortControllerRef ,
92
+ )
93
+
94
+ handleUpdateDeploymentStatusDetailsBreakdownData ?.( response )
95
+
96
+ return response
97
+ }
98
+
99
+ const [
100
+ isDeploymentTimelineLoading ,
101
+ deploymentStatusDetailsBreakdownData ,
102
+ deploymentStatusDetailsBreakdownDataError ,
103
+ reloadDeploymentStatusDetailsBreakdownData ,
104
+ setDeploymentStatusDetailsBreakdownData ,
105
+ ] = useAsync (
106
+ getDeploymentStatusWrapper ,
107
+ [ appId , envId , showDeploymentStatusModal , selectedTab ] ,
108
+ ! ! showDeploymentStatusModal ,
109
+ )
110
+
111
+ const handleAppDetailsExternalSync = async ( ) => {
112
+ appDetailsPollingTimeoutRef . current = setTimeout (
113
+ async ( ) => {
114
+ try {
72
115
const response = await getAppDetailsWrapper ( )
73
116
setFetchedAppDetails ( response )
74
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
75
- handleExternalSync ( )
76
- } ,
77
- Number ( window . _env_ . DEVTRON_APP_DETAILS_POLLING_INTERVAL ) || 30000 ,
78
- )
79
- } catch {
80
- // Do nothing
81
- }
117
+ } catch {
118
+ // Do nothing
119
+ }
120
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
121
+ handleAppDetailsExternalSync ( )
122
+ } ,
123
+ Number ( window . _env_ . DEVTRON_APP_DETAILS_POLLING_INTERVAL ) || 30000 ,
124
+ )
82
125
}
83
126
84
- const appDetails = type === 'release' ? fetchedAppDetails ?. appDetails : appDetailsProp
85
- const deploymentStatusDetailsBreakdownData =
86
- type === 'release'
87
- ? fetchedAppDetails ?. deploymentStatusDetailsBreakdownData
88
- : deploymentStatusDetailsBreakdownDataProps
127
+ const handleDeploymentStatusExternalSync = async ( ) => {
128
+ const isDeploymentInProgress = PROGRESSING_DEPLOYMENT_STATUS . includes (
129
+ deploymentStatusDetailsBreakdownData ?. deploymentStatus ,
130
+ )
131
+
132
+ const pollingIntervalFromFlag = Number ( window . _env_ . DEVTRON_APP_DETAILS_POLLING_INTERVAL ) || 30000
133
+
134
+ deploymentStatusPollingTimeoutRef . current = setTimeout (
135
+ async ( ) => {
136
+ try {
137
+ const response = await getDeploymentStatusWrapper ( )
138
+ setDeploymentStatusDetailsBreakdownData ( response )
139
+ } catch {
140
+ // Do nothing
141
+ }
142
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
143
+ handleDeploymentStatusExternalSync ( )
144
+ } ,
145
+ isDeploymentInProgress ? 10000 : pollingIntervalFromFlag ,
146
+ )
147
+ }
89
148
90
149
const areInitialAppDetailsLoadingWithAbortedError =
91
150
areInitialAppDetailsLoading || getIsRequestAborted ( fetchedAppDetailsError )
92
151
152
+ const isDeploymentStatusLoadingWithAbortedError =
153
+ isDeploymentTimelineLoading || getIsRequestAborted ( deploymentStatusDetailsBreakdownDataError )
154
+
93
155
const isTimelineRequiredAndLoading =
94
- selectedTab === AppStatusModalTabType . DEPLOYMENT_STATUS &&
95
- appDetails ?. deploymentAppType !== DeploymentAppTypes . HELM &&
96
- isDeploymentTimelineLoading
156
+ selectedTab === AppStatusModalTabType . DEPLOYMENT_STATUS && isDeploymentStatusLoadingWithAbortedError
97
157
98
158
// Adding useEffect to initiate timer for external sync and clear it on unmount
99
159
useEffect ( ( ) => {
100
160
if (
101
161
! areInitialAppDetailsLoading &&
102
162
! fetchedAppDetailsError &&
103
163
fetchedAppDetails &&
104
- ! pollingTimeoutRef . current
164
+ ! appDetailsPollingTimeoutRef . current
105
165
) {
106
166
// eslint-disable-next-line @typescript-eslint/no-floating-promises
107
- handleExternalSync ( )
167
+ handleAppDetailsExternalSync ( )
108
168
}
109
169
} , [ areInitialAppDetailsLoading , fetchedAppDetails , fetchedAppDetailsError ] )
110
170
171
+ useEffect ( ( ) => {
172
+ if (
173
+ ! isDeploymentTimelineLoading &&
174
+ ! deploymentStatusDetailsBreakdownDataError &&
175
+ deploymentStatusDetailsBreakdownData &&
176
+ ! deploymentStatusPollingTimeoutRef . current
177
+ ) {
178
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
179
+ handleDeploymentStatusExternalSync ( )
180
+ }
181
+ } , [ isDeploymentTimelineLoading , deploymentStatusDetailsBreakdownData , deploymentStatusDetailsBreakdownDataError ] )
182
+
183
+ const handleClearDeploymentStatusTimeout = ( ) => {
184
+ if ( deploymentStatusPollingTimeoutRef . current ) {
185
+ clearTimeout ( deploymentStatusPollingTimeoutRef . current )
186
+ deploymentStatusPollingTimeoutRef . current = null
187
+ }
188
+ }
189
+
111
190
useEffect (
112
191
( ) => ( ) => {
113
- if ( pollingTimeoutRef . current ) {
114
- clearTimeout ( pollingTimeoutRef . current )
192
+ if ( appDetailsPollingTimeoutRef . current ) {
193
+ clearTimeout ( appDetailsPollingTimeoutRef . current )
115
194
}
116
195
117
- abortControllerRef . current . abort ( )
196
+ handleClearDeploymentStatusTimeout ( )
197
+
198
+ appDetailsAbortControllerRef . current . abort ( )
199
+ deploymentStatusAbortControllerRef . current . abort ( )
118
200
} ,
119
201
[ ] ,
120
202
)
@@ -130,7 +212,8 @@ const AppStatusModal = ({
130
212
setShowConfigDriftModal ( false )
131
213
}
132
214
133
- const handleSelectTab = ( updatedTab : AppStatusModalTabType ) => {
215
+ const handleSelectTab = async ( updatedTab : AppStatusModalTabType ) => {
216
+ handleClearDeploymentStatusTimeout ( )
134
217
setSelectedTab ( updatedTab )
135
218
}
136
219
@@ -224,6 +307,14 @@ const AppStatusModal = ({
224
307
)
225
308
}
226
309
310
+ const timelineError =
311
+ selectedTab === AppStatusModalTabType . DEPLOYMENT_STATUS ? deploymentStatusDetailsBreakdownDataError : null
312
+
313
+ const bodyErrorData = fetchedAppDetailsError || timelineError
314
+ const bodyErrorReload = fetchedAppDetailsError
315
+ ? reloadInitialAppDetails
316
+ : reloadDeploymentStatusDetailsBreakdownData
317
+
227
318
return (
228
319
< Drawer position = "right" width = "1024px" onClose = { handleClose } onEscape = { handleClose } >
229
320
< div
@@ -270,10 +361,10 @@ const AppStatusModal = ({
270
361
progressingProps = { {
271
362
pageLoader : true ,
272
363
} }
273
- error = { fetchedAppDetailsError }
364
+ error = { bodyErrorData }
274
365
errorScreenManagerProps = { {
275
- code : fetchedAppDetailsError ?. code ,
276
- reload : reloadInitialAppDetails ,
366
+ code : bodyErrorData ?. code ,
367
+ reload : bodyErrorReload ,
277
368
} }
278
369
>
279
370
{ renderContent ( ) }
0 commit comments