diff --git a/changelog/12079.txt b/changelog/12079.txt new file mode 100644 index 0000000000000..e41d032b77b70 --- /dev/null +++ b/changelog/12079.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix Version History queryParams on LinkedBlock +``` diff --git a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs index 9281ce6cedfee..ea0c579620fb9 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs @@ -19,7 +19,11 @@ - +
diff --git a/ui/lib/core/addon/components/linked-block.js b/ui/lib/core/addon/components/linked-block.js index 769180183e13f..3d1a6f517536b 100644 --- a/ui/lib/core/addon/components/linked-block.js +++ b/ui/lib/core/addon/components/linked-block.js @@ -3,6 +3,28 @@ import Component from '@ember/component'; import hbs from 'htmlbars-inline-precompile'; import { encodePath } from 'vault/utils/path-encoding-helpers'; +/** + * @module LinkedBlock + * LinkedBlock components are linkable divs that yield any content nested within them. They are often used in list views such as when listing the secret engines. + * + * @example + * ```js + * + * // Use any wrapped content here + * + * ``` + * + * @param {Array} params=null - These are values sent to the router's transitionTo method. First item is route, second is the optional path. + * @param {Object} [queryParams=null] - queryParams can be passed via this property. It needs to be an object. + * @param {String} [linkPrefix=null] - Overwrite the params with custom route. See KMIP. + * @param {Boolean} [encode=false] - Encode the path. + */ + let LinkedBlockComponent = Component.extend({ router: service(), diff --git a/ui/lib/core/addon/components/list-item.js b/ui/lib/core/addon/components/list-item.js index b22cf10362d78..33ff65f492b67 100644 --- a/ui/lib/core/addon/components/list-item.js +++ b/ui/lib/core/addon/components/list-item.js @@ -8,6 +8,7 @@ export default Component.extend({ flashMessages: service(), tagName: '', linkParams: null, + queryParams: null, componentName: null, hasMenu: true, diff --git a/ui/lib/core/addon/templates/components/list-item.hbs b/ui/lib/core/addon/templates/components/list-item.hbs index d3cd2807b77b8..db971d92f88be 100644 --- a/ui/lib/core/addon/templates/components/list-item.hbs +++ b/ui/lib/core/addon/templates/components/list-item.hbs @@ -1,7 +1,13 @@ {{#if componentName}} {{component componentName item=item}} {{else if linkParams}} - +
{{#link-to params=linkParams class="has-text-weight-semibold has-text-black is-display-flex is-flex-1 is-no-underline"}} diff --git a/ui/tests/acceptance/secrets/backend/kv/secret-test.js b/ui/tests/acceptance/secrets/backend/kv/secret-test.js index c1c80d9a99a16..9f3545e58fffb 100644 --- a/ui/tests/acceptance/secrets/backend/kv/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/kv/secret-test.js @@ -114,6 +114,33 @@ module('Acceptance | secrets/secret/create', function(hooks) { assert.equal(currentURL(), `/vault/secrets/${enginePath}/show/meep`, 'navigates to show secret'); }); + test('it navigates to version history and to a specific version', async function(assert) { + const path = `kv-path-${new Date().getTime()}`; + await listPage.visitRoot({ backend: 'secret' }); + await settled(); + await listPage.create(); + await settled(); + await editPage.createSecret(path, 'foo', 'bar'); + await click('[data-test-popup-menu-trigger="version"]'); + await settled(); + await click('[data-test-version-history]'); + await settled(); + assert + .dom('[data-test-list-item-content]') + .hasText('Version 1 Current', 'shows version one data on the version history as current'); + assert.dom('[data-test-list-item-content]').exists({ count: 1 }, 'renders a single version'); + + await click('.linked-block'); + await settled(); + await settled(); + assert.dom('[data-test-masked-input]').hasText('bar', 'renders secret on the secret version show page'); + assert.equal( + currentURL(), + `/vault/secrets/secret/show/${path}?version=1`, + 'redirects to the show page with queryParam version=1' + ); + }); + test('version 1 performs the correct capabilities lookup', async function(assert) { let enginePath = `kv-${new Date().getTime()}`; let secretPath = 'foo/bar'; @@ -188,6 +215,7 @@ module('Acceptance | secrets/secret/create', function(hooks) { 'navigates to the ancestor created earlier' ); }); + test('first level secrets redirect properly upon deletion', async function(assert) { let enginePath = `kv-${new Date().getTime()}`; let secretPath = 'test';