Fix KV Version History queryParams on the component LinkedBlock (#12079)

* fix the issue

* add test coverage

* add documentation to link-block

* add changelog

* modify for browserstack
This commit is contained in:
Angel Garbarino 2021-07-14 15:38:55 -06:00 committed by GitHub
parent f7635ec1b8
commit 84da2424a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 2 deletions

3
changelog/12079.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: Fix Version History queryParams on LinkedBlock
```

View File

@ -19,7 +19,11 @@
</p.levelLeft> </p.levelLeft>
</PageHeader> </PageHeader>
<ListView @items={{reverse model.versions}} @itemNoun="version" as |list|> <ListView @items={{reverse model.versions}} @itemNoun="version" as |list|>
<ListItem @hasMenu={{false}} @linkParams={{array 'vault.cluster.secrets.backend.show' model.id (query-params version=list.item.version) }} as |Item|> <ListItem
@hasMenu={{false}}
@linkParams={{array 'vault.cluster.secrets.backend.show' model.id}}
@queryParams={{hash version=list.item.version}}
as |Item|>
<Item.content> <Item.content>
<div class="columns is-flex-1"> <div class="columns is-flex-1">
<div> <div>

View File

@ -3,6 +3,28 @@ import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile'; import hbs from 'htmlbars-inline-precompile';
import { encodePath } from 'vault/utils/path-encoding-helpers'; 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
* <LinkedBlock
* @params={{array 'vault.cluster.secrets.backend.show 'my-secret-path'}}
* @queryParams={{hash version=1}}
* @class="list-item-row"
* data-test-list-item-link
* >
* // Use any wrapped content here
* </LinkedBlock>
* ```
*
* @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({ let LinkedBlockComponent = Component.extend({
router: service(), router: service(),

View File

@ -8,6 +8,7 @@ export default Component.extend({
flashMessages: service(), flashMessages: service(),
tagName: '', tagName: '',
linkParams: null, linkParams: null,
queryParams: null,
componentName: null, componentName: null,
hasMenu: true, hasMenu: true,

View File

@ -1,7 +1,13 @@
{{#if componentName}} {{#if componentName}}
{{component componentName item=item}} {{component componentName item=item}}
{{else if linkParams}} {{else if linkParams}}
<LinkedBlock @params={{linkParams}} @linkPrefix={{@linkPrefix}} @class="list-item-row" data-test-list-item-link> <LinkedBlock
@params={{linkParams}}
@queryParams={{@queryParams}}
@linkPrefix={{@linkPrefix}}
@class="list-item-row"
data-test-list-item-link
>
<div class="level is-mobile"> <div class="level is-mobile">
<div class="level-left is-flex-1" data-test-list-item-content> <div class="level-left is-flex-1" data-test-list-item-content>
{{#link-to params=linkParams class="has-text-weight-semibold has-text-black is-display-flex is-flex-1 is-no-underline"}} {{#link-to params=linkParams class="has-text-weight-semibold has-text-black is-display-flex is-flex-1 is-no-underline"}}

View File

@ -114,6 +114,33 @@ module('Acceptance | secrets/secret/create', function(hooks) {
assert.equal(currentURL(), `/vault/secrets/${enginePath}/show/meep`, 'navigates to show secret'); 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) { test('version 1 performs the correct capabilities lookup', async function(assert) {
let enginePath = `kv-${new Date().getTime()}`; let enginePath = `kv-${new Date().getTime()}`;
let secretPath = 'foo/bar'; let secretPath = 'foo/bar';
@ -188,6 +215,7 @@ module('Acceptance | secrets/secret/create', function(hooks) {
'navigates to the ancestor created earlier' 'navigates to the ancestor created earlier'
); );
}); });
test('first level secrets redirect properly upon deletion', async function(assert) { test('first level secrets redirect properly upon deletion', async function(assert) {
let enginePath = `kv-${new Date().getTime()}`; let enginePath = `kv-${new Date().getTime()}`;
let secretPath = 'test'; let secretPath = 'test';