diff --git a/frontend/src/container/LogsSearchFilter/SearchFields/QueryBuilder/QueryBuilder.tsx b/frontend/src/container/LogsSearchFilter/SearchFields/QueryBuilder/QueryBuilder.tsx index 5b06c3ca82..0859e12499 100644 --- a/frontend/src/container/LogsSearchFilter/SearchFields/QueryBuilder/QueryBuilder.tsx +++ b/frontend/src/container/LogsSearchFilter/SearchFields/QueryBuilder/QueryBuilder.tsx @@ -175,6 +175,7 @@ export interface QueryBuilderProps { onDropDownToggleHandler: (value: boolean) => VoidFunction; fieldsQuery: QueryFields[][]; setFieldsQuery: (q: QueryFields[][]) => void; + syncKeyPrefix: () => void; } function QueryBuilder({ @@ -182,6 +183,7 @@ function QueryBuilder({ fieldsQuery, setFieldsQuery, onDropDownToggleHandler, + syncKeyPrefix, }: QueryBuilderProps): JSX.Element { const handleUpdate = (query: Query, queryIndex: number): void => { const updated = [...fieldsQuery]; @@ -195,6 +197,9 @@ function QueryBuilder({ else updated.splice(queryIndex, 2); setFieldsQuery(updated); + + // initiate re-render query panel + syncKeyPrefix(); }; const QueryUI = ( diff --git a/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx b/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx index 50e2947ed2..5fcd180515 100644 --- a/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx +++ b/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx @@ -47,9 +47,12 @@ function SearchFields({ } }, [parsedQuery]); - const updateFieldsQuery = (updated: QueryFields[][]): void => { - setFieldsQuery(updated); - keyPrefixRef.current = hashCode(JSON.stringify(updated)); + // syncKeyPrefix initiates re-render. useful in situations like + // delete field (in search panel). this method allows condiitonally + // setting keyPrefix as doing it on every update of query initiates + // a re-render. this is a problem for text fields where input focus goes away. + const syncKeyPrefix = (): void => { + keyPrefixRef.current = hashCode(JSON.stringify(fieldsQuery)); }; const addSuggestedField = useCallback( @@ -102,7 +105,8 @@ function SearchFields({ keyPrefix={keyPrefixRef.current} onDropDownToggleHandler={onDropDownToggleHandler} fieldsQuery={fieldsQuery} - setFieldsQuery={updateFieldsQuery} + setFieldsQuery={setFieldsQuery} + syncKeyPrefix={syncKeyPrefix} />