diff --git a/ui/app/components/secure-variable-form.hbs b/ui/app/components/secure-variable-form.hbs index bf78bbd15..6d2868b4b 100644 --- a/ui/app/components/secure-variable-form.hbs +++ b/ui/app/components/secure-variable-form.hbs @@ -1,12 +1,10 @@ -
+ {{!-- TODO: {{if this.parseError 'is-danger'}} on inputs --}}
{{#if this.duplicatePathWarning}}

- There is already a Secure Variable located at {{@model.path}}. + There is already a Secure Variable located at + {{@model.path}} + .
- Please choose a different path, or edit the existing Secure Variable. + Please choose a different path, or + + edit the existing Secure Variable + + .

{{/if}}
{{#each this.keyValues as |entry iter|}} -
- -
+ + + {{#if (eq entry this.keyValues.lastObject)}} + + {{else}} + + {{/if}} + {{#each-in entry.warnings as |k v|}} + + {{v}} + + {{/each-in}} + {{/each}} -
+ class="button is-primary" + type="submit" + > + Save + {{pluralize "Variable" @this.keyValues.length}} +
- + \ No newline at end of file diff --git a/ui/app/components/secure-variable-form.js b/ui/app/components/secure-variable-form.js index 1b119d855..4cb052b10 100644 --- a/ui/app/components/secure-variable-form.js +++ b/ui/app/components/secure-variable-form.js @@ -12,9 +12,6 @@ export default class SecureVariableFormComponent extends Component { @service router; @service flashMessages; - @tracked - shouldHideValues = true; - /** * @typedef {Object} DuplicatePathWarning * @property {string} path @@ -25,10 +22,6 @@ export default class SecureVariableFormComponent extends Component { */ @tracked duplicatePathWarning = null; - get valueFieldType() { - return this.shouldHideValues ? 'password' : 'text'; - } - get shouldDisableSave() { return !this.args.model?.path; } @@ -68,11 +61,6 @@ export default class SecureVariableFormComponent extends Component { } } - @action - toggleShowHide() { - this.shouldHideValues = !this.shouldHideValues; - } - @action appendRow() { this.keyValues.pushObject({ key: '', diff --git a/ui/app/components/secure-variable-form/input-group.hbs b/ui/app/components/secure-variable-form/input-group.hbs new file mode 100644 index 000000000..a2569369c --- /dev/null +++ b/ui/app/components/secure-variable-form/input-group.hbs @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/ui/app/components/secure-variable-form/input-group.js b/ui/app/components/secure-variable-form/input-group.js new file mode 100644 index 000000000..36eac0a4a --- /dev/null +++ b/ui/app/components/secure-variable-form/input-group.js @@ -0,0 +1,18 @@ +// @ts-check + +import { action } from '@ember/object'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; + +export default class InputGroup extends Component { + @tracked isObscured = true; + + get inputType() { + return this.isObscured ? 'password' : 'text'; + } + + @action + toggleInputType() { + this.isObscured = !this.isObscured; + } +} diff --git a/ui/tests/integration/components/secure-variable-form-test.js b/ui/tests/integration/components/secure-variable-form-test.js index d779cfb64..fe2caf46b 100644 --- a/ui/tests/integration/components/secure-variable-form-test.js +++ b/ui/tests/integration/components/secure-variable-form-test.js @@ -81,42 +81,52 @@ module('Integration | Component | secure-variable-form', function (hooks) { ); }); - test('Values can be toggled to show/hide', async function (assert) { - this.set( - 'mockedModel', - server.create('variable', { - keyValues: [{ key: 'foo', value: 'bar' }], - }) - ); - - assert.expect(6); - - await render(hbs``); - await click('.key-value button.add-more'); // add a second variable - - findAll('input.value-input').forEach((input, iter) => { - assert.equal( - input.getAttribute('type'), - 'password', - `Value ${iter + 1} is hidden by default` + module('editing and creating new key/value pairs', function () { + test('it should allow each key/value row to toggle password visibility', async function (assert) { + this.set( + 'mockedModel', + server.create('variable', { + keyValues: [{ key: 'foo', value: 'bar' }], + }) ); - }); - await click('.key-value button.show-hide-values'); - findAll('input.value-input').forEach((input, iter) => { + assert.expect(6); + + await render(hbs``); + await click('.key-value button.add-more'); // add a second variable + + findAll('input.value-input').forEach((input, iter) => { + assert.equal( + input.getAttribute('type'), + 'password', + `Value ${iter + 1} is hidden by default` + ); + }); + + await click('.key-value button.show-hide-values'); + const [firstRow, secondRow] = findAll('input.value-input'); + assert.equal( - input.getAttribute('type'), + firstRow.getAttribute('type'), 'text', - `Value ${iter + 1} is shown when toggled` + 'Only the row that is clicked on toggles visibility' ); - }); - - await click('.key-value button.show-hide-values'); - findAll('input.value-input').forEach((input, iter) => { assert.equal( - input.getAttribute('type'), + secondRow.getAttribute('type'), 'password', - `Value ${iter + 1} is hidden when toggled again` + 'Rows that are not clicked remain obscured' + ); + + await click('.key-value button.show-hide-values'); + assert.equal( + firstRow.getAttribute('type'), + 'password', + 'Only the row that is clicked on toggles visibility' + ); + assert.equal( + secondRow.getAttribute('type'), + 'password', + 'Rows that are not clicked remain obscured' ); }); });