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

[ML] AIOps: Fixes render loop when using a saved search. #166934

Merged
merged 2 commits into from Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -71,7 +71,7 @@ export const LogCategorizationPage: FC = () => {
const [globalState, setGlobalState] = useUrlState('_g');
const [selectedField, setSelectedField] = useState<string | undefined>();
const [selectedCategory, setSelectedCategory] = useState<Category | null>(null);
const [selectedSavedSearch, setSelectedDataView] = useState(savedSearch);
const [selectedSavedSearch, setSelectedSavedSearch] = useState(savedSearch);
const [loading, setLoading] = useState(false);
const [totalCount, setTotalCount] = useState(0);
const [eventRate, setEventRate] = useState<EventRate>([]);
Expand All @@ -91,7 +91,7 @@ export const LogCategorizationPage: FC = () => {

useEffect(() => {
if (savedSearch) {
setSelectedDataView(savedSearch);
setSelectedSavedSearch(savedSearch);
}
}, [savedSearch]);

Expand All @@ -114,7 +114,7 @@ export const LogCategorizationPage: FC = () => {
// When the user loads saved search and then clear or modify the query
// we should remove the saved search and replace it with the index pattern id
if (selectedSavedSearch !== null) {
setSelectedDataView(null);
setSelectedSavedSearch(null);
}

setUrlState({
Expand Down
18 changes: 12 additions & 6 deletions x-pack/plugins/aiops/public/hooks/use_search.ts
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { useMemo } from 'react';

import type { DataView } from '@kbn/data-views-plugin/public';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';

Expand All @@ -24,12 +26,16 @@ export const useSearch = (
},
} = useAiopsAppContext();

const searchData = getEsQueryFromSavedSearch({
dataView,
uiSettings,
savedSearch,
filterManager,
});
const searchData = useMemo(
() =>
getEsQueryFromSavedSearch({
dataView,
uiSettings,
savedSearch,
filterManager,
}),
[dataView, uiSettings, savedSearch, filterManager]
);

if (searchData === undefined || (aiopsListState && aiopsListState.searchString !== '')) {
if (aiopsListState?.filters && readOnly === false) {
Expand Down