Skip to content

Commit

Permalink
Update limits.yml and fix functional plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Jun 22, 2021
1 parent 05dd22e commit 9815b74
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 76 deletions.
4 changes: 2 additions & 2 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pageLoadAssetSize:
searchprofiler: 67080
security: 95864
securityOss: 30806
securitySolution: 76000
securitySolution: 217673
share: 99061
snapshotRestore: 79032
spaces: 57868
Expand Down Expand Up @@ -107,7 +107,7 @@ pageLoadAssetSize:
dataVisualizer: 27530
banners: 17946
mapsEms: 26072
timelines: 28613
timelines: 230410
screenshotMode: 17856
visTypePie: 35583
cases: 144442
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { PluginInitializerContext } from '../../../../src/core/public';
import { Plugin } from './plugin';
import { PluginSetup } from './types';
export { TimelineModel } from './timelines/store/timeline/model';
export type { TimelineModel } from './timelines/store/timeline/model';

export const plugin = (context: PluginInitializerContext): Plugin => new Plugin(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@

import { AuthenticatedUser } from '../../../../../../security/common/model';

import { TimelineStatus, TimelineType } from '../../../../../common/types/timeline';
import { TimelineStatus, TimelineType, SavedTimeline } from '../../../../../common/types/timeline';
import { NoteSavedObject } from '../../../../../common/types/timeline/note';

import { pickSavedTimeline } from './pick_saved_timeline';

describe('pickSavedTimeline', () => {
const mockDateNow = new Date('2020-04-03T23:00:00.000Z').valueOf();
const getMockSavedTimeline = () => ({
const getMockSavedTimeline = (): SavedTimeline & {
savedObjectId?: string | null;
version?: string;
eventNotes?: NoteSavedObject[];
globalNotes?: NoteSavedObject[];
pinnedEventIds?: [];
} => ({
savedObjectId: '7af80430-03f4-11eb-9d9d-ffba20fabba8',
version: 'WzQ0ODgsMV0=',
created: 1601563413330,
Expand Down Expand Up @@ -91,7 +98,7 @@ describe('pickSavedTimeline', () => {

test('Updating a timeline', () => {
const savedTimeline = getMockSavedTimeline();
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand All @@ -113,7 +120,7 @@ describe('pickSavedTimeline', () => {

test('Updating a timeline', () => {
const savedTimeline = getMockSavedTimeline();
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand Down Expand Up @@ -143,7 +150,7 @@ describe('pickSavedTimeline', () => {

test('Updating a timeline with a new title', () => {
const savedTimeline = getMockSavedTimeline();
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand All @@ -152,7 +159,7 @@ describe('pickSavedTimeline', () => {

test('Updating a timeline without title', () => {
const savedTimeline = getMockSavedTimeline();
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand All @@ -161,7 +168,7 @@ describe('pickSavedTimeline', () => {

test('Updating an immutable timeline with a new title', () => {
const savedTimeline = { ...getMockSavedTimeline(), status: TimelineStatus.immutable };
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand Down Expand Up @@ -192,7 +199,7 @@ describe('pickSavedTimeline', () => {

test('Updating an untitled draft timeline with a title', () => {
const savedTimeline = { ...getMockSavedTimeline(), status: TimelineStatus.draft };
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand All @@ -201,7 +208,7 @@ describe('pickSavedTimeline', () => {

test('Updating a draft timeline with a new title', () => {
const savedTimeline = { ...getMockSavedTimeline(), status: TimelineStatus.draft };
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand All @@ -210,7 +217,7 @@ describe('pickSavedTimeline', () => {

test('Updating a draft timeline without title', () => {
const savedTimeline = { ...getMockSavedTimeline(), status: TimelineStatus.draft };
const timelineId = savedTimeline.savedObjectId;
const timelineId = savedTimeline.savedObjectId ?? null;
const userInfo = { username: 'elastic' } as AuthenticatedUser;
const result = pickSavedTimeline(timelineId, savedTimeline, userInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { SavedTimeline, TimelineType, TimelineStatus } from '../../../../../comm

export const pickSavedTimeline = (
timelineId: string | null,
savedTimeline: SavedTimeline,
savedTimeline: SavedTimeline & { savedObjectId?: string | null },
userInfo: AuthenticatedUser | null
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any => {
): SavedTimeline & { savedObjectId?: string | null } => {
const dateNow = new Date().valueOf();

if (timelineId == null) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/timelines/common/types/timeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export enum TimelineType {
export const TimelineTypeLiteralRt = runtimeTypes.union([
runtimeTypes.literal(TimelineType.template),
runtimeTypes.literal(TimelineType.default),
runtimeTypes.literal(TimelineType.test),
]);

export const TimelineTypeLiteralWithNullRt = unionWithNullType(TimelineTypeLiteralRt);
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/timelines/public/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { I18nProvider } from '@kbn/i18n/react';
import { Store } from 'redux';

import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { createStore } from '../store/t_grid';

import { TGrid as TGridComponent } from './tgrid';
Expand All @@ -24,6 +25,7 @@ const EMPTY_BROWSER_FIELDS = {};
type TGridComponent = TGridProps & {
store?: Store;
storage: Storage;
data?: DataPublicPluginStart;
};

export const TGrid = (props: TGridComponent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Filter,
IIndexPattern,
Query,
DataPublicPluginStart,
} from '../../../../../../../src/plugins/data/public';
import { useDeepEqualSelector } from '../../../hooks/use_selector';
import { Refetch } from '../../../store/t_grid/inputs';
Expand Down Expand Up @@ -135,6 +136,7 @@ export interface TGridIntegratedProps {
graphEventId: string | undefined;
leadingControlColumns: ControlColumnProps[];
trailingControlColumns: ControlColumnProps[];
data?: DataPublicPluginStart;
}

const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
Expand Down Expand Up @@ -166,6 +168,7 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
graphEventId,
leadingControlColumns,
trailingControlColumns,
data,
}) => {
const dispatch = useDispatch();
const columnsHeader = isEmpty(columns) ? defaultHeaders : columns;
Expand Down Expand Up @@ -245,6 +248,7 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
startDate: start,
endDate: end,
skip: !canQueryTimeline,
data,
});

const totalCountMinusDeleted = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import type {
RowRenderer,
SortColumnTimeline,
} from '../../../../common/types/timeline';
import { esQuery, Filter, Query } from '../../../../../../../src/plugins/data/public';
import {
esQuery,
Filter,
Query,
DataPublicPluginStart,
} from '../../../../../../../src/plugins/data/public';
import { useDeepEqualSelector } from '../../../hooks/use_selector';
import { Refetch } from '../../../store/t_grid/inputs';
import { defaultHeaders } from '../body/column_headers/default_headers';
Expand Down Expand Up @@ -114,6 +119,7 @@ export interface TGridStandaloneProps {
graphEventId?: string;
leadingControlColumns: ControlColumnProps[];
trailingControlColumns: ControlColumnProps[];
data?: DataPublicPluginStart;
}

const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
Expand All @@ -135,6 +141,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
graphEventId,
leadingControlColumns,
trailingControlColumns,
data,
}) => {
const dispatch = useDispatch();
const columnsHeader = isEmpty(columns) ? defaultHeaders : columns;
Expand Down Expand Up @@ -212,6 +219,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
startDate: start,
endDate: end,
skip: !canQueryTimeline,
data,
});

const totalCountMinusDeleted = useMemo(
Expand Down
75 changes: 38 additions & 37 deletions x-pack/plugins/timelines/public/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
isCompleteResponse,
isErrorResponse,
} from '../../../../../src/plugins/data/public';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';

import {
Direction,
TimelineFactoryQueryTypes,
Expand Down Expand Up @@ -82,6 +80,7 @@ export interface UseTimelineEventsProps {
sort?: TimelineRequestSortField[];
startDate: string;
timerangeKind?: 'absolute' | 'relative';
data?: DataPublicPluginStart;
}

const createFilter = (filterQuery: ESQuery | string | undefined) =>
Expand Down Expand Up @@ -122,9 +121,9 @@ export const useTimelineEvents = ({
sort = initSortDefault,
skip = false,
timerangeKind,
data,
}: UseTimelineEventsProps): [boolean, TimelineArgs] => {
const dispatch = useDispatch();
const { data } = useKibana<{ data: DataPublicPluginStart }>().services;
const refetch = useRef<Refetch>(noop);
const abortCtrl = useRef(new AbortController());
const searchSubscription$ = useRef(new Subscription());
Expand Down Expand Up @@ -185,50 +184,52 @@ export const useTimelineEvents = ({
prevTimelineRequest.current = request;
abortCtrl.current = new AbortController();
setLoading(true);
searchSubscription$.current = data.search
.search<TimelineRequest<typeof language>, TimelineResponse<typeof language>>(request, {
strategy:
request.language === 'eql' ? 'timelineEqlSearchStrategy' : 'timelineSearchStrategy',
abortSignal: abortCtrl.current.signal,
})
.subscribe({
next: (response) => {
if (isCompleteResponse(response)) {
if (data && data.search) {
searchSubscription$.current = data.search
.search<TimelineRequest<typeof language>, TimelineResponse<typeof language>>(request, {
strategy:
request.language === 'eql' ? 'timelineEqlSearchStrategy' : 'timelineSearchStrategy',
abortSignal: abortCtrl.current.signal,
})
.subscribe({
next: (response) => {
if (isCompleteResponse(response)) {
setLoading(false);
setTimelineResponse((prevResponse) => {
const newTimelineResponse = {
...prevResponse,
events: getTimelineEvents(response.edges),
inspect: getInspectResponse(response, prevResponse.inspect),
pageInfo: response.pageInfo,
totalCount: response.totalCount,
updatedAt: Date.now(),
};
return newTimelineResponse;
});
searchSubscription$.current.unsubscribe();
} else if (isErrorResponse(response)) {
setLoading(false);
addWarning(i18n.ERROR_TIMELINE_EVENTS);
searchSubscription$.current.unsubscribe();
}
},
error: (msg) => {
setLoading(false);
setTimelineResponse((prevResponse) => {
const newTimelineResponse = {
...prevResponse,
events: getTimelineEvents(response.edges),
inspect: getInspectResponse(response, prevResponse.inspect),
pageInfo: response.pageInfo,
totalCount: response.totalCount,
updatedAt: Date.now(),
};
return newTimelineResponse;
addError(msg, {
title: i18n.FAIL_TIMELINE_EVENTS,
});
searchSubscription$.current.unsubscribe();
} else if (isErrorResponse(response)) {
setLoading(false);
addWarning(i18n.ERROR_TIMELINE_EVENTS);
searchSubscription$.current.unsubscribe();
}
},
error: (msg) => {
setLoading(false);
addError(msg, {
title: i18n.FAIL_TIMELINE_EVENTS,
});
searchSubscription$.current.unsubscribe();
},
});
},
});
}
};

searchSubscription$.current.unsubscribe();
abortCtrl.current.abort();
asyncSearch();
refetch.current = asyncSearch;
},
[data.search, addWarning, addError, skip]
[data, addWarning, addError, skip]
);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/timelines/public/methods/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import { Store } from 'redux';
import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import type { TGridProps } from '../types';
import { LastUpdatedAtProps, LoadingPanelProps } from '../components';

const TimelineLazy = lazy(() => import('../components'));
export const getTGridLazy = (
props: TGridProps,
{ store, storage }: { store?: Store; storage: Storage }
{ store, storage, data }: { store?: Store; storage: Storage; data: DataPublicPluginStart }
) => {
return (
<Suspense fallback={<EuiLoadingSpinner />}>
<TimelineLazy {...props} store={store} storage={storage} />
<TimelineLazy {...props} store={store} storage={storage} data={data} />
</Suspense>
);
};
Expand Down
Loading

0 comments on commit 9815b74

Please sign in to comment.