@@ -3,6 +3,8 @@ import { useHistory } from 'react-router-dom'
3
3
4
4
import {
5
5
API_STATUS_CODES ,
6
+ BULK_DEPLOY_ACTIVE_IMAGE_TAG ,
7
+ BULK_DEPLOY_LATEST_IMAGE_TAG ,
6
8
Button ,
7
9
ButtonStyleType ,
8
10
ButtonVariantType ,
@@ -48,7 +50,6 @@ import { getIsMaterialApproved } from '../cdMaterials.utils'
48
50
import { TriggerViewContext } from '../config'
49
51
import { TRIGGER_VIEW_PARAMS } from '../Constants'
50
52
import { FilterConditionViews , HandleRuntimeParamChange , TriggerViewContextType } from '../types'
51
- import { BULK_DEPLOY_ACTIVE_IMAGE_TAG , BULK_DEPLOY_LATEST_IMAGE_TAG } from './constants'
52
53
import ImageSelectionCTA from './ImageSelectionCTA'
53
54
import MaterialListEmptyState from './MaterialListEmptyState'
54
55
import MaterialListSkeleton from './MaterialListSkeleton'
@@ -58,6 +59,8 @@ import {
58
59
getApprovedImageClass ,
59
60
getConsumedAndAvailableMaterialList ,
60
61
getFilterActionBarTabs ,
62
+ getIsConsumedImageAvailable ,
63
+ getIsExceptionUser ,
61
64
getIsImageApprover ,
62
65
getSequentialCDCardTitleProps ,
63
66
getTriggerArtifactInfoProps ,
@@ -113,7 +116,8 @@ const DeployImageContent = ({
113
116
const { isSuperAdmin } = useMainContext ( )
114
117
const { onClickApprovalNode } = useContext < TriggerViewContextType > ( TriggerViewContext )
115
118
116
- const isExceptionUser = materialResponse ?. deploymentApprovalInfo ?. approvalConfigData ?. isExceptionUser ?? false
119
+ // Assumption: isExceptionUser is a global trait
120
+ const isExceptionUser = getIsExceptionUser ( materialResponse )
117
121
const requestedUserId = materialResponse ?. requestedUserId
118
122
const isApprovalConfigured = getIsApprovalPolicyConfigured (
119
123
materialResponse ?. deploymentApprovalInfo ?. approvalConfigData ,
@@ -122,10 +126,9 @@ const DeployImageContent = ({
122
126
const canApproverDeploy = materialResponse ?. canApproverDeploy ?? false
123
127
const resourceFilters = materialResponse ?. resourceFilters ?? [ ]
124
128
const hideImageTaggingHardDelete = materialResponse ?. hideImageTaggingHardDelete ?? false
125
- const isConsumedImageAvailable =
126
- materials . some ( ( materialItem ) => materialItem . deployed && materialItem . latest ) ?? false
127
- const isPreOrPostCD = stageType === DeploymentNodeType . PRECD || stageType === DeploymentNodeType . POSTCD
128
129
const runtimeParamsList = materialResponse ?. runtimeParams || [ ]
130
+ const isConsumedImageAvailable = getIsConsumedImageAvailable ( materials )
131
+ const isPreOrPostCD = stageType === DeploymentNodeType . PRECD || stageType === DeploymentNodeType . POSTCD
129
132
const isCDNode = stageType === DeploymentNodeType . CD
130
133
131
134
const tagOptions : SelectPickerOptionType < string > [ ] = useMemo ( ( ) => {
@@ -143,13 +146,33 @@ const DeployImageContent = ({
143
146
144
147
const selectedTagOption = useMemo ( ( ) => {
145
148
const selectedTag = tagOptions . find ( ( option ) => option . value === selectedTagName )
146
- return selectedTag || { label : 'Multiple Tags' , value : '' }
147
- } , [ selectedTagName , tagOptions ] )
149
+ const areMultipleTagsPresent = Object . values ( appInfoMap ) . some ( ( appDetails ) => {
150
+ const selectedImage = appDetails . materialResponse ?. materials ?. find (
151
+ ( material : CDMaterialType ) => material . isSelected ,
152
+ )
153
+
154
+ if ( ! selectedImage ) {
155
+ return false
156
+ }
157
+
158
+ return ! selectedImage . imageReleaseTags ?. some ( ( tagDetails ) => tagDetails . tagName === selectedTagName )
159
+ } )
160
+
161
+ if ( areMultipleTagsPresent || ! selectedTag ) {
162
+ return { label : 'Multiple Tags' , value : '' }
163
+ }
148
164
149
- const showRuntimeParams = ! ! ( isBulkTrigger && RuntimeParamTabs && isPreOrPostCD )
165
+ return selectedTag
166
+ } , [ selectedTagName , tagOptions , appInfoMap ] )
167
+
168
+ const sortedAppValues = useMemo (
169
+ ( ) => Object . values ( appInfoMap ) . sort ( ( a , b ) => stringComparatorBySortOrder ( a . appName , b . appName ) ) ,
170
+ [ appInfoMap ] ,
171
+ )
150
172
151
173
const getHandleAppChange = ( newAppId : number ) => ( e : SyntheticEvent ) => {
152
174
stopPropagation ( e )
175
+
153
176
if ( 'key' in e && e . key !== 'Enter' && e . key !== ' ' ) {
154
177
return
155
178
}
@@ -186,11 +209,6 @@ const DeployImageContent = ({
186
209
const showActionBar = FilterActionBar && ! isSearchApplied && ! ! resourceFilters ?. length && ! showConfiguredFilters
187
210
const areNoMoreImagesPresent = materials . length >= materialResponse ?. totalCount
188
211
189
- const sortedAppValues = useMemo (
190
- ( ) => Object . values ( appInfoMap || { } ) . sort ( ( a , b ) => stringComparatorBySortOrder ( a . appName , b . appName ) ) ,
191
- [ appInfoMap ] ,
192
- )
193
-
194
212
const handleSidebarTabChange : RuntimeParamsSidebarProps [ 'handleSidebarTabChange' ] = ( e ) => {
195
213
setDeployViewState ( ( prevState ) => ( {
196
214
...prevState ,
@@ -258,15 +276,15 @@ const DeployImageContent = ({
258
276
}
259
277
260
278
const handleImageSelection : ImageSelectionCTAProps [ 'handleImageSelection' ] = ( materialIndex ) => {
261
- const updatedMaterialList = materialList . map ( ( material , index ) => ( {
262
- ...material ,
263
- isSelected : index === materialIndex ,
264
- } ) )
265
-
266
279
setMaterialResponse ( ( prevData ) => {
267
280
const updatedMaterialResponse = structuredClone ( prevData )
268
- updatedMaterialResponse . materials = updatedMaterialList
269
- return updatedMaterialResponse
281
+ return {
282
+ ...updatedMaterialResponse ,
283
+ materials : updatedMaterialResponse . materials . map ( ( material , index ) => ( {
284
+ ...material ,
285
+ isSelected : index === materialIndex ,
286
+ } ) ) ,
287
+ }
270
288
} )
271
289
}
272
290
@@ -299,7 +317,7 @@ const DeployImageContent = ({
299
317
placeholder : 'Search by image tag' ,
300
318
autoFocus : true ,
301
319
} }
302
- dataTestId = "cd-trigger-search-by-commit-hash "
320
+ dataTestId = "cd-trigger-search-by-image-tag "
303
321
/>
304
322
)
305
323
@@ -308,21 +326,21 @@ const DeployImageContent = ({
308
326
imageReleaseTags ,
309
327
imageComment ,
310
328
) => {
311
- const updatedMaterialList = materialList . map ( ( material ) => {
312
- if ( + material . id === + matId ) {
313
- return {
314
- ...material ,
315
- imageReleaseTags,
316
- imageComment,
317
- }
318
- }
319
- return material
320
- } )
321
-
322
329
setMaterialResponse ( ( prevData ) => {
323
330
const updatedMaterialResponse = structuredClone ( prevData )
324
- updatedMaterialResponse . materials = updatedMaterialList
325
- return updatedMaterialResponse
331
+ return {
332
+ ...updatedMaterialResponse ,
333
+ materials : updatedMaterialResponse . materials . map ( ( material ) => {
334
+ if ( + material . id === + matId ) {
335
+ return {
336
+ ...material ,
337
+ imageReleaseTags,
338
+ imageComment,
339
+ }
340
+ }
341
+ return material
342
+ } ) ,
343
+ }
326
344
} )
327
345
}
328
346
@@ -455,7 +473,7 @@ const DeployImageContent = ({
455
473
return (
456
474
< div className = "flexbox-col h-100 dc__overflow-auto bg__primary" >
457
475
< div className = "dc__position-sticky dc__top-0 pt-12 bg__primary dc__zi-1" >
458
- { showRuntimeParams && (
476
+ { ! ! ( RuntimeParamTabs && isPreOrPostCD ) && (
459
477
< div className = "px-16 pb-8" >
460
478
< RuntimeParamTabs
461
479
tabs = { CD_MATERIAL_SIDEBAR_TABS }
@@ -504,6 +522,7 @@ const DeployImageContent = ({
504
522
role = "button"
505
523
tabIndex = { 0 }
506
524
onClick = { getHandleAppChange ( appDetails . appId ) }
525
+ onKeyDown = { getHandleAppChange ( appDetails . appId ) }
507
526
>
508
527
< Tooltip content = { appDetails . appName } >
509
528
< span className = "lh-20 cn-9 fw-6 fs-13 dc__truncate" > { appDetails . appName } </ span >
0 commit comments