Skip to content

Commit

Permalink
use existing filterManager
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Sep 9, 2021
1 parent 2c7d13b commit 562b063
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SourcererScopeName } from '../../store/sourcerer/model';
import { useSourcererScope } from '../../containers/sourcerer';
import { timelineSelectors } from '../../../timelines/store/timeline';
import { ShowTopNButton } from './actions/show_top_n';
import { FilterManager } from '../../../../../../../src/plugins/data/public';

export interface UseHoverActionItemsProps {
dataProvider?: DataProvider | DataProvider[];
Expand Down Expand Up @@ -68,13 +69,13 @@ export const useHoverActionItems = ({
ownFocus,
showTopN,
stKeyboardEvent,
timelineId,
timelineId = 'timeline-1',
toggleColumn,
toggleTopN,
values,
}: UseHoverActionItemsProps): UseHoverActionItems => {
const kibana = useKibana();
const { timelines } = kibana.services;
const { timelines, uiSettings } = kibana.services;
// Common actions used by the alert table and alert flyout
const {
getAddToTimelineButton,
Expand All @@ -84,17 +85,19 @@ export const useHoverActionItems = ({
getFilterOutValueButton,
getOverflowButton,
} = timelines.getHoverActions();

const filterManagerBackup = useMemo(() => kibana.services.data.query.filterManager, [
kibana.services.data.query.filterManager,
]);
const getManageTimeline = useMemo(() => timelineSelectors.getManageTimelineById(), []);
const { filterManager: activeFilterMananager } = useDeepEqualSelector((state) =>
const { filterManager: activeFilterManager } = useDeepEqualSelector((state) =>
getManageTimeline(state, timelineId ?? '')
);
const filterManager = useMemo(
() => (timelineId === TimelineId.active ? activeFilterMananager : filterManagerBackup),
[timelineId, activeFilterMananager, filterManagerBackup]
() =>
timelineId === TimelineId.active
? activeFilterManager ?? new FilterManager(uiSettings)
: filterManagerBackup,
[uiSettings, timelineId, activeFilterManager, filterManagerBackup]
);

// Regarding data from useManageTimeline:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { activeTimeline } from '../../../containers/active_timeline_context';
import { DetailsPanel } from '../../side_panel';
import { ExitFullScreen } from '../../../../common/components/exit_full_screen';
import { defaultControlColumn } from '../body/control_columns';
import { useDeepEqualSelector } from '../../../../common/hooks/use_selector';

const TimelineHeaderContainer = styled.div`
margin-top: 6px;
Expand Down Expand Up @@ -193,7 +194,17 @@ export const QueryTabContentComponent: React.FC<Props> = ({
} = useSourcererScope(SourcererScopeName.timeline);

const { uiSettings } = useKibana().services;
const [filterManager] = useState<FilterManager>(new FilterManager(uiSettings));

const getManageTimeline = useMemo(() => timelineSelectors.getManageTimelineById(), []);
const { filterManager: activeFilterManager } = useDeepEqualSelector((state) =>
getManageTimeline(state, timelineId ?? '')
);

const filterManager = useMemo(() => activeFilterManager ?? new FilterManager(uiSettings), [
activeFilterManager,
uiSettings,
]);

const esQueryConfig = useMemo(() => esQuery.getEsQueryConfig(uiSettings), [uiSettings]);
const kqlQuery: {
query: string;
Expand Down Expand Up @@ -256,7 +267,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
id: timelineId,
})
);
}, [filterManager, timelineId, dispatch]);
}, [activeFilterManager, dispatch, filterManager, timelineId, uiSettings]);

const [
isQueryLoading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const addTimelineToStore = ({
return {
...timelineById,
[id]: {
...(timelineById[id] ? timelineById[id] : {}),
...timeline,
isLoading: timelineById[id].isLoading,
initialized: timelineById[id].initialized,
Expand Down

0 comments on commit 562b063

Please sign in to comment.