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

[Advanced Settings] Fix code editor field #177772

Merged

Conversation

ElenaStoeva
Copy link
Contributor

@ElenaStoeva ElenaStoeva commented Feb 25, 2024

Fixes #177600

Summary

This PR fixes the incorrect behaviour described in #177600, which seems to be caused because the onChange handler of the code editor component is redundantly called with the current value when the "Reset to default" link or the "Save" button is clicked. This fix adds a check for whether the value passed to the onChange is different from the current value and only then it would update the field.

@ElenaStoeva ElenaStoeva added Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages release_note:skip Skip the PR/issue when compiling release notes labels Feb 25, 2024
@ElenaStoeva ElenaStoeva self-assigned this Feb 25, 2024
@ElenaStoeva
Copy link
Contributor Author

/ci

@ElenaStoeva ElenaStoeva added the Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more label Mar 4, 2024
@ElenaStoeva ElenaStoeva marked this pull request as ready for review March 4, 2024 12:37
@ElenaStoeva ElenaStoeva requested a review from a team as a code owner March 4, 2024 12:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-deployment-management (Team:Deployment Management)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
advancedSettings 36.7KB 36.7KB +9.0B
apm 3.2MB 3.2MB +9.0B
infra 1.4MB 1.4MB +9.0B
profiling 400.9KB 400.9KB +9.0B
telemetryManagementSection 33.5KB 33.6KB +9.0B
total +45.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @ElenaStoeva

@@ -90,14 +90,17 @@ export const CodeEditorInput = ({
);

const debouncedUpdateValue = useMemo(() => {
// Trigger update 1000 ms after the user stopped typing to reduce validation requests to the server
return debounce(updateValue, 1000);
// Trigger update 500 ms after the user stopped typing to reduce validation requests to the server
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to reduce the debounce period?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The debounce period is set to 500 for the other field types and I initially set it to 1000 for the code editor to allow more time for the user to finish typing in, but later I realised that with a longer period there is a higher risk of the user clicking on the Save/reset button before the period is over. So I decided to make it 500 as the rest of the fields.

await debouncedUpdateValue(newValue, onUpdate);
// Only update the value when the onChange handler is called with a different value from the current one
if (newValue !== value) {
// @ts-expect-error
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why there is a TS error here and if we could fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review @yuliacech! I see that there are two TS errors in the code editor component and I think they are caused because this component is used by both json and markdown type settings, while the getFieldInputValue function expects a parameter of a typed setting field. I can't think of an easy fix at this moment so I opened #177998 to track this work.

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Thanks a for patching this up, @ElenaStoeva!
Tested locally and the fix works as expected 👍

@ElenaStoeva ElenaStoeva merged commit f4bb26d into elastic:main Mar 5, 2024
16 checks passed
@ElenaStoeva ElenaStoeva added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Mar 5, 2024
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 5, 2024
Fixes elastic#177600

## Summary

This PR fixes the incorrect behaviour described in
elastic#177600, which seems to be
caused because the `onChange` handler of the code editor component is
redundantly called with the current value when the "Reset to default"
link or the "Save" button is clicked. This fix adds a check for whether
the value passed to the `onChange` is different from the current value
and only then it would update the field.

(cherry picked from commit f4bb26d)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.13

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 5, 2024
# Backport

This will backport the following commits from `main` to `8.13`:
- [[Advanced Settings] Fix code editor field
(#177772)](#177772)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-03-05T12:02:40Z","message":"[Advanced
Settings] Fix code editor field (#177772)\n\nFixes
https://github.com/elastic/kibana/issues/177600\r\n\r\n##
Summary\r\n\r\nThis PR fixes the incorrect behaviour described
in\r\nhttps://github.com//issues/177600, which seems to
be\r\ncaused because the `onChange` handler of the code editor component
is\r\nredundantly called with the current value when the \"Reset to
default\"\r\nlink or the \"Save\" button is clicked. This fix adds a
check for whether\r\nthe value passed to the `onChange` is different
from the current value\r\nand only then it would update the
field.","sha":"f4bb26d0efc7e6e375b8d67fad6d3a0da00bd584","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Kibana
Management","Team:Deployment
Management","release_note:skip","backport:prev-minor","v8.14.0"],"title":"[Advanced
Settings] Fix code editor
field","number":177772,"url":"https://github.com/elastic/kibana/pull/177772","mergeCommit":{"message":"[Advanced
Settings] Fix code editor field (#177772)\n\nFixes
https://github.com/elastic/kibana/issues/177600\r\n\r\n##
Summary\r\n\r\nThis PR fixes the incorrect behaviour described
in\r\nhttps://github.com//issues/177600, which seems to
be\r\ncaused because the `onChange` handler of the code editor component
is\r\nredundantly called with the current value when the \"Reset to
default\"\r\nlink or the \"Save\" button is clicked. This fix adds a
check for whether\r\nthe value passed to the `onChange` is different
from the current value\r\nand only then it would update the
field.","sha":"f4bb26d0efc7e6e375b8d67fad6d3a0da00bd584"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177772","number":177772,"mergeCommit":{"message":"[Advanced
Settings] Fix code editor field (#177772)\n\nFixes
https://github.com/elastic/kibana/issues/177600\r\n\r\n##
Summary\r\n\r\nThis PR fixes the incorrect behaviour described
in\r\nhttps://github.com//issues/177600, which seems to
be\r\ncaused because the `onChange` handler of the code editor component
is\r\nredundantly called with the current value when the \"Reset to
default\"\r\nlink or the \"Save\" button is clicked. This fix adds a
check for whether\r\nthe value passed to the `onChange` is different
from the current value\r\nand only then it would update the
field.","sha":"f4bb26d0efc7e6e375b8d67fad6d3a0da00bd584"}}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
@ElenaStoeva ElenaStoeva deleted the advanced-settings/fix-code-editor-field branch April 12, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v8.13.0 v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Advanced settings] JSON field changes happen twice
5 participants