From a17edd9d0fa05a03cba359f3a8b23efb616f6a4d Mon Sep 17 00:00:00 2001 From: Chelsea Shaw Date: Wed, 17 Mar 2021 11:32:27 -0500 Subject: [PATCH] UI: Connection "Add Role" automatically populates database in form (#11119) * Database role create form sets url param itemKey as database on init * add test for new functionality * Add changelog --- changelog/11119.txt | 3 +++ ui/app/components/database-role-edit.js | 3 +++ ui/app/templates/components/database-connection.hbs | 2 +- .../acceptance/secrets/backend/database/secret-test.js | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog/11119.txt diff --git a/changelog/11119.txt b/changelog/11119.txt new file mode 100644 index 000000000..6ce5c6d4a --- /dev/null +++ b/changelog/11119.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Add role from database connection automatically populates the database for new role +``` diff --git a/ui/app/components/database-role-edit.js b/ui/app/components/database-role-edit.js index 992c712c7..b6820ea82 100644 --- a/ui/app/components/database-role-edit.js +++ b/ui/app/components/database-role-edit.js @@ -19,6 +19,9 @@ export default class DatabaseRoleEdit extends Component { ) { this.wizard.transitionFeatureMachine(this.wizard.featureState, 'CONTINUE', 'database'); } + if (this.args.initialKey) { + this.args.model.database = [this.args.initialKey]; + } } @tracked loading = false; diff --git a/ui/app/templates/components/database-connection.hbs b/ui/app/templates/components/database-connection.hbs index 0ecf92af4..b0b555cf5 100644 --- a/ui/app/templates/components/database-connection.hbs +++ b/ui/app/templates/components/database-connection.hbs @@ -60,7 +60,7 @@ @secret='' @mode="create" @type="add" - @queryParams={{query-params initialKey=(or filter baseKey.id) itemType="role"}} + @queryParams={{query-params initialKey=@model.name itemType="role"}} @data-test-secret-create=true > Add role diff --git a/ui/tests/acceptance/secrets/backend/database/secret-test.js b/ui/tests/acceptance/secrets/backend/database/secret-test.js index 947f565be..38b9ce3bd 100644 --- a/ui/tests/acceptance/secrets/backend/database/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/database/secret-test.js @@ -139,6 +139,14 @@ module('Acceptance | secrets/database/*', function(hooks) { assert .dom(`[data-test-row-value="Write concern"]`) .hasText('{ "wtimeout": 5000 }', 'Write concern is now showing on the table'); + // click "Add Role" + await click('[data-test-secret-create="true"]'); + await settled(); + assert.equal( + searchSelectComponent.selectedOptions[0].text, + connectionDetails.id, + 'Database connection is pre-selected on the form' + ); }); test('buttons show up for managing connection', async function(assert) {