@@ -19,7 +19,6 @@ import {
19
19
genericCDMaterialsService ,
20
20
GenericEmptyState ,
21
21
getStageTitle ,
22
- handleAnalyticsEvent ,
23
22
Icon ,
24
23
MODAL_TYPE ,
25
24
ModuleNameMap ,
@@ -64,11 +63,11 @@ import { getCDPipelineURL, importComponentFromFELibrary, useAppContext } from '@
64
63
import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackManager.service'
65
64
66
65
import { getIsMaterialApproved } from '../cdMaterials.utils'
67
- import { CD_MATERIAL_GA_EVENT } from '../Constants'
68
66
import { FilterConditionViews } from '../types'
69
67
import { BULK_DEPLOY_ACTIVE_IMAGE_TAG , BULK_DEPLOY_LATEST_IMAGE_TAG } from './constants'
70
68
import DeployImageContent from './DeployImageContent'
71
69
import DeployImageHeader from './DeployImageHeader'
70
+ import { loadOlderImages } from './service'
72
71
import { BuildDeployModalProps , DeployImageContentProps , GetInitialAppListProps } from './types'
73
72
74
73
const BulkCDStrategy = importComponentFromFELibrary ( 'BulkCDStrategy' , null , 'function' )
@@ -460,55 +459,34 @@ const BulkDeployModal = ({ handleClose, stageType, workflows, isVirtualEnvironme
460
459
} ) )
461
460
}
462
461
463
- const loadOlderImages = async ( ) => {
464
- handleAnalyticsEvent ( CD_MATERIAL_GA_EVENT . FetchMoreImagesClicked )
465
- // Even if user changes selectedAppId this will persist since a state closure
466
- const selectedApp = appInfoMap [ selectedAppId ]
467
-
468
- setAppInfoMap ( ( prev ) => ( {
469
- ...prev ,
470
- [ selectedAppId ] : {
471
- ...prev [ selectedAppId ] ,
472
- deployViewState : {
473
- ...prev [ selectedAppId ] . deployViewState ,
474
- isLoadingOlderImages : true ,
475
- } ,
476
- } ,
477
- } ) )
478
-
479
- const materialList = selectedApp . materialResponse ?. materials || [ ]
480
- const appDetails = appInfoMap [ selectedAppId ]
481
- const isConsumedImageAvailable =
482
- materialList . some ( ( materialItem ) => materialItem . deployed && materialItem . latest ) ?? false
483
-
484
- // TODO: Common
462
+ const handleLoadOlderImages = async ( ) => {
485
463
try {
486
- const newMaterialsResponse = await genericCDMaterialsService (
487
- CDMaterialServiceEnum . CD_MATERIALS ,
488
- appDetails . pipelineId ,
489
- stageType ,
490
- null ,
491
- {
492
- offset : materialList . length - Number ( isConsumedImageAvailable ) ,
493
- size : 20 ,
494
- search : appDetails . deployViewState . appliedSearchText || '' ,
495
- } ,
496
- )
464
+ // Even if user changes selectedAppId this will persist since a state closure
465
+ const selectedApp = appInfoMap [ selectedAppId ]
497
466
498
- // NOTE: Looping through _newResponse and removing elements that are already deployed and latest
499
- // NOTE: This is done to avoid duplicate images
500
- const filteredNewMaterialResponse = [ ...newMaterialsResponse . materials ] . filter (
501
- ( materialItem ) => ! ( materialItem . deployed && materialItem . latest ) ,
502
- )
503
-
504
- // updating the index of materials to maintain consistency
505
- const _newMaterialsResponse = filteredNewMaterialResponse . map ( ( materialItem , index ) => ( {
506
- ...materialItem ,
507
- index : materialList . length + index ,
467
+ setAppInfoMap ( ( prev ) => ( {
468
+ ...prev ,
469
+ [ selectedAppId ] : {
470
+ ...prev [ selectedAppId ] ,
471
+ deployViewState : {
472
+ ...prev [ selectedAppId ] . deployViewState ,
473
+ isLoadingOlderImages : true ,
474
+ } ,
475
+ } ,
508
476
} ) )
509
477
510
- const newMaterials = structuredClone ( materialList ) . concat ( _newMaterialsResponse )
478
+ const materialList = selectedApp . materialResponse ?. materials || [ ]
479
+ const appDetails = appInfoMap [ selectedAppId ]
511
480
const { materialResponse, deployViewState } = appDetails
481
+ const newMaterials = await loadOlderImages ( {
482
+ materialList,
483
+ resourceFilters : materialResponse ?. resourceFilters ,
484
+ filterView : deployViewState . filterView ,
485
+ appliedSearchText : appDetails . deployViewState . appliedSearchText || '' ,
486
+ stageType,
487
+ isRollbackTrigger : false ,
488
+ pipelineId : appDetails . pipelineId ,
489
+ } )
512
490
513
491
setAppInfoMap ( ( prev ) => ( {
514
492
...prev ,
@@ -524,36 +502,6 @@ const BulkDeployModal = ({ handleClose, stageType, workflows, isVirtualEnvironme
524
502
} ,
525
503
} ,
526
504
} ) )
527
-
528
- const baseSuccessMessage = `Fetched ${ _newMaterialsResponse . length } images.`
529
-
530
- if ( materialResponse ?. resourceFilters ?. length && ! deployViewState . appliedSearchText ) {
531
- const eligibleImages = _newMaterialsResponse . filter (
532
- ( mat ) => mat . filterState === FilterStates . ALLOWED ,
533
- ) . length
534
-
535
- const infoMessage =
536
- eligibleImages === 0
537
- ? 'No new eligible images found.'
538
- : `${ eligibleImages } new eligible images found.`
539
-
540
- if ( deployViewState . filterView === FilterConditionViews . ELIGIBLE ) {
541
- ToastManager . showToast ( {
542
- variant : ToastVariantType . info ,
543
- description : `${ baseSuccessMessage } ${ infoMessage } ` ,
544
- } )
545
- } else {
546
- ToastManager . showToast ( {
547
- variant : ToastVariantType . success ,
548
- description : `${ baseSuccessMessage } ${ infoMessage } ` ,
549
- } )
550
- }
551
- } else {
552
- ToastManager . showToast ( {
553
- variant : ToastVariantType . success ,
554
- description : baseSuccessMessage ,
555
- } )
556
- }
557
505
} catch ( error ) {
558
506
showError ( error )
559
507
} finally {
@@ -968,7 +916,7 @@ const BulkDeployModal = ({ handleClose, stageType, workflows, isVirtualEnvironme
968
916
reloadMaterials = { reloadOrSearchSelectedApp }
969
917
parentEnvironmentName = { parentEnvironmentName }
970
918
isVirtualEnvironment = { isVirtualEnvironment }
971
- loadOlderImages = { loadOlderImages }
919
+ loadOlderImages = { handleLoadOlderImages }
972
920
triggerType = { triggerType }
973
921
deployViewState = { deployViewState }
974
922
setDeployViewState = { setDeployViewState }
0 commit comments