From 27b1fc36e152b20f697d69b922aedc72dd6b68b5 Mon Sep 17 00:00:00 2001 From: Zizhou Wang Date: Wed, 24 Nov 2021 14:23:51 -0500 Subject: [PATCH] Separate alert events into alert detail in detail panel --- .../public/components/SessionView/index.tsx | 2 +- .../SessionViewDetailPanel/index.tsx | 71 ++++++++++++++----- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/session_view/public/components/SessionView/index.tsx b/x-pack/plugins/session_view/public/components/SessionView/index.tsx index 3a9ee2a0dfc2a..5c9263b647f8a 100644 --- a/x-pack/plugins/session_view/public/components/SessionView/index.tsx +++ b/x-pack/plugins/session_view/public/components/SessionView/index.tsx @@ -158,7 +158,7 @@ export const SessionView = ({ sessionEntityId, height }: SessionViewDeps) => { }; const renderSessionViewDetailPanel = () => { - if (selectedProcess && isDetailOpen) { + if (isDetailOpen) { return ( { - const [selectedDetailTab, setSelectedDetailTab] = useState(''); - const [processEventsTabs, setProcessEventsTabs] = useState([]); + const [selectedCommandTab, setSelectedCommandTab] = useState(''); + const [commandTabs, setCommandTabs] = useState([]); + const [selectedAlertTab, setSelectedAlertTab] = useState(''); + const [alertTabs, setAlertTabs] = useState([]); const styles = useStyles({ height }); @@ -57,10 +61,15 @@ export const SessionViewDetailPanel = ({ ), + kind: processEvent?.event.kind, })); - setProcessEventsTabs(selectedProcessEvents); - setSelectedDetailTab(selectedProcessEvents?.[0]?.id || ''); + const [commandTabs, alertTabs] = partition(selectedProcessEvents, { kind: EventKind.event }); + + setCommandTabs(commandTabs); + setSelectedCommandTab(commandTabs[0]?.id || ''); + setAlertTabs(alertTabs); + setSelectedAlertTab(alertTabs[0]?.id || ''); }, [selectedProcess]); const handleAnimationEnd = () => { @@ -69,7 +78,7 @@ export const SessionViewDetailPanel = ({ } }; - const renderSelectedProcessEvents = () => { + const renderSelectedProcessCommandDetail = () => { if (selectedProcess) { return (
@@ -83,18 +92,49 @@ export const SessionViewDetailPanel = ({ - {processEventsTabs.map((tab, idx) => ( + {commandTabs.map((tab, idx) => ( + setSelectedCommandTab(tab.id)} + isSelected={tab.id === selectedCommandTab} + > + {tab.name} + + ))} + + + {commandTabs.find((tab) => tab.id === selectedCommandTab)?.content} +
+ ); + } + }; + + const renderSelectedProcessAlertDetail = () => { + if (selectedProcess && selectedProcess.hasAlerts()) { + return ( +
+ + + + + + + + {alertTabs.map((tab, idx) => ( setSelectedDetailTab(tab.id)} - isSelected={tab.id === selectedDetailTab} + onClick={() => setSelectedAlertTab(tab.id)} + isSelected={tab.id === selectedAlertTab} > {tab.name} ))} - {processEventsTabs.find((tab) => tab.id === selectedDetailTab)?.content} + {alertTabs.find((tab) => tab.id === selectedAlertTab)?.content}
); } @@ -107,7 +147,7 @@ export const SessionViewDetailPanel = ({ css={isDetailMounted ? styles.detailPanelIn : styles.detailPanelOut} onAnimationEnd={handleAnimationEnd} > - {renderSelectedProcessEvents()} + {renderSelectedProcessCommandDetail()} @@ -122,12 +162,7 @@ export const SessionViewDetailPanel = ({ {/* Add server detail */} - - - - - - {/* Add alert detail conditionally */} + {renderSelectedProcessAlertDetail()} ); };