Skip to content

Commit

Permalink
[8.13] [Advanced Settings] Fix code editor field (#177772) (#177999)
Browse files Browse the repository at this point in the history
# 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]>
  • Loading branch information
kibanamachine and ElenaStoeva authored Mar 5, 2024
1 parent 5d0a60e commit 44a9430
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
return debounce(updateValue, 500);
}, [updateValue]);

const onChange: CodeEditorProps['onChange'] = async (newValue) => {
// @ts-expect-error
setValue(newValue);
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
setValue(newValue);
await debouncedUpdateValue(newValue, onUpdate);
}
};

useEffect(() => {
Expand Down

0 comments on commit 44a9430

Please sign in to comment.