Skip to content

Commit

Permalink
[ML] Fixing filtering in log pattern analysis flyout (elastic#157530)
Browse files Browse the repository at this point in the history
Filters are no longer being picked up by `useData` in the log pattern
analysis flyout, this looks like it might be a race condition caused by
the `useEffect` which loads the state data.
This state data will never change while the flyout is open and so rather
than using a initial render `useEffect` the state can be loaded and used
when `aiopsListState` is initialized.
  • Loading branch information
jgowdyelastic authored May 15, 2023
1 parent 037ff39 commit b6b0355
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React, { FC, useState, useEffect, useCallback, useRef } from 'react';
import React, { FC, useState, useEffect, useCallback, useRef, useMemo } from 'react';
import type { SavedSearch } from '@kbn/discover-plugin/public';
import type { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -60,12 +60,15 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
uiSettings,
} = useAiopsAppContext();
const { euiTheme } = useEuiTheme();
const { filters, query } = useMemo(() => getState(), [getState]);

const mounted = useRef(false);
const { runCategorizeRequest, cancelRequest, randomSampler } = useCategorizeRequest();
const [aiopsListState, setAiopsListState] = usePageUrlState<AiOpsPageUrlState>(
const [aiopsListState] = usePageUrlState<AiOpsPageUrlState>(
'AIOPS_INDEX_VIEWER',
getDefaultAiOpsListState()
getDefaultAiOpsListState({
searchQuery: createMergedEsQuery(query, filters, dataView, uiSettings),
})
);
const [selectedCategory, setSelectedCategory] = useState<Category | null>(null);
const [selectedSavedSearch /* , setSelectedSavedSearch*/] = useState(savedSearch);
Expand Down Expand Up @@ -109,16 +112,6 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
true
);

useEffect(() => {
const { filters, query } = getState();

setAiopsListState({
...aiopsListState,
searchQuery: createMergedEsQuery(query, filters, dataView, uiSettings),
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const loadCategories = useCallback(async () => {
const { title: index, timeFieldName: timeField } = dataView;

Expand Down

0 comments on commit b6b0355

Please sign in to comment.