diff --git a/lib/shared/addon/components/cru-cloud-provider/component.js b/lib/shared/addon/components/cru-cloud-provider/component.js index bbf8f5a00..ad36c4f0e 100644 --- a/lib/shared/addon/components/cru-cloud-provider/component.js +++ b/lib/shared/addon/components/cru-cloud-provider/component.js @@ -9,6 +9,7 @@ import { isEmpty } from '@ember/utils'; import C from 'ui/utils/constants'; import { azure as AzureInfo } from './cloud-provider-info'; import { next } from '@ember/runloop'; +import { debouncedObserver } from 'ui/utils/debounce'; const azureDefaults = C.AZURE_DEFAULTS; const GENERIC_PATH = 'cluster.rancherKubernetesEngineConfig.cloudProvider.cloudConfig'; @@ -81,29 +82,34 @@ export default Component.extend({ } }), - configAnswersDidChange: observer('configAnswers', function() { - const configAnswers = get(this, 'configAnswers'); + configAnswersDidChange: debouncedObserver('mappedConfigAnswers.@each.{key,value}', function() { + const mappedAnswers = get(this, 'mappedConfigAnswers'); const selectedCloudProvider = get(this, 'selectedCloudProvider'); + const configAnswersOut = {}; + let pathForSet; switch (selectedCloudProvider) { case 'azure': - - set(this, AZURE_PATH, configAnswers); + pathForSet = AZURE_PATH; break; case 'amazonec2': - - set(this, AWS_PATH, configAnswers); + pathForSet = AWS_PATH; break; default: - - set(this, GENERIC_PATH, configAnswers); + pathForSet = GENERIC_PATH; break; } + + mappedAnswers.forEach((answer) => { + set(configAnswersOut, answer.key, answer.value); + }); + + set(this, pathForSet, configAnswersOut); }), selectedCloudProviderOverrideAvailable: computed( @@ -158,6 +164,20 @@ export default Component.extend({ } }), + mappedConfigAnswers: computed('configAnswers', function() { + const configAnswers = (get(this, 'configAnswers') || {}); + const out = []; + + Object.keys(configAnswers).forEach((answerKey) => { + out.push({ + key: answerKey, + value: configAnswers[answerKey] + }); + }); + + return out; + }), + checkDefaults(record) { get(this, 'azureDefaults').forEach((def) => { if (isEmpty(record[def])) { diff --git a/lib/shared/addon/components/cru-cloud-provider/template.hbs b/lib/shared/addon/components/cru-cloud-provider/template.hbs index 2c7f61f62..25c0f302c 100644 --- a/lib/shared/addon/components/cru-cloud-provider/template.hbs +++ b/lib/shared/addon/components/cru-cloud-provider/template.hbs @@ -146,20 +146,20 @@ {{#if (eq selectedCloudProvider "azure")}} - {{#each-in configAnswers as |key value|}} + {{#each mappedConfigAnswers as |answer|}}
-
{{#input-or-display editable=(not-eq mode "view") - value=(get configAnswers key) - obfuscate=(if (eq (get (get azureDescriptions key) "type") "password") true false) + value=(get configAnswers answer.key) + obfuscate=(if (eq (get (get azureDescriptions answer.key) "type") "password") true false) }} {{input class="form-control input-sm value" spellcheck="false" - type=(or (get (get azureDescriptions key) "type") "text") - value=(mut (get configAnswers key)) + type=(or (get (get azureDescriptions answer.key) "type") "text") + value=answer.value placeholder=(t "generic.value") }} {{/input-or-display}}
- {{/each-in}} + {{/each}} {{/if}} {{#if (not-eq mode "view")}}