Skip to content

Commit

Permalink
Merge pull request elastic#14 from Elastic-AWP-Platform/alert-detail-…
Browse files Browse the repository at this point in the history
…in-detail-panel

Separate alert events into alert detail in detail panel
  • Loading branch information
Jack authored Nov 25, 2021
2 parents e816c8b + 27b1fc3 commit e0cd5bf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const SessionView = ({ sessionEntityId, height }: SessionViewDeps) => {
};

const renderSessionViewDetailPanel = () => {
if (selectedProcess && isDetailOpen) {
if (isDetailOpen) {
return (
<SessionViewDetailPanel
isDetailMounted={isDetailMounted}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/
import React, { useState, useEffect, ReactNode } from 'react';
import MonacoEditor from 'react-monaco-editor';
import { partition } from 'lodash';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSpacer, EuiSplitPanel, EuiTitle, EuiTabs, EuiTab } from '@elastic/eui';
import { Process } from '../../hooks/use_process_tree';
import { EventKind, Process } from '../../hooks/use_process_tree';
import { useStyles } from './styles';

interface SessionViewDetailPanelDeps {
Expand All @@ -19,10 +20,11 @@ interface SessionViewDetailPanelDeps {
session?: any;
}

interface ProcessEventTabData {
interface ProcessDetailTabData {
id: string | number;
name: string;
content: ReactNode;
kind: string;
}

/**
Expand All @@ -34,8 +36,10 @@ export const SessionViewDetailPanel = ({
selectedProcess,
setIsDetailOpen,
}: SessionViewDetailPanelDeps) => {
const [selectedDetailTab, setSelectedDetailTab] = useState<string | number>('');
const [processEventsTabs, setProcessEventsTabs] = useState<ProcessEventTabData[]>([]);
const [selectedCommandTab, setSelectedCommandTab] = useState<string | number>('');
const [commandTabs, setCommandTabs] = useState<ProcessDetailTabData[]>([]);
const [selectedAlertTab, setSelectedAlertTab] = useState<string | number>('');
const [alertTabs, setAlertTabs] = useState<ProcessDetailTabData[]>([]);

const styles = useStyles({ height });

Expand All @@ -57,10 +61,15 @@ export const SessionViewDetailPanel = ({
<EuiSpacer size="xxl" />
</div>
),
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 = () => {
Expand All @@ -69,7 +78,7 @@ export const SessionViewDetailPanel = ({
}
};

const renderSelectedProcessEvents = () => {
const renderSelectedProcessCommandDetail = () => {
if (selectedProcess) {
return (
<div>
Expand All @@ -83,18 +92,49 @@ export const SessionViewDetailPanel = ({
</EuiTitle>
<EuiSpacer />
<EuiTabs>
{processEventsTabs.map((tab, idx) => (
{commandTabs.map((tab, idx) => (
<EuiTab
key={idx}
onClick={() => setSelectedCommandTab(tab.id)}
isSelected={tab.id === selectedCommandTab}
>
{tab.name}
</EuiTab>
))}
</EuiTabs>
<EuiSpacer size="xxl" />
{commandTabs.find((tab) => tab.id === selectedCommandTab)?.content}
</div>
);
}
};

const renderSelectedProcessAlertDetail = () => {
if (selectedProcess && selectedProcess.hasAlerts()) {
return (
<div>
<EuiTitle size="s">
<span>
<FormattedMessage
id="xpack.sessionView.alertDetail"
defaultMessage="Alert detail"
/>
</span>
</EuiTitle>
<EuiSpacer />
<EuiTabs>
{alertTabs.map((tab, idx) => (
<EuiTab
key={idx}
onClick={() => setSelectedDetailTab(tab.id)}
isSelected={tab.id === selectedDetailTab}
onClick={() => setSelectedAlertTab(tab.id)}
isSelected={tab.id === selectedAlertTab}
>
{tab.name}
</EuiTab>
))}
</EuiTabs>
<EuiSpacer size="xxl" />
{processEventsTabs.find((tab) => tab.id === selectedDetailTab)?.content}
{alertTabs.find((tab) => tab.id === selectedAlertTab)?.content}
</div>
);
}
Expand All @@ -107,7 +147,7 @@ export const SessionViewDetailPanel = ({
css={isDetailMounted ? styles.detailPanelIn : styles.detailPanelOut}
onAnimationEnd={handleAnimationEnd}
>
{renderSelectedProcessEvents()}
{renderSelectedProcessCommandDetail()}
<EuiTitle size="s">
<span>
<FormattedMessage id="xpack.sessionView.sessionDetail" defaultMessage="Session detail" />
Expand All @@ -122,12 +162,7 @@ export const SessionViewDetailPanel = ({
</EuiTitle>
{/* Add server detail */}
<EuiSpacer size="xxl" />
<EuiTitle size="s">
<span>
<FormattedMessage id="xpack.sessionView.alertDetail" defaultMessage="Alert detail" />
</span>
</EuiTitle>
{/* Add alert detail conditionally */}
{renderSelectedProcessAlertDetail()}
</EuiSplitPanel.Inner>
);
};

0 comments on commit e0cd5bf

Please sign in to comment.