From dd43e0db2ff352ad1e06d17c75e289ba470cbf46 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:45:50 -0500 Subject: [PATCH] UI: Allow navigate to list from View Secret card (#22502) --- changelog/22502.txt | 3 ++ ui/app/components/get-credentials-card.js | 23 +++++++++- .../components/get-credentials-card.hbs | 13 ++---- .../vault/cluster/secrets/backend/list.hbs | 6 +-- ui/lib/core/addon/components/input-search.js | 6 +++ .../components/get-credentials-card-test.js | 42 +++++++++++++++++++ 6 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 changelog/22502.txt diff --git a/changelog/22502.txt b/changelog/22502.txt new file mode 100644 index 0000000000..b9d21c2ce2 --- /dev/null +++ b/changelog/22502.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: KV View Secret card will link to list view if input ends in "/" +``` \ No newline at end of file diff --git a/ui/app/components/get-credentials-card.js b/ui/app/components/get-credentials-card.js index 999b85a07f..cd6015e9e7 100644 --- a/ui/app/components/get-credentials-card.js +++ b/ui/app/components/get-credentials-card.js @@ -22,6 +22,7 @@ * @param {string} backend - Passed to SearchSelect query method to fetch dropdown options */ +// TODO: kv engine cleanup remove secrets related logic import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; @@ -32,18 +33,38 @@ export default class GetCredentialsCard extends Component { @tracked role = ''; @tracked secret = ''; + constructor() { + super(...arguments); + this.secret = this.args?.initialValue || ''; + } + + get buttonText() { + if (this.args.type === 'secret') { + if (this.secret.endsWith('/')) { + return 'View list'; + } + return 'View secret'; + } + return 'Get credentials'; + } + get buttonDisabled() { return !this.role && !this.secret; } @action - transitionToCredential() { + transitionToCredential(evt) { + evt.preventDefault(); const role = this.role; const secret = this.secret; if (role) { this.router.transitionTo('vault.cluster.secrets.backend.credentials', role); } if (secret) { + if (secret.endsWith('/')) { + this.router.transitionTo('vault.cluster.secrets.backend.list', secret); + return; + } this.router.transitionTo('vault.cluster.secrets.backend.show', secret); } } diff --git a/ui/app/templates/components/get-credentials-card.hbs b/ui/app/templates/components/get-credentials-card.hbs index 4ded373929..93c6775d03 100644 --- a/ui/app/templates/components/get-credentials-card.hbs +++ b/ui/app/templates/components/get-credentials-card.hbs @@ -3,7 +3,7 @@ SPDX-License-Identifier: BUSL-1.1 ~}} -
\ No newline at end of file diff --git a/ui/app/templates/vault/cluster/secrets/backend/list.hbs b/ui/app/templates/vault/cluster/secrets/backend/list.hbs index d8b919ad07..9ff9ff56a7 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/list.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/list.hbs @@ -31,10 +31,10 @@ @renderInputSearch={{true}} @title="View secret" @searchLabel="Secret path" - @subText="Type the path of the secret you want to read" + @subText="Type the path of the secret you want to view. Include a trailing slash to navigate to the list view." @placeholder="secret/" - @backend="kv" @type="secret" + @initialValue={{this.baseKey.id}} /> @@ -148,7 +148,7 @@