ui: [Bugfix] KV creation from within a 'folder' (#8613)

* ui: Prefill an newly created KV for the when we are on a create route

* ui: Add some KV creation tests
This commit is contained in:
John Cowen 2020-09-09 09:12:09 +01:00 committed by hashicorp-ci
parent b3ca781602
commit 3c1f24525a
3 changed files with 62 additions and 16 deletions

View File

@ -31,7 +31,7 @@
<label for="" class="type-text{{if api.data.error.Value ' has-error'}}"> <label for="" class="type-text{{if api.data.error.Value ' has-error'}}">
<span>Value</span> <span>Value</span>
{{#if json}} {{#if json}}
<CodeEditor @value={{atob api.data.Value}} @onkeyup={{action api.change "value"}} /> <CodeEditor @name="value" @value={{atob api.data.Value}} @onkeyup={{action api.change "value"}} />
{{else}} {{else}}
<textarea autofocus={{not api.isCreate}} name="value" oninput={{action api.change}}>{{atob api.data.Value}}</textarea> <textarea autofocus={{not api.isCreate}} name="value" oninput={{action api.change}}>{{atob api.data.Value}}</textarea>
{{/if}} {{/if}}

View File

@ -9,6 +9,11 @@ export default Route.extend({
repo: service('repository/kv'), repo: service('repository/kv'),
sessionRepo: service('repository/session'), sessionRepo: service('repository/session'),
model: function(params) { model: function(params) {
const create =
this.routeName
.split('.')
.pop()
.indexOf('create') !== -1;
const key = params.key; const key = params.key;
const dc = this.modelFor('dc').dc.Name; const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1); const nspace = this.modelFor('nspace').nspace.substr(1);
@ -19,7 +24,12 @@ export default Route.extend({
typeof key !== 'undefined' typeof key !== 'undefined'
? this.repo.findBySlug(ascend(key, 1) || '/', dc, nspace) ? this.repo.findBySlug(ascend(key, 1) || '/', dc, nspace)
: this.repo.findBySlug('/', dc, nspace), : this.repo.findBySlug('/', dc, nspace),
item: typeof key !== 'undefined' ? this.repo.findBySlug(key, dc, nspace) : undefined, item: create
? this.repo.create({
Datacenter: dc,
Namespace: nspace,
})
: this.repo.findBySlug(key, dc, nspace),
session: null, session: null,
}).then(model => { }).then(model => {
// TODO: Consider loading this after initial page load // TODO: Consider loading this after initial page load

View File

@ -1,6 +1,6 @@
@setupApplicationTest @setupApplicationTest
Feature: dc / kvs / create Feature: dc / kvs / create
Scenario: Scenario: Creating a root KV
Given 1 datacenter model with the value "datacenter" Given 1 datacenter model with the value "datacenter"
When I visit the kv page for yaml When I visit the kv page for yaml
--- ---
@ -8,7 +8,43 @@ Feature: dc / kvs / create
--- ---
Then the url should be /datacenter/kv/create Then the url should be /datacenter/kv/create
And the title should be "New Key/Value - Consul" And the title should be "New Key/Value - Consul"
Then I fill in with yaml
@ignore ---
Scenario: Test we can create a KV additional: key-value
Then ok value: value
---
And I submit
Then the url should be /datacenter/kv
Then a PUT request was made to "/v1/kv/key-value?dc=datacenter&ns=@namespace"
And "[data-notification]" has the "notification-update" class
And "[data-notification]" has the "success" class
Scenario: Creating a folder
Given 1 datacenter model with the value "datacenter"
When I visit the kv page for yaml
---
dc: datacenter
---
Then the url should be /datacenter/kv/create
And the title should be "New Key/Value - Consul"
Then I fill in with yaml
---
additional: key-value/
---
And I submit
Then the url should be /datacenter/kv
Then a PUT request was made to "/v1/kv/key-value/?dc=datacenter&ns=@namespace"
And "[data-notification]" has the "notification-update" class
And "[data-notification]" has the "success" class
Scenario: Clicking create from within a folder
Given 1 datacenter model with the value "datacenter"
And 1 kv model from yaml
---
- key-value/
---
When I visit the kvs page for yaml
---
dc: datacenter
---
And I click kv on the kvs
And I click create
And I see the text "New Key / Value" in "h1"