Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Fixup KV folder creation then further creation within that folder #12081

Merged
merged 5 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit makes the "pass an empty id to get a new ember-data object" work

}
// 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the actual bug

)
}}
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was mainly copy/pasted from the above (not visible unless you view the entire file). We were already testing: "creating a folder" and "clicking create from within a folder" but not "creating a folder and then immediately clicking create form within that folder".

I also noticed that we weren't asserting for existence of the input field in the "clicking create from within a folder" test that already existed. Whilst this test wasn't failing even with the extra assertion, I thought it would be a good idea to add here to helper prevent any possible regression in the future (line 52)