forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create detail panel hook for session view
- Loading branch information
1 parent
c3e7708
commit d7cbe6a
Showing
7 changed files
with
204 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
.../security_solution/public/timelines/components/side_panel/hooks/use_load_detail_panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* 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, { useMemo, useCallback, useRef } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { timelineActions, timelineSelectors } from '../../../store/timeline'; | ||
import type { EntityType } from '../../../../../../timelines/common'; | ||
import { useSourcererDataView } from '../../../../common/containers/sourcerer'; | ||
import { SourcererScopeName } from '../../../../common/store/sourcerer/model'; | ||
import { activeTimeline } from '../../../containers/active_timeline_context'; | ||
import { TimelineId, TimelineTabs } from '../../../../../common/types/timeline'; | ||
import { timelineDefaults } from '../../../store/timeline/defaults'; | ||
import { useDeepEqualSelector } from '../../../../common/hooks/use_selector'; | ||
import { DetailsPanel } from '..'; | ||
|
||
export interface UseLoadDetailPanelConfig { | ||
entityType?: EntityType; | ||
isFlyoutView?: boolean; | ||
sourcerScope: SourcererScopeName; | ||
timelineId: TimelineId; | ||
tabType?: TimelineTabs; | ||
} | ||
|
||
export interface UseLoadDetailPanelReturn { | ||
openDetailsPanel: (eventId?: string, onClose?: () => void) => void; | ||
handleOnDetailsPanelClosed: () => void; | ||
FlyoutDetailsPanel: JSX.Element; | ||
shouldShowFlyoutDetailsPanel: boolean; | ||
} | ||
|
||
export const useLoadDetailPanel = ({ | ||
entityType, | ||
isFlyoutView, | ||
sourcerScope, | ||
timelineId, | ||
tabType, | ||
}: UseLoadDetailPanelConfig): UseLoadDetailPanelReturn => { | ||
const { browserFields, docValueFields, selectedPatterns, runtimeMappings } = | ||
useSourcererDataView(sourcerScope); | ||
const getTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []); | ||
const dispatch = useDispatch(); | ||
|
||
const expandedDetail = useDeepEqualSelector( | ||
(state) => (getTimeline(state, timelineId) ?? timelineDefaults).expandedDetail | ||
); | ||
const onFlyoutClose = useRef(() => {}); | ||
|
||
const shouldShowFlyoutDetailsPanel = useMemo(() => { | ||
if ( | ||
tabType && | ||
expandedDetail && | ||
expandedDetail[tabType] && | ||
!!expandedDetail[tabType]?.panelView | ||
) { | ||
return true; | ||
} | ||
return false; | ||
}, [expandedDetail, tabType]); | ||
|
||
const loadDetailsPanel = useCallback( | ||
(eventId?: string) => { | ||
if (eventId) { | ||
dispatch( | ||
timelineActions.toggleDetailPanel({ | ||
panelView: 'eventDetail', | ||
tabType, | ||
timelineId, | ||
params: { | ||
eventId, | ||
indexName: selectedPatterns.join(','), | ||
}, | ||
}) | ||
); | ||
} | ||
}, | ||
[dispatch, selectedPatterns, tabType, timelineId] | ||
); | ||
|
||
const openDetailsPanel = useCallback( | ||
(eventId?: string, onClose?: () => void) => { | ||
loadDetailsPanel(eventId); | ||
onFlyoutClose.current = onClose ?? (() => {}); | ||
}, | ||
[loadDetailsPanel] | ||
); | ||
|
||
const handleOnDetailsPanelClosed = useCallback(() => { | ||
if (onFlyoutClose.current) onFlyoutClose.current(); | ||
dispatch(timelineActions.toggleDetailPanel({ tabType, timelineId })); | ||
|
||
if ( | ||
tabType && | ||
expandedDetail[tabType]?.panelView && | ||
timelineId === TimelineId.active && | ||
shouldShowFlyoutDetailsPanel | ||
) { | ||
activeTimeline.toggleExpandedDetail({}); | ||
} | ||
}, [dispatch, timelineId, expandedDetail, tabType, shouldShowFlyoutDetailsPanel]); | ||
|
||
const FlyoutDetailsPanel = useMemo( | ||
() => ( | ||
<DetailsPanel | ||
browserFields={browserFields} | ||
docValueFields={docValueFields} | ||
entityType={entityType} | ||
handleOnPanelClosed={handleOnDetailsPanelClosed} | ||
isFlyoutView={isFlyoutView} | ||
runtimeMappings={runtimeMappings} | ||
tabType={tabType} | ||
timelineId={timelineId} | ||
/> | ||
), | ||
[ | ||
browserFields, | ||
docValueFields, | ||
entityType, | ||
handleOnDetailsPanelClosed, | ||
isFlyoutView, | ||
runtimeMappings, | ||
tabType, | ||
timelineId, | ||
] | ||
); | ||
|
||
return { | ||
openDetailsPanel, | ||
handleOnDetailsPanelClosed, | ||
shouldShowFlyoutDetailsPanel, | ||
FlyoutDetailsPanel, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters