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

KVv2 json cursor jumps on "enter" #27569

Merged
merged 37 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ee027c2
it works...but does it break everything else?
Monkeychip Jun 21, 2024
3bf188c
Update code-mirror.js
Monkeychip Jun 21, 2024
7b2413f
Update code-mirror.js
Monkeychip Jun 21, 2024
9d3351c
return to original
Monkeychip Jun 21, 2024
033e8b7
Merge branch 'main' into ui/VAULT-28328/kv-cursor-jump-saga-cont
Monkeychip Jun 21, 2024
877abc1
changelog
Monkeychip Jun 21, 2024
e47758f
Merge branch 'main' into ui/VAULT-28328/kv-cursor-jump-saga-cont
Monkeychip Jun 25, 2024
c081fe1
Merge branch 'main' into ui/VAULT-28328/kv-cursor-jump-saga-cont
Monkeychip Jun 27, 2024
b058b82
different approach to move onto parse at create and edit. it breaks t…
Monkeychip Jul 1, 2024
1c63043
use onBlur event on codemirrror
Monkeychip Jul 1, 2024
f64de9f
maybe? lets run the tests and find out
Monkeychip Jul 1, 2024
731db27
update comments
Monkeychip Jul 1, 2024
a861f36
wip for conditional to only compare on kvv2
Monkeychip Jul 2, 2024
8998b98
remove onblur leftovers
Monkeychip Jul 2, 2024
fc08596
missed two
Monkeychip Jul 2, 2024
16ddc25
clean up
Monkeychip Jul 2, 2024
54ffc48
test coverage
Monkeychip Jul 2, 2024
5c0bea6
try catch logical operator instead
Monkeychip Jul 3, 2024
74e4e96
stringify helper and not native json stringify to maintain object shape
Monkeychip Jul 3, 2024
5e5c7cb
remove comment
Monkeychip Jul 3, 2024
f721028
Update json-editor.js
Monkeychip Jul 3, 2024
229ca6a
Update json-editor.js
Monkeychip Jul 3, 2024
243d378
Update json-editor.js
Monkeychip Jul 3, 2024
3b19547
Merge branch 'main' into ui/VAULT-28328/kv-cursor-jump-saga-cont
Monkeychip Jul 3, 2024
c1e902b
Test fix
Monkeychip Jul 3, 2024
c2a7627
maybe
Monkeychip Jul 3, 2024
a732021
more specific cursor test
Monkeychip Jul 3, 2024
29fd0e6
json-editor test cleanup
Monkeychip Jul 3, 2024
0c7cc7e
Delete ui/testrun1.txt
Monkeychip Jul 3, 2024
1851165
Delete ui/testrun2.txt
Monkeychip Jul 3, 2024
8dcb08c
Merge branch 'main' into ui/VAULT-28328/kv-cursor-jump-saga-cont
Monkeychip Jul 3, 2024
5a905c0
remove non json test it doesn't test anything
Monkeychip Jul 3, 2024
5d57ed3
update test and comment for how it's testing non-json content
Monkeychip Jul 5, 2024
5dc9165
test fix
Monkeychip Jul 5, 2024
a2dcf28
put shape of json blob back:
Monkeychip Jul 5, 2024
bffd06c
send in original without parsing or stringify
Monkeychip Jul 5, 2024
a049d43
welp friday things
Monkeychip Jul 5, 2024
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
Prev Previous commit
Next Next commit
different approach to move onto parse at create and edit. it breaks t…
…hings, hopefully fixed in next commits
  • Loading branch information
Monkeychip committed Jul 1, 2024
commit b058b82272aa4ae640e0e2e2437dfabc13950629
10 changes: 2 additions & 8 deletions ui/lib/core/addon/modifiers/code-mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ export default class CodeMirrorModifier extends Modifier {
} else {
// this hook also fires any time there is a change to tracked state
this._editor.setOption('readOnly', namedArgs.readOnly);
//* Comparing tracked state against editor.getValue *//
// 1. Parse so that you can compare values.
// this is important because editor.getValue will return exactly what is displayed on the editor including new-lines. Whereas nameArg tracked content could have already been modified (e.g. parsed) and may not include new lines.
const editorValue = JSON.parse(this._editor.getValue());
const namedArgsContent = JSON.parse(namedArgs.content);
// 2. in JavaScript two objects are considered equal only if they are the same object. So after parsing to remove excess white space, we stringify them.
if (JSON.stringify(editorValue) !== JSON.stringify(namedArgsContent)) {
// every time setValue is called the cursor jumps to the start of the editor so it's pertinent it's only called when necessary.
if (namedArgs.content && this._editor.getValue() !== namedArgs.content) {
// when setValue is called if there is a change in the value, the cursor will jump to the beginning of the text field. Heads up if you've found yourself debugging this behavior. It's likely due to the parsing the namedArgs value before it hits the codeMirrorModifier.
this._editor.setValue(namedArgs.content);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/kv/addon/components/kv-data-fields.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{#if @showJson}}
<JsonEditor
@title="{{if (eq @type 'create') 'Secret' 'Version'}} data"
@value={{this.stringifiedSecretData}}
@value={{this.codeMirrorSecretData}}
@allowObscure={{true}}
@valueUpdated={{this.handleJson}}
@readOnly={{eq @type "details"}}
Expand Down
12 changes: 7 additions & 5 deletions ui/lib/kv/addon/components/kv-data-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { stringify } from 'core/helpers/stringify';

export default class KvDataFields extends Component {
@tracked lintingErrors;
@tracked codeMirrorSecretData = this.args.secret?.secretData
? stringify([this.args.secret.secretData], {})
: this.startingValue;

get startingValue() {
// must pass the third param called "space" in JSON.stringify to structure object with whitespace
Expand All @@ -37,16 +40,15 @@ export default class KvDataFields extends Component {
return JSON.stringify({ '': '' }, null, 2);
}

get stringifiedSecretData() {
return this.args.secret?.secretData ? stringify([this.args.secret.secretData], {}) : this.startingValue;
}

@action
handleJson(value, codemirror) {
codemirror.performLint();
this.lintingErrors = codemirror.state.lint.marked.length > 0;
if (!this.lintingErrors) {
this.args.secret.secretData = JSON.parse(value);
// parse on save not on onChange to avoid problems with json comparisons within the codemirror modifier.
// update the codemirror value so the modifier correct parses and updates values
this.codeMirrorSecretData = value;
this.args.secret.secretData = value;
}
}
}
5 changes: 4 additions & 1 deletion ui/lib/kv/addon/components/page/secret/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ export default class KvSecretEdit extends Component {
*save(event) {
event.preventDefault();
try {
// before validating, set the secretData to the parsed value otherwise you'll hit validation errors
// and only parse the value right before saving, otherwise the value will be parsed on every change and run into issues with the codemirror modifier comparison checks
const { secret } = this.args;
secret.secretData = JSON.parse(secret.secretData);
const { isValid, state, invalidFormMessage } = this.args.secret.validate();
this.modelValidations = isValid ? null : state;
this.invalidFormAlert = invalidFormMessage;
if (isValid) {
const { secret } = this.args;
yield secret.save();
this.flashMessages.success(`Successfully created new version of ${secret.path}.`);
this.router.transitionTo('vault.cluster.secrets.backend.kv.secret.details', {
Expand Down
6 changes: 4 additions & 2 deletions ui/lib/kv/addon/components/page/secrets/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export default class KvSecretCreate extends Component {
*save(event) {
event.preventDefault();
this.resetErrors();

// before validating, set the secretData to the parsed value otherwise you'll hit validation errors
// and only parse the value right before saving, otherwise the value will be parsed on every change and run into issues with the codemirror modifier comparison checks
const { secret, metadata } = this.args;
secret.secretData = JSON.parse(secret.secretData);
const { isValid, state } = this.validate();
this.modelValidations = isValid ? null : state;
this.invalidFormAlert = isValid ? '' : 'There is an error with this form.';

const { secret, metadata } = this.args;
if (isValid) {
try {
// try saving secret data first
Expand Down
Loading