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] severity field in the cases list and allow to filter by it #131694

Merged
merged 73 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 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
5f44fbe
Add the severity field to the create form
May 5, 2022
5106252
Fix test
May 5, 2022
c7b9223
Add severity field tests
May 5, 2022
e3e0dca
Add test cases for the severity field in the create form
May 5, 2022
da31573
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
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
ca68fda
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 6, 2022
42acda8
WIP: List filter
May 6, 2022
e1e980d
Fix backend API for severity filter
May 6, 2022
1561248
Allow severity filter
May 6, 2022
7f04a4a
fix test cases
May 6, 2022
28f7ff6
Merge remote-tracking branch 'origin/feature/cases-severity-field-ui'…
May 6, 2022
36f2ae8
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 6, 2022
012972c
Merge remote-tracking branch 'origin/feature/cases-severity-field-ui'…
May 6, 2022
3ff11a2
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 6, 2022
2577132
Merge branch 'feature/cases-severity-field-create-form' into feature/…
May 6, 2022
e7a0ed4
Add tests for the severity filter
May 6, 2022
5a89f9b
Adds validation for severity column in the all cases list test
May 6, 2022
f18427e
Add tests for the table filter
May 6, 2022
b342e20
add API tests for filtering
May 6, 2022
2781374
Merge remote-tracking branch 'upstream/main' into feature/cases-sever…
May 9, 2022
b6672a9
remove comment
May 9, 2022
da96a48
update tests for the api
May 9, 2022
a1a54dd
Update useGetCases test
May 9, 2022
ec674cc
Add test for rbac
May 9, 2022
5b168a3
Fix severities order
May 9, 2022
bbd09d0
Change test title
May 9, 2022
775b2bb
Rollback fixture changes
May 9, 2022
bb05c1e
add cases for severity fitert
May 9, 2022
5d33d28
update comment
May 9, 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
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export const CasesFindRequestRt = rt.partial({
* The status of the case (open, closed, in-progress)
*/
status: CaseStatusRt,
/**
* The severity of the case
*/
severity: CaseSeverityRt,
/**
* The reporters to filter by
*/
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CasesFindResponse,
CasesStatusResponse,
CasesMetricsResponse,
CaseSeverity,
} from '../api';
import { SnakeToCamelCase } from '../types';

Expand All @@ -45,6 +46,9 @@ export type StatusAllType = typeof StatusAll;

export type CaseStatusWithAllStatus = CaseStatuses | StatusAllType;

export const SeverityAll = 'all' as const;
export type CaseSeverityWithAll = CaseSeverity | typeof SeverityAll;

/**
* The type for the `refreshRef` prop (a `React.Ref`) defined by the `CaseViewComponentProps`.
*
Expand Down Expand Up @@ -84,6 +88,7 @@ export interface QueryParams {

export interface FilterOptions {
search: string;
severity: CaseSeverityWithAll;
status: CaseStatusWithAllStatus;
tags: string[];
reporters: User[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ describe('AllCasesListGeneric', () => {
.childAt(0)
.prop('value')
).toBe(useGetCasesMockState.data.cases[0].createdAt);

expect(
wrapper.find(`[data-test-subj="case-table-column-severity"]`).first().text().toLowerCase()
).toBe(useGetCasesMockState.data.cases[0].severity);

expect(wrapper.find(`[data-test-subj="case-table-case-count"]`).first().text()).toEqual(
'Showing 10 cases'
);
Expand All @@ -223,6 +228,7 @@ describe('AllCasesListGeneric', () => {
createdAt: null,
createdBy: null,
status: null,
severity: null,
tags: null,
title: null,
totalComment: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export const AllCasesList = React.memo<AllCasesListProps>(
tags: filterOptions.tags,
status: filterOptions.status,
owner: filterOptions.owner,
severity: filterOptions.severity,
}}
setFilterRefetch={setFilterRefetch}
hiddenStatuses={hiddenStatuses}
Expand Down
67 changes: 42 additions & 25 deletions x-pack/plugins/cases/public/components/all_cases/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiHealth,
} from '@elastic/eui';
import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';
import styled from 'styled-components';

import { Case, DeleteCase } from '../../../common/ui/types';
import { CaseStatuses, ActionConnector } from '../../../common/api';
import { CaseStatuses, ActionConnector, CaseSeverity } from '../../../common/api';
import { OWNER_INFO } from '../../../common/constants';
import { getEmptyTagValue } from '../empty_value';
import { FormattedRelativePreferenceDate } from '../formatted_date';
Expand All @@ -40,6 +41,7 @@ import { TruncatedText } from '../truncated_text';
import { getConnectorIcon } from '../utils';
import type { CasesOwners } from '../../client/helpers/can_use_cases';
import { useCasesFeatures } from '../cases_context/use_cases_features';
import { severities } from '../severity/config';

export type CasesColumns =
| EuiTableActionsColumnType<Case>
Expand Down Expand Up @@ -300,30 +302,6 @@ export const useCasesColumns = ({
return getEmptyTagValue();
},
},
...(isSelectorView
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section was merely moved down to allow the severity field to show before the status.

? [
{
align: RIGHT_ALIGNMENT,
render: (theCase: Case) => {
if (theCase.id != null) {
return (
<EuiButton
data-test-subj={`cases-table-row-select-${theCase.id}`}
onClick={() => {
assignCaseAction(theCase);
}}
size="s"
fill={true}
>
{i18n.SELECT}
</EuiButton>
);
}
return getEmptyTagValue();
},
},
]
: []),
...(!isSelectorView
? [
{
Expand Down Expand Up @@ -351,6 +329,45 @@ export const useCasesColumns = ({
},
]
: []),
{
name: i18n.SEVERITY,
render: (theCase: Case) => {
if (theCase.severity != null) {
const severityData = severities[theCase.severity ?? CaseSeverity.LOW];
return (
<EuiHealth data-test-subj="case-table-column-severity" color={severityData.color}>
{severityData.label}
</EuiHealth>
);
}
return getEmptyTagValue();
},
},

...(isSelectorView
? [
{
align: RIGHT_ALIGNMENT,
render: (theCase: Case) => {
if (theCase.id != null) {
return (
<EuiButton
data-test-subj={`cases-table-row-select-${theCase.id}`}
onClick={() => {
assignCaseAction(theCase);
}}
size="s"
fill={true}
>
{i18n.SELECT}
</EuiButton>
);
}
return getEmptyTagValue();
},
},
]
: []),
...(userCanCrud && !isSelectorView
? [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 React from 'react';
import { AppMockRenderer, createAppMockRenderer } from '../../common/mock';
import userEvent from '@testing-library/user-event';
import { waitFor } from '@testing-library/dom';
import { SeverityFilter } from './severity_filter';

describe('Severity form field', () => {
const onSeverityChange = jest.fn();
let appMockRender: AppMockRenderer;
const props = {
isLoading: false,
selectedSeverity: CaseSeverity.LOW,
isDisabled: false,
onSeverityChange,
};
beforeEach(() => {
appMockRender = createAppMockRenderer();
});
it('renders', () => {
const result = appMockRender.render(<SeverityFilter {...props} />);
expect(result.getByTestId('case-severity-filter')).not.toHaveAttribute('disabled');
});

// default to LOW in this test configuration
it('defaults to the correct value', () => {
const result = appMockRender.render(<SeverityFilter {...props} />);
// two items. one for the popover one for the selected field
expect(result.getAllByTestId('case-severity-filter-low').length).toBe(2);
});

it('selects the correct value when changed', async () => {
const result = appMockRender.render(<SeverityFilter {...props} />);
userEvent.click(result.getByTestId('case-severity-filter'));
userEvent.click(result.getByTestId('case-severity-filter-high'));
await waitFor(() => {
expect(onSeverityChange).toHaveBeenCalledWith('high');
});
});

it('selects the correct value when changed (all)', async () => {
const result = appMockRender.render(<SeverityFilter {...props} />);
userEvent.click(result.getByTestId('case-severity-filter'));
userEvent.click(result.getByTestId('case-severity-filter-all'));
await waitFor(() => {
expect(onSeverityChange).toHaveBeenCalledWith('all');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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,
EuiText,
} from '@elastic/eui';
import React from 'react';
import { CaseSeverityWithAll, SeverityAll } from '../../containers/types';
import { severitiesWithAll } from '../severity/config';

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

export const SeverityFilter: React.FC<Props> = ({
selectedSeverity,
onSeverityChange,
isLoading,
isDisabled,
}) => {
const caseSeverities = Object.keys(severitiesWithAll) as CaseSeverityWithAll[];
const options: Array<EuiSuperSelectOption<CaseSeverityWithAll>> = caseSeverities.map(
(severity) => {
const severityData = severitiesWithAll[severity];
return {
value: severity,
inputDisplay: (
<EuiFlexGroup
gutterSize="xs"
alignItems={'center'}
responsive={false}
data-test-subj={`case-severity-filter-${severity}`}
>
<EuiFlexItem grow={false}>
{severity === SeverityAll ? (
<EuiText size="s">{severityData.label}</EuiText>
) : (
<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-filter"
/>
);
};
SeverityFilter.displayName = 'SeverityFilter';
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { mount } from 'enzyme';

import { CaseStatuses } from '../../../common/api';
import { OBSERVABILITY_OWNER, SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { TestProviders } from '../../common/mock';
import { AppMockRenderer, createAppMockRenderer, TestProviders } from '../../common/mock';
import { useGetTags } from '../../containers/use_get_tags';
import { useGetReporters } from '../../containers/use_get_reporters';
import { DEFAULT_FILTER_OPTIONS } from '../../containers/use_get_cases';
import { CasesTableFilters } from './table_filters';
import userEvent from '@testing-library/user-event';

jest.mock('../../containers/use_get_reporters');
jest.mock('../../containers/use_get_tags');
Expand All @@ -35,7 +36,9 @@ const props = {
};

describe('CasesTableFilters ', () => {
let appMockRender: AppMockRenderer;
beforeEach(() => {
appMockRender = createAppMockRenderer();
jest.clearAllMocks();
(useGetTags as jest.Mock).mockReturnValue({ tags: ['coke', 'pepsi'], fetchTags });
(useGetReporters as jest.Mock).mockReturnValue({
Expand All @@ -57,6 +60,19 @@ describe('CasesTableFilters ', () => {
expect(wrapper.find(`[data-test-subj="case-status-filter"]`).first().exists()).toBeTruthy();
});

it('should render the case severity filter dropdown', () => {
const result = appMockRender.render(<CasesTableFilters {...props} />);
expect(result.getByTestId('case-severity-filter')).toBeTruthy();
});

it('should call onFilterChange when the severity filter changes', () => {
const result = appMockRender.render(<CasesTableFilters {...props} />);
userEvent.click(result.getByTestId('case-severity-filter'));
userEvent.click(result.getByTestId('case-severity-filter-high'));

expect(onFilterChanged).toBeCalledWith({ severity: 'high' });
});

it('should call onFilterChange when selected tags change', () => {
const wrapper = mount(
<TestProviders>
Expand Down
Loading