@@ -15,6 +15,9 @@ import {
15
15
CHECKBOX_VALUE ,
16
16
VisibleModal ,
17
17
WorkflowNodeType ,
18
+ KeyValueListType ,
19
+ HandleKeyValueChangeType ,
20
+ KeyValueListActionType ,
18
21
} from '@devtron-labs/devtron-fe-common-lib'
19
22
import { toast } from 'react-toastify'
20
23
import Tippy from '@tippyjs/react'
@@ -84,9 +87,11 @@ import GitCommitInfoGeneric from '../../../common/GitCommitInfoGeneric'
84
87
import { getDefaultConfig } from '../../../notifications/notifications.service'
85
88
import BulkSourceChange from './BulkSourceChange'
86
89
import { CIPipelineBuildType } from '../../../ciPipeline/types'
90
+ import { validateAndGetValidRuntimeParams } from '../../../app/details/triggerView/TriggerView.utils'
87
91
88
92
const ApprovalMaterialModal = importComponentFromFELibrary ( 'ApprovalMaterialModal' )
89
93
const getCIBlockState = importComponentFromFELibrary ( 'getCIBlockState' , null , 'function' )
94
+ const getRuntimeParams = importComponentFromFELibrary ( 'getRuntimeParams' , null , 'function' )
90
95
91
96
// FIXME: IN CIMaterials we are sending isCDLoading while in CD materials we are sending isCILoading
92
97
let inprogressStatusTimer
@@ -130,6 +135,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
130
135
const [ selectAllValue , setSelectAllValue ] = useState < CHECKBOX_VALUE > ( CHECKBOX_VALUE . CHECKED )
131
136
const [ isConfigPresent , setConfigPresent ] = useState < boolean > ( false )
132
137
const [ isDefaultConfigPresent , setDefaultConfig ] = useState < boolean > ( false )
138
+ // Mapping pipelineId to runtime params
139
+ const [ runtimeParams , setRuntimeParams ] = useState < Record < string , KeyValueListType [ ] > > ( { } )
133
140
134
141
// ref to make sure that on initial mount after we fetch workflows we handle modal based on url
135
142
const handledLocation = useRef ( false )
@@ -767,6 +774,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
767
774
getBranchValues ( ciNodeId , filteredWorkflows , filteredCIPipelines . get ( _appID ) ) ,
768
775
)
769
776
: { result : null } ,
777
+ getRuntimeParams ? getRuntimeParams ( ciNodeId ) : null ,
770
778
] )
771
779
. then ( ( resp ) => {
772
780
// need to set result for getCIBlockState call only as for updateCIMaterialList
@@ -786,11 +794,18 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
786
794
} )
787
795
setFilteredWorkflows ( workflows )
788
796
}
797
+
798
+ if ( resp [ 2 ] ) {
799
+ setRuntimeParams ( {
800
+ [ ciNodeId ] : resp [ 2 ] ,
801
+ } )
802
+ }
789
803
} )
790
804
. catch ( ( errors : ServerErrors ) => {
791
805
if ( ! abortControllerRef . current . signal . aborted ) {
792
806
showError ( errors )
793
807
setErrorCode ( errors . code )
808
+ setPageViewType ( ViewType . ERROR )
794
809
}
795
810
} )
796
811
. finally ( ( ) => {
@@ -947,11 +962,22 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
947
962
return
948
963
}
949
964
965
+ const runtimeParamsValidationResponse = validateAndGetValidRuntimeParams (
966
+ runtimeParams ?. [ selectedCINode ?. id ] ?? [ ] ,
967
+ )
968
+
969
+ if ( ! runtimeParamsValidationResponse . isValid ) {
970
+ setCDLoading ( false )
971
+ toast . error ( runtimeParamsValidationResponse . message )
972
+ return
973
+ }
974
+
950
975
const payload = {
951
976
pipelineId : + selectedCINode . id ,
952
977
ciPipelineMaterials,
953
978
invalidateCache,
954
979
pipelineType : node . isJobCI ? CIPipelineBuildType . CI_JOB : CIPipelineBuildType . CI_BUILD ,
980
+ ...( ! node . isJobCI ? { runtimeParams : runtimeParamsValidationResponse . validParams } : { } ) ,
955
981
}
956
982
957
983
triggerCINode ( payload )
@@ -1132,6 +1158,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1132
1158
preventBodyScroll ( false )
1133
1159
setShowCIModal ( false )
1134
1160
setShowMaterialRegexModal ( false )
1161
+ setRuntimeParams ( { } )
1135
1162
}
1136
1163
1137
1164
const closeCDModal = ( e : React . MouseEvent ) : void => {
@@ -1198,6 +1225,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1198
1225
setCDLoading ( false )
1199
1226
setShowBulkCDModal ( false )
1200
1227
setResponseList ( [ ] )
1228
+ setRuntimeParams ( { } )
1201
1229
1202
1230
history . push ( {
1203
1231
search : '' ,
@@ -1521,11 +1549,22 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1521
1549
} )
1522
1550
}
1523
1551
1552
+ const runtimeParamsValidationResponse = validateAndGetValidRuntimeParams (
1553
+ runtimeParams ?. [ selectedCINode ?. id ] ?? [ ] ,
1554
+ )
1555
+ if ( ! runtimeParamsValidationResponse . isValid ) {
1556
+ setCDLoading ( false )
1557
+ setCILoading ( false )
1558
+ toast . error ( runtimeParamsValidationResponse . message )
1559
+ return
1560
+ }
1561
+
1524
1562
const payload = {
1525
1563
pipelineId : + node . id ,
1526
1564
ciPipelineMaterials,
1527
1565
invalidateCache : appIgnoreCache [ + node . id ] ,
1528
1566
pipelineType : node . isJobCI ? CIPipelineBuildType . CI_JOB : CIPipelineBuildType . CI_BUILD ,
1567
+ ...( ! node . isJobCI ? { runtimeParams : runtimeParamsValidationResponse ?. validParams } : { } ) ,
1529
1568
}
1530
1569
_CITriggerPromiseList . push ( triggerCINode ( payload ) )
1531
1570
} )
@@ -1666,6 +1705,35 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1666
1705
return errorMessage
1667
1706
}
1668
1707
1708
+ /**
1709
+ * For CI Material only since don't have selectedApp here
1710
+ */
1711
+ const handleRuntimeParametersChange = ( { action, data } : HandleKeyValueChangeType ) => {
1712
+ let _runtimeParams = selectedCINode ?. id ? runtimeParams [ selectedCINode . id ] : [ ]
1713
+
1714
+ switch ( action ) {
1715
+ case KeyValueListActionType . ADD :
1716
+ _runtimeParams . unshift ( { key : '' , value : '' } )
1717
+ break
1718
+
1719
+ case KeyValueListActionType . UPDATE_KEY :
1720
+ _runtimeParams [ data . index ] . key = data . value
1721
+ break
1722
+
1723
+ case KeyValueListActionType . UPDATE_VALUE :
1724
+ _runtimeParams [ data . index ] . value = data . value
1725
+ break
1726
+
1727
+ case KeyValueListActionType . DELETE :
1728
+ _runtimeParams = _runtimeParams . filter ( ( _ , index ) => index !== data . index )
1729
+ break
1730
+ }
1731
+
1732
+ if ( selectedCINode ?. id ) {
1733
+ setRuntimeParams ( { [ selectedCINode . id ] : _runtimeParams } )
1734
+ }
1735
+ }
1736
+
1669
1737
const createBulkCITriggerData = ( ) : BulkCIDetailType [ ] => {
1670
1738
const _selectedAppWorkflowList : BulkCIDetailType [ ] = [ ]
1671
1739
filteredWorkflows . forEach ( ( wf ) => {
@@ -1818,6 +1886,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1818
1886
isCITriggerBlocked = { nd ?. isCITriggerBlocked }
1819
1887
ciBlockState = { nd ?. ciBlockState }
1820
1888
isJobCI = { ! ! nd ?. isJobCI }
1889
+ runtimeParams = { runtimeParams [ nd ?. id ] ?? [ ] }
1890
+ handleRuntimeParametersChange = { handleRuntimeParametersChange }
1821
1891
/>
1822
1892
) }
1823
1893
</ div >
@@ -1875,6 +1945,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
1875
1945
responseList = { responseList }
1876
1946
isLoading = { isCILoading }
1877
1947
setLoading = { setCILoading }
1948
+ runtimeParams = { runtimeParams }
1949
+ setRuntimeParams = { setRuntimeParams }
1878
1950
/>
1879
1951
)
1880
1952
}
0 commit comments