Skip to content

Commit

Permalink
adds status filter changes to rule details page
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Aug 9, 2021
1 parent c3f634b commit d33c233
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { noop } from 'lodash/fp';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { connect, ConnectedProps, useDispatch } from 'react-redux';
import styled from 'styled-components';
import deepEqual from 'fast-deep-equal';
import {
ExceptionListTypeEnum,
ExceptionListIdentifiers,
} from '@kbn/securitysolution-io-ts-list-types';

import { Dispatch } from 'redux';
import { isTab } from '../../../../../../../timelines/public';
import {
useDeepEqualSelector,
Expand Down Expand Up @@ -63,6 +64,8 @@ import { StepDefineRule } from '../../../../components/rules/step_define_rule';
import { StepScheduleRule } from '../../../../components/rules/step_schedule_rule';
import {
buildAlertsRuleIdFilter,
buildAlertStatusFilter,
buildAlertStatusFilterRuleRegistry,
buildShowBuildingBlockFilter,
buildShowBuildingBlockFilterRuleRegistry,
buildThreatMatchFilter,
Expand Down Expand Up @@ -98,7 +101,7 @@ import {
resetKeyboardFocus,
showGlobalFilters,
} from '../../../../../timelines/components/timeline/helpers';
import { timelineSelectors } from '../../../../../timelines/store/timeline';
import { timelineActions, timelineSelectors } from '../../../../../timelines/store/timeline';
import { timelineDefaults } from '../../../../../timelines/store/timeline/defaults';
import { useSourcererScope } from '../../../../../common/containers/sourcerer';
import { SourcererScopeName } from '../../../../../common/store/sourcerer/model';
Expand All @@ -118,6 +121,11 @@ import { MissingPrivilegesCallOut } from '../../../../components/callouts/missin
import { useRuleWithFallback } from '../../../../containers/detection_engine/rules/use_rule_with_fallback';
import { BadgeOptions } from '../../../../../common/components/header_page/types';
import { AlertsStackByField } from '../../../../components/alerts_kpis/common/types';
import { Status } from '../../../../../../common/detection_engine/schemas/common/schemas';
import {
AlertsTableFilterGroup,
FILTER_OPEN,
} from '../../../../components/alerts_table/alerts_filter_group';

/**
* Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space.
Expand Down Expand Up @@ -155,7 +163,13 @@ const ruleDetailTabs = [
},
];

const RuleDetailsPageComponent = () => {
type DetectionEngineComponentProps = PropsFromRedux;

const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
clearEventsDeleted,
clearEventsLoading,
clearSelected,
}) => {
const { navigateToApp } = useKibana().services.application;
const dispatch = useDispatch();
const containerElement = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -226,6 +240,7 @@ const RuleDetailsPageComponent = () => {
const mlCapabilities = useMlCapabilities();
const { formatUrl } = useFormatUrl(SecurityPageName.rules);
const { globalFullScreen } = useGlobalFullScreen();
const [filterGroup, setFilterGroup] = useState<Status>(FILTER_OPEN);

// TODO: Once we are past experimental phase this code should be removed
const ruleRegistryEnabled = useIsExperimentalFeatureEnabled('ruleRegistryEnabled');
Expand Down Expand Up @@ -315,6 +330,18 @@ const RuleDetailsPageComponent = () => {
[rule, ruleLoading]
);

// Callback for when open/closed filter changes
const onFilterGroupChangedCallback = useCallback(
(newFilterGroup: Status) => {
const timelineId = TimelineId.detectionsPage;
clearEventsLoading!({ id: timelineId });
clearEventsDeleted!({ id: timelineId });
clearSelected!({ id: timelineId });
setFilterGroup(newFilterGroup);
},
[clearEventsLoading, clearEventsDeleted, clearSelected, setFilterGroup]
);

// Set showBuildingBlockAlerts if rule is a Building Block Rule otherwise we won't show alerts
useEffect(() => {
setShowBuildingBlockAlerts(rule?.building_block_type != null);
Expand All @@ -324,11 +351,23 @@ const RuleDetailsPageComponent = () => {
() => [
...buildAlertsRuleIdFilter(ruleId),
...(ruleRegistryEnabled
? buildShowBuildingBlockFilterRuleRegistry(showBuildingBlockAlerts) // TODO: Once we are past experimental phase this code should be removed
: buildShowBuildingBlockFilter(showBuildingBlockAlerts)),
? [
...buildShowBuildingBlockFilterRuleRegistry(showBuildingBlockAlerts), // TODO: Once we are past experimental phase this code should be removed
...buildAlertStatusFilterRuleRegistry(filterGroup),
]
: [
...buildShowBuildingBlockFilter(showBuildingBlockAlerts),
...buildAlertStatusFilter(filterGroup),
]),
...buildThreatMatchFilter(showOnlyThreatIndicatorAlerts),
],
[ruleId, ruleRegistryEnabled, showBuildingBlockAlerts, showOnlyThreatIndicatorAlerts]
[
ruleId,
ruleRegistryEnabled,
showBuildingBlockAlerts,
showOnlyThreatIndicatorAlerts,
filterGroup,
]
);

const alertMergedFilters = useMemo(() => [...alertDefaultFilters, ...filters], [
Expand Down Expand Up @@ -705,6 +744,8 @@ const RuleDetailsPageComponent = () => {
</Display>
{ruleDetailTab === RuleDetailTabs.alerts && (
<>
<AlertsTableFilterGroup onFilterGroupChanged={onFilterGroupChangedCallback} />
<EuiSpacer size="m" />
<Display show={!globalFullScreen}>
<AlertsHistogramPanel
filters={alertMergedFilters}
Expand Down Expand Up @@ -760,8 +801,20 @@ const RuleDetailsPageComponent = () => {
);
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
clearSelected: ({ id }: { id: string }) => dispatch(timelineActions.clearSelected({ id })),
clearEventsLoading: ({ id }: { id: string }) =>
dispatch(timelineActions.clearEventsLoading({ id })),
clearEventsDeleted: ({ id }: { id: string }) =>
dispatch(timelineActions.clearEventsDeleted({ id })),
});

const connector = connect(null, mapDispatchToProps);

type PropsFromRedux = ConnectedProps<typeof connector>;

RuleDetailsPageComponent.displayName = 'RuleDetailsPageComponent';

export const RuleDetailsPage = React.memo(RuleDetailsPageComponent);
export const RuleDetailsPage = connector(React.memo(RuleDetailsPageComponent));

RuleDetailsPage.displayName = 'RuleDetailsPage';
2 changes: 1 addition & 1 deletion x-pack/test/security_solution_cypress/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function SecuritySolutionCypressCliTestRunner({ getService }: FtrPr
await withProcRunner(log, async (procs) => {
await procs.run('cypress', {
cmd: 'yarn',
args: ['cypress:run'],
args: ['cypress:open'],
cwd: resolve(__dirname, '../../plugins/security_solution'),
env: {
FORCE_COLOR: '1',
Expand Down

0 comments on commit d33c233

Please sign in to comment.