-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Add KV view for wrap tool #29677
base: main
Are you sure you want to change the base?
Conversation
Build Results: |
CI Results: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Excellent PR description, thanks for including screenshots. 📸
I think this is nearly there! There is a bug when there's a linting error and the user toggles to the key/value view. The wrap data button is disabled and the linting errors get a little wonky. We also want to be consistent with the type for this.wrapData
. I offered a couple suggestions of either initializing it as null
or an {}
. Let me know if you want to discuss more at all or have any questions 😄
ui/app/components/tools/wrap.js
Outdated
@tracked errorMessage = ''; | ||
@tracked showJson = true; | ||
get jsonWrapStartValue() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getters are useful for computing return values. we're just returning a static string here so this can just be a variable.
On that note - If it's only used in the getter below, we probably don't need a variable and can just reference this string below.
Another option is to initialize this.wrapData = {}
. This would remove the need for the ternary (I'm not worried about preserving the line break) and we could just consistently returned the stringified object. Since stringify
is a helper, it can actually be called directly in the template if you want to go that route instead.
vault/ui/app/components/tools/unwrap.hbs
Line 22 in 4617af3
@value={{stringify this.unwrapData}} |
|
||
await this.renderComponent(); | ||
await codemirror().setValue(this.wrapData); | ||
await click('[data-test-toggle-input="json"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After toggling, before submitting can we input one more row of data? I want to make sure the tracked property is updated properly. It may be useful to input a multi line string here as well! That way we're also making sure to test for the original request.
ui/app/components/tools/wrap.hbs
Outdated
{{#if this.showJson}} | ||
<div class="field"> | ||
<div class="control"> | ||
<JsonEditor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the screenshot, it looks like we could use a bit of a margin between this and the toolbar. The JsonEditor
has "splattributes" which means if you apply class=
here that will apply to where ever ...attributes
is spread in the component. (ember docs if you want to read up more)
Adding class="has-top-margin-s"
should make this visually match the spacing we see in the KV secrets view (or -m
like below if that looks better to you!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I think going with -s
for the json editor and -l
for the KV object editor looks good and prevents the Data to wrap
label from jumping around too much.
ui/app/components/tools/wrap.js
Outdated
|
||
@action | ||
reset(clearData = true) { | ||
this.token = ''; | ||
this.errorMessage = ''; | ||
this.wrapTTL = null; | ||
if (clearData) this.wrapData = '{\n}'; | ||
if (clearData) this.wrapData = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the type consistent for this.wrapData
. Since we use it for a falsey check above - kinda thinking we should initialize this as null
and reset it to that for consistency. That way if it does have a value, we know it will consistently be an object. It's a little confusing now if it should be a JSON object or a string
@@ -46,13 +63,13 @@ export default class ToolsWrap extends Component { | |||
codemirror.performLint(); | |||
const hasErrors = codemirror?.state.lint.marked?.length > 0; | |||
this.buttonDisabled = hasErrors; | |||
if (!hasErrors) this.wrapData = val; | |||
if (!hasErrors) this.wrapData = JSON.parse(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we get into a weird state if there are linting errors and the user toggles the JSON
button (go to the key/value view and then back to the json editor). the JSON "resets", though it still shows there's a linting issue and the wrap button is still disabled. One way to address this is by resetting the linting errors when a user toggles.
Description
This PR adds a KV view to the wrap tool based off the existing pattern when creating KV secrets. This resolves #28579. The default view is the still the JSON editor, but can be toggled between the two views while retaining input.
Previous:

Current:


TODO only if you're a HashiCorp employee
backport/
label that matches the desired release branch. Note that in the CE repo, the latest release branch will look likebackport/x.x.x
, but older release branches will bebackport/ent/x.x.x+ent
.of a public function, even if that change is in a CE file, double check that
applying the patch for this PR to the ENT repo and running tests doesn't
break any tests. Sometimes ENT only tests rely on public functions in CE
files.
in the PR description, commit message, or branch name.
description. Also, make sure the changelog is in this PR, not in your ENT PR.