-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Add severity field to the Case view page. (#131521)
- Loading branch information
Showing
12 changed files
with
342 additions
and
5 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
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, | ||
}, | ||
}; |
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/cases/public/components/severity/selector.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,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
64
x-pack/plugins/cases/public/components/severity/selector.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,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'; |
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/cases/public/components/severity/sidebar_selector.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,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
28
x-pack/plugins/cases/public/components/severity/translations.ts
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,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', | ||
}); |
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
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/cases/public/components/user_actions/severity.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,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(); | ||
}); | ||
}); |
Oops, something went wrong.