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: Add KV view for wrap tool #29677

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lane-wetmore
Copy link
Contributor

@lane-wetmore lane-wetmore commented Feb 19, 2025

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:
image

Current:
image
image

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch. Note that in the CE repo, the latest release branch will look like backport/x.x.x, but older release branches will be backport/ent/x.x.x+ent.
    • LTS: If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    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.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

@lane-wetmore lane-wetmore self-assigned this Feb 19, 2025
@lane-wetmore lane-wetmore requested a review from a team as a code owner February 19, 2025 22:44
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Feb 19, 2025
Copy link

github-actions bot commented Feb 19, 2025

Build Results:
All builds succeeded! ✅

Copy link

github-actions bot commented Feb 19, 2025

CI Results:
All Go tests succeeded! ✅

@lane-wetmore lane-wetmore added this to the 1.20.0-rc milestone Feb 20, 2025
@lane-wetmore lane-wetmore requested a review from a team as a code owner February 20, 2025 17:30
@lane-wetmore lane-wetmore requested a review from mladlow February 20, 2025 17:30
Copy link
Contributor

@hellobontempo hellobontempo left a 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 😄

@tracked errorMessage = '';
@tracked showJson = true;
get jsonWrapStartValue() {
Copy link
Contributor

@hellobontempo hellobontempo Feb 20, 2025

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.

@value={{stringify this.unwrapData}}


await this.renderComponent();
await codemirror().setValue(this.wrapData);
await click('[data-test-toggle-input="json"]');
Copy link
Contributor

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.

{{#if this.showJson}}
<div class="field">
<div class="control">
<JsonEditor
Copy link
Contributor

@hellobontempo hellobontempo Feb 21, 2025

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!)

Copy link
Contributor Author

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.


@action
reset(clearData = true) {
this.token = '';
this.errorMessage = '';
this.wrapTTL = null;
if (clearData) this.wrapData = '{\n}';
if (clearData) this.wrapData = '';
Copy link
Contributor

@hellobontempo hellobontempo Feb 21, 2025

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

@hellobontempo hellobontempo Feb 21, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrap/Unwrap: Use the same GUI as in KV view to support multiline strings
2 participants