Skip to content

Commit

Permalink
[8.8] [Security Solution] Fix error messages on Rule Details page tak…
Browse files Browse the repository at this point in the history
…ing too much space (#157271) (#158079)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Security Solution] Fix error messages on Rule Details page taking
too much space (#157271)](#157271)

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

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

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"nikita.indik@elastic.co"},"sourceCommit":{"committedDate":"2023-05-18T13:38:03Z","message":"[Security
Solution] Fix error messages on Rule Details page taking too much space
(#157271)\n\n## Summary\r\n\r\nWhen a large \"last execution\" error
message is displayed on Rule Details\r\npage it takes too much vertical
space:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/2946766/214444343-dde0d9cd-6bc7-4aca-a6cf-07891d206888.png\r\n\r\nThis
PR changes the error callout component. Error text is now
displayed\r\nusing EUI's TextBlock component. Users will see a scroll if
error text\r\ntakes too much vertical space. Now it's also possible to
view the text\r\nfullscreen or copy it to clipboard.\r\n\r\n<img
width=\"1206\" alt=\"Screenshot 2023-05-10 at 16 16
40\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/bca81852-afa0-44f6-acad-51c7c60c8a6f\">\r\n\r\n
---\r\n\r\nAnother addition is a button to expand a row in the Execution
Log to\r\nview / copy a full error message.\r\n<img width=\"1179\"
alt=\"Screenshot 2023-05-10 at 16 15
16\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/624e3fdc-8dd7-4fa1-a8a6-b1608be17eec\">\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\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- [x] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[x] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [x] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n\r\n**Known
issue**: Copy button is not shown in Execution Log expandable\r\nrow in
Safari. Opened an issue in
EUI:\r\nhttps://github.com/elastic/eui/issues/6770","sha":"f214b55704dd9c300be845530de956a27fd12bab","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:Detections
and Resp","Feature:Rule Monitoring","Team:Security Solution
Platform","Team:Detection Rule Management","Feature:Rule
Details","backport:prev-minor","v8.9.0"],"number":157271,"url":"#157271
Solution] Fix error messages on Rule Details page taking too much space
(#157271)\n\n## Summary\r\n\r\nWhen a large \"last execution\" error
message is displayed on Rule Details\r\npage it takes too much vertical
space:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/2946766/214444343-dde0d9cd-6bc7-4aca-a6cf-07891d206888.png\r\n\r\nThis
PR changes the error callout component. Error text is now
displayed\r\nusing EUI's TextBlock component. Users will see a scroll if
error text\r\ntakes too much vertical space. Now it's also possible to
view the text\r\nfullscreen or copy it to clipboard.\r\n\r\n<img
width=\"1206\" alt=\"Screenshot 2023-05-10 at 16 16
40\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/bca81852-afa0-44f6-acad-51c7c60c8a6f\">\r\n\r\n
---\r\n\r\nAnother addition is a button to expand a row in the Execution
Log to\r\nview / copy a full error message.\r\n<img width=\"1179\"
alt=\"Screenshot 2023-05-10 at 16 15
16\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/624e3fdc-8dd7-4fa1-a8a6-b1608be17eec\">\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\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- [x] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[x] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [x] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n\r\n**Known
issue**: Copy button is not shown in Execution Log expandable\r\nrow in
Safari. Opened an issue in
EUI:\r\nhttps://github.com/elastic/eui/issues/6770","sha":"f214b55704dd9c300be845530de956a27fd12bab"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#157271
Solution] Fix error messages on Rule Details page taking too much space
(#157271)\n\n## Summary\r\n\r\nWhen a large \"last execution\" error
message is displayed on Rule Details\r\npage it takes too much vertical
space:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/2946766/214444343-dde0d9cd-6bc7-4aca-a6cf-07891d206888.png\r\n\r\nThis
PR changes the error callout component. Error text is now
displayed\r\nusing EUI's TextBlock component. Users will see a scroll if
error text\r\ntakes too much vertical space. Now it's also possible to
view the text\r\nfullscreen or copy it to clipboard.\r\n\r\n<img
width=\"1206\" alt=\"Screenshot 2023-05-10 at 16 16
40\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/bca81852-afa0-44f6-acad-51c7c60c8a6f\">\r\n\r\n
---\r\n\r\nAnother addition is a button to expand a row in the Execution
Log to\r\nview / copy a full error message.\r\n<img width=\"1179\"
alt=\"Screenshot 2023-05-10 at 16 15
16\"\r\nsrc=\"https://github.com/elastic/kibana/assets/15949146/624e3fdc-8dd7-4fa1-a8a6-b1608be17eec\">\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\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- [x] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[x] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
For maintainers\r\n\r\n- [x] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n\r\n**Known
issue**: Copy button is not shown in Execution Log expandable\r\nrow in
Safari. Opened an issue in
EUI:\r\nhttps://github.com/elastic/eui/issues/6770","sha":"f214b55704dd9c300be845530de956a27fd12bab"}}]}]
BACKPORT-->

Co-authored-by: Nikita Indik <nikita.indik@elastic.co>
  • Loading branch information
kibanamachine and nikitaindik committed May 18, 2023
1 parent eccc8a9 commit ea447c6
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 37 deletions.
Expand Up @@ -6,8 +6,15 @@
*/

import React from 'react';
import { css } from '@emotion/react';
import type { EuiBasicTableColumn } from '@elastic/eui';
import { EuiLink, EuiText } from '@elastic/eui';
import {
EuiLink,
EuiText,
EuiButtonIcon,
EuiScreenReaderOnly,
RIGHT_ALIGNMENT,
} from '@elastic/eui';
import type { DocLinksStart } from '@kbn/core/public';
import { FormattedMessage } from '@kbn/i18n-react';

Expand All @@ -25,6 +32,37 @@ import { RuleDurationFormat } from './rule_duration_format';

import * as i18n from './translations';

type TableColumn = EuiBasicTableColumn<RuleExecutionResult>;

interface UseColumnsArgs {
toggleRowExpanded: (item: RuleExecutionResult) => void;
isRowExpanded: (item: RuleExecutionResult) => boolean;
}

export const expanderColumn = ({
toggleRowExpanded,
isRowExpanded,
}: UseColumnsArgs): TableColumn => {
return {
align: RIGHT_ALIGNMENT,
width: '40px',
isExpander: true,
name: (
<EuiScreenReaderOnly>
<span>{i18n.EXPAND_ROW}</span>
</EuiScreenReaderOnly>
),
render: (item: RuleExecutionResult) =>
item.security_status === 'succeeded' ? null : (
<EuiButtonIcon
onClick={() => toggleRowExpanded(item)}
aria-label={isRowExpanded(item) ? i18n.COLLAPSE : i18n.EXPAND}
iconType={isRowExpanded(item) ? 'arrowUp' : 'arrowDown'}
/>
),
};
};

export const EXECUTION_LOG_COLUMNS: Array<EuiBasicTableColumn<RuleExecutionResult>> = [
{
name: (
Expand Down Expand Up @@ -69,22 +107,39 @@ export const EXECUTION_LOG_COLUMNS: Array<EuiBasicTableColumn<RuleExecutionResul
truncateText: false,
width: '10%',
},
{
field: 'security_message',
name: (
<TableHeaderTooltipCell
title={i18n.COLUMN_MESSAGE}
tooltipContent={i18n.COLUMN_MESSAGE_TOOLTIP}
/>
),
render: (value: string) => <>{value}</>,
sortable: false,
truncateText: false,
width: '35%',
},
];

export const GET_EXECUTION_LOG_METRICS_COLUMNS = (
export const getMessageColumn = (width: string) => ({
field: 'security_message',
name: (
<TableHeaderTooltipCell
title={i18n.COLUMN_MESSAGE}
tooltipContent={i18n.COLUMN_MESSAGE_TOOLTIP}
/>
),
render: (value: string, record: RuleExecutionResult) => {
if (record.security_status === 'succeeded') {
return value;
}

return (
<div
css={css`
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
`}
>
{value}
</div>
);
},
sortable: false,
width,
});

export const getExecutionLogMetricsColumns = (
docLinks: DocLinksStart
): Array<EuiBasicTableColumn<RuleExecutionResult>> => [
{
Expand Down
Expand Up @@ -20,6 +20,7 @@ import {
EuiSwitch,
EuiBasicTable,
EuiButton,
EuiDescriptionList,
} from '@elastic/eui';

import type { Filter, Query } from '@kbn/es-query';
Expand Down Expand Up @@ -60,8 +61,15 @@ import { isAbsoluteTimeRange, isRelativeTimeRange } from '../../../../../common/
import { SourcererScopeName } from '../../../../../common/store/sourcerer/model';
import { useExecutionResults } from '../../../../rule_monitoring';
import { useRuleDetailsContext } from '../rule_details_context';
import { useExpandableRows } from '../../../../rule_monitoring/components/basic/tables/use_expandable_rows';
import { TextBlock } from '../../../../rule_monitoring/components/basic/text/text_block';
import * as i18n from './translations';
import { EXECUTION_LOG_COLUMNS, GET_EXECUTION_LOG_METRICS_COLUMNS } from './execution_log_columns';
import {
EXECUTION_LOG_COLUMNS,
getMessageColumn,
getExecutionLogMetricsColumns,
expanderColumn,
} from './execution_log_columns';
import { ExecutionLogSearchBar } from './execution_log_search_bar';

const EXECUTION_UUID_FIELD_NAME = 'kibana.alert.rule.execution.uuid';
Expand Down Expand Up @@ -361,7 +369,7 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
{
field: EXECUTION_UUID_FIELD_NAME,
name: i18n.COLUMN_ACTIONS,
width: '5%',
width: '64px',
actions: [
{
name: 'Edit',
Expand All @@ -386,14 +394,50 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
[onFilterByExecutionIdCallback]
);

const executionLogColumns = useMemo(
() =>
showMetricColumns
? [...EXECUTION_LOG_COLUMNS, ...GET_EXECUTION_LOG_METRICS_COLUMNS(docLinks), ...actions]
: [...EXECUTION_LOG_COLUMNS, ...actions],
[actions, docLinks, showMetricColumns]
const getItemId = useCallback((item: RuleExecutionResult): string => {
return `${item.execution_uuid}`;
}, []);

const renderExpandedItem = useCallback(
(item: RuleExecutionResult) => (
<EuiDescriptionList
className="eui-fullWidth"
listItems={[
{
title: i18n.ROW_DETAILS_MESSAGE,
description: <TextBlock text={item.security_message} />,
},
]}
/>
),
[]
);

const rows = useExpandableRows<RuleExecutionResult>({
getItemId,
renderItem: renderExpandedItem,
});

const executionLogColumns = useMemo(() => {
const columns = [...EXECUTION_LOG_COLUMNS];

if (showMetricColumns) {
columns.push(getMessageColumn('20%'), ...getExecutionLogMetricsColumns(docLinks));
} else {
columns.push(getMessageColumn('50%'));
}

columns.push(
...actions,
expanderColumn({
toggleRowExpanded: rows.toggleRowExpanded,
isRowExpanded: rows.isRowExpanded,
})
);

return columns;
}, [actions, docLinks, showMetricColumns, rows.toggleRowExpanded, rows.isRowExpanded]);

return (
<EuiPanel hasBorder>
{/* Filter bar */}
Expand Down Expand Up @@ -478,6 +522,9 @@ const ExecutionLogTableComponent: React.FC<ExecutionLogTableProps> = ({
sorting={sorting}
pagination={pagination}
onChange={onTableChangeCallback}
itemId={getItemId}
itemIdToExpandedRowMap={rows.itemIdToExpandedRowMap}
isExpandable={true}
/>
</EuiPanel>
);
Expand Down
Expand Up @@ -229,3 +229,31 @@ export const GREATER_THAN_YEAR = i18n.translate(
defaultMessage: '> 1 Year',
}
);

export const ROW_DETAILS_MESSAGE = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.ruleExecutionLog.fullMessage',
{
defaultMessage: 'Full message',
}
);

export const EXPAND_ROW = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.ruleExecutionLog.expandRow',
{
defaultMessage: 'Expand rows',
}
);

export const EXPAND = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.ruleExecutionLog.expand',
{
defaultMessage: 'Expand',
}
);

export const COLLAPSE = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.ruleExecutionLog.collapse',
{
defaultMessage: 'Collapse',
}
);
Expand Up @@ -7,7 +7,8 @@

import React from 'react';

import { EuiCallOut } from '@elastic/eui';
import { EuiCallOut, EuiCodeBlock } from '@elastic/eui';

import { FormattedDate } from '../../../../common/components/formatted_date';
import { RuleExecutionStatus } from '../../../../../common/detection_engine/rule_monitoring';

Expand All @@ -30,20 +31,36 @@ const RuleStatusFailedCallOutComponent: React.FC<RuleStatusFailedCallOutProps> =
}

return (
<EuiCallOut
title={
<>
{title} <FormattedDate value={date} fieldName="execution_summary.last_execution.date" />
</>
}
color={color}
iconType="warning"
data-test-subj="ruleStatusFailedCallOut"
<div
css={`
pre {
margin-block-end: 0;
margin-right: 24px; // Otherwise the copy button overlaps the scrollbar
padding-inline-end: 0;
}
`}
>
{message.split('\n').map((line) => (
<p>{line}</p>
))}
</EuiCallOut>
<EuiCallOut
title={
<>
{title} <FormattedDate value={date} fieldName="execution_summary.last_execution.date" />
</>
}
color={color}
iconType="warning"
data-test-subj="ruleStatusFailedCallOut"
>
<EuiCodeBlock
className="eui-fullWidth"
paddingSize="none"
isCopyable
overflowHeight={96}
transparentBackground
>
{message}
</EuiCodeBlock>
</EuiCallOut>
</div>
);
};

Expand Down

0 comments on commit ea447c6

Please sign in to comment.