Skip to content

Commit b471c7a

Browse files
wildematPhilippeOberti
authored andcommitted
[Security Solution] cleanup types for row actions
1 parent f52103b commit b471c7a

12 files changed

Lines changed: 123 additions & 146 deletions

File tree

x-pack/solutions/security/plugins/security_solution/common/types/header_actions/index.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs';
1717
import type { SortColumnTable } from '@kbn/securitysolution-data-table';
1818
import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
1919
import type { OnRowSelected, SetEventsDeleted, SetEventsLoading } from '..';
20-
import type { BrowserFields, TimelineNonEcsData } from '../../search_strategy';
20+
import type { BrowserFields } from '../../search_strategy';
2121

2222
export type ColumnHeaderType = 'not-filtered' | 'text-filter';
2323

@@ -81,40 +81,33 @@ export type RowCellRender =
8181
| ((props: ActionProps) => JSX.Element);
8282

8383
export interface ActionProps {
84-
action?: RowCellRender;
8584
ariaRowindex: number;
8685
checked: boolean;
87-
columnId: string;
8886
columnValues: string;
89-
data: TimelineNonEcsData[];
90-
disableExpandAction?: boolean;
9187
disabled?: boolean;
88+
disableExpandAction?: boolean;
89+
disablePinAction?: boolean;
90+
disableTimelineAction?: boolean;
9291
ecsData: Ecs;
9392
eventId: string;
9493
eventIdToNoteIds?: Readonly<Record<string, string[]>>;
95-
index: number;
96-
isEventPinned?: boolean;
94+
index?: number;
9795
isEventViewer?: boolean;
96+
isEventPinned?: boolean;
9897
loadingEventIds: Readonly<string[]>;
9998
onEventDetailsPanelOpened: () => void;
10099
onRowSelected: OnRowSelected;
101100
onRuleChange?: () => void;
101+
pinnedEventIds?: Readonly<Record<string, boolean>>;
102102
refetch?: () => void;
103-
rowIndex: number;
104-
setEventsDeleted: SetEventsDeleted;
105-
setEventsLoading: SetEventsLoading;
106-
showCheckboxes: boolean;
107-
/**
108-
* This prop is used to determine if the notes button should be displayed
109-
* as the part of Row Actions
110-
* */
103+
setEventsDeleted?: SetEventsDeleted;
104+
setEventsLoading?: SetEventsLoading;
105+
showCheckboxes?: boolean;
111106
showNotes?: boolean;
112107
tabType?: string;
113108
timelineId: string;
114109
toggleShowNotes?: () => void;
115110
width?: number;
116-
disablePinAction?: boolean;
117-
disableTimelineAction?: boolean;
118111
}
119112

120113
interface AdditionalControlColumnProps {

x-pack/solutions/security/plugins/security_solution/public/cases/components/case_events/table.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import type {
1212
import type { CaseViewEventsTableProps } from '@kbn/cases-plugin/common/ui';
1313
import type { EuiTheme } from '@kbn/react-kibana-context-styled';
1414
import type { SubsetDataTableModel } from '@kbn/securitysolution-data-table';
15-
import { type DataView } from '@kbn/data-views-plugin/public';
1615
import {
17-
getPageRowIndex,
1816
addBuildingBlockStyle,
19-
defaultHeaders,
20-
DataTableComponent,
2117
dataTableActions,
18+
DataTableComponent,
19+
defaultHeaders,
20+
getPageRowIndex,
2221
getTableByIdSelector,
2322
tableDefaults,
2423
} from '@kbn/securitysolution-data-table';
24+
import { type DataView } from '@kbn/data-views-plugin/public';
2525
import type { DeprecatedRowRenderer } from '@kbn/timelines-plugin/common';
26-
import React, { useMemo, useEffect, useContext, type FC, useState, useCallback } from 'react';
26+
import React, { type FC, useCallback, useContext, useEffect, useMemo, useState } from 'react';
2727
import { useDispatch, useSelector } from 'react-redux';
2828

2929
import { ThemeContext } from 'styled-components';

x-pack/solutions/security/plugins/security_solution/public/common/components/control_columns/checkbox.test.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,22 @@
55
* 2.0.
66
*/
77

8-
import { render, fireEvent } from '@testing-library/react';
8+
import { fireEvent, render } from '@testing-library/react';
9+
import type { RowCheckBoxProps } from './checkbox';
910
import { HeaderCheckBox, RowCheckBox } from './checkbox';
1011
import React from 'react';
11-
import type { ActionProps, HeaderActionProps } from '../../../../common/types';
12+
import type { HeaderActionProps } from '../../../../common/types';
1213
import { TimelineTabs } from '../../../../common/types';
1314

1415
describe('checkbox control column', () => {
1516
describe('RowCheckBox', () => {
16-
const defaultProps: ActionProps = {
17+
const defaultProps: RowCheckBoxProps = {
1718
ariaRowindex: 1,
18-
columnId: 'test-columnId',
19-
columnValues: 'test-columnValues',
2019
checked: false,
20+
columnValues: 'test-columnValues',
2121
onRowSelected: jest.fn(),
2222
eventId: 'test-event-id',
2323
loadingEventIds: [],
24-
onEventDetailsPanelOpened: jest.fn(),
25-
showCheckboxes: true,
26-
data: [],
27-
ecsData: {
28-
_id: 'test-ecsData-id',
29-
},
30-
index: 1,
31-
rowIndex: 1,
32-
showNotes: true,
33-
timelineId: 'test-timelineId',
34-
setEventsLoading: jest.fn(),
35-
setEventsDeleted: jest.fn(),
3624
};
3725
test('displays loader when id is included on loadingEventIds', () => {
3826
const { getByTestId } = render(

x-pack/solutions/security/plugins/security_solution/public/common/components/control_columns/checkbox.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@ import React, { useCallback } from 'react';
1010
import type { ActionProps, HeaderActionProps } from '../../../../common/types';
1111
import * as i18n from './translations';
1212

13+
export type RowCheckBoxProps = Pick<
14+
ActionProps,
15+
| 'ariaRowindex'
16+
| 'checked'
17+
| 'columnValues'
18+
| 'disabled'
19+
| 'eventId'
20+
| 'loadingEventIds'
21+
| 'onRowSelected'
22+
>;
23+
1324
export const RowCheckBox = ({
14-
eventId,
15-
onRowSelected,
16-
checked,
1725
ariaRowindex,
26+
checked,
1827
columnValues,
1928
disabled,
29+
eventId,
2030
loadingEventIds,
21-
}: ActionProps) => {
31+
onRowSelected,
32+
}: RowCheckBoxProps) => {
2233
const handleSelectEvent = useCallback(
2334
(event: React.ChangeEvent<HTMLInputElement>) => {
2435
if (!disabled) {

x-pack/solutions/security/plugins/security_solution/public/common/components/control_columns/row_action/index.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import {
1515
DocumentDetailsRightPanelKey,
1616
} from '../../../../flyout/document_details/shared/constants/panel_keys';
1717
import type {
18+
ControlColumnProps,
1819
SetEventsDeleted,
1920
SetEventsLoading,
20-
ControlColumnProps,
2121
} from '../../../../../common/types';
2222
import type { TimelineItem, TimelineNonEcsData } from '../../../../../common/search_strategy';
2323
import type { ColumnHeaderOptions, OnRowSelected } from '../../../../../common/types/timeline';
2424
import { useIsExperimentalFeatureEnabled } from '../../../hooks/use_experimental_features';
25-
import { NotesEventTypes, DocumentEventTypes } from '../../../lib/telemetry';
25+
import { DocumentEventTypes, NotesEventTypes } from '../../../lib/telemetry';
2626
import { getMappedNonEcsValue } from '../../../utils/get_mapped_non_ecs_value';
2727
import { useUserPrivileges } from '../../user_privileges';
2828

@@ -36,15 +36,15 @@ export type RowActionProps = EuiDataGridCellValueElementProps & {
3636
loadingEventIds: Readonly<string[]>;
3737
onRowSelected: OnRowSelected;
3838
onRuleChange?: () => void;
39+
pageRowIndex: number;
40+
refetch?: () => void;
3941
selectedEventIds: Readonly<Record<string, TimelineNonEcsData[]>>;
42+
setEventsDeleted: SetEventsDeleted;
43+
setEventsLoading: SetEventsLoading;
4044
showCheckboxes: boolean;
4145
tabType?: string;
4246
tableId: string;
4347
width: number;
44-
setEventsLoading: SetEventsLoading;
45-
setEventsDeleted: SetEventsDeleted;
46-
pageRowIndex: number;
47-
refetch?: () => void;
4848
};
4949

5050
const RowActionComponent = ({
@@ -58,15 +58,15 @@ const RowActionComponent = ({
5858
onRowSelected,
5959
onRuleChange,
6060
pageRowIndex,
61+
refetch,
6162
rowIndex,
6263
selectedEventIds,
64+
setEventsLoading,
65+
setEventsDeleted,
6366
showCheckboxes,
6467
tabType,
6568
tableId,
66-
setEventsLoading,
67-
setEventsDeleted,
6869
width,
69-
refetch,
7070
}: RowActionProps) => {
7171
const { data: timelineNonEcsData, ecs: ecsData, _id: eventId, _index: indexName } = data ?? {};
7272
const { telemetry } = useKibana().services;
@@ -158,9 +158,9 @@ const RowActionComponent = ({
158158
checked={Object.keys(selectedEventIds).includes(eventId)}
159159
columnId={controlColumn.id || ''}
160160
columnValues={columnValues || ''}
161-
data={timelineNonEcsData}
162161
data-test-subj="actions"
163162
disabled={disabled}
163+
disableTimelineAction={!canReadTimelines}
164164
ecsData={ecsData}
165165
eventId={eventId}
166166
index={index}
@@ -169,17 +169,16 @@ const RowActionComponent = ({
169169
onEventDetailsPanelOpened={handleOnEventDetailPanelOpened}
170170
onRowSelected={onRowSelected}
171171
onRuleChange={onRuleChange}
172+
refetch={refetch}
172173
rowIndex={rowIndex}
174+
setEventsLoading={setEventsLoading}
175+
setEventsDeleted={setEventsDeleted}
173176
showCheckboxes={showCheckboxes}
177+
showNotes={showNotes}
174178
tabType={tabType}
175179
timelineId={tableId}
176180
toggleShowNotes={securitySolutionNotesDisabled ? undefined : toggleShowNotes}
177181
width={width}
178-
setEventsLoading={setEventsLoading}
179-
setEventsDeleted={setEventsDeleted}
180-
refetch={refetch}
181-
showNotes={showNotes}
182-
disableTimelineAction={!canReadTimelines}
183182
/>
184183
)}
185184
</>

x-pack/solutions/security/plugins/security_solution/public/common/components/control_columns/transform_control_columns.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import type { EuiDataGridCellValueElementProps, EuiDataGridControlColumn } from
1010
import type { ComponentType } from 'react';
1111
import React from 'react';
1212
import type { EuiTheme } from '@kbn/kibana-react-plugin/common';
13-
import { addBuildingBlockStyle, getPageRowIndex } from '@kbn/securitysolution-data-table';
1413
import type { SortColumnTable } from '@kbn/securitysolution-data-table';
14+
import { addBuildingBlockStyle, getPageRowIndex } from '@kbn/securitysolution-data-table';
1515
import type {
1616
BrowserFields,
1717
TimelineItem,
1818
TimelineNonEcsData,
1919
} from '../../../../common/search_strategy';
2020
import type {
21-
SetEventsDeleted,
22-
SetEventsLoading,
2321
ColumnHeaderOptions,
2422
ControlColumnProps,
2523
OnRowSelected,
2624
OnSelectAll,
25+
SetEventsDeleted,
26+
SetEventsLoading,
2727
} from '../../../../common/types';
2828
import { RowAction } from './row_action';
2929

x-pack/solutions/security/plugins/security_solution/public/common/components/header_actions/actions.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,43 @@ const ActionsContainer = styled.div`
4848

4949
const emptyNotes: string[] = [];
5050

51-
const ActionsComponent: React.FC<ActionProps> = ({
51+
type ActionsComponentProps = Pick<
52+
ActionProps,
53+
| 'ariaRowindex'
54+
| 'columnValues'
55+
| 'disableExpandAction'
56+
| 'disablePinAction'
57+
| 'disableTimelineAction'
58+
| 'ecsData'
59+
| 'eventId'
60+
| 'eventIdToNoteIds'
61+
| 'isEventViewer'
62+
| 'isEventPinned'
63+
| 'onEventDetailsPanelOpened'
64+
| 'onRuleChange'
65+
| 'refetch'
66+
| 'showNotes'
67+
| 'timelineId'
68+
| 'toggleShowNotes'
69+
>;
70+
71+
const ActionsComponent: React.FC<ActionsComponentProps> = ({
5272
ariaRowindex,
5373
columnValues,
5474
disableExpandAction = false,
75+
disablePinAction = true,
76+
disableTimelineAction = false,
5577
ecsData,
5678
eventId,
5779
eventIdToNoteIds,
58-
isEventPinned = false,
5980
isEventViewer = false,
81+
isEventPinned = false,
6082
onEventDetailsPanelOpened,
6183
onRuleChange,
84+
refetch,
6285
showNotes,
6386
timelineId,
64-
refetch,
6587
toggleShowNotes,
66-
disablePinAction = true,
67-
disableTimelineAction = false,
6888
}) => {
6989
const dispatch = useDispatch();
7090

@@ -186,11 +206,11 @@ const ActionsComponent: React.FC<ActionProps> = ({
186206
);
187207

188208
// we hide the analyzer icon if the data is not available for the resolver
189-
// or if we are on the cases alerts table and the the visualization in flyout advanced setting is disabled
209+
// or if we are on the cases alerts table and the visualization in flyout advanced setting is disabled
190210
const showAnalyzerIcon = useIsInvestigateInResolverActionEnabled(ecsData);
191211

192212
// we hide the session view icon if the session view is not available
193-
// or if we are on the cases alerts table and the the visualization in flyout advanced setting is disabled
213+
// or if we are on the cases alerts table and the visualization in flyout advanced setting is disabled
194214
// or if the user is not on an enterprise license or on the kubernetes page
195215
const isEnterprisePlus = useLicense().isEnterprise();
196216
const showSessionViewIcon = useMemo(

x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_creation_ui/components/rule_preview/preview_table_control_columns.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';
8+
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
99
import React from 'react';
1010
import styled from 'styled-components';
1111
import {
@@ -47,7 +47,12 @@ const ActionsContainer = styled.div`
4747
display: flex;
4848
`;
4949

50-
const PreviewActionsComponent: React.FC<ActionProps> = ({
50+
type PreviewActionsComponentProps = Pick<
51+
ActionProps,
52+
'ariaRowindex' | 'columnValues' | 'onEventDetailsPanelOpened'
53+
>;
54+
55+
const PreviewActionsComponent: React.FC<PreviewActionsComponentProps> = ({
5156
ariaRowindex,
5257
columnValues,
5358
onEventDetailsPanelOpened,

x-pack/solutions/security/plugins/security_solution/public/timelines/components/timeline/body/helpers.test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { eventHasNotes, eventIsPinned, getPinOnClick, getPinTooltip } from './helpers';
8+
import { eventHasNotes, getPinOnClick, getPinTooltip } from './helpers';
99
import { TimelineTypeEnum } from '../../../../../common/api/timeline';
1010

1111
describe('helpers', () => {
@@ -131,22 +131,6 @@ describe('helpers', () => {
131131
});
132132
});
133133

134-
describe('eventIsPinned', () => {
135-
test('returns true when the specified event id is contained in the pinnedEventIds', () => {
136-
const eventId = 'race-for-the-prize';
137-
const pinnedEventIds = { [eventId]: true, 'waiting-for-superman': true };
138-
139-
expect(eventIsPinned({ eventId, pinnedEventIds })).toEqual(true);
140-
});
141-
142-
test('returns false when the specified event id is NOT contained in the pinnedEventIds', () => {
143-
const eventId = 'safety-pin';
144-
const pinnedEventIds = { 'thumb-tack': true };
145-
146-
expect(eventIsPinned({ eventId, pinnedEventIds })).toEqual(false);
147-
});
148-
});
149-
150134
describe('getPinOnClick', () => {
151135
const eventId = 'abcd';
152136

x-pack/solutions/security/plugins/security_solution/public/timelines/components/timeline/body/helpers.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export interface IsPinnedParams {
4444
pinnedEventIds: Readonly<Record<string, boolean>>;
4545
}
4646

47-
export const eventIsPinned = ({ eventId, pinnedEventIds }: IsPinnedParams): boolean =>
48-
pinnedEventIds[eventId] === true;
49-
5047
export interface GetPinOnClickParams {
5148
allowUnpinning: boolean;
5249
eventId: string;

0 commit comments

Comments
 (0)