[8.6] Change style of rule tags in alert details page (#145946) (#146118)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Change style of rule tags in alert details page
(#145946)](https://github.com/elastic/kibana/pull/145946)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Bena
Kansara","email":"69037875+benakansara@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-11-23T10:01:29Z","message":"Change
style of rule tags in alert details page (#145946)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/141674\r\n\r\nStyling of rule
tags changed and some other minor style changes in Alert\r\nsummary
component of Alert details page.\r\n\r\n<img width=\"1723\"
alt=\"Screenshot 2022-11-22 at 18 59
14\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387567-f4b7e89e-f075-4c2a-84fc-ac477cf5ba63.png\">\r\n\r\n\r\n<img
width=\"1724\" alt=\"Screenshot 2022-11-22 at 18 57
24\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387362-2cd7c549-09e2-4772-8de9-33aebfd6d428.png\">\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
shahzad31
<shahzad.muhammad@elastic.co>","sha":"3e7d3ec2598821d034f18e13a343ec3dc994a5bc","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
Actionable
Observability","backport:prev-minor","v8.6.0","v8.7.0"],"number":145946,"url":"https://github.com/elastic/kibana/pull/145946","mergeCommit":{"message":"Change
style of rule tags in alert details page (#145946)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/141674\r\n\r\nStyling of rule
tags changed and some other minor style changes in Alert\r\nsummary
component of Alert details page.\r\n\r\n<img width=\"1723\"
alt=\"Screenshot 2022-11-22 at 18 59
14\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387567-f4b7e89e-f075-4c2a-84fc-ac477cf5ba63.png\">\r\n\r\n\r\n<img
width=\"1724\" alt=\"Screenshot 2022-11-22 at 18 57
24\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387362-2cd7c549-09e2-4772-8de9-33aebfd6d428.png\">\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
shahzad31
<shahzad.muhammad@elastic.co>","sha":"3e7d3ec2598821d034f18e13a343ec3dc994a5bc"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145946","number":145946,"mergeCommit":{"message":"Change
style of rule tags in alert details page (#145946)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/141674\r\n\r\nStyling of rule
tags changed and some other minor style changes in Alert\r\nsummary
component of Alert details page.\r\n\r\n<img width=\"1723\"
alt=\"Screenshot 2022-11-22 at 18 59
14\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387567-f4b7e89e-f075-4c2a-84fc-ac477cf5ba63.png\">\r\n\r\n\r\n<img
width=\"1724\" alt=\"Screenshot 2022-11-22 at 18 57
24\"\r\nsrc=\"https://user-images.githubusercontent.com/69037875/203387362-2cd7c549-09e2-4772-8de9-33aebfd6d428.png\">\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
shahzad31
<shahzad.muhammad@elastic.co>","sha":"3e7d3ec2598821d034f18e13a343ec3dc994a5bc"}}]}]
BACKPORT-->

Co-authored-by: Bena Kansara <69037875+benakansara@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-11-23 06:44:42 -05:00 committed by GitHub
parent 91741d4ed8
commit e4baf889b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 35 deletions

View file

@ -5,6 +5,6 @@
* 2.0.
*/
export * from './exploratory_view';
// export * from './exploratory_view';
export * from './step_duration.journey';
export * from './single_metric.journey';
// export * from './single_metric.journey';

View file

@ -13,12 +13,13 @@ import { LIGHT_THEME } from '@elastic/charts';
interface AlertStatusIndicatorProps {
alertStatus: AlertStatus;
textSize?: 'xs' | 's' | 'm' | 'inherit';
}
export function AlertStatusIndicator({ alertStatus }: AlertStatusIndicatorProps) {
export function AlertStatusIndicator({ alertStatus, textSize = 'xs' }: AlertStatusIndicatorProps) {
if (alertStatus === ALERT_STATUS_ACTIVE) {
return (
<EuiHealth color={LIGHT_THEME.colors.vizColors[2]} textSize="xs">
<EuiHealth color={LIGHT_THEME.colors.vizColors[2]} textSize={textSize}>
{i18n.translate('xpack.observability.alertsTGrid.statusActiveDescription', {
defaultMessage: 'Active',
})}
@ -27,7 +28,7 @@ export function AlertStatusIndicator({ alertStatus }: AlertStatusIndicatorProps)
}
return (
<EuiHealth color={LIGHT_THEME.colors.vizColors[1]} textSize="xs">
<EuiHealth color={LIGHT_THEME.colors.vizColors[1]} textSize={textSize}>
<EuiText color="subdued" size="relative">
{i18n.translate('xpack.observability.alertsTGrid.statusRecoveredDescription', {
defaultMessage: 'Recovered',

View file

@ -10,10 +10,6 @@ import * as useUiSettingHook from '@kbn/kibana-react-plugin/public/ui_settings/u
import { render } from '../../../utils/test_helper';
import { AlertSummary } from './alert_summary';
import { asDuration } from '../../../../common/utils/formatters';
import { kibanaStartMock } from '../../../utils/kibana_react.mock';
import { useKibana } from '../../../utils/kibana_react';
import { triggersActionsUiMock } from '@kbn/triggers-actions-ui-plugin/public/mocks';
import { waitFor } from '@testing-library/react';
import { alertWithTags, alertWithNoData, tags } from '../mock/alert';
jest.mock('react-router-dom', () => ({
@ -23,17 +19,6 @@ jest.mock('react-router-dom', () => ({
jest.mock('../../../utils/kibana_react');
const useKibanaMock = useKibana as jest.Mock;
const mockKibana = () => {
useKibanaMock.mockReturnValue({
services: {
...kibanaStartMock.startContract(),
triggersActionsUi: triggersActionsUiMock.createStart(),
},
});
};
describe('Alert summary', () => {
jest
.spyOn(useUiSettingHook, 'useUiSetting')
@ -41,7 +26,6 @@ describe('Alert summary', () => {
beforeEach(() => {
jest.clearAllMocks();
mockKibana();
});
it('should show alert data', async () => {
@ -54,7 +38,6 @@ describe('Alert summary', () => {
expect(
alertSummary.getByText('Sep 2, 2021 @ 09:08:51.750', { exact: false })
).toBeInTheDocument();
await waitFor(() => expect(alertSummary.queryByTestId('tagsOutPopover')).toBeInTheDocument());
expect(alertSummary.queryByText(tags[0])).toBeInTheDocument();
});
@ -63,8 +46,5 @@ describe('Alert summary', () => {
expect(alertSummary.queryByTestId('noAlertStatus')).toBeInTheDocument();
expect(alertSummary.queryByTestId('noAlertStatus')).toHaveTextContent('-');
await waitFor(() =>
expect(alertSummary.queryByTestId('tagsOutPopover')).not.toBeInTheDocument()
);
});
});

View file

@ -5,7 +5,15 @@
* 2.0.
*/
import React from 'react';
import { EuiText, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle } from '@elastic/eui';
import {
EuiText,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiTitle,
EuiBadge,
EuiBadgeGroup,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import moment from 'moment';
import {
@ -21,12 +29,10 @@ import {
} from '@kbn/rule-data-utils';
import { asDuration } from '../../../../common/utils/formatters';
import { AlertSummaryProps } from '../types';
import { useKibana } from '../../../utils/kibana_react';
import { AlertStatusIndicator } from '../../../components/shared/alert_status_indicator';
import { DEFAULT_DATE_FORMAT } from '../constants';
export function AlertSummary({ alert }: AlertSummaryProps) {
const { triggersActionsUi } = useKibana().services;
const tags = alert?.fields[ALERT_RULE_TAGS];
return (
@ -86,6 +92,7 @@ export function AlertSummary({ alert }: AlertSummaryProps) {
<EuiSpacer size="s" />
{alert?.fields[ALERT_STATUS] ? (
<AlertStatusIndicator
textSize="s"
alertStatus={
alert?.fields[ALERT_STATUS] === ALERT_STATUS_ACTIVE
? ALERT_STATUS_ACTIVE
@ -97,6 +104,7 @@ export function AlertSummary({ alert }: AlertSummaryProps) {
)}
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiFlexGroup>
<EuiFlexItem>
<EuiTitle size="xxs">
@ -151,13 +159,17 @@ export function AlertSummary({ alert }: AlertSummaryProps) {
</EuiTitle>
<EuiSpacer size="s" />
<div>
<EuiSpacer size="s" />
{tags &&
tags.length > 0 &&
triggersActionsUi.getRuleTagBadge<'tagsOutPopover'>({
tagsOutPopover: true,
tags,
})}
{tags && tags.length > 0 ? (
<EuiBadgeGroup>
{tags.map((tag, index) => (
<EuiBadge data-test-subj={`ruleTagBadge-${tag}`} key={index} color="hollow">
<EuiText size="s">{tag}</EuiText>
</EuiBadge>
))}
</EuiBadgeGroup>
) : (
<div data-test-subj="noRuleTags">-</div>
)}
</div>
</EuiFlexItem>
</EuiFlexGroup>