From 547cbd3e7342813b178ae33cf3c7494ba95346c1 Mon Sep 17 00:00:00 2001 From: Aleksandar Djindjic Date: Tue, 20 Dec 2022 19:05:18 +0100 Subject: [PATCH] Rule details flyout on create rule page (#236) * rule details flyout on create rule page Signed-off-by: Aleksandar Djindjic * do not block deletetion if no notifications Signed-off-by: Aleksandar Djindjic Signed-off-by: Aleksandar Djindjic --- .../DetectionRules/DetectionRules.tsx | 29 ++++++++++++++++++- .../DetectionRules/DetectionRulesTable.tsx | 9 +++++- .../DetectionRules/utils/constants.tsx | 18 +++++++++--- .../RuleViewerFlyout/RuleViewerFlyout.tsx | 7 +++-- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRules.tsx b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRules.tsx index 09e19ef00..7aec70c02 100644 --- a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRules.tsx +++ b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRules.tsx @@ -11,9 +11,13 @@ import { CriteriaWithPagination, EuiText, } from '@elastic/eui'; -import React, { useMemo } from 'react'; + +import React, { useMemo, useState } from 'react'; import { DetectionRulesTable } from './DetectionRulesTable'; import { RuleItem, RuleItemInfo } from './types/interfaces'; +import { RuleViewerFlyout } from '../../../../../Rules/components/RuleViewerFlyout/RuleViewerFlyout'; +import { RuleTableItem } from '../../../../../Rules/utils/helpers'; +import { RuleItemInfoBase } from '../../../../../Rules/models/types'; export interface CreateDetectorRulesState { allRules: RuleItemInfo[]; @@ -35,6 +39,8 @@ export const DetectionRules: React.FC = ({ onRuleToggle, onAllRulesToggle, }) => { + const [flyoutData, setFlyoutData] = useState(null); + let enabledRulesCount = 0; rulesState.allRules.forEach((ruleItem) => { if (ruleItem.enabled) { @@ -60,8 +66,28 @@ export const DetectionRules: React.FC = ({ onPageChange(nextValues.page); }; + const onRuleDetails = (ruleItem: RuleItem) => { + setFlyoutData(() => ({ + title: ruleItem.name, + level: ruleItem.severity, + category: ruleItem.logType, + description: ruleItem.description, + source: ruleItem.library, + ruleInfo: rulesState.allRules.find((r) => r._id === ruleItem.id) as RuleItemInfoBase, + ruleId: ruleItem.id, + })); + }; + return ( + {flyoutData ? ( + setFlyoutData(() => null)} + history={null as any} + ruleTableItem={flyoutData} + ruleService={null as any} + /> + ) : null} @@ -85,6 +111,7 @@ export const DetectionRules: React.FC = ({ onAllRulesToggled={onAllRulesToggle} onRuleActivationToggle={onRuleToggle} onTableChange={onTableChange} + onRuleDetails={onRuleDetails} /> diff --git a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx index 197732a3a..c80126b18 100644 --- a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx +++ b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/DetectionRulesTable.tsx @@ -17,6 +17,7 @@ export interface DetectionRulesTableProps { onRuleActivationToggle: (changedItem: RuleItem, isActive: boolean) => void; onTableChange?: (nextValues: CriteriaWithPagination) => void; loading?: boolean; + onRuleDetails?: (ruleItem: RuleItem) => void; } const rulePriorityBySeverity: { [severity: string]: number } = { @@ -34,6 +35,7 @@ export const DetectionRulesTable: React.FC = ({ onRuleActivationToggle, onTableChange, loading = false, + onRuleDetails, }) => { //Filter table by rule type const search: Search = { @@ -77,7 +79,12 @@ export const DetectionRulesTable: React.FC = ({ return (
`${item.name}`} search={search} diff --git a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/utils/constants.tsx b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/utils/constants.tsx index 381e466a4..6c62db00a 100644 --- a/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/utils/constants.tsx +++ b/public/pages/CreateDetector/components/DefineDetector/components/DetectionRules/utils/constants.tsx @@ -16,15 +16,25 @@ export type ActiveToggleOnChangeEvent = React.BaseSyntheticEvent< export const getRulesColumns = ( allEnabled: boolean, onAllRulesToggled?: (enabled: boolean) => void, - onActivationToggle?: (item: RuleItem, active: boolean) => void + onActivationToggle?: (item: RuleItem, active: boolean) => void, + onRuleDetails?: (item: RuleItem) => void ): EuiBasicTableColumn[] => { const columns: EuiBasicTableColumn[] = [ { field: 'name', name: 'Rule name', - render: (ruleName: string, item: RuleItem): ReactNode => ( - {ruleName} - ), + render: (ruleName: string, item: RuleItem): ReactNode => { + const onRuleNameClicker = () => { + if (onRuleDetails) { + onRuleDetails(item); + } + }; + return ( + + {ruleName} + + ); + }, }, { field: 'severity', diff --git a/public/pages/Rules/components/RuleViewerFlyout/RuleViewerFlyout.tsx b/public/pages/Rules/components/RuleViewerFlyout/RuleViewerFlyout.tsx index c2c8a9c00..a1c265da7 100644 --- a/public/pages/Rules/components/RuleViewerFlyout/RuleViewerFlyout.tsx +++ b/public/pages/Rules/components/RuleViewerFlyout/RuleViewerFlyout.tsx @@ -20,7 +20,8 @@ import { RuleTableItem } from '../../utils/helpers'; import { DeleteRuleModal } from '../DeleteModal/DeleteModal'; import { RuleContentViewer } from '../RuleContentViewer/RuleContentViewer'; import { RuleViewerFlyoutHeaderActions } from './RuleViewFlyoutHeaderActions'; -import { RuleService, NotificationsStart } from '../../../../services'; +import { RuleService } from '../../../../services'; +import { NotificationsStart } from 'opensearch-dashboards/public'; export interface RuleViewerFlyoutProps { history?: RouteComponentProps['history']; @@ -87,7 +88,9 @@ export const RuleViewerFlyout: React.FC = ({ closeDeleteModal(); hideFlyout(true); } else { - errorNotificationToast(notifications, 'delete', 'rule', deleteRuleRes.error); + if (notifications) { + errorNotificationToast(notifications, 'delete', 'rule', deleteRuleRes.error); + } } };