Skip to content

Commit

Permalink
ui: Fixup KV folder creation then further creation within that folder (
Browse files Browse the repository at this point in the history
…#12081)

The fix here is two fold:

- We shouldn't be providing the DataSource (which loads the data) with an id when we are creating from within a folder (in the buggy code we are providing the parentKey of the new KV you are creating)
- Being able to provide an empty id to the DataSource/KV repository and that repository responding with a newly created object is more towards the "new way of doing forms", therefore the corresponding code to return a newly created ember-data object. As we changed the actual bug in point 1 here, we need to make sure the repository responds with an empty object when the request id is empty.
  • Loading branch information
johncowen authored Jan 19, 2022
1 parent b0e3956 commit cdb8a35
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/12081.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fixed a bug with creating multiple nested KVs in one interaction
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{disabled (or disabld api.disabled)}}
>
{{#if api.isCreate}}
<label class="type-text{{if api.data.error.Key ' has-error'}}">
<label data-test-kv-key class="type-text{{if api.data.error.Key ' has-error'}}">
<span>Key or folder</span>
<input autofocus="autofocus" type="text" value={{left-trim api.data.Key parent}} name="additional" oninput={{action api.change}} placeholder="Key or folder" />
<em>To create a folder, end a key with <code>/</code></em>
Expand Down
15 changes: 12 additions & 3 deletions ui/packages/consul-ui/app/services/repository/kv.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ export default class KvService extends RepositoryService {
});
}
} else {
item = await super.findBySlug(...arguments);
if (params.id === '') {
item = await this.create({
Datacenter: params.dc,
Namespace: params.ns,
Partition: params.partition,
});
} else {
item = await super.findBySlug(...arguments);
}
}
// TODO: Whilst KV is using DataForm and DataForm does the model > changeset conversion
// a model > changeset conversion is not needed here
// TODO: Whilst KV is using DataForm and DataForm does the model >
// changeset conversion a model > changeset conversion is not needed here
// until we move KV to just use DataWriter like the other new stuff
return item;
}

Expand Down
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/templates/dc/kv/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ as |parentKey|}}
partition=route.params.partition
nspace=route.params.nspace
dc=route.params.dc
key=(if (string-ends-with routeName 'create') parentKey route.params.key)
key=(if (string-ends-with routeName 'create') '' route.params.key)
)
}}
as |loader|>
Expand Down
24 changes: 24 additions & 0 deletions ui/packages/consul-ui/tests/acceptance/dc/kvs/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,27 @@ Feature: dc / kvs / create
And I click create
And I see the text "New Key / Value" in "h1"
And I see the text "key-value" in "[data-test-breadcrumbs] li:nth-child(2) a"
And I see the "[data-test-kv-key]" element
Scenario: Clicking create from within a just created 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/
---
Given 1 kv model from yaml
---
- key-value/
---
And I submit
Then the url should be /datacenter/kv
And I click "[data-test-kv]"
And I click "[data-test-create]"
And I see the text "New Key / Value" in "h1"
And I see the text "key-value" in "[data-test-breadcrumbs] li:nth-child(2) a"
And I see the "[data-test-kv-key]" element

0 comments on commit cdb8a35

Please sign in to comment.