From eb5538ae6fa52e1acbe0ae4f6145d89c64383145 Mon Sep 17 00:00:00 2001
From: PhilippeOberti
Date: Mon, 19 Sep 2022 07:57:10 -0500
Subject: [PATCH] [TIP] Fix many small UI issues
- add EuiTooltip for all EuiButtonIcon
- add missing translations
- replace css with EuiFlexGroup where possible
- extract fieldValueValid logic
---
.../indicator_barchart_legend_action.tsx | 22 +++--
.../indicator_value_actions.tsx | 11 ++-
.../components/block/indicator_block.tsx | 2 +-
.../indicators_table/actions_row_cell.tsx | 8 +-
.../indicators_table/cell_actions.tsx | 6 +-
.../components/indicators_table/styles.ts | 18 ----
.../open_indicator_flyout_button.tsx | 18 ++--
.../indicators/lib/field_value.test.ts | 83 +++++++++++++-----
.../modules/indicators/lib/field_value.ts | 10 +++
.../__snapshots__/filter_in.test.tsx.snap | 84 +++++++++++--------
.../components/filter_in/filter_in.tsx | 37 ++++----
.../__snapshots__/filter_out.test.tsx.snap | 84 +++++++++++--------
.../components/filter_out/filter_out.tsx | 37 ++++----
.../add_to_timeline.test.tsx.snap | 68 +++++++++------
.../add_to_timeline/add_to_timeline.tsx | 26 ++++--
.../components/add_to_timeline/styles.ts | 5 --
.../investigate_in_timeline_button.tsx | 6 +-
...gate_in_timeline_button_icon.test.tsx.snap | 12 +--
.../investigate_in_timeline_button_icon.tsx | 23 +++--
.../styles.ts | 18 ----
.../hooks/use_investigate_in_timeline.ts | 8 +-
21 files changed, 329 insertions(+), 257 deletions(-)
delete mode 100644 x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/styles.ts
delete mode 100644 x-pack/plugins/threat_intelligence/public/modules/timeline/components/investigate_in_timeline_button_icon/styles.ts
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_barchart_legend_action/indicator_barchart_legend_action.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_barchart_legend_action/indicator_barchart_legend_action.tsx
index e015e409ec227..c87f812da76fb 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_barchart_legend_action/indicator_barchart_legend_action.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_barchart_legend_action/indicator_barchart_legend_action.tsx
@@ -6,7 +6,8 @@
*/
import React, { useState, VFC } from 'react';
-import { EuiButtonIcon, EuiContextMenuPanel, EuiPopover } from '@elastic/eui';
+import { EuiButtonIcon, EuiContextMenuPanel, EuiPopover, EuiToolTip } from '@elastic/eui';
+import { i18n } from '@kbn/i18n';
import { ComponentType } from '../../../../../common/types/component_type';
import { FilterIn } from '../../../query_bar/components/filter_in';
import { FilterOut } from '../../../query_bar/components/filter_out';
@@ -17,6 +18,10 @@ export const TIMELINE_BUTTON_TEST_ID = 'tiBarchartTimelineButton';
export const FILTER_IN_BUTTON_TEST_ID = 'tiBarchartFilterInButton';
export const FILTER_OUT_BUTTON_TEST_ID = 'tiBarchartFilterOutButton';
+const BUTTON_LABEL = i18n.translate('xpack.threatIntelligence.indicator.barChart.popover', {
+ defaultMessage: 'More actions',
+});
+
export interface IndicatorBarchartLegendActionProps {
/**
* Indicator
@@ -59,12 +64,15 @@ export const IndicatorBarchartLegendAction: VFC setPopover(!isPopoverOpen)}
- />
+
+ setPopover(!isPopoverOpen)}
+ />
+
}
isOpen={isPopoverOpen}
closePopover={() => setPopover(false)}
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_value_actions/indicator_value_actions.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_value_actions/indicator_value_actions.tsx
index 1fdc58f85cfcf..f3c5fd7c2e7d8 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_value_actions/indicator_value_actions.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicator_value_actions/indicator_value_actions.tsx
@@ -7,12 +7,12 @@
import type { EuiButtonEmpty, EuiButtonIcon } from '@elastic/eui';
import React, { VFC } from 'react';
-import { EMPTY_VALUE } from '../../../../../common/constants';
+import { EuiFlexGroup } from '@elastic/eui';
import { Indicator } from '../../../../../common/types/indicator';
import { FilterIn } from '../../../query_bar/components/filter_in';
import { FilterOut } from '../../../query_bar/components/filter_out';
import { AddToTimeline } from '../../../timeline/components/add_to_timeline';
-import { getIndicatorFieldAndValue } from '../../lib/field_value';
+import { fieldAndValueValid, getIndicatorFieldAndValue } from '../../lib/field_value';
export const TIMELINE_BUTTON_TEST_ID = 'TimelineButton';
export const FILTER_IN_BUTTON_TEST_ID = 'FilterInButton';
@@ -44,8 +44,7 @@ export const IndicatorValueActions: VFC = ({
...props
}) => {
const { key, value } = getIndicatorFieldAndValue(indicator, field);
-
- if (!key || value === EMPTY_VALUE || !key) {
+ if (!fieldAndValueValid(key, value)) {
return null;
}
@@ -54,7 +53,7 @@ export const IndicatorValueActions: VFC = ({
const timelineTestId = `${props['data-test-subj']}${TIMELINE_BUTTON_TEST_ID}`;
return (
- <>
+
= ({
field={field}
data-test-subj={timelineTestId}
/>
- >
+
);
};
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_flyout/tabs/indicators_flyout_overview/components/block/indicator_block.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_flyout/tabs/indicators_flyout_overview/components/block/indicator_block.tsx
index 3fbd7d7365d50..9537131a574a3 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_flyout/tabs/indicators_flyout_overview/components/block/indicator_block.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_flyout/tabs/indicators_flyout_overview/components/block/indicator_block.tsx
@@ -25,7 +25,7 @@ const VisibleOnHover = euiStyled.div`
& .actionsWrapper {
visibility: hidden;
display: inline-block;
- margin-inline-start: ${theme.eui.euiSizeXS};
+ margin-inline-start: ${theme.eui.euiSizeS};
}
&:hover .actionsWrapper {
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/actions_row_cell.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/actions_row_cell.tsx
index 277b64fcacc3d..1744bf8ac06ce 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/actions_row_cell.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/actions_row_cell.tsx
@@ -6,17 +6,15 @@
*/
import React, { useContext, VFC } from 'react';
+import { EuiFlexGroup } from '@elastic/eui';
import { InvestigateInTimelineButtonIcon } from '../../../timeline/components/investigate_in_timeline_button_icon';
import { Indicator } from '../../../../../common/types/indicator';
import { OpenIndicatorFlyoutButton } from '../open_indicator_flyout_button/open_indicator_flyout_button';
import { IndicatorsTableContext } from './context';
-import { useStyles } from './styles';
const INVESTIGATE_TEST_ID = 'tiIndicatorTableInvestigateInTimelineButtonIcon';
export const ActionsRowCell: VFC<{ indicator: Indicator }> = ({ indicator }) => {
- const styles = useStyles();
-
const indicatorTableContext = useContext(IndicatorsTableContext);
if (!indicatorTableContext) {
@@ -26,13 +24,13 @@ export const ActionsRowCell: VFC<{ indicator: Indicator }> = ({ indicator }) =>
const { setExpanded, expanded } = indicatorTableContext;
return (
-
+
-
+
);
};
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/cell_actions.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/cell_actions.tsx
index fa255f053ab67..0f111f96c4c25 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/cell_actions.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/cell_actions.tsx
@@ -8,11 +8,10 @@
import React, { VFC } from 'react';
import { EuiDataGridColumnCellActionProps } from '@elastic/eui/src/components/datagrid/data_grid_types';
import { ComponentType } from '../../../../../common/types/component_type';
-import { EMPTY_VALUE } from '../../../../../common/constants';
import { Indicator } from '../../../../../common/types/indicator';
import { Pagination } from '../../hooks/use_indicators';
import { AddToTimeline } from '../../../timeline/components/add_to_timeline';
-import { getIndicatorFieldAndValue } from '../../lib/field_value';
+import { fieldAndValueValid, getIndicatorFieldAndValue } from '../../lib/field_value';
import { FilterIn } from '../../../query_bar/components/filter_in';
import { FilterOut } from '../../../query_bar/components/filter_out';
@@ -47,8 +46,7 @@ export const CellActions: VFC = ({
}) => {
const indicator = indicators[rowIndex % pagination.pageSize];
const { key, value } = getIndicatorFieldAndValue(indicator, columnId);
-
- if (!value || value === EMPTY_VALUE || !key) {
+ if (!fieldAndValueValid(key, value)) {
return <>>;
}
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/styles.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/styles.ts
deleted file mode 100644
index 3ae7bf4ef16d9..0000000000000
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/indicators_table/styles.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * 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 { CSSObject } from '@emotion/react';
-
-export const useStyles = () => {
- const rowActionsDiv: CSSObject = {
- display: 'flex',
- };
-
- return {
- rowActionsDiv,
- };
-};
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/open_indicator_flyout_button/open_indicator_flyout_button.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/open_indicator_flyout_button/open_indicator_flyout_button.tsx
index 48900019265c7..08a27381ce9a7 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/components/open_indicator_flyout_button/open_indicator_flyout_button.tsx
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/components/open_indicator_flyout_button/open_indicator_flyout_button.tsx
@@ -12,6 +12,13 @@ import { Indicator } from '../../../../../common/types/indicator';
export const BUTTON_TEST_ID = 'tiToggleIndicatorFlyoutButton';
+const BUTTON_LABEL: string = i18n.translate(
+ 'xpack.threatIntelligence.indicator.table.viewDetailsButton',
+ {
+ defaultMessage: 'View details',
+ }
+);
+
export interface OpenIndicatorFlyoutButtonProps {
/**
* {@link Indicator} passed to the flyout component.
@@ -35,22 +42,15 @@ export const OpenIndicatorFlyoutButton: VFC = ({
onOpen,
isOpen,
}) => {
- const buttonLabel: string = i18n.translate(
- 'xpack.threatIntelligence.indicator.table.viewDetailsButton',
- {
- defaultMessage: 'View details',
- }
- );
-
return (
-
+
onOpen(indicator)}
/>
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts
index fa9746e80cc21..bd6a36aaf2d50 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.test.ts
@@ -5,39 +5,76 @@
* 2.0.
*/
-import { getIndicatorFieldAndValue } from './field_value';
+import { fieldAndValueValid, getIndicatorFieldAndValue } from './field_value';
import {
generateMockFileIndicator,
generateMockUrlIndicator,
} from '../../../../common/types/indicator';
+import { EMPTY_VALUE } from '../../../../common/constants';
-describe('getIndicatorFieldAndValue()', () => {
- it('should return field/value pair for an indicator', () => {
- const mockData = generateMockUrlIndicator();
- const mockKey = 'threat.feed.name';
+describe('field_value', () => {
+ describe('getIndicatorFieldAndValue()', () => {
+ it('should return field/value pair for an indicator', () => {
+ const mockData = generateMockUrlIndicator();
+ const mockKey = 'threat.feed.name';
- const result = getIndicatorFieldAndValue(mockData, mockKey);
- expect(result.key).toEqual(mockKey);
- expect(result.value).toEqual((mockData.fields[mockKey] as unknown as string[])[0]);
- });
+ const result = getIndicatorFieldAndValue(mockData, mockKey);
+ expect(result.key).toEqual(mockKey);
+ expect(result.value).toEqual((mockData.fields[mockKey] as unknown as string[])[0]);
+ });
+
+ it('should return a null value for an incorrect field', () => {
+ const mockData = generateMockUrlIndicator();
+ const mockKey = 'abc';
+
+ const result = getIndicatorFieldAndValue(mockData, mockKey);
+ expect(result.key).toEqual(mockKey);
+ expect(result.value).toBeNull();
+ });
- it('should return a null value for an incorrect field', () => {
- const mockData = generateMockUrlIndicator();
- const mockKey = 'abc';
+ it('should return field/value pair for an indicator and DisplayName field', () => {
+ const mockData = generateMockFileIndicator();
+ const mockKey = 'threat.indicator.name';
- const result = getIndicatorFieldAndValue(mockData, mockKey);
- expect(result.key).toEqual(mockKey);
- expect(result.value).toBeNull();
+ const result = getIndicatorFieldAndValue(mockData, mockKey);
+ expect(result.key).toEqual(
+ (mockData.fields['threat.indicator.name_origin'] as unknown as string[])[0]
+ );
+ expect(result.value).toEqual((mockData.fields[mockKey] as unknown as string[])[0]);
+ });
});
- it('should return field/value pair for an indicator and DisplayName field', () => {
- const mockData = generateMockFileIndicator();
- const mockKey = 'threat.indicator.name';
+ describe('fieldAndValueValid()', () => {
+ it('should return false for null value', () => {
+ const mockField = 'abc';
+ const mockValue = null;
+
+ const result = fieldAndValueValid(mockField, mockValue);
+ expect(result).toEqual(false);
+ });
+
+ it(`should return false for ${EMPTY_VALUE} value`, () => {
+ const mockField = 'abc';
+ const mockValue = EMPTY_VALUE;
+
+ const result = fieldAndValueValid(mockField, mockValue);
+ expect(result).toEqual(false);
+ });
+
+ it('should return false for empty field', () => {
+ const mockField = '';
+ const mockValue = 'abc';
+
+ const result = fieldAndValueValid(mockField, mockValue);
+ expect(result).toEqual(false);
+ });
+
+ it('should return true if field and value are correct', () => {
+ const mockField = 'abc';
+ const mockValue = 'abc';
- const result = getIndicatorFieldAndValue(mockData, mockKey);
- expect(result.key).toEqual(
- (mockData.fields['threat.indicator.name_origin'] as unknown as string[])[0]
- );
- expect(result.value).toEqual((mockData.fields[mockKey] as unknown as string[])[0]);
+ const result = fieldAndValueValid(mockField, mockValue);
+ expect(result).toEqual(true);
+ });
});
});
diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts
index f463537b120c4..958b33e6a6347 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts
+++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/lib/field_value.ts
@@ -5,6 +5,7 @@
* 2.0.
*/
+import { EMPTY_VALUE } from '../../../../common/constants';
import { unwrapValue } from './unwrap_value';
import { Indicator, RawIndicatorFieldId } from '../../../../common/types/indicator';
@@ -29,3 +30,12 @@ export const getIndicatorFieldAndValue = (
value,
};
};
+
+/**
+ * Checks if field and value are correct
+ * @param field Indicator string field
+ * @param value Indicator string|null value for the field
+ * @returns true if correct, false if not
+ */
+export const fieldAndValueValid = (field: string | null, value: string | null): boolean =>
+ value != null && value !== '' && value !== EMPTY_VALUE && field != null && field !== '';
diff --git a/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/filter_in/__snapshots__/filter_in.test.tsx.snap b/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/filter_in/__snapshots__/filter_in.test.tsx.snap
index 1ceba15da5ad6..34e37aaf1dd40 100644
--- a/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/filter_in/__snapshots__/filter_in.test.tsx.snap
+++ b/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/filter_in/__snapshots__/filter_in.test.tsx.snap
@@ -127,6 +127,31 @@ Object {
"asFragment": [Function],
"baseElement":
+ ,
+ "container":
+
@@ -142,24 +167,7 @@ Object {
/>
-
-
+
+
+
+
+