1
- import React , { useState } from 'react'
2
- import { showError , Progressing , Drawer , DeleteDialog , noop , DockerConfigOverrideType } from '@devtron-labs/devtron-fe-common-lib'
1
+ import React , { useEffect , useState } from 'react'
2
+ import {
3
+ showError ,
4
+ Progressing ,
5
+ Drawer ,
6
+ DeleteDialog ,
7
+ noop ,
8
+ DockerConfigOverrideType ,
9
+ Reload ,
10
+ } from '@devtron-labs/devtron-fe-common-lib'
3
11
import { ReactComponent as CloseIcon } from '../../assets/icons/ic-cross.svg'
4
12
import { ReactComponent as EditIcon } from '../../assets/icons/ic-pencil.svg'
5
13
import { ReactComponent as DeleteIcon } from '../../assets/icons/ic-delete-interactive.svg'
6
14
import { Workflow } from '../workflowEditor/Workflow'
7
15
import { Link , useHistory , useLocation , useParams , useRouteMatch } from 'react-router-dom'
8
16
import { URLS } from '../../config'
9
- import { CIConfigDiffViewProps } from './types'
17
+ import { CIConfigDiffViewProps , ProcessedWorkflowsType } from './types'
10
18
import { WorkflowType } from '../app/details/triggerView/types'
11
19
import { CIBuildConfigDiff } from './CIBuildConfigDiff'
12
20
import Tippy from '@tippyjs/react'
13
21
import { getInitDataWithCIPipeline , saveCIPipeline } from '../ciPipeline/ciPipeline.service'
14
22
import { toast } from 'react-toastify'
23
+ import { ConfigOverrideWorkflowDetails } from '../../services/service.types'
24
+ import { getConfigOverrideWorkflowDetails , getWorkflowList } from '../../services/service'
25
+ import { WorkflowCreate } from '../app/details/triggerView/config'
26
+ import { processWorkflow } from '../app/details/triggerView/workflow.service'
15
27
16
28
export default function CIConfigDiffView ( {
17
29
parentReloading,
18
30
ciConfig,
19
31
configOverridenPipelines,
20
- configOverrideWorkflows,
21
- processedWorkflows,
22
32
toggleConfigOverrideDiffModal,
23
33
reload,
24
34
gitMaterials,
@@ -34,7 +44,42 @@ export default function CIConfigDiffView({
34
44
const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false )
35
45
const [ deleteInProgress , setDeleteInProgress ] = useState ( false )
36
46
const [ selectedWFId , setSelectedWFId ] = useState ( 0 )
47
+ const [ configOverrideWorkflows , setConfigOverrideWorkflows ] = useState < ConfigOverrideWorkflowDetails [ ] > ( [ ] )
48
+ const [ processedWorkflows , setProcessedWorkflows ] = useState < ProcessedWorkflowsType > ( {
49
+ workflows : [ ] ,
50
+ } )
51
+ const [ loading , setLoading ] = useState < boolean > ( true )
52
+ const [ error , setError ] = useState < boolean > ( false )
53
+
54
+ const handleOnMountAPICalls = async ( ) => {
55
+ setLoading ( true )
56
+ setError ( false )
57
+ try {
58
+ const [ { result : _configOverridenWorkflows } , { result : _processedWorkflows } ] = await Promise . all ( [
59
+ getConfigOverrideWorkflowDetails ( appId ) ,
60
+ getWorkflowList ( appId ) ,
61
+ ] )
62
+
63
+ const { workflows = [ ] } =
64
+ processWorkflow ( _processedWorkflows , ciConfig , null , null , WorkflowCreate , WorkflowCreate . workflow ) ||
65
+ { }
66
+
67
+ setProcessedWorkflows ( { workflows } )
68
+ setConfigOverrideWorkflows ( _configOverridenWorkflows ?. workflows ?? [ ] )
69
+ } catch ( e ) {
70
+ showError ( e )
71
+ setError ( true )
72
+ } finally {
73
+ setLoading ( false )
74
+ }
75
+ }
76
+
77
+ useEffect ( ( ) => {
78
+ handleOnMountAPICalls ( )
79
+ } , [ ] )
80
+
37
81
const wfCIMap = new Map < number , number > ( )
82
+ // NOTE: Even on reload after delete the data is going to be stale since we are not updating configOverrideWorkflows
38
83
const _configOverridenWorkflows = configOverrideWorkflows . filter ( ( _cwf ) => {
39
84
const _ciPipeline = configOverridenPipelines ?. find ( ( _ci ) => _ci . id === _cwf . ciPipelineId )
40
85
if ( ! ! _ciPipeline ) {
@@ -173,48 +218,56 @@ export default function CIConfigDiffView({
173
218
}
174
219
}
175
220
221
+ const renderBodyContent = ( ) => {
222
+ if ( parentReloading || loading ) {
223
+ return < Progressing pageLoader />
224
+ }
225
+
226
+ if ( error ) {
227
+ return < Reload reload = { handleOnMountAPICalls } />
228
+ }
229
+
230
+ return _overridenWorkflows . map ( ( _wf ) => (
231
+ < div className = "mb-20 dc__position-rel" key = { _wf . id } >
232
+ < Workflow
233
+ key = { _wf . id }
234
+ id = { + _wf . id }
235
+ name = { _wf . name }
236
+ startX = { _wf . startX }
237
+ startY = { _wf . startY }
238
+ height = { getWorkflowHeight ( _wf ) }
239
+ width = "100%"
240
+ nodes = { _wf . nodes }
241
+ history = { history }
242
+ location = { location }
243
+ match = { match }
244
+ handleCDSelect = { noop }
245
+ handleCISelect = { noop }
246
+ openEditWorkflow = { noop }
247
+ showDeleteDialog = { noop }
248
+ addCIPipeline = { noop }
249
+ addWebhookCD = { noop }
250
+ cdWorkflowList = { _configOverridenWorkflows }
251
+ />
252
+ { renderViewBuildPipelineRow ( + _wf . id ) }
253
+ < CIBuildConfigDiff
254
+ configOverridenWorkflows = { _configOverridenWorkflows }
255
+ wfId = { _wf . id }
256
+ configOverridenPipelines = { configOverridenPipelines }
257
+ materials = { ciConfig ?. materials }
258
+ globalCIConfig = { globalCIConfig }
259
+ gitMaterials = { gitMaterials }
260
+ />
261
+ </ div >
262
+ ) )
263
+ }
264
+
176
265
return (
177
266
< Drawer parentClassName = "dc__overflow-hidden" position = "right" width = "87%" minWidth = "1024px" maxWidth = "1246px" >
178
267
< div className = "modal__body modal__config-override-diff br-0 modal__body--p-0 dc__overflow-hidden" >
179
268
{ renderConfigDiffModalTitle ( ) }
180
269
< div className = "config-override-diff__view h-100 p-20 dc__window-bg dc__overflow-scroll" >
181
- { parentReloading || processedWorkflows . processing ? (
182
- < Progressing pageLoader />
183
- ) : (
184
- _overridenWorkflows . map ( ( _wf ) => (
185
- < div className = "mb-20 dc__position-rel" >
186
- < Workflow
187
- key = { _wf . id }
188
- id = { + _wf . id }
189
- name = { _wf . name }
190
- startX = { _wf . startX }
191
- startY = { _wf . startY }
192
- height = { getWorkflowHeight ( _wf ) }
193
- width = { '100%' }
194
- nodes = { _wf . nodes }
195
- history = { history }
196
- location = { location }
197
- match = { match }
198
- handleCDSelect = { noop }
199
- handleCISelect = { noop }
200
- openEditWorkflow = { noop }
201
- showDeleteDialog = { noop }
202
- addCIPipeline = { noop }
203
- addWebhookCD = { noop }
204
- cdWorkflowList = { _configOverridenWorkflows }
205
- />
206
- { renderViewBuildPipelineRow ( + _wf . id ) }
207
- < CIBuildConfigDiff
208
- configOverridenWorkflows = { _configOverridenWorkflows }
209
- wfId = { _wf . id }
210
- configOverridenPipelines = { configOverridenPipelines }
211
- materials = { ciConfig ?. materials }
212
- globalCIConfig = { globalCIConfig }
213
- gitMaterials = { gitMaterials }
214
- />
215
- </ div >
216
- ) )
217
- ) }
270
+ { renderBodyContent ( ) }
218
271
</ div >
219
272
{ showDeleteDialog && (
220
273
< DeleteDialog
0 commit comments