diff --git a/lib/global-admin/addon/components/new-multi-cluster-app/component.js b/lib/global-admin/addon/components/new-multi-cluster-app/component.js index e10086868..11f0cc8e0 100644 --- a/lib/global-admin/addon/components/new-multi-cluster-app/component.js +++ b/lib/global-admin/addon/components/new-multi-cluster-app/component.js @@ -584,8 +584,10 @@ export default Component.extend(NewOrEdit, CatalogApp, { return false; } - if ( get(this, 'actuallySave') && get(this, 'selectedTemplateModel.questions')) { - primaryResource.set('answers', this.buildAnswerMap()) + if ( get(this, 'actuallySave') ) { + if ( get(this, 'selectedTemplateModel.questions') ) { + primaryResource.set('answers', this.buildAnswerMap()) + } return true; } else { diff --git a/lib/global-admin/addon/components/new-multi-cluster-app/template.hbs b/lib/global-admin/addon/components/new-multi-cluster-app/template.hbs index e0c09a4c5..e9ceee9f8 100644 --- a/lib/global-admin/addon/components/new-multi-cluster-app/template.hbs +++ b/lib/global-admin/addon/components/new-multi-cluster-app/template.hbs @@ -245,7 +245,10 @@ showHeader=false }} {{else}} - {{input-custom-answers app=primaryResource}} + {{input-custom-answers + app=multiClusterApp + isMultiClusterApp=true + }} {{/if}} {{/if}} diff --git a/lib/global-admin/addon/multi-cluster-apps/catalog/launch/route.js b/lib/global-admin/addon/multi-cluster-apps/catalog/launch/route.js index 96d12f383..368f4ad42 100644 --- a/lib/global-admin/addon/multi-cluster-apps/catalog/launch/route.js +++ b/lib/global-admin/addon/multi-cluster-apps/catalog/launch/route.js @@ -66,9 +66,16 @@ export default Route.extend({ neuApp = results.app; } } else { + let defaultAnswwer = store.createRecord({ + clusterId: null, + projectId: null, + type: 'answer', + values: [] + }); + neuApp = store.createRecord({ type: 'multiclusterapp', - answers: [], + answers: [defaultAnswwer], catalogId: results.tpl.catalogId, targets: [], members: [], diff --git a/lib/shared/addon/components/input-custom-answers/component.js b/lib/shared/addon/components/input-custom-answers/component.js index 9d7b4f18b..351a1d7ac 100644 --- a/lib/shared/addon/components/input-custom-answers/component.js +++ b/lib/shared/addon/components/input-custom-answers/component.js @@ -29,20 +29,18 @@ export default Component.extend({ growl: service(), layout, - pasteOrUpload: false, - showInput: true, - accept: '.yml, .yaml', - app: null, + pasteOrUpload: false, + showInput: true, + accept: '.yml, .yaml', + app: null, + isMultiClusterApp: false, + intialAnswerMap: null, init() { this._super(...arguments); - - if (!dotObject) { - import('dot-object').then( (module) => { - dotObject = module.default; - }); - } + this.initLazyModules(); + this.initInitialAnswerMap(); }, actions: { @@ -56,7 +54,17 @@ export default Component.extend({ cancel() { set(this, 'pasteOrUpload', false); - } + }, + + updateAnswers(answers) { + const { isMultiClusterApp } = this; + + if (isMultiClusterApp) { + set(this, 'app.answers.firstObject.values', answers); + } else { + set(this, 'app.answers', answers); + } + }, }, actualAccept: computed('accept', function() { @@ -156,4 +164,33 @@ export default Component.extend({ reader.readAsText(file); } }, + + initInitialAnswerMap() { + const { isMultiClusterApp } = this; + let answers; + + if (isMultiClusterApp) { + answers = this.getInitialMultiClusterAnswerMap(); + } else { + answers = this.getInitialMap(); + } + + set(this, 'intialAnswerMap', answers); + }, + + getInitialMultiClusterAnswerMap() { + return get(this, 'app.answers.firstObject.values'); + }, + + getInitialMap() { + return get(this, 'app.answers'); + }, + + initLazyModules() { + if (!dotObject) { + import('dot-object').then( (module) => { + dotObject = module.default; + }); + } + }, }); diff --git a/lib/shared/addon/components/input-custom-answers/template.hbs b/lib/shared/addon/components/input-custom-answers/template.hbs index ba371718b..f35211581 100644 --- a/lib/shared/addon/components/input-custom-answers/template.hbs +++ b/lib/shared/addon/components/input-custom-answers/template.hbs @@ -1,15 +1,34 @@
{{#if pasteOrUpload}} - + {{else}} - + {{/if}} - +
{{#if pasteOrUpload}}
- +
{{input-yaml @@ -24,12 +43,12 @@ {{top-errors errors=yamlErrors}} {{else if showInput}} {{form-key-value - initialMap=app.answers - changed=(action (mut app.answers)) + initialMap=intialAnswerMap + changed="updateAnswers" allowEmptyValue=true addInitialEmptyRow=true editing=true - header=(t 'newCatalog.answers.label') + header=(t "newCatalog.answers.label") addActionLabel="newCatalog.answers.addAction" keyLabel="newContainer.environment.keyLabel" keyPlaceholder="newContainer.environment.keyPlaceholder"