forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] severity field in the cases list and allow to filter by it (e…
- Loading branch information
Showing
25 changed files
with
423 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/cases/public/components/all_cases/severity_filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.