4
4
API_STATUS_CODES ,
5
5
ApiQueuingWithBatch ,
6
6
Button ,
7
- CIMaterialType ,
8
- CommonNodeAttr ,
9
7
ComponentSizeType ,
10
8
DocLink ,
11
9
Drawer ,
@@ -17,7 +15,6 @@ import {
17
15
PromiseAllStatusType ,
18
16
RuntimePluginVariables ,
19
17
showError ,
20
- SourceTypeMap ,
21
18
stopPropagation ,
22
19
stringComparatorBySortOrder ,
23
20
ToastManager ,
@@ -44,141 +41,58 @@ import { importComponentFromFELibrary } from '@Components/common'
44
41
import { SOURCE_NOT_CONFIGURED } from '@Config/constants'
45
42
46
43
import { getModuleConfigured } from '../../appDetails/appDetails.service'
47
- import { CI_MATERIAL_EMPTY_STATE_MESSAGING , IGNORE_CACHE_INFO } from '../Constants'
44
+ import { IGNORE_CACHE_INFO } from '../Constants'
48
45
import BuildImageHeader from './BuildImageHeader'
49
46
import GitInfoMaterial from './GitInfoMaterial'
50
47
import { getCIMaterials , triggerBuild } from './service'
51
48
import { BulkBuildImageModalProps , GitInfoMaterialProps } from './types'
52
- import { getCanNodeHaveMaterial , getIsRegexBranchNotAvailable , getTriggerBuildPayload } from './utils'
49
+ import {
50
+ getBulkCIDataPromiseGetterList ,
51
+ getBulkCIErrorMessage ,
52
+ getBulkCIWarningMessage ,
53
+ getCanNodeHaveMaterial ,
54
+ getTriggerBuildPayload ,
55
+ } from './utils'
53
56
54
- const getRuntimeParams = importComponentFromFELibrary ( 'getRuntimeParams' , null , 'function' )
55
57
const validateRuntimeParameters = importComponentFromFELibrary (
56
58
'validateRuntimeParameters' ,
57
59
( ) => ( { isValid : true , cellError : { } } ) ,
58
60
'function' ,
59
61
)
60
62
61
63
const BulkBuildImageModal = ( {
62
- handleClose,
64
+ handleClose : handleCloseProp ,
63
65
workflows,
64
66
reloadWorkflows,
65
67
filteredCIPipelineMap,
68
+ reloadWorkflowStatus,
66
69
} : BulkBuildImageModalProps ) => {
67
70
const [ selectedAppIdState , setSelectedAppIdState ] = useState < number | null > ( null )
68
71
const [ showWebhookModal , setShowWebhookModal ] = useState ( false )
69
72
const [ isBuildTriggerLoading , setIsBuildTriggerLoading ] = useState ( false )
70
73
const [ responseList , setResponseList ] = useState < ResponseRowType [ ] > ( [ ] )
71
74
72
- const [ blobStorageConfigurationLoading , blobStorageConfiguration ] = useAsync (
73
- ( ) => getModuleConfigured ( ModuleNameMap . BLOB_STORAGE ) ,
74
- [ ] ,
75
+ const [ blobStorageConfigurationLoading , blobStorageConfiguration ] = useAsync ( ( ) =>
76
+ getModuleConfigured ( ModuleNameMap . BLOB_STORAGE ) ,
75
77
)
76
78
77
79
const blobStorageNotConfigured = ! blobStorageConfigurationLoading && ! blobStorageConfiguration ?. result ?. enabled
78
80
79
- const getWarningMessage = ( ciNode : CommonNodeAttr ) : string => {
80
- if ( ciNode . isLinkedCD ) {
81
- return 'Uses another environment as image source'
82
- }
83
-
84
- if ( ciNode . isLinkedCI ) {
85
- return 'Has linked build pipeline'
86
- }
87
-
88
- if ( ciNode . type === WorkflowNodeType . WEBHOOK ) {
89
- return 'Has webhook build pipeline'
90
- }
91
-
92
- return ''
93
- }
94
-
95
- const getErrorMessage = (
96
- _appId : number ,
97
- _ciNode : CommonNodeAttr ,
98
- filteredCIPipelines : BulkCIDetailType [ 'filteredCIPipelines' ] ,
99
- materialList : CIMaterialType [ ] ,
100
- ) : string => {
101
- const selectedCIPipeline = filteredCIPipelines ?. find ( ( _ci ) => _ci . id === + _ciNode . id )
102
-
103
- if ( _ciNode . inputMaterialList ?. length > 0 ) {
104
- if ( getIsRegexBranchNotAvailable ( selectedCIPipeline , materialList ) ) {
105
- return 'Primary branch is not set'
106
- }
107
- if ( selectedCIPipeline ?. ciMaterial ) {
108
- const invalidInputMaterial = _ciNode . inputMaterialList . find (
109
- ( _mat ) =>
110
- _mat . isBranchError ||
111
- _mat . isRepoError ||
112
- _mat . isDockerFileError ||
113
- _mat . isMaterialSelectionError ||
114
- ( _mat . type === SourceTypeMap . WEBHOOK && _mat . history . length === 0 ) ,
115
- )
116
-
117
- if ( invalidInputMaterial ) {
118
- if ( invalidInputMaterial . isRepoError ) {
119
- return invalidInputMaterial . repoErrorMsg
120
- }
121
- if ( invalidInputMaterial . isDockerFileError ) {
122
- return invalidInputMaterial . dockerFileErrorMsg
123
- }
124
- if ( invalidInputMaterial . isBranchError ) {
125
- return invalidInputMaterial . branchErrorMsg
126
- }
127
- if ( invalidInputMaterial . isMaterialSelectionError ) {
128
- return invalidInputMaterial . materialSelectionErrorMsg
129
- }
130
- return CI_MATERIAL_EMPTY_STATE_MESSAGING . NoMaterialFound
131
- }
132
- }
133
- }
134
- return ''
135
- }
136
-
137
81
const initialDataAbortControllerRef = useRef < AbortController > ( new AbortController ( ) )
138
82
83
+ const selectedWorkflows = workflows . filter (
84
+ ( workflow ) =>
85
+ workflow . isSelected &&
86
+ workflow . nodes . some ( ( node ) => node . type === WorkflowNodeType . CI || node . type === WorkflowNodeType . WEBHOOK ) ,
87
+ )
88
+
139
89
// Returns map of appId to BulkCIDetailType
140
90
const getInitialAppList = async ( appId ?: number ) : Promise < Record < number , BulkCIDetailType > > => {
141
- const validWorkflows = workflows . filter (
142
- ( workflow ) =>
143
- workflow . isSelected &&
144
- ( ! appId || workflow . appId === appId ) &&
145
- workflow . nodes . some (
146
- ( node ) => node . type === WorkflowNodeType . CI || node . type === WorkflowNodeType . WEBHOOK ,
147
- ) ,
148
- )
149
-
150
- const { ciMaterialPromiseList, runtimeParamsPromiseList } = validWorkflows . reduce (
151
- ( acc , workflow ) => {
152
- const currentNode = workflow . nodes . find (
153
- ( node ) => node . type === WorkflowNodeType . CI || node . type === WorkflowNodeType . WEBHOOK ,
154
- )
155
-
156
- if ( ! getCanNodeHaveMaterial ( currentNode ) ) {
157
- acc . ciMaterialPromiseList . push ( ( ) => [ ] )
158
- acc . runtimeParamsPromiseList . push ( ( ) => [ ] )
159
-
160
- return acc
161
- }
91
+ const validWorkflows = selectedWorkflows . filter ( ( workflow ) => ! appId || workflow . appId === appId )
162
92
163
- acc . ciMaterialPromiseList . push ( ( ) =>
164
- getCIMaterials ( {
165
- ciNodeId : currentNode . id ,
166
- abortControllerRef : initialDataAbortControllerRef ,
167
- isCINodePresent : ! ! currentNode ,
168
- selectedWorkflow : workflow ,
169
- } ) ,
170
- )
171
-
172
- // TODO: Check runtime param page should show error state in case of its error
173
- if ( getRuntimeParams ) {
174
- acc . runtimeParamsPromiseList . push ( ( ) => getRuntimeParams ( currentNode . id ) )
175
- } else {
176
- acc . runtimeParamsPromiseList . push ( ( ) => [ ] )
177
- }
178
-
179
- return acc
180
- } ,
181
- { ciMaterialPromiseList : [ ] , runtimeParamsPromiseList : [ ] } ,
93
+ const { ciMaterialPromiseList, runtimeParamsPromiseList } = getBulkCIDataPromiseGetterList (
94
+ validWorkflows ,
95
+ initialDataAbortControllerRef ,
182
96
)
183
97
184
98
if ( ciMaterialPromiseList . length === 0 ) {
@@ -187,7 +101,6 @@ const BulkBuildImageModal = ({
187
101
188
102
const ciMaterialList =
189
103
await ApiQueuingWithBatch < Awaited < ReturnType < typeof getCIMaterials > > > ( ciMaterialPromiseList )
190
- // TODO: Add show regex modal logic later
191
104
const runtimeParamsList = await ApiQueuingWithBatch < RuntimePluginVariables [ ] > ( runtimeParamsPromiseList )
192
105
193
106
return validWorkflows . reduce < Record < number , BulkCIDetailType > > ( ( acc , workflow , index ) => {
@@ -225,8 +138,8 @@ const BulkBuildImageModal = ({
225
138
isValid : runtimeParamsList [ index ] . status !== PromiseAllStatusType . REJECTED ,
226
139
cellError : { } ,
227
140
} ,
228
- warningMessage : getWarningMessage ( node ) ,
229
- errorMessage : getErrorMessage (
141
+ warningMessage : getBulkCIWarningMessage ( node ) ,
142
+ errorMessage : getBulkCIErrorMessage (
230
143
workflow . appId ,
231
144
node ,
232
145
filteredCIPipelineMap . get ( String ( workflow . appId ) ) ,
@@ -288,6 +201,13 @@ const BulkBuildImageModal = ({
288
201
setShowWebhookModal ( false )
289
202
}
290
203
204
+ const handleClose = ( ) => {
205
+ if ( responseList . length ) {
206
+ reloadWorkflowStatus ( )
207
+ }
208
+ handleCloseProp ( )
209
+ }
210
+
291
211
const validateBulkRuntimeParams = ( ) : boolean => {
292
212
const currentAppList = structuredClone ( sortedAppList )
293
213
const updatedAppInfoMap = structuredClone ( appInfoMap )
@@ -451,7 +371,6 @@ const BulkBuildImageModal = ({
451
371
if ( responseList . length ) {
452
372
return (
453
373
< TriggerResponseModalFooter
454
- // TODO: Refetch workflows after triggering build
455
374
closePopup = { handleClose }
456
375
responseList = { responseList }
457
376
isLoading = { isBuildTriggerLoading }
@@ -551,8 +470,8 @@ const BulkBuildImageModal = ({
551
470
const renderContent = ( ) => {
552
471
if ( isLoadingAppInfoMap || isBuildTriggerLoading ) {
553
472
const message = isBuildTriggerLoading
554
- ? BULK_CI_BUILD_STATUS ( sortedAppList . length )
555
- : BULK_CI_MATERIAL_STATUS ( sortedAppList . length )
473
+ ? BULK_CI_BUILD_STATUS ( selectedWorkflows . length )
474
+ : BULK_CI_MATERIAL_STATUS ( selectedWorkflows . length )
556
475
557
476
return < GenericEmptyState { ...message } SvgImage = { MechanicalOperation } contentClassName = "text-center" />
558
477
}
0 commit comments