Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Add severity field to the Case view page. #131521

Merged
merged 44 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8abc0d3
Add severity field to create API and migration
May 3, 2022
c7986b0
Adds integration test for severity field migration
May 3, 2022
8ff9f9b
remove exclusive test
May 3, 2022
04c413e
Change severity levels
May 3, 2022
9d488bc
Update integration tests for post case
May 3, 2022
13f3406
Add more integration tests
May 3, 2022
a749da5
Fix all cases list test
May 3, 2022
f76213a
Fix some server test
May 3, 2022
d62bf70
Fix util server test
May 3, 2022
8906ccd
Fix client util test
May 3, 2022
99923ec
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 3, 2022
ede3328
Merge branch 'main' into feature/cases-severity-field
academo May 3, 2022
70300c2
Convert event log's duration from number to string in Kibana (keep as…
mikecote May 3, 2022
bcb2ab1
filter o11y rule aggregations (#131301)
mgiota May 3, 2022
7caa070
[Cloud Posture] Display and save rules per benchmark (#131412)
JordanSh May 3, 2022
ed7c949
Adding aria-label for discover data grid select document checkbox (#1…
bhavyarm May 3, 2022
e120e56
Update API docs (#130999)
thomasneirynck May 3, 2022
16467d1
[CI] Use GCS buckets for bazel remote caching (#131345)
brianseeders May 3, 2022
1186b3e
[Actionable Observability] Add license modal to rules table (#131232)
mgiota May 3, 2022
0e91bd6
[RAM] Add shareable rule status filter (#130705)
JiaweiWu May 3, 2022
f11b843
[storybook] Watch for changes in packages (#131467)
clintandrewhall May 3, 2022
c574ab6
Improve saved objects migrations failure errors and logs (#131359)
TinaHeiligers May 4, 2022
fed45c9
[Unified observability] Add tour step to guided setup (#131149)
May 4, 2022
9dd98b9
[Lens] Improved interval input (#131372)
flash1293 May 4, 2022
8fa9dc8
[Vega] Adjust vega doc for usage of ems files (#130948)
flash1293 May 4, 2022
e2b8cf4
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 4, 2022
de4a093
Excess intersections
cnasikas May 4, 2022
87f2cd5
Create severity user action
cnasikas May 4, 2022
6958994
Add severity selector to the case vie wpage
May 4, 2022
23417a1
Add test cases for the severity field
May 4, 2022
caa528a
Add severity to create_case user action
cnasikas May 4, 2022
f528955
Fix and add integration tests
cnasikas May 5, 2022
7a7037a
Minor improvements
cnasikas May 5, 2022
76faded
Merge branch 'main' into feature/cases-severity-field
academo May 5, 2022
4ec9ac3
Merge branch 'feature/cases-severity-field' into feature/cases-severi…
May 5, 2022
58eb811
Add severity user action builder
May 5, 2022
54d6c1e
use correct colors for the severity levels
May 5, 2022
83724b1
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 5, 2022
b2890b1
return null if no severydata found
May 5, 2022
248092a
disable super select if not permissions
May 5, 2022
fff645c
Use isDisabled at the superselect level
May 5, 2022
7d01839
Fix broken TS
May 5, 2022
4faab1e
Merge branch 'main' into feature/cases-severity-field-ui
academo May 5, 2022
918d56b
Merge branch 'main' into feature/cases-severity-field-ui
academo May 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export interface FieldMappings {

export type UpdateKey = keyof Pick<
CasePatchRequest,
'connector' | 'description' | 'status' | 'tags' | 'title' | 'settings'
'connector' | 'description' | 'status' | 'tags' | 'title' | 'settings' | 'severity'
>;

export interface UpdateByKey {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/public/common/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export const MARKED_CASE_AS = i18n.translate('xpack.cases.caseView.markedCaseAs'
defaultMessage: 'marked case as',
});

export const SET_SEVERITY_TO = i18n.translate('xpack.cases.caseView.setSeverityTo', {
defaultMessage: 'set severity to',
});

export const OPEN_CASES = i18n.translate('xpack.cases.caseTable.openCases', {
defaultMessage: 'Open cases',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { EuiFlexGroup, EuiFlexItem, EuiLoadingContent } from '@elastic/eui';
import React, { useCallback, useMemo } from 'react';
import { CaseSeverity } from '../../../../common/api';
import { useConnectors } from '../../../containers/configure/use_connectors';
import { useCaseViewNavigation } from '../../../common/navigation';
import { UpdateKey, UseFetchAlertData } from '../../../../common/ui/types';
Expand All @@ -23,6 +24,7 @@ import * as i18n from '../translations';
import { getNoneConnector, normalizeActionConnector } from '../../configure_cases/utils';
import { getConnectorById } from '../../utils';
import { UseGetCaseUserActions } from '../../../containers/use_get_case_user_actions';
import { SeveritySidebarSelector } from '../../severity/sidebar_selector';

export const CaseViewActivity = ({
initLoadingData,
Expand Down Expand Up @@ -108,6 +110,12 @@ export const CaseViewActivity = ({
(newTags) => onUpdateField({ key: 'tags', value: newTags }),
[onUpdateField]
);

const onUpdateSeverity = useCallback(
(newSeverity: CaseSeverity) => onUpdateField({ key: 'severity', value: newSeverity }),
[onUpdateField]
);

const { loading: isLoadingConnectors, connectors } = useConnectors();

const [connectorName, isValidConnector] = useMemo(() => {
Expand Down Expand Up @@ -180,6 +188,12 @@ export const CaseViewActivity = ({
)}
</EuiFlexItem>
<EuiFlexItem grow={2}>
<SeveritySidebarSelector
academo marked this conversation as resolved.
Show resolved Hide resolved
isDisabled={!userCanCrud}
isLoading={isLoading}
selectedSeverity={caseData.severity}
onSeverityChange={onUpdateSeverity}
/>
<UserList
data-test-subj="case-view-user-list-reporter"
email={emailContent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export const useOnUpdateField = ({
callUpdate('settings', settingsUpdate);
}
break;
case 'severity':
const severityUpdate = getTypedPayload<CaseAttributes['severity']>(value);
if (caseData.severity !== value) {
callUpdate('severity', severityUpdate);
}
default:
return null;
}
Expand Down
29 changes: 29 additions & 0 deletions x-pack/plugins/cases/public/components/severity/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { euiLightVars } from '@kbn/ui-theme';
import { CaseSeverity } from '../../../common/api';
import { CRITICAL, HIGH, LOW, MEDIUM } from './translations';

export const severities = {
[CaseSeverity.LOW]: {
color: euiLightVars.euiColorVis0,
label: LOW,
},
[CaseSeverity.MEDIUM]: {
color: euiLightVars.euiColorVis5,
label: MEDIUM,
},
[CaseSeverity.HIGH]: {
color: euiLightVars.euiColorVis7,
label: HIGH,
},
[CaseSeverity.CRITICAL]: {
color: euiLightVars.euiColorVis9,
label: CRITICAL,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 { CaseSeverity } from '../../../common/api';
import { render } from '@testing-library/react';
import React from 'react';
import { SeveritySelector } from './selector';
import userEvent from '@testing-library/user-event';

describe('Severity field selector', () => {
const onSeverityChange = jest.fn();
it('renders a list of severity fields', () => {
const result = render(
<SeveritySelector
selectedSeverity={CaseSeverity.MEDIUM}
onSeverityChange={onSeverityChange}
isLoading={false}
isDisabled={false}
/>
);

expect(result.getByTestId('case-severity-selection')).toBeTruthy();
expect(result.getAllByTestId('case-severity-selection-medium').length).toBeTruthy();
});

it('renders a list of severity options when clicked', () => {
const result = render(
<SeveritySelector
selectedSeverity={CaseSeverity.MEDIUM}
onSeverityChange={onSeverityChange}
isLoading={false}
isDisabled={false}
/>
);
userEvent.click(result.getByTestId('case-severity-selection'));
expect(result.getByTestId('case-severity-selection-low')).toBeTruthy();
expect(result.getAllByTestId('case-severity-selection-medium').length).toBeTruthy();
expect(result.getByTestId('case-severity-selection-high')).toBeTruthy();
expect(result.getByTestId('case-severity-selection-critical')).toBeTruthy();
});

it('calls onSeverityChange with the newly selected severity when clicked', () => {
const result = render(
<SeveritySelector
selectedSeverity={CaseSeverity.MEDIUM}
onSeverityChange={onSeverityChange}
isLoading={false}
isDisabled={false}
/>
);
userEvent.click(result.getByTestId('case-severity-selection'));
expect(result.getByTestId('case-severity-selection-low')).toBeTruthy();
userEvent.click(result.getByTestId('case-severity-selection-low'));
expect(onSeverityChange).toHaveBeenLastCalledWith('low');
});
});
64 changes: 64 additions & 0 deletions x-pack/plugins/cases/public/components/severity/selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 {
EuiFlexGroup,
EuiFlexItem,
EuiHealth,
EuiSuperSelect,
EuiSuperSelectOption,
} from '@elastic/eui';
import React from 'react';
import { CaseSeverity } from '../../../common/api';
import { severities } from './config';

interface Props {
selectedSeverity: CaseSeverity;
onSeverityChange: (status: CaseSeverity) => void;
isLoading: boolean;
isDisabled: boolean;
}

export const SeveritySelector: React.FC<Props> = ({
selectedSeverity,
onSeverityChange,
isLoading,
isDisabled,
}) => {
const caseSeverities = Object.keys(severities) as CaseSeverity[];
const options: Array<EuiSuperSelectOption<CaseSeverity>> = caseSeverities.map((severity) => {
const severityData = severities[severity];
return {
value: severity,
inputDisplay: (
<EuiFlexGroup
gutterSize="xs"
alignItems={'center'}
responsive={false}
data-test-subj={`case-severity-selection-${severity}`}
>
<EuiFlexItem grow={false}>
<EuiHealth color={severityData.color}>{severityData.label}</EuiHealth>
</EuiFlexItem>
</EuiFlexGroup>
),
};
});

return (
<EuiSuperSelect
disabled={isDisabled}
fullWidth={true}
isLoading={isLoading}
options={options}
valueOfSelected={selectedSeverity}
onChange={onSeverityChange}
data-test-subj="case-severity-selection"
/>
);
};
SeveritySelector.displayName = 'SeveritySelector';
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 { EuiFlexItem, EuiHorizontalRule, EuiSpacer, EuiText } from '@elastic/eui';
import React from 'react';
import { CaseSeverity } from '../../../common/api';
import { SeveritySelector } from './selector';
import { SEVERITY_TITLE } from './translations';

interface Props {
selectedSeverity: CaseSeverity;
onSeverityChange: (status: CaseSeverity) => void;
isLoading: boolean;
isDisabled: boolean;
}

export const SeveritySidebarSelector: React.FC<Props> = ({
selectedSeverity,
onSeverityChange,
isLoading,
isDisabled,
}) => {
return (
<EuiFlexItem grow={false}>
<EuiText>
<h4>{SEVERITY_TITLE}</h4>
</EuiText>
<EuiHorizontalRule margin="xs" />
<SeveritySelector
isLoading={isLoading}
selectedSeverity={selectedSeverity}
onSeverityChange={onSeverityChange}
isDisabled={isDisabled}
/>
<EuiSpacer size="m" />
</EuiFlexItem>
);
};
SeveritySidebarSelector.displayName = 'SeveritySidebarSelector';
28 changes: 28 additions & 0 deletions x-pack/plugins/cases/public/components/severity/translations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const LOW = i18n.translate('xpack.cases.severity.low', {
defaultMessage: 'Low',
});

export const MEDIUM = i18n.translate('xpack.cases.severity.medium', {
defaultMessage: 'Medium',
});

export const HIGH = i18n.translate('xpack.cases.severity.high', {
defaultMessage: 'High',
});

export const CRITICAL = i18n.translate('xpack.cases.severity.critical', {
defaultMessage: 'Critical',
});

export const SEVERITY_TITLE = i18n.translate('xpack.cases.severity.title', {
defaultMessage: 'Severity',
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createConnectorUserActionBuilder } from './connector';
import { createDescriptionUserActionBuilder } from './description';
import { createPushedUserActionBuilder } from './pushed';
import { createSettingsUserActionBuilder } from './settings';
import { createSeverityUserActionBuilder } from './severity';
import { createStatusUserActionBuilder } from './status';
import { createTagsUserActionBuilder } from './tags';
import { createTitleUserActionBuilder } from './title';
Expand All @@ -20,10 +21,7 @@ export const builderMap: UserActionBuilderMap = {
tags: createTagsUserActionBuilder,
title: createTitleUserActionBuilder,
status: createStatusUserActionBuilder,
// TODO: Build severity user action
severity: () => ({
build: () => [],
}),
severity: createSeverityUserActionBuilder,
pushed: createPushedUserActionBuilder,
comment: createCommentUserActionBuilder,
description: createDescriptionUserActionBuilder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { EuiCommentList } from '@elastic/eui';
import { Actions, CaseSeverity } from '../../../common/api';
import React from 'react';
import { AppMockRenderer, createAppMockRenderer } from '../../common/mock';
import { getUserAction } from '../../containers/mock';
import { getMockBuilderArgs } from './mock';
import { createSeverityUserActionBuilder } from './severity';

jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');

const builderArgs = getMockBuilderArgs();
describe('createSeverityUserActionBuilder', () => {
let appMockRenderer: AppMockRenderer;
beforeEach(() => {
appMockRenderer = createAppMockRenderer();
});
it('renders correctly', () => {
const userAction = getUserAction('severity', Actions.update, {
payload: { severity: CaseSeverity.LOW },
});
const builder = createSeverityUserActionBuilder({
...builderArgs,
userAction,
});
const createdUserAction = builder.build();

const result = appMockRenderer.render(<EuiCommentList comments={createdUserAction} />);
expect(result.getByTestId('severity-update-user-action-severity-title')).toBeTruthy();
expect(result.getByTestId('severity-update-user-action-severity-title-low')).toBeTruthy();
});
});
Loading