From 4de1c697a2c94b006de4747c69b022575706e7ca Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:26:16 -0500 Subject: [PATCH] UI: fix DB Postgres test (#28227) --- ui/app/components/database-connection.js | 52 ++++++++++--------- .../components/database-connection.hbs | 16 ++++-- .../secrets/backend/database/secret-test.js | 16 ++++-- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/ui/app/components/database-connection.js b/ui/app/components/database-connection.js index 84c7380952..8c291be717 100644 --- a/ui/app/components/database-connection.js +++ b/ui/app/components/database-connection.js @@ -8,6 +8,7 @@ import { service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { waitFor } from '@ember/test-waiters'; +import { task } from 'ember-concurrency'; const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root'; const SHOW_ROUTE = 'vault.cluster.secrets.backend.show'; @@ -56,42 +57,43 @@ export default class DatabaseConnectionEdit extends Component { this.args.model[attr] = value; } - @action - async handleCreateConnection(evt) { - evt.preventDefault(); - const secret = this.args.model; - secret - .save() - .then(() => { + handleCreateConnection = task( + waitFor(async (evt) => { + evt.preventDefault(); + try { + const secret = this.args.model; + await secret.save(); this.showSaveModal = true; - }) - .catch((e) => { + } catch (e) { const errorMessage = getErrorMessage(e.errors); this.flashMessages.danger(errorMessage); - }); - } + } + }) + ); @action continueWithoutRotate() { + if (this.continueWithRotate.isRunning) return; this.showSaveModal = false; const { name } = this.args.model; this.transitionToRoute(SHOW_ROUTE, name); } - @action - @waitFor - async continueWithRotate() { - this.showSaveModal = false; - const { backend, name } = this.args.model; - try { - await this.rotateCredentials(backend, name); - this.flashMessages.success(`Successfully rotated root credentials for connection "${name}"`); - this.transitionToRoute(SHOW_ROUTE, name); - } catch (e) { - this.flashMessages.danger(`Error rotating root credentials: ${e.errors}`); - this.transitionToRoute(SHOW_ROUTE, name); - } - } + continueWithRotate = task( + waitFor(async () => { + const { backend, name } = this.args.model; + try { + await this.rotateCredentials(backend, name); + this.flashMessages.success(`Successfully rotated root credentials for connection "${name}"`); + this.transitionToRoute(SHOW_ROUTE, name); + } catch (e) { + this.flashMessages.danger(`Error rotating root credentials: ${e.errors}`); + this.transitionToRoute(SHOW_ROUTE, name); + } finally { + this.showSaveModal = false; + } + }) + ); @action handleUpdateConnection(evt) { diff --git a/ui/app/templates/components/database-connection.hbs b/ui/app/templates/components/database-connection.hbs index 4c099b7948..c7ef46b3f1 100644 --- a/ui/app/templates/components/database-connection.hbs +++ b/ui/app/templates/components/database-connection.hbs @@ -102,7 +102,7 @@ {{/if}} -