@@ -17,12 +17,13 @@ import {FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR} from '@angular/forms';
1717import { ClusterSpecService } from '@app/core/services/cluster-spec' ;
1818import { StepRegistry } from '@app/wizard/config' ;
1919import { StepBase } from '@app/wizard/step/base' ;
20+ import { WizardMode } from '@app/wizard/types/wizard-mode' ;
2021import { ApplicationService } from '@core/services/application' ;
2122import { WizardService } from '@core/services/wizard/wizard' ;
2223import { ApplicationsListView } from '@shared/components/application-list/component' ;
2324import { Application , ApplicationSettings , createApplicationInstallation } from '@shared/entity/application' ;
24- import _ , { merge } from 'lodash' ;
25- import { forkJoin , takeUntil } from 'rxjs' ;
25+ import _ from 'lodash' ;
26+ import { forkJoin , switchMap , takeUntil } from 'rxjs' ;
2627
2728enum Controls {
2829 Applications = 'applications' ,
@@ -49,6 +50,7 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
4950 readonly ApplicationsListView = ApplicationsListView ;
5051
5152 applications : Application [ ] = [ ] ;
53+ wizardMode : WizardMode ;
5254
5355 private _applicationSettings : ApplicationSettings ;
5456
@@ -62,6 +64,8 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
6264 }
6365
6466 ngOnInit ( ) : void {
67+ this . wizardMode = window . history . state ?. mode ;
68+
6569 this . form = this . _builder . group ( {
6670 [ Controls . Applications ] : this . _builder . control ( '' ) ,
6771 } ) ;
@@ -81,45 +85,60 @@ export class ApplicationsStepComponent extends StepBase implements OnInit, OnDes
8185 }
8286 return application ;
8387 } ) || [ ] ;
84-
85- merge ( this . _clusterSpecService . datacenterChanges , this . _applicationService . applicationChanges )
86- . pipe ( takeUntil ( this . _unsubscribe ) )
87- . subscribe ( _ => {
88- this . loadDefaultAndEnforcedApplications ( ) ;
88+ this . _loadDefaultAndEnforcedApplications ( ) ;
89+ if ( this . wizardMode !== WizardMode . CustomizeClusterTemplate && this . wizardMode !== WizardMode . EditClusterTemplate ) {
90+ this . _clusterSpecService . datacenterChanges . pipe ( takeUntil ( this . _unsubscribe ) ) . subscribe ( _ => {
91+ this . _applicationService . applications = [ ] ;
92+ this . applications = [ ] ;
93+ this . _loadDefaultAndEnforcedApplications ( ) ;
8994 } ) ;
95+ }
9096 }
9197
92- private loadDefaultAndEnforcedApplications ( ) {
93- const defaultAndEnforcedApplications = this . _applicationService . applicationDefinitions . filter (
94- application => application . spec . default || application . spec . enforced
95- ) ;
96-
97- // Fetch individual application definitions and create ApplicationInstallations
98- forkJoin (
99- defaultAndEnforcedApplications . map ( application =>
100- this . _applicationService . getApplicationDefinition ( application . name )
98+ private _loadDefaultAndEnforcedApplications ( ) {
99+ this . _applicationService
100+ . listApplicationDefinitions ( )
101+ . pipe (
102+ switchMap ( apps => {
103+ const defaultAndEnforcedApplications = apps . filter ( application => {
104+ return (
105+ ( application . spec . default || application . spec . enforced ) &&
106+ ( ! application . spec . selector ?. datacenters ||
107+ application . spec . selector ?. datacenters ?. includes ( this . _clusterSpecService . datacenter ) )
108+ ) ;
109+ } ) ;
110+ return forkJoin (
111+ defaultAndEnforcedApplications . map ( application =>
112+ this . _applicationService . getApplicationDefinition ( application . name )
113+ )
114+ ) ;
115+ } )
101116 )
102- ) . subscribe ( applicationDefinitions => {
103- applicationDefinitions . forEach ( appDef => {
104- if ( appDef . name === 'k8sgpt' ) {
105- appDef . spec . enforced = true ;
106- }
107-
108- if ( appDef . name === 'cert-manager' ) {
109- appDef . spec . default = true ;
110- }
111-
112- const applicationInstallation = createApplicationInstallation (
113- appDef ,
114- this . _applicationSettings ?. defaultNamespace
115- ) ;
116- this . onApplicationAdded ( applicationInstallation ) ;
117+ // Fetch individual application definitions and create ApplicationInstallations
118+ . subscribe ( applicationDefinitions => {
119+ applicationDefinitions . forEach ( appDef => {
120+ if ( appDef . name === 'k8sgpt' ) {
121+ appDef . spec . enforced = true ;
122+ }
123+
124+ if ( appDef . name === 'cert-manager' ) {
125+ appDef . spec . default = true ;
126+ }
127+
128+ const applicationInstallation = createApplicationInstallation (
129+ appDef ,
130+ this . _applicationSettings ?. defaultNamespace
131+ ) ;
132+ this . onApplicationAdded ( applicationInstallation ) ;
133+ } ) ;
117134 } ) ;
118- } ) ;
119135 }
120136
121137 onApplicationAdded ( application : Application ) : void {
122138 application . id = `${ application . name } /${ application . spec . namespace . name } ` ;
139+ if ( this . applications . find ( app => app . id === application . id ) ) {
140+ return ;
141+ }
123142 this . applications = [ ...this . applications , application ] ;
124143 this . _onApplicationsChanged ( ) ;
125144 }
0 commit comments