diff --git a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/use_get_timeline_id_from_dom.tsx b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/use_get_timeline_id_from_dom.tsx deleted file mode 100644 index fcb547842aec4..0000000000000 --- a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/use_get_timeline_id_from_dom.tsx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React, { useEffect, useState } from 'react'; - -import { SELECTOR_TIMELINE_GLOBAL_CONTAINER } from '../../../timelines/components/timeline/styles'; - -export const useGetTimelineId = function ( - elem: React.MutableRefObject, - getTimelineId: boolean = false -) { - const [timelineId, setTimelineId] = useState(null); - - useEffect(() => { - let startElem: Element | (Node & ParentNode) | null = elem.current; - if (startElem != null && getTimelineId) { - for (; startElem && startElem !== document; startElem = startElem.parentNode) { - const myElem: Element = startElem as Element; - if ( - myElem != null && - myElem.classList != null && - myElem.classList.contains(SELECTOR_TIMELINE_GLOBAL_CONTAINER) && - myElem.hasAttribute('data-timeline-id') - ) { - setTimelineId(myElem.getAttribute('data-timeline-id')); - break; - } - } - } - }, [elem, getTimelineId]); - - return timelineId; -}; diff --git a/x-pack/plugins/security_solution/public/common/components/event_details/table/action_cell.tsx b/x-pack/plugins/security_solution/public/common/components/event_details/table/action_cell.tsx index 454c047c9facf..74d46cf3431dc 100644 --- a/x-pack/plugins/security_solution/public/common/components/event_details/table/action_cell.tsx +++ b/x-pack/plugins/security_solution/public/common/components/event_details/table/action_cell.tsx @@ -5,13 +5,13 @@ * 2.0. */ -import React, { useCallback, useState, useRef } from 'react'; +import React, { useCallback, useState, useContext } from 'react'; import { HoverActions } from '../../hover_actions'; import { useActionCellDataProvider } from './use_action_cell_data_provider'; import { EventFieldsData, FieldsData } from '../types'; -import { useGetTimelineId } from '../../drag_and_drop/use_get_timeline_id_from_dom'; import { ColumnHeaderOptions } from '../../../../../common/types/timeline'; import { BrowserField } from '../../../containers/source'; +import { TimelineContext } from '../../../../../../timelines/public'; interface Props { contextId: string; @@ -52,12 +52,9 @@ export const ActionCell: React.FC = React.memo( values, }); - const draggableRef = useRef(null); const [showTopN, setShowTopN] = useState(false); - const [goGetTimelineId, setGoGetTimelineId] = useState(false); - const timelineIdFind = useGetTimelineId(draggableRef, goGetTimelineId); + const { timelineId: timelineIdFind } = useContext(TimelineContext); const [hoverActionsOwnFocus] = useState(false); - const toggleTopN = useCallback(() => { setShowTopN((prevShowTopN) => { const newShowTopN = !prevShowTopN; @@ -76,7 +73,6 @@ export const ActionCell: React.FC = React.memo( dataProvider={actionCellConfig?.dataProvider} enableOverflowButton={true} field={data.field} - goGetTimelineId={setGoGetTimelineId} isObjectArray={data.isObjectArray} onFilterAdded={onFilterAdded} ownFocus={hoverActionsOwnFocus} diff --git a/x-pack/plugins/security_solution/public/common/components/events_viewer/events_viewer.tsx b/x-pack/plugins/security_solution/public/common/components/events_viewer/events_viewer.tsx index 057d28b0112ad..c8b8cf57c698d 100644 --- a/x-pack/plugins/security_solution/public/common/components/events_viewer/events_viewer.tsx +++ b/x-pack/plugins/security_solution/public/common/components/events_viewer/events_viewer.tsx @@ -52,6 +52,7 @@ import { SELECTOR_TIMELINE_GLOBAL_CONTAINER } from '../../../timelines/component import { timelineSelectors, timelineActions } from '../../../timelines/store/timeline'; import { useDeepEqualSelector } from '../../hooks/use_selector'; import { defaultControlColumn } from '../../../timelines/components/timeline/body/control_columns'; +import { TimelineContext } from '../../../../../timelines/public'; export const EVENTS_VIEWER_HEADER_HEIGHT = 90; // px const UTILITY_BAR_HEIGHT = 19; // px @@ -287,7 +288,7 @@ const EventsViewerComponent: React.FC = ({ const leadingControlColumns: ControlColumnProps[] = [defaultControlColumn]; const trailingControlColumns: ControlColumnProps[] = []; - + const timelineContext = useMemo(() => ({ timelineId: id }), [id]); return ( = ({ {utilityBar && !resolverIsShowing(graphEventId) && ( {utilityBar?.(refetch, totalCountMinusDeleted)} )} - - + + + - {graphEventId && } - - - -