mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
UI Bug fix, cursor jumps in KVv2 after initial input (#27120)
* the fix * changelog * fix tests * fix kv test * fix
This commit is contained in:
parent
25f038afac
commit
66268d6648
4 changed files with 22 additions and 5 deletions
3
changelog/27120.txt
Normal file
3
changelog/27120.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
ui: Fix KVv2 cursor jumping inside json editor after initial input.
|
||||
```
|
||||
|
|
@ -29,8 +29,16 @@ import { stringify } from 'core/helpers/stringify';
|
|||
export default class KvDataFields extends Component {
|
||||
@tracked lintingErrors;
|
||||
|
||||
get startingValue() {
|
||||
// must pass the third param called "space" in JSON.stringify to structure object with whitespace
|
||||
// otherwise the following codemirror modifier check will pass `this._editor.getValue() !== namedArgs.content` and _setValue will be called.
|
||||
// the method _setValue moves the cursor to the beginning of the text field.
|
||||
// the effect is that the cursor jumps after the first key input.
|
||||
return JSON.stringify({ '': '' }, null, 2);
|
||||
}
|
||||
|
||||
get stringifiedSecretData() {
|
||||
return this.args.secret?.secretData ? stringify([this.args.secret.secretData], {}) : '{ "": "" }';
|
||||
return this.args.secret?.secretData ? stringify([this.args.secret.secretData], {}) : this.startingValue;
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
/* eslint-disable no-useless-escape */
|
||||
import { module, test } from 'qunit';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { click, currentURL, fillIn, findAll, setupOnerror, typeIn, visit } from '@ember/test-helpers';
|
||||
|
|
@ -281,7 +281,13 @@ module('Acceptance | kv-v2 workflow | edge cases', function (hooks) {
|
|||
await fillIn(FORM.inputByAttr('path'), 'complex');
|
||||
|
||||
await click(FORM.toggleJson);
|
||||
assert.strictEqual(codemirror().getValue(), '{ "": "" }');
|
||||
|
||||
assert.strictEqual(
|
||||
codemirror().getValue(),
|
||||
`{
|
||||
\"\": \"\"
|
||||
}`
|
||||
);
|
||||
codemirror().setValue('{ "foo3": { "name": "bar3" } }');
|
||||
await click(FORM.saveBtn);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ module('Integration | Component | kv-v2 | KvDataFields', function (hooks) {
|
|||
await render(hbs`<KvDataFields @showJson={{true}} @secret={{this.secret}} />`, { owner: this.engine });
|
||||
assert.strictEqual(
|
||||
codemirror().getValue(' '),
|
||||
`{ \"\": \"\" }`, // eslint-disable-line no-useless-escape
|
||||
'json editor initializes with empty object'
|
||||
`{ \"\": \"\" }`, // eslint-disable-line no-useless-escape
|
||||
'json editor initializes with empty object that includes whitespace'
|
||||
);
|
||||
await fillIn(`${FORM.jsonEditor} textarea`, 'blah');
|
||||
assert.strictEqual(codemirror().state.lint.marked.length, 1, 'codemirror lints input');
|
||||
|
|
|
|||
Loading…
Reference in a new issue