Skip to content

Commit

Permalink
[Security Solutions] Removes tech debt of exporting all from linter r…
Browse files Browse the repository at this point in the history
…ule for timeline plugin (#120437)

## Summary

See: #110903

This removes all the top level API `export *` spots from:
* `timeline` plugin within both the common and public section

This reduces the number of metrics and warning about undocumented functions.

I also add this text to timeline:

```
// Careful of exporting anything from this file as any file(s) you export here will cause your page bundle size to increase.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.

// When you do have to add things here you might want to consider creating a package to share with
// other plugins instead as packages are easier to break down and you do not have to carry the cost of extra plugin weight on
// first download since the other plugins/areas of your code can directly pull from the package in their async imports.
// See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api
```
  • Loading branch information
FrankHassanabad authored Dec 7, 2021
1 parent 062be17 commit 3c8ba82
Show file tree
Hide file tree
Showing 56 changed files with 255 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useKibana } from '../../../common/lib/kibana';

import * as i18n from './translations';
import { CreateFieldComponentType, TimelineId } from '../../../../../timelines/common';
import { tGridActions } from '../../../../../timelines/public';
import { upsertColumn } from '../../../../../timelines/public';
import { useDataView } from '../../../common/containers/source/use_data_view';
import { SourcererScopeName } from '../../../common/store/sourcerer/model';
import { sourcererSelectors } from '../../../common/store';
Expand Down Expand Up @@ -59,7 +59,7 @@ export const CreateFieldButton = React.memo<CreateFieldButtonProps>(

// Add the new field to the event table
dispatch(
tGridActions.upsertColumn({
upsertColumn({
column: {
columnHeaderType: defaultColumnHeaderType,
id: field.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ jest.mock('../../../common/components/drag_and_drop/draggable_wrapper', () => {
};
});

jest.mock('../../store/timeline', () => {
const original = jest.requireActual('../../store/timeline');
return {
...original,
timelineActions: {
...original.timelineActions,
toggleDetailPanel: jest.fn(),
},
};
});

describe('FormattedIp', () => {
const props = {
value: '192.168.1.1',
Expand All @@ -53,16 +64,13 @@ describe('FormattedIp', () => {
fieldName: 'host.ip',
};

let toggleDetailPanel: jest.SpyInstance;
let toggleExpandedDetail: jest.SpyInstance;

beforeAll(() => {
toggleDetailPanel = jest.spyOn(timelineActions, 'toggleDetailPanel');
toggleExpandedDetail = jest.spyOn(activeTimeline, 'toggleExpandedDetail');
});

afterEach(() => {
toggleDetailPanel.mockClear();
toggleExpandedDetail.mockClear();
});
test('should render ip address', () => {
Expand Down Expand Up @@ -98,7 +106,7 @@ describe('FormattedIp', () => {

wrapper.find('[data-test-subj="network-details"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).not.toHaveBeenCalled();
expect(timelineActions.toggleDetailPanel).not.toHaveBeenCalled();
expect(toggleExpandedDetail).not.toHaveBeenCalled();
});
});
Expand All @@ -120,7 +128,7 @@ describe('FormattedIp', () => {

wrapper.find('[data-test-subj="network-details"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).toHaveBeenCalledWith({
expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({
panelView: 'networkDetail',
params: {
flowTarget: 'source',
Expand Down Expand Up @@ -176,7 +184,7 @@ describe('FormattedIp', () => {

wrapper.find('[data-test-subj="network-details"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).toHaveBeenCalledWith({
expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({
panelView: 'networkDetail',
params: {
flowTarget: 'source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ jest.mock('../../../../../common/components/draggables', () => ({
DefaultDraggable: () => <div data-test-subj="DefaultDraggable" />,
}));

jest.mock('../../../../store/timeline', () => {
const original = jest.requireActual('../../../../store/timeline');
return {
...original,
timelineActions: {
...original.timelineActions,
toggleDetailPanel: jest.fn(),
},
};
});

describe('HostName', () => {
const props = {
fieldName: 'host.name',
Expand All @@ -49,16 +60,13 @@ describe('HostName', () => {
value: 'Mock Host',
};

let toggleDetailPanel: jest.SpyInstance;
let toggleExpandedDetail: jest.SpyInstance;

beforeAll(() => {
toggleDetailPanel = jest.spyOn(timelineActions, 'toggleDetailPanel');
toggleExpandedDetail = jest.spyOn(activeTimeline, 'toggleExpandedDetail');
});

afterEach(() => {
toggleDetailPanel.mockClear();
toggleExpandedDetail.mockClear();
});
test('should render host name', () => {
Expand Down Expand Up @@ -96,7 +104,7 @@ describe('HostName', () => {

wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).not.toHaveBeenCalled();
expect(timelineActions.toggleDetailPanel).not.toHaveBeenCalled();
expect(toggleExpandedDetail).not.toHaveBeenCalled();
});
});
Expand All @@ -118,7 +126,7 @@ describe('HostName', () => {

wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).toHaveBeenCalledWith({
expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({
panelView: 'hostDetail',
params: {
hostName: props.value,
Expand Down Expand Up @@ -172,7 +180,7 @@ describe('HostName', () => {

wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click');
await waitFor(() => {
expect(toggleDetailPanel).toHaveBeenCalledWith({
expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({
panelView: 'hostDetail',
params: {
hostName: props.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import type {
TimelinePersistInput,
SerializedFilterQuery,
} from '../../../../common/types/timeline';
import { tGridActions } from '../../../../../timelines/public';
import { ResolveTimelineConfig } from '../../components/open_timeline/types';
export const {
export {
applyDeltaToColumnWidth,
clearEventsDeleted,
clearEventsLoading,
Expand All @@ -46,7 +44,8 @@ export const {
updateItemsPerPageOptions,
updateSort,
upsertColumn,
} = tGridActions;
} from '../../../../../timelines/public';
import { ResolveTimelineConfig } from '../../components/open_timeline/types';

const actionCreator = actionCreatorFactory('x-pack/security_solution/local/timeline');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import { createSelector } from 'reselect';

import { tGridSelectors } from '../../../../../timelines/public';
export { getManageTimelineById } from '../../../../../timelines/public';
import { State } from '../../../common/store/types';

import { TimelineModel } from './model';
import { AutoSavedWarningMsg, InsertTimeline, TimelineById } from './types';

export const { getManageTimelineById } = tGridSelectors;

const selectTimelineById = (state: State): TimelineById => state.timeline.timelineById;

const selectAutoSaveMsg = (state: State): AutoSavedWarningMsg => state.timeline.autoSavedWarningMsg;
Expand Down
82 changes: 75 additions & 7 deletions x-pack/plugins/timelines/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,82 @@
* 2.0.
*/

// TODO: https://github.com/elastic/kibana/issues/110904
/* eslint-disable @kbn/eslint/no_export_all */
// Careful of exporting anything from this file as any file(s) you export here will cause your page bundle size to increase.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.

// When you do have to add things here you might want to consider creating a package to share with
// other plugins instead as packages are easier to break down and you do not have to carry the cost of extra plugin weight on
// first download since the other plugins/areas of your code can directly pull from the package in their async imports.
// See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api

export { DELETED_SECURITY_SOLUTION_DATA_VIEW } from './constants';

export * from './types';
export * from './search_strategy';
export * from './utils/accessibility';
export type {
ActionProps,
AlertWorkflowStatus,
CellValueElementProps,
CreateFieldComponentType,
ColumnId,
ColumnRenderer,
ColumnHeaderType,
ColumnHeaderOptions,
ControlColumnProps,
DataProvidersAnd,
DataProvider,
GenericActionRowCellRenderProps,
HeaderActionProps,
HeaderCellRender,
QueryOperator,
QueryMatch,
RowCellRender,
RowRenderer,
SetEventsDeleted,
SetEventsLoading,
} from './types';

export { IS_OPERATOR, EXISTS_OPERATOR, DataProviderType, TimelineId } from './types';

export type {
BeatFields,
BrowserField,
BrowserFields,
CursorType,
DocValueFields,
EqlOptionsData,
EqlOptionsSelected,
FieldsEqlOptions,
FieldInfo,
IndexField,
IndexFieldsStrategyRequest,
IndexFieldsStrategyResponse,
LastTimeDetails,
TimelineNonEcsData,
Inspect,
SortField,
TimerangeInput,
TimelineEdges,
TimelineItem,
TimelineEventsAllStrategyResponse,
TimelineEventsAllRequestOptions,
TimelineEventsDetailsItem,
TimelineEventsDetailsStrategyResponse,
TimelineEventsDetailsRequestOptions,
TimelineEventsLastEventTimeStrategyResponse,
TimelineEventsLastEventTimeRequestOptions,
TimelineEqlRequestOptions,
TimelineEqlResponse,
TimelineKpiStrategyRequest,
TimelineKpiStrategyResponse,
TotalValue,
PaginationInputPaginated,
} from './search_strategy';

export const PLUGIN_ID = 'timelines';
export const PLUGIN_NAME = 'timelines';
export {
Direction,
EntityType,
LastEventIndexKey,
EMPTY_BROWSER_FIELDS,
EMPTY_DOCVALUE_FIELD,
EMPTY_INDEX_FIELDS,
} from './search_strategy';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { EuiDataGridCellValueElementProps } from '@elastic/eui';
import type { Filter } from '@kbn/es-query';
import { RowRenderer } from '../../..';
import { RowRenderer } from '../../../types';
import { Ecs } from '../../../ecs';
import { BrowserFields, TimelineNonEcsData } from '../../../search_strategy';
import { ColumnHeaderOptions } from '../columns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import React, { memo, useMemo, useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { CaseStatuses, StatusAll, CasesContextValue } from '../../../../../../cases/common';
import { TimelineItem } from '../../../../../common/';
import { TimelineItem } from '../../../../../common/search_strategy';
import { useAddToCase, normalizedEventFields } from '../../../../hooks/use_add_to_case';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { TimelinesStartServices } from '../../../../types';
import { tGridActions } from '../../../../';
import { setOpenAddToExistingCase, setOpenAddToNewCase } from '../../../../store/t_grid/actions';

export interface AddToCaseActionProps {
event?: TimelineItem;
Expand Down Expand Up @@ -68,8 +68,7 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
updateCase: onCaseSuccess,
userCanCrud: casePermissions?.crud ?? false,
owner: [owner],
onClose: () =>
dispatch(tGridActions.setOpenAddToExistingCase({ id: eventId, isOpen: false })),
onClose: () => dispatch(setOpenAddToExistingCase({ id: eventId, isOpen: false })),
};
}, [
casePermissions?.crud,
Expand All @@ -84,7 +83,7 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
]);

const closeCaseFlyoutOpen = useCallback(() => {
dispatch(tGridActions.setOpenAddToNewCase({ id: eventId, isOpen: false }));
dispatch(setOpenAddToNewCase({ id: eventId, isOpen: false }));
}, [dispatch, eventId]);

const createCaseFlyoutProps = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { KEYBOARD_DRAG_OFFSET, getFieldIdFromDraggable } from '@kbn/securitysolu
import { Dispatch } from 'redux';
import { isString, keyBy } from 'lodash/fp';

import { stopPropagationAndPreventDefault, TimelineId } from '../../../common';
import type { BrowserField, BrowserFields, ColumnHeaderOptions } from '../../../common';
import { stopPropagationAndPreventDefault } from '../../../common/utils/accessibility';
import { TimelineId } from '../../../common/types';
import type { BrowserField, BrowserFields } from '../../../common/search_strategy';
import type { ColumnHeaderOptions } from '../../../common/types';
import { tGridActions } from '../../store/t_grid';
import { DEFAULT_COLUMN_MIN_WIDTH } from '../t_grid/body/constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import React, { useCallback } from 'react';
import { DropResult, DragDropContext, BeforeCapture } from 'react-beautiful-dnd';
import { useDispatch } from 'react-redux';

import type { ColumnHeaderOptions, BrowserFields } from '../../../common';
import type { BrowserFields } from '../../../common/search_strategy';
import type { ColumnHeaderOptions } from '../../../common/types';
import { useAddToTimelineSensor } from '../../hooks/use_add_to_timeline';
import { addFieldToTimelineColumns, getTimelineIdFromColumnDroppableId } from './helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { DraggableId } from 'react-beautiful-dnd';
import { useDispatch } from 'react-redux';

import { isEmpty } from 'lodash';
import { DataProvider, stopPropagationAndPreventDefault, TimelineId } from '../../../../common';
import { stopPropagationAndPreventDefault } from '../../../../common/utils/accessibility';
import { DataProvider, TimelineId } from '../../../../common/types';
import { TooltipWithKeyboardShortcut } from '../../tooltip_with_keyboard_shortcut';
import { getAdditionalScreenReaderOnlyContext } from '../utils';
import { useAddToTimeline } from '../../../hooks/use_add_to_timeline';
import { HoverActionComponentProps } from './types';
import { tGridActions } from '../../..';
import { addProviderToTimeline } from '../../../store/t_grid/actions';
import { useAppToasts } from '../../../hooks/use_app_toasts';
import * as i18n from './translations';

Expand Down Expand Up @@ -74,7 +75,7 @@ const AddToTimelineButton: React.FC<AddToTimelineButtonProps> = React.memo(
addDataProvider.forEach((provider) => {
if (provider) {
dispatch(
tGridActions.addProviderToTimeline({
addProviderToTimeline({
id: TimelineId.active,
dataProvider: provider,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useMemo } from 'react';
import { EuiContextMenuItem, EuiButtonEmpty, EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { stopPropagationAndPreventDefault } from '../../../../common';
import { stopPropagationAndPreventDefault } from '../../../../common/utils/accessibility';
import { TooltipWithKeyboardShortcut } from '../../tooltip_with_keyboard_shortcut';
import { getAdditionalScreenReaderOnlyContext } from '../utils';
import { defaultColumnHeaderType } from '../../t_grid/body/column_headers/default_headers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import copy from 'copy-to-clipboard';
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { i18n } from '@kbn/i18n';

import { stopPropagationAndPreventDefault } from '../../../../common';
import { stopPropagationAndPreventDefault } from '../../../../common/utils/accessibility';
import { WithCopyToClipboard } from '../../clipboard/with_copy_to_clipboard';
import { HoverActionComponentProps } from './types';
import { COPY_TO_CLIPBOARD_BUTTON_CLASS_NAME } from '../../clipboard';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';

import { stopPropagationAndPreventDefault } from '../../../../common';
import { stopPropagationAndPreventDefault } from '../../../../common/utils/accessibility';
import { TooltipWithKeyboardShortcut } from '../../tooltip_with_keyboard_shortcut';
import { createFilter, getAdditionalScreenReaderOnlyContext } from '../utils';
import { HoverActionComponentProps, FilterValueFnArgs } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';

import { stopPropagationAndPreventDefault } from '../../../../common';
import { stopPropagationAndPreventDefault } from '../../../../common/utils/accessibility';
import { TooltipWithKeyboardShortcut } from '../../tooltip_with_keyboard_shortcut';
import { createFilter, getAdditionalScreenReaderOnlyContext } from '../utils';
import { HoverActionComponentProps, FilterValueFnArgs } from './types';
Expand Down
Loading

0 comments on commit 3c8ba82

Please sign in to comment.