Skip to content

Commit

Permalink
fix: more test + types
Browse files Browse the repository at this point in the history
  • Loading branch information
logeekal committed Oct 15, 2024
1 parent e97eaee commit fc3061a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import React, { useMemo, useCallback, memo } from 'react';
import type { EuiDataGridSorting } from '@elastic/eui';
import { EuiButtonIcon, EuiToolTip, EuiCheckbox } from '@elastic/eui';
import { useDispatch } from 'react-redux';

import styled from 'styled-components';
import type { HeaderActionProps, SortDirection } from '../../../../common/types';
import type { HeaderActionProps } from '../../../../common/types';
import { TimelineId } from '../../../../common/types';
import { isFullScreen } from '../../../timelines/components/timeline/body/column_headers';
import { isActiveTimeline } from '../../../helpers';
Expand Down Expand Up @@ -52,17 +51,13 @@ const ActionsContainer = styled.div`

const HeaderActionsComponent: React.FC<HeaderActionProps> = memo(
({
width,
browserFields,
columnHeaders,
isEventViewer = false,
isSelectAllChecked,
onSelectAll,
showEventsSelect,
showSelectAllCheckbox,
showFullScreenToggle = true,
sort,
tabType,
timelineId,
fieldBrowserOptions,
}) => {
Expand Down Expand Up @@ -105,28 +100,6 @@ const HeaderActionsComponent: React.FC<HeaderActionProps> = memo(
[onSelectAll]
);

const onSortColumns = useCallback(
(cols: EuiDataGridSorting['columns']) =>
dispatch(
timelineActions.updateSort({
id: timelineId,
sort: cols.map(({ id, direction }) => {
const columnHeader = columnHeaders.find((ch) => ch.id === id);
const columnType = columnHeader?.type ?? '';
const esTypes = columnHeader?.esTypes ?? [];

return {
columnId: id,
columnType,
esTypes,
sortDirection: direction as SortDirection,
};
}),
})
),
[columnHeaders, dispatch, timelineId]
);

const onResetColumns = useCallback(() => {
dispatch(timelineActions.updateColumns({ id: timelineId, columns: defaultColumns }));
}, [defaultColumns, dispatch, timelineId]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ import {
} from './__mocks__';
import { resolveTimeline } from '../../containers/api';
import { defaultUdtHeaders } from '../timeline/unified_components/default_headers';
import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features';

jest.mock('../../../common/hooks/use_experimental_features');
const useIsExperimentalFeatureEnabledMock = useIsExperimentalFeatureEnabled as jest.Mock;

jest.mock('react-redux', () => {
const actual = jest.requireActual('react-redux');
Expand Down Expand Up @@ -68,7 +66,6 @@ jest.mock('uuid', () => {
});

const mockUpdateTimeline = jest.fn();
mockUpdateTimeline.x = 'test';
jest.mock('./use_update_timeline', () => {
const actual = jest.requireActual('./use_update_timeline');
return {
Expand Down Expand Up @@ -491,8 +488,7 @@ describe('helpers', () => {
const newTimeline = defaultTimelineToTimelineModel(
timeline,
false,
TimelineTypeEnum.template,
false
TimelineTypeEnum.template
);
expect(newTimeline).toEqual({
...defaultTimeline,
Expand All @@ -514,12 +510,7 @@ describe('helpers', () => {
timelineType: TimelineTypeEnum.default,
};

const newTimeline = defaultTimelineToTimelineModel(
timeline,
false,
TimelineTypeEnum.default,
false
);
const newTimeline = defaultTimelineToTimelineModel(timeline, false, TimelineTypeEnum.default);
expect(newTimeline).toEqual({
...defaultTimeline,
dateRange: { end: '2020-07-08T08:20:18.966Z', start: '2020-07-07T08:20:18.966Z' },
Expand All @@ -538,12 +529,7 @@ describe('helpers', () => {
timelineType: TimelineTypeEnum.default,
};

const newTimeline = defaultTimelineToTimelineModel(
timeline,
false,
TimelineTypeEnum.default,
false
);
const newTimeline = defaultTimelineToTimelineModel(timeline, false, TimelineTypeEnum.default);
expect(newTimeline).toEqual({
...defaultTimeline,
dateRange: { end: '2020-07-08T08:20:18.966Z', start: '2020-07-07T08:20:18.966Z' },
Expand All @@ -566,12 +552,7 @@ describe('helpers', () => {
columns: customColumns as ColumnHeaderResult[],
};

const newTimeline = defaultTimelineToTimelineModel(
timeline,
false,
TimelineTypeEnum.default,
false
);
const newTimeline = defaultTimelineToTimelineModel(timeline, false, TimelineTypeEnum.default);
expect(newTimeline).toEqual({
...defaultTimeline,
dateRange: { end: '2020-07-08T08:20:18.966Z', start: '2020-07-07T08:20:18.966Z' },
Expand All @@ -594,12 +575,7 @@ describe('helpers', () => {
excludedRowRendererIds,
};

const newTimeline = defaultTimelineToTimelineModel(
timeline,
false,
TimelineTypeEnum.default,
false
);
const newTimeline = defaultTimelineToTimelineModel(timeline, false, TimelineTypeEnum.default);
expect(newTimeline).toEqual({
...defaultTimeline,
dateRange: { end: '2020-07-08T08:20:18.966Z', start: '2020-07-07T08:20:18.966Z' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mockUseResizeObserver.mockImplementation(() => ({}));

jest.mock('../../../../../common/lib/kibana');

describe('Timeline', () => {
describe('EQL Tab', () => {
let props = {} as EqlTabContentComponentProps;
const startDate = '2018-03-23T18:49:23.132Z';
const endDate = '2018-03-24T03:33:52.253Z';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { EuiDataGridControlColumn } from '@elastic/eui';
import { DataLoadingState } from '@kbn/unified-data-table';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import type { RunTimeMappings } from '@kbn/timelines-plugin/common/search_strategy';
import { InputsModelId } from '../../../../../common/store/inputs/constants';
import { useKibana } from '../../../../../common/lib/kibana';
import {
DocumentDetailsLeftPanelKey,
Expand Down Expand Up @@ -45,6 +46,7 @@ import { useTimelineControlColumn } from '../shared/use_timeline_control_columns
import { LeftPanelNotesTab } from '../../../../../flyout/document_details/left';
import { useNotesInFlyout } from '../../properties/use_notes_in_flyout';
import { NotesFlyout } from '../../properties/notes_flyout';
import { TimelineRefetch } from '../../refetch_timeline';

export type Props = TimelineTabCommonProps & PropsFromRedux;

Expand All @@ -54,10 +56,8 @@ export const EqlTabContentComponent: React.FC<Props> = ({
end,
eqlOptions,
timelineId,
isLive,
itemsPerPage,
itemsPerPageOptions,
renderCellValue,
rowRenderers,
start,
timerangeKind,
Expand All @@ -70,7 +70,6 @@ export const EqlTabContentComponent: React.FC<Props> = ({
const { portalNode: eqlEventsCountPortalNode } = useEqlEventsCountPortal();
const { setTimelineFullScreen, timelineFullScreen } = useTimelineFullScreen();
const {
browserFields,
dataViewId,
loading: loadingSourcerer,
selectedPatterns,
Expand Down Expand Up @@ -245,36 +244,42 @@ export const EqlTabContentComponent: React.FC<Props> = ({

return (
<>
<>
<InPortal node={eqlEventsCountPortalNode}>
{totalCount >= 0 ? (
<EventsCountBadge data-test-subj="eql-events-count">{totalCount}</EventsCountBadge>
) : null}
</InPortal>
{NotesFlyoutMemo}
<FullWidthFlexGroup>
<UnifiedTimelineBody
header={unifiedHeader}
columns={augmentedColumnHeaders}
isSortEnabled={false}
rowRenderers={rowRenderers}
timelineId={timelineId}
itemsPerPage={itemsPerPage}
itemsPerPageOptions={itemsPerPageOptions}
sort={TIMELINE_NO_SORTING}
events={events}
refetch={refetch}
dataLoadingState={dataLoadingState}
totalCount={isBlankTimeline ? 0 : totalCount}
onChangePage={loadPage}
activeTab={activeTab}
updatedAt={refreshedAt}
isTextBasedQuery={false}
pageInfo={pageInfo}
leadingControlColumns={leadingControlColumns as EuiDataGridControlColumn[]}
/>
</FullWidthFlexGroup>
</>
<TimelineRefetch
id={`${timelineId}-${TimelineTabs.eql}`}
inputId={InputsModelId.timeline}
inspect={inspect}
loading={isQueryLoading}
refetch={refetch}
skip={!canQueryTimeline}
/>
<InPortal node={eqlEventsCountPortalNode}>
{totalCount >= 0 ? (
<EventsCountBadge data-test-subj="eql-events-count">{totalCount}</EventsCountBadge>
) : null}
</InPortal>
{NotesFlyoutMemo}
<FullWidthFlexGroup>
<UnifiedTimelineBody
header={unifiedHeader}
columns={augmentedColumnHeaders}
isSortEnabled={false}
rowRenderers={rowRenderers}
timelineId={timelineId}
itemsPerPage={itemsPerPage}
itemsPerPageOptions={itemsPerPageOptions}
sort={TIMELINE_NO_SORTING}
events={events}
refetch={refetch}
dataLoadingState={dataLoadingState}
totalCount={isBlankTimeline ? 0 : totalCount}
onChangePage={loadPage}
activeTab={activeTab}
updatedAt={refreshedAt}
isTextBasedQuery={false}
pageInfo={pageInfo}
leadingControlColumns={leadingControlColumns as EuiDataGridControlColumn[]}
/>
</FullWidthFlexGroup>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

import { isEmpty } from 'lodash/fp';
import React, { useMemo, useCallback, memo } from 'react';
import styled from 'styled-components';
import type { ConnectedProps } from 'react-redux';
import { connect } from 'react-redux';
import deepEqual from 'fast-deep-equal';
import type { EuiDataGridControlColumn } from '@elastic/eui';
import { DataLoadingState } from '@kbn/unified-data-table';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import type { RunTimeMappings } from '@kbn/timelines-plugin/common/search_strategy';
import {
DocumentDetailsLeftPanelKey,
DocumentDetailsRightPanelKey,
} from '../../../../../flyout/document_details/shared/constants/panel_keys';
import type { ControlColumnProps } from '../../../../../../common/types';
import { useKibana } from '../../../../../common/lib/kibana';
import { timelineSelectors } from '../../../../store';
import type { Direction } from '../../../../../../common/search_strategy';
Expand All @@ -30,7 +27,6 @@ import { SourcererScopeName } from '../../../../../sourcerer/store/model';
import { timelineDefaults } from '../../../../store/defaults';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';
import { useSourcererDataView } from '../../../../../sourcerer/containers';
import { useTimelineFullScreen } from '../../../../../common/containers/use_full_screen';
import type { TimelineModel } from '../../../../store/model';
import type { State } from '../../../../../common/store';
import { TimelineTabs } from '../../../../../../common/types/timeline';
Expand All @@ -42,10 +38,6 @@ import { LeftPanelNotesTab } from '../../../../../flyout/document_details/left';
import { useNotesInFlyout } from '../../properties/use_notes_in_flyout';
import { NotesFlyout } from '../../properties/notes_flyout';

const ExitFullScreenContainer = styled.div`
width: 180px;
`;

interface PinnedFilter {
bool: {
should: Array<{ match_phrase: { _id: string } }>;
Expand All @@ -55,8 +47,6 @@ interface PinnedFilter {

export type Props = TimelineTabCommonProps & PropsFromRedux;

const trailingControlColumns: ControlColumnProps[] = []; // stable reference

const rowDetailColumn = [
{
id: 'row-details',
Expand All @@ -73,20 +63,14 @@ export const PinnedTabContentComponent: React.FC<Props> = ({
itemsPerPage,
itemsPerPageOptions,
pinnedEventIds,
renderCellValue,
rowRenderers,
sort,
eventIdToNoteIds,
}) => {
const { telemetry } = useKibana().services;
const {
browserFields,
dataViewId,
loading: loadingSourcerer,
sourcererDataView,
selectedPatterns,
} = useSourcererDataView(SourcererScopeName.timeline);
const { setTimelineFullScreen, timelineFullScreen } = useTimelineFullScreen();
const { dataViewId, sourcererDataView, selectedPatterns } = useSourcererDataView(
SourcererScopeName.timeline
);

const filterQuery = useMemo(() => {
if (isEmpty(pinnedEventIds)) {
Expand Down Expand Up @@ -243,11 +227,6 @@ export const PinnedTabContentComponent: React.FC<Props> = ({
onToggleShowNotes,
});

const isQueryLoading = useMemo(
() => [DataLoadingState.loading, DataLoadingState.loadingMore].includes(queryLoadingState),
[queryLoadingState]
);

const NotesFlyoutMemo = useMemo(() => {
return (
<NotesFlyout
Expand Down Expand Up @@ -276,7 +255,7 @@ export const PinnedTabContentComponent: React.FC<Props> = ({
events={events}
refetch={refetch}
dataLoadingState={queryLoadingState}
totalCount={events.length}
totalCount={totalCount}
onChangePage={loadPage}
activeTab={TimelineTabs.pinned}
updatedAt={refreshedAt}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { IS_DRAGGING_CLASS_NAME } from '@kbn/securitysolution-t-grid';
import styled from '@emotion/styled';
import { euiThemeVars } from '@kbn/ui-theme';
import { useTimelineEventsCountPortal } from '../../../../../../common/hooks/use_timeline_events_count';
import { useTimelineFullScreen } from '../../../../../../common/containers/use_full_screen';
import {
type TimelineStatus,
TimelineStatusEnum,
Expand Down Expand Up @@ -69,7 +68,6 @@ const QueryTabHeaderComponent: React.FC<Props> = ({
totalCount,
}) => {
const { portalNode: timelineEventsCountPortalNode } = useTimelineEventsCountPortal();
const { setTimelineFullScreen, timelineFullScreen } = useTimelineFullScreen();
const getTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []);

const getIsDataProviderVisible = useMemo(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc3061a

Please sign in to comment.