Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Refactor Timeline Notes to use EuiCommentList #85256

Merged
merged 25 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bf22803
[Security Solution] Refactor Timeline Notes to use EuiCommentList
patrykkopycinski Dec 8, 2020
c1ec96f
notes
patrykkopycinski Dec 8, 2020
28b51e5
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 9, 2020
b5bc4f0
fix types
patrykkopycinski Dec 9, 2020
9973744
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 9, 2020
5a65c46
unit tests
patrykkopycinski Dec 9, 2020
d1bd98f
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 9, 2020
76785e7
selector
patrykkopycinski Dec 9, 2020
e1f07c4
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 9, 2020
448acd7
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
4ac5a96
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
653415a
uncomment Pinned tab
patrykkopycinski Dec 10, 2020
b29cd52
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
31f2674
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
6b54390
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
1980e89
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
8eeca9b
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 10, 2020
4a3680c
note event details
patrykkopycinski Dec 11, 2020
93b957e
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
patrykkopycinski Dec 11, 2020
755ac96
cleanup
patrykkopycinski Dec 12, 2020
46de710
cleanup
patrykkopycinski Dec 12, 2020
3c8cfbf
transparent background
patrykkopycinski Dec 12, 2020
72c543e
don't display elastic as an owner when note is created
patrykkopycinski Dec 12, 2020
ea36541
Merge branch 'master' of github.com:elastic/kibana into feat/timeline…
XavierM Dec 12, 2020
107c945
review + bugs fixed found
XavierM Dec 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({ ecsRowData,

return (
<>
<ActionIconItem id="attachAlertToCase">
<ActionIconItem>
patrykkopycinski marked this conversation as resolved.
Show resolved Hide resolved
<EuiPopover
id="attachAlertToCasePanel"
button={button}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getOr, get, isNumber } from 'lodash/fp';
import deepmerge from 'deepmerge';
import uuid from 'uuid';
import styled from 'styled-components';
import deepEqual from 'fast-deep-equal';

import { escapeDataProviderId } from '../drag_and_drop/helpers';
import { useTimeZone } from '../../lib/kibana';
Expand Down Expand Up @@ -193,4 +194,11 @@ export const BarChartComponent: React.FC<BarChartComponentProps> = ({
);
};

export const BarChart = React.memo(BarChartComponent);
export const BarChart = React.memo(
BarChartComponent,
(prevProps, nextProps) =>
prevProps.stackByField === nextProps.stackByField &&
prevProps.timelineId === nextProps.timelineId &&
deepEqual(prevProps.configs, nextProps.configs) &&
deepEqual(prevProps.barChart, nextProps.barChart)
);
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ const ReputationLinkComponent: React.FC<{
[ipReputationLinksSetting, domain, defaultNameMapping, allItemsLimit]
);

const renderCallback = useCallback(
(rowItem) =>
isReputationLink(rowItem) && (
<ExternalLink
url={rowItem.url_template}
overflowIndexStart={overflowIndexStart}
allItemsLimit={allItemsLimit}
>
<>{rowItem.name ?? domain}</>
</ExternalLink>
),
[allItemsLimit, domain, overflowIndexStart]
);

return ipReputationLinks?.length > 0 ? (
<section>
<EuiFlexGroup
Expand Down Expand Up @@ -357,19 +371,7 @@ const ReputationLinkComponent: React.FC<{
<DefaultFieldRendererOverflow
rowItems={ipReputationLinks}
idPrefix="moreReputationLink"
render={(rowItem) => {
return (
isReputationLink(rowItem) && (
<ExternalLink
url={rowItem.url_template}
overflowIndexStart={overflowIndexStart}
allItemsLimit={allItemsLimit}
>
<>{rowItem.name ?? domain}</>
</ExternalLink>
)
);
}}
render={renderCallback}
moreMaxHeight={DEFAULT_MORE_MAX_HEIGHT}
overflowIndexStart={overflowIndexStart}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,17 @@ export interface Props extends Pick<GlobalTimeArgs, 'from' | 'to' | 'deleteQuery
value?: string[] | string | null;
}

const NO_FILTERS: Filter[] = [];
const DEFAULT_QUERY: Query = { query: '', language: 'kuery' };

const TopNComponent: React.FC<Props> = ({
combinedQueries,
defaultView,
deleteQuery,
filters = NO_FILTERS,
filters,
field,
from,
indexPattern,
indexNames,
options,
query = DEFAULT_QUERY,
query,
setAbsoluteRangeDatePickerTarget,
setQuery,
timelineId,
Expand Down Expand Up @@ -132,7 +129,6 @@ const TopNComponent: React.FC<Props> = ({
filters={filters}
from={from}
headerChildren={headerChildren}
indexPattern={indexPattern}
onlyField={field}
query={query}
setAbsoluteRangeDatePickerTarget={setAbsoluteRangeDatePickerTarget}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState } from 'react';
import { createPortalNode, OutPortal } from 'react-reverse-portal';

/**
* A singleton portal for rendering content in the global header
*/
const timelineEventsCountPortalNodeSingleton = createPortalNode();

export const useTimelineEventsCountPortal = () => {
const [timelineEventsCountPortalNode] = useState(timelineEventsCountPortalNodeSingleton);

return { timelineEventsCountPortalNode };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you return timelineEventsCountPortalNodeSingleton ? What the advantage of using useState here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question @cnasikas
I've just followed the pattern that we're using for other portals

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I am trying to understand it :). timelineEventsCountPortalNodeSingleton is a singleton and after the importation of the file, it will be the same instance across security solution. Theoretically, it shouldn't create rerenders. And I am wondering, is something I do not get with the useState?

};

export const TimelineEventsCountBadge = React.memo(() => {
const { timelineEventsCountPortalNode } = useTimelineEventsCountPortal();

return <OutPortal node={timelineEventsCountPortalNode} />;
});

TimelineEventsCountBadge.displayName = 'TimelineEventsCountBadge';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export interface Note {
/** When the note was created */
created: Date;
eventId?: string | null;
/** Uniquely identifies the note */
id: string;
/** When not `null`, this represents the last edit */
Expand All @@ -18,5 +19,6 @@ export interface Note {
user: string;
/** SaveObjectID for note */
saveObjectId: string | null | undefined;
timelineId?: string | null;
version: string | null | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { keys } from 'lodash/fp';
import { keys, values } from 'lodash/fp';
import memoizeOne from 'memoize-one';
import { createSelector } from 'reselect';
import { Note } from '../../lib/note';
Expand All @@ -25,6 +25,17 @@ export const getNotes = memoizeOne((notesById: NotesById, noteIds: string[]): No
}, [])
);

export const selectNotesByTimelineSavedObjectId = (
state: State,
timelineSavedObjectId: string
): Note[] =>
values(state.app.notesById).reduce((acc: Note[], note: Note) => {
if (note.timelineId === timelineSavedObjectId) {
return [...acc, note];
}
return acc;
}, []);

export const selectNotesByIdSelector = createSelector(
selectNotesById,
(notesById: NotesById) => notesById
Expand All @@ -33,4 +44,7 @@ export const selectNotesByIdSelector = createSelector(
export const notesByIdsSelector = () =>
createSelector(selectNotesById, (notesById: NotesById) => notesById);

export const selectNotesByTimelineSavedObjectIdSelector = () =>
createSelector(selectNotesByTimelineSavedObjectId, (notes: Note[]) => notes);

export const errorsSelector = () => createSelector(getErrors, (errors) => errors);
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { createSelector } from 'reselect';

import { Filter, Query } from '../../../../../../../src/plugins/data/public';
import { State } from '../types';

import { InputsModel, InputsRange, GlobalQuery } from './model';
Expand Down Expand Up @@ -64,21 +65,18 @@ export const timelineQueryByIdSelector = () =>

export const globalSelector = () => createSelector(selectGlobal, (global) => global);

const DEFAULT_QUERY: Query = { query: '', language: 'kuery' };

export const globalQuerySelector = () =>
createSelector(
selectGlobal,
(global) =>
global.query || {
query: '',
language: 'kuery',
}
);
createSelector(selectGlobal, (global) => global.query || DEFAULT_QUERY);

export const globalSavedQuerySelector = () =>
createSelector(selectGlobal, (global) => global.savedQuery || null);

const NO_FILTERS: Filter[] = [];

export const globalFiltersQuerySelector = () =>
createSelector(selectGlobal, (global) => global.filters || []);
createSelector(selectGlobal, (global) => global.filters || NO_FILTERS);

export const getTimelineSelector = () => createSelector(selectTimeline, (timeline) => timeline);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,23 @@ export const getSourcererScopeSelector = () => {
: selectedPatterns;
});

const getIndexPattern = memoizeOne(
(indexPattern, title) => ({
...indexPattern,
title,
}),
(newArgs, lastArgs) => newArgs[0] === lastArgs[0] && newArgs[1].length === lastArgs[1].length
);

const mapStateToProps = (state: State, scopeId: SourcererScopeName): ManageScope => {
const scope = getScopeIdSelector(state, scopeId);
const selectedPatterns = getSelectedPatterns(scope.selectedPatterns.sort().join());
const indexPattern = getIndexPattern(scope.indexPattern, selectedPatterns.join());

return {
...scope,
selectedPatterns,
indexPattern: {
...scope.indexPattern,
title: selectedPatterns.join(),
},
indexPattern,
};
};
return mapStateToProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { HistogramData, AlertsAggregation, AlertsBucket, AlertsGroupBucket } fro
import { AlertSearchResponse } from '../../containers/detection_engine/alerts/types';
import * as i18n from './translations';

const EMPTY_ALERTS_DATA: HistogramData[] = [];

export const formatAlertsData = (alertsData: AlertSearchResponse<{}, AlertsAggregation> | null) => {
const groupBuckets: AlertsGroupBucket[] =
alertsData?.aggregations?.alertsByGrouping?.buckets ?? [];
Expand All @@ -25,7 +27,7 @@ export const formatAlertsData = (alertsData: AlertSearchResponse<{}, AlertsAggre
g: group,
})),
];
}, []);
}, EMPTY_ALERTS_DATA);
};

export const getAlertsHistogramQuery = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const InvestigateInTimelineActionComponent: React.FC<InvestigateInTimelineAction
content={ACTION_INVESTIGATE_IN_TIMELINE}
dataTestSubj="send-alert-to-timeline"
iconType="timeline"
id="sendAlertToTimeline"
onClick={investigateInTimelineAlertClick}
isDisabled={false}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ describe('Alerts by category', () => {
indexPattern: mockIndexPattern,
setQuery: jest.fn(),
to,
query: {
query: '',
language: 'kuery',
},
};
describe('before loading data', () => {
beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@ import { LinkButton } from '../../../common/components/links';

const ID = 'alertsByCategoryOverview';

const NO_FILTERS: Filter[] = [];
const DEFAULT_QUERY: Query = { query: '', language: 'kuery' };
const DEFAULT_STACK_BY = 'event.module';

interface Props extends Pick<GlobalTimeArgs, 'from' | 'to' | 'deleteQuery' | 'setQuery'> {
filters?: Filter[];
filters: Filter[];
hideHeaderChildren?: boolean;
indexPattern: IIndexPattern;
indexNames: string[];
query?: Query;
query: Query;
}

const AlertsByCategoryComponent: React.FC<Props> = ({
deleteQuery,
filters = NO_FILTERS,
filters,
from,
hideHeaderChildren = false,
indexPattern,
indexNames,
query = DEFAULT_QUERY,
query,
setQuery,
to,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ describe('EventCounts', () => {
const to = '2020-01-21T20:49:57.080Z';

const testProps = {
filters: [],
from,
indexNames: [],
indexPattern: mockIndexPattern,
setQuery: jest.fn(),
to,
query: {
query: '',
language: 'kuery',
},
};

test('it filters the `Host events` widget with a `host.name` `exists` filter', () => {
Expand Down
Loading