[8.16] [Search Profiler] Index field no longer resets on query edit (#215420) (#215496)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Search Profiler] Index field no longer resets on query edit
(#215420)](https://github.com/elastic/kibana/pull/215420)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Matthew
Kime","email":"matt@mattki.me"},"sourceCommit":{"committedDate":"2025-03-21T13:29:33Z","message":"[Search
Profiler] Index field no longer resets on query edit (#215420)\n\n##
Summary\n\nPreviously, editing the query would reset the index field to
`_all`.\nThis was due to using `useState` instead of `useRef` to store
the query\nvalue.\n\nCloses
https://github.com/elastic/kibana/issues/214416\n\nHow to test\n1. Go to
search profiler\n2. Enter an index name, anything but `_all` - which is
already there\n3. Edit the query\n4. Did the index value remain
unchanged? Good! Its fixed!\n\nALSO - need to test to make sure this
works with content in the
url.","sha":"f77e29f5827c621d29959cbbf8514ce497565263","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:Kibana
Management","Feature:Search
Profiler","backport:prev-major","v9.1.0"],"title":"[Search Profiler]
Index field no longer resets on query
edit","number":215420,"url":"https://github.com/elastic/kibana/pull/215420","mergeCommit":{"message":"[Search
Profiler] Index field no longer resets on query edit (#215420)\n\n##
Summary\n\nPreviously, editing the query would reset the index field to
`_all`.\nThis was due to using `useState` instead of `useRef` to store
the query\nvalue.\n\nCloses
https://github.com/elastic/kibana/issues/214416\n\nHow to test\n1. Go to
search profiler\n2. Enter an index name, anything but `_all` - which is
already there\n3. Edit the query\n4. Did the index value remain
unchanged? Good! Its fixed!\n\nALSO - need to test to make sure this
works with content in the
url.","sha":"f77e29f5827c621d29959cbbf8514ce497565263"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215420","number":215420,"mergeCommit":{"message":"[Search
Profiler] Index field no longer resets on query edit (#215420)\n\n##
Summary\n\nPreviously, editing the query would reset the index field to
`_all`.\nThis was due to using `useState` instead of `useRef` to store
the query\nvalue.\n\nCloses
https://github.com/elastic/kibana/issues/214416\n\nHow to test\n1. Go to
search profiler\n2. Enter an index name, anything but `_all` - which is
already there\n3. Edit the query\n4. Did the index value remain
unchanged? Good! Its fixed!\n\nALSO - need to test to make sure this
works with content in the
url.","sha":"f77e29f5827c621d29959cbbf8514ce497565263"}}]}] BACKPORT-->

Co-authored-by: Matthew Kime <matt@mattki.me>
This commit is contained in:
Kibana Machine 2025-03-21 16:48:56 +01:00 committed by GitHub
parent 4872b3d560
commit 2d13929ba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import React, { useRef, memo, useCallback, useState } from 'react';
import React, { useRef, memo, useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import {
@ -53,9 +53,8 @@ export const ProfileQueryEditor = memo(() => {
const searchProfilerQuery =
searchProfilerQueryURI &&
decompressFromEncodedURIComponent(searchProfilerQueryURI.replace(/^data:text\/plain,/, ''));
const [editorValue, setEditorValue] = useState(
searchProfilerQuery ? searchProfilerQuery : INITIAL_EDITOR_VALUE
);
const editorValue = useRef(searchProfilerQuery || INITIAL_EDITOR_VALUE);
const requestProfile = useRequestProfile();
@ -63,7 +62,7 @@ export const ProfileQueryEditor = memo(() => {
dispatch({ type: 'setProfiling', value: true });
try {
const { data: result, error } = await requestProfile({
query: editorValue,
query: editorValue.current,
index: indexInputRef.current.value,
});
if (error) {
@ -163,8 +162,8 @@ export const ProfileQueryEditor = memo(() => {
>
<Editor
onEditorReady={onEditorReady}
setEditorValue={setEditorValue}
editorValue={editorValue}
setEditorValue={(val) => (editorValue.current = val)}
editorValue={editorValue.current}
licenseEnabled={licenseEnabled}
/>
</EuiFlexItem>