Skip to content

Commit

Permalink
Improve timeline query
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jul 14, 2020
1 parent 3191f98 commit f21e4cd
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,64 @@ describe('EventsViewer', () => {
expect(wrapper.find(`[data-test-subj="header-section-subtitle"]`).first().exists()).toBe(false);
});

test('it does NOT render when start is empty', async () => {
mockUseFetchIndexPatterns.mockImplementation(() => [
{
browserFields: mockBrowserFields,
indexPatterns: mockIndexPattern,
docValueFields: mockDocValueFields,
isLoading: true,
},
]);

const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mockEventViewerResponse} addTypename={false}>
<StatefulEventsViewer
defaultModel={eventsDefaultModel}
end={to}
id={'test-stateful-events-viewer'}
start={''}
/>
</MockedProvider>
</TestProviders>
);

await wait();
wrapper.update();

expect(wrapper.find(`[data-test-subj="header-section-subtitle"]`).first().exists()).toBe(false);
});

test('it does NOT render when end is empty', async () => {
mockUseFetchIndexPatterns.mockImplementation(() => [
{
browserFields: mockBrowserFields,
indexPatterns: mockIndexPattern,
docValueFields: mockDocValueFields,
isLoading: true,
},
]);

const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mockEventViewerResponse} addTypename={false}>
<StatefulEventsViewer
defaultModel={eventsDefaultModel}
end={''}
id={'test-stateful-events-viewer'}
start={from}
/>
</MockedProvider>
</TestProviders>
);

await wait();
wrapper.update();

expect(wrapper.find(`[data-test-subj="header-section-subtitle"]`).first().exists()).toBe(false);
});

test('it renders the Fields Browser as a settings gear', async () => {
const wrapper = mount(
<TestProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ const EventsViewerComponent: React.FC<Props> = ({
});

const canQueryTimeline = useMemo(
() => combinedQueries != null && isLoadingIndexPattern != null && !isLoadingIndexPattern,
[isLoadingIndexPattern, combinedQueries]
() =>
combinedQueries != null &&
isLoadingIndexPattern != null &&
!isLoadingIndexPattern &&
!isEmpty(start) &&
!isEmpty(end),
[isLoadingIndexPattern, combinedQueries, start, end]
);

const fields = useMemo(
Expand Down Expand Up @@ -158,6 +163,8 @@ const EventsViewerComponent: React.FC<Props> = ({
limit={itemsPerPage}
sortField={sortField}
sourceId="default"
startDate={start}
endDate={end}
>
{({
events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const mockEventViewerResponse = [
],
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
sourceId: 'default',
timerange: {
interval: '12h',
from: '2019-08-26T22:10:56.791Z',
to: '2019-08-27T22:10:56.794Z',
},
pagination: { limit: 25, cursor: null, tiebreaker: null },
sortField: { sortFieldId: '@timestamp', direction: 'desc' },
defaultIndex: ['filebeat-*', 'auditbeat-*', 'packetbeat-*'],
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/security_solution/public/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4614,6 +4614,7 @@ export namespace GetTimelineQuery {
defaultIndex: string[];
inspect: boolean;
docValueFields: DocValueFieldsInput[];
timerange: TimerangeInput;
};

export type Query = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ describe('Timeline', () => {
expect(wrapper.find('[data-test-subj="events-table"]').exists()).toEqual(false);
});

test('it does NOT render the timeline table when start is empty', () => {
const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mocks}>
<TimelineComponent {...props} start={''} />
</MockedProvider>
</TestProviders>
);

expect(wrapper.find('[data-test-subj="events-table"]').exists()).toEqual(false);
});

test('it does NOT render the timeline table when end is empty', () => {
const wrapper = mount(
<TestProviders>
<MockedProvider mocks={mocks}>
<TimelineComponent {...props} end={''} />
</MockedProvider>
</TestProviders>
);

expect(wrapper.find('[data-test-subj="events-table"]').exists()).toEqual(false);
});

test('it does NOT render the paging footer when you do NOT have any data providers', () => {
const wrapper = mount(
<TestProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,13 @@ export const TimelineComponent: React.FC<Props> = ({
);

const canQueryTimeline = useMemo(
() => combinedQueries != null && isLoadingSource != null && !isLoadingSource,
[isLoadingSource, combinedQueries]
() =>
combinedQueries != null &&
isLoadingSource != null &&
!isLoadingSource &&
!isEmpty(start) &&
!isEmpty(end),
[isLoadingSource, combinedQueries, start, end]
);
const columnsHeader = isEmpty(columns) ? defaultHeaders : columns;
const timelineQueryFields = useMemo(() => columnsHeader.map((c) => c.id), [columnsHeader]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const timelineQuery = gql`
$defaultIndex: [String!]!
$inspect: Boolean!
$docValueFields: [docValueFieldsInput!]!
$timerange: TimerangeInput!
) {
source(id: $sourceId) {
id
Expand All @@ -26,6 +27,7 @@ export const timelineQuery = gql`
filterQuery: $filterQuery
defaultIndex: $defaultIndex
docValueFields: $docValueFields
timerange: $timerange
) {
totalCount
inspect @include(if: $inspect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ export interface CustomReduxProps {

export interface OwnProps extends QueryTemplateProps {
children?: (args: TimelineArgs) => React.ReactNode;
endDate: string;
eventType?: EventType;
id: string;
indexPattern?: IIndexPattern;
indexToAdd?: string[];
limit: number;
sortField: SortField;
fields: string[];
startDate: string;
}

type TimelineQueryProps = OwnProps & PropsFromRedux & WithKibanaProps & CustomReduxProps;
Expand All @@ -78,6 +80,7 @@ class TimelineQueryComponent extends QueryTemplate<
children,
clearSignalsState,
docValueFields,
endDate,
eventType = 'raw',
id,
indexPattern,
Expand All @@ -89,6 +92,7 @@ class TimelineQueryComponent extends QueryTemplate<
filterQuery,
sourceId,
sortField,
startDate,
} = this.props;
const defaultKibanaIndex = kibana.services.uiSettings.get<string[]>(DEFAULT_INDEX_KEY);
const defaultIndex =
Expand All @@ -102,6 +106,11 @@ class TimelineQueryComponent extends QueryTemplate<
fieldRequested: fields,
filterQuery: createFilter(filterQuery),
sourceId,
timerange: {
interval: '12h',
from: startDate,
to: endDate,
},
pagination: { limit, cursor: null, tiebreaker: null },
sortField,
defaultIndex,
Expand Down

0 comments on commit f21e4cd

Please sign in to comment.