From feaea818d081f672df21041c67010a9b08cced74 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 11 Jun 2025 13:31:13 +0200 Subject: [PATCH 1/8] Attempt to preventing edit query overwriting ofter submission of query --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index eda085062883e..29bb0baff81c8 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -170,9 +170,11 @@ export const ESQLEditor = memo(function ESQLEditor({ }); const onQueryUpdate = useCallback( (value: string) => { + setCode(value); + setCodeStateOnSubmission(value); onTextLangQueryChange({ esql: value } as AggregateQuery); }, - [onTextLangQueryChange] + [onTextLangQueryChange, setCode] ); const onQuerySubmit = useCallback(() => { @@ -224,11 +226,11 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery) { + if (code !== fixedQuery && fixedQuery !== codeWhenSubmitted) { setCode(fixedQuery); } } - }, [code, fixedQuery]); + }, [code, fixedQuery, codeWhenSubmitted]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => { From bd8ad3af4dfb4252484ca57b2e5b6d6e70a2d206 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 11 Jun 2025 18:44:39 +0200 Subject: [PATCH 2/8] Fix race condition in the inline editor mode --- .../private/kbn-esql-editor/src/esql_editor.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index 29bb0baff81c8..dbfee844ee797 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -170,11 +170,15 @@ export const ESQLEditor = memo(function ESQLEditor({ }); const onQueryUpdate = useCallback( (value: string) => { - setCode(value); - setCodeStateOnSubmission(value); + if (!editorIsInline) { + // preventing a race condition in the inline editor mode + // making sure functional tests don't fail in the non-inline mode mode, because resetting the query doesn't work + setCode(value); + setCodeStateOnSubmission(value); + } onTextLangQueryChange({ esql: value } as AggregateQuery); }, - [onTextLangQueryChange, setCode] + [onTextLangQueryChange, setCode, editorIsInline] ); const onQuerySubmit = useCallback(() => { From 9aa3b5c16a87ba4b12998230353e9c20cbe6d84a Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 11 Jun 2025 22:16:00 +0200 Subject: [PATCH 3/8] Fix another test --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index dbfee844ee797..aef7e78c5f871 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -230,11 +230,11 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery && fixedQuery !== codeWhenSubmitted) { + if (code !== fixedQuery && (!editorIsInline || fixedQuery !== codeWhenSubmitted)) { setCode(fixedQuery); } } - }, [code, fixedQuery, codeWhenSubmitted]); + }, [code, fixedQuery, codeWhenSubmitted, editorIsInline]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => { From 8cf92e9e57cd86b3ce47d2690dff92b7e60497d5 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 12 Jun 2025 09:12:56 +0200 Subject: [PATCH 4/8] Cleanup --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index aef7e78c5f871..2ac8c50222e77 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -172,9 +172,8 @@ export const ESQLEditor = memo(function ESQLEditor({ (value: string) => { if (!editorIsInline) { // preventing a race condition in the inline editor mode - // making sure functional tests don't fail in the non-inline mode mode, because resetting the query doesn't work + // making sure functional tests don't fail in the non-inline mode, because resetting the query doesn't work setCode(value); - setCodeStateOnSubmission(value); } onTextLangQueryChange({ esql: value } as AggregateQuery); }, @@ -230,7 +229,7 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery && (!editorIsInline || fixedQuery !== codeWhenSubmitted)) { + if (code !== fixedQuery && (editorIsInline === true || fixedQuery !== codeWhenSubmitted)) { setCode(fixedQuery); } } From 4f7a38bb147bd8bbb434b5aa660ddf5f5bc40eff Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 12 Jun 2025 11:49:28 +0200 Subject: [PATCH 5/8] Another test to fix --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index bb134138298f3..844144006626d 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -174,6 +174,7 @@ export const ESQLEditor = memo(function ESQLEditor({ // preventing a race condition in the inline editor mode // making sure functional tests don't fail in the non-inline mode, because resetting the query doesn't work setCode(value); + setCodeStateOnSubmission(value); } onTextLangQueryChange({ esql: value } as AggregateQuery); }, From 06786216461c17c7947e9f9d2d2385789ff0eb24 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 13 Jun 2025 16:57:57 +0200 Subject: [PATCH 6/8] Another test to fix it --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index 844144006626d..4f6c2e8a3f27c 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -172,9 +172,7 @@ export const ESQLEditor = memo(function ESQLEditor({ (value: string) => { if (!editorIsInline) { // preventing a race condition in the inline editor mode - // making sure functional tests don't fail in the non-inline mode, because resetting the query doesn't work setCode(value); - setCodeStateOnSubmission(value); } onTextLangQueryChange({ esql: value } as AggregateQuery); }, @@ -230,11 +228,11 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery && (editorIsInline === true || fixedQuery !== codeWhenSubmitted)) { + if (code !== fixedQuery && !isQueryLoading) { setCode(fixedQuery); } } - }, [code, fixedQuery, codeWhenSubmitted, editorIsInline]); + }, [code, fixedQuery, codeWhenSubmitted, editorIsInline, isQueryLoading]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => { From 3c75aa552229f33ab3e06e4652cf87631021d753 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 13 Jun 2025 16:59:25 +0200 Subject: [PATCH 7/8] Cleanup --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index 4f6c2e8a3f27c..23c3628adecba 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -232,7 +232,7 @@ export const ESQLEditor = memo(function ESQLEditor({ setCode(fixedQuery); } } - }, [code, fixedQuery, codeWhenSubmitted, editorIsInline, isQueryLoading]); + }, [code, fixedQuery, isQueryLoading]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => { From eb960447edbe510326220fd5f0448991ed5cce4a Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 13 Jun 2025 18:42:23 +0200 Subject: [PATCH 8/8] Another test --- .../packages/private/kbn-esql-editor/src/esql_editor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index 7a04c14792860..b72ad926ae6a5 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -228,11 +228,11 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery && !isQueryLoading) { + if (code !== fixedQuery && (editorIsInline || !isQueryLoading)) { setCode(fixedQuery); } } - }, [code, fixedQuery, isQueryLoading]); + }, [code, fixedQuery, isQueryLoading, editorIsInline]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => {