From 2e47e39cf7468336adf90ac1b903e8c102a32842 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw Date: Mon, 23 Nov 2020 10:38:09 -0600 Subject: [PATCH] Fix delete role issue on transform (#10417) * Fix bug where adding and then removing a new role on a transformation when no other roles have been created causes an error * Update test on search-select to reflect new behavior which does not add created options to list on delete * Add changelog --- changelog/10417.txt | 4 ++++ ui/lib/core/addon/components/search-select.js | 6 ++++-- ui/tests/integration/components/search-select-test.js | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 changelog/10417.txt diff --git a/changelog/10417.txt b/changelog/10417.txt new file mode 100644 index 000000000..7ff4c3cc8 --- /dev/null +++ b/changelog/10417.txt @@ -0,0 +1,4 @@ +```release-note:bug +ui: Fix bug in Transform secret engine when a new role is added and then removed from a transformation +``` + diff --git a/ui/lib/core/addon/components/search-select.js b/ui/lib/core/addon/components/search-select.js index 36cd3faa8..a0a6c4d73 100644 --- a/ui/lib/core/addon/components/search-select.js +++ b/ui/lib/core/addon/components/search-select.js @@ -136,7 +136,7 @@ export default Component.extend({ this.onChange(val); }, createOption(optionId) { - let newOption = { name: optionId, id: optionId }; + let newOption = { name: optionId, id: optionId, new: true }; this.selectedOptions.pushObject(newOption); this.handleChange(); }, @@ -147,7 +147,9 @@ export default Component.extend({ }, discardSelection(selected) { this.selectedOptions.removeObject(selected); - this.options.pushObject(selected); + if (!selected.new) { + this.options.pushObject(selected); + } this.handleChange(); }, constructSuggestion(id) { diff --git a/ui/tests/integration/components/search-select-test.js b/ui/tests/integration/components/search-select-test.js index b7b476f12..34f3654a2 100644 --- a/ui/tests/integration/components/search-select-test.js +++ b/ui/tests/integration/components/search-select-test.js @@ -162,7 +162,7 @@ module('Integration | Component | search select', function(hooks) { assert.equal(component.options.length, 3, 'shows all options'); }); - test('it adds created item to list items on create and reinserts into drop down on delete', async function(assert) { + test('it adds created item to list items on create and removes without adding back to options on delete', async function(assert) { const models = ['identity/entity']; this.set('models', models); this.set('onChange', sinon.spy()); @@ -180,7 +180,7 @@ module('Integration | Component | search select', function(hooks) { assert.equal(component.selectedOptions.length, 0, 'there are no selected options'); assert.ok(this.onChange.calledWith([])); await clickTrigger(); - assert.equal(component.options.length, 4, 'shows all options, including created option'); + assert.equal(component.options.length, 3, 'does not add deleted option back to list'); }); test('it uses fallback component if endpoint 403s', async function(assert) {