Skip to content

Commit

Permalink
remove more types
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed Sep 27, 2024
1 parent 5a4114d commit 2acec55
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
* 2.0.
*/

import type { SortField, Maybe } from '../common';
import type {
DataProviderType,
TimelineType,
TimelineStatus,
RowRendererId,
} from '../../api/timeline';
import type { SortField } from '../common';

export * from './events';

Expand All @@ -20,122 +14,6 @@ export interface TimelineRequestSortField<Field = string> extends SortField<Fiel
esTypes: string[];
}

export interface ColumnHeaderInput {
aggregatable?: Maybe<boolean>;
category?: Maybe<string>;
columnHeaderType?: Maybe<string>;
description?: Maybe<string>;
example?: Maybe<string>;
indexes?: Maybe<string[]>;
id?: Maybe<string>;
name?: Maybe<string>;
placeholder?: Maybe<string>;
searchable?: Maybe<boolean>;
type?: Maybe<string>;
}

export interface QueryMatchInput {
field?: Maybe<string>;

displayField?: Maybe<string>;

value?: Maybe<string>;

displayValue?: Maybe<string>;

operator?: Maybe<string>;
}

export interface DataProviderInput {
id?: Maybe<string>;
name?: Maybe<string>;
enabled?: Maybe<boolean>;
excluded?: Maybe<boolean>;
kqlQuery?: Maybe<string>;
queryMatch?: Maybe<QueryMatchInput>;
and?: Maybe<DataProviderInput[]>;
type?: Maybe<DataProviderType>;
}

export interface EqlOptionsInput {
eventCategoryField?: Maybe<string>;
tiebreakerField?: Maybe<string>;
timestampField?: Maybe<string>;
query?: Maybe<string>;
size?: Maybe<number>;
}

export interface FilterMetaTimelineInput {
alias?: Maybe<string>;
controlledBy?: Maybe<string>;
disabled?: Maybe<boolean>;
field?: Maybe<string>;
formattedValue?: Maybe<string>;
index?: Maybe<string>;
key?: Maybe<string>;
negate?: Maybe<boolean>;
params?: Maybe<string>;
type?: Maybe<string>;
value?: Maybe<string>;
}

export interface FilterTimelineInput {
exists?: Maybe<string>;
meta?: Maybe<FilterMetaTimelineInput>;
match_all?: Maybe<string>;
missing?: Maybe<string>;
query?: Maybe<string>;
range?: Maybe<string>;
script?: Maybe<string>;
}

export interface SerializedFilterQueryInput {
filterQuery?: Maybe<SerializedKueryQueryInput>;
}

export interface SerializedKueryQueryInput {
kuery?: Maybe<KueryFilterQueryInput>;
serializedQuery?: Maybe<string>;
}

export interface KueryFilterQueryInput {
kind?: Maybe<string>;
expression?: Maybe<string>;
}

export interface DateRangePickerInput {
start?: Maybe<number>;
end?: Maybe<number>;
}

export interface SortTimelineInput {
columnId?: Maybe<string>;
sortDirection?: Maybe<string>;
}

export interface TimelineInput {
columns?: Maybe<ColumnHeaderInput[]>;
dataProviders?: Maybe<DataProviderInput[]>;
dataViewId?: Maybe<string>;
description?: Maybe<string>;
eqlOptions?: Maybe<EqlOptionsInput>;
eventType?: Maybe<string>;
excludedRowRendererIds?: Maybe<RowRendererId[]>;
filters?: Maybe<FilterTimelineInput[]>;
kqlMode?: Maybe<string>;
kqlQuery?: Maybe<SerializedFilterQueryInput>;
indexNames?: Maybe<string[]>;
title?: Maybe<string>;
templateTimelineId?: Maybe<string>;
templateTimelineVersion?: Maybe<number>;
timelineType?: Maybe<TimelineType>;
dateRange?: Maybe<DateRangePickerInput>;
savedQueryId?: Maybe<string>;
sort?: Maybe<SortTimelineInput[]>;
status?: Maybe<TimelineStatus>;
savedSearchId: Maybe<string>;
}

export enum FlowDirection {
uniDirectional = 'uniDirectional',
biDirectional = 'biDirectional',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
CopyTimelineResponse,
GetDraftTimelinesResponse,
GetTimelinesRequestQuery,
SavedTimeline,
} from '../../../common/api/timeline';
import {
ImportTimelineResult,
Expand Down Expand Up @@ -49,10 +50,9 @@ import type {
ImportDataProps,
ImportDataResponse,
} from '../../detection_engine/rule_management/logic';
import type { TimelineInput } from '../../../common/search_strategy';

interface RequestPostTimeline {
timeline: TimelineInput;
timeline: SavedTimeline;
signal?: AbortSignal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('Timeline save middleware', () => {
});

describe('#convertTimelineAsInput ', () => {
test('should return a TimelineInput instead of TimelineModel ', () => {
test('should return a SavedTimeline instead of TimelineModel ', () => {
const columns: TimelineModel['columns'] = [
{
columnHeaderType: 'not-filtered',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import { TimelineStatusEnum, TimelineTypeEnum } from '../../../../common/api/tim
import type {
TimelineErrorResponse,
PersistTimelineResponse,
SavedTimeline,
} from '../../../../common/api/timeline';
import type { TimelineInput } from '../../../../common/search_strategy';
import type { TimelineModel } from '../model';
import type { ColumnHeaderOptions } from '../../../../common/types/timeline';
import { refreshTimelines } from './helpers';
Expand Down Expand Up @@ -156,7 +156,7 @@ export const saveTimelineMiddleware: (kibana: CoreStart) => Middleware<{}, State
return ret;
};

const timelineInput: TimelineInput = {
const timelineInput: SavedTimeline = {
columns: null,
dataProviders: null,
dataViewId: null,
Expand All @@ -182,8 +182,8 @@ const timelineInput: TimelineInput = {
export const convertTimelineAsInput = (
timeline: TimelineModel,
timelineTimeRange: inputsModel.TimeRange
): TimelineInput =>
Object.keys(timelineInput).reduce<TimelineInput>((acc, key) => {
): SavedTimeline =>
Object.keys(timelineInput).reduce<SavedTimeline>((acc, key) => {
if (has(key, timeline)) {
if (key === 'kqlQuery') {
return set(`${key}.filterQuery`, get(`${key}.filterQuery`, timeline), acc);
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/security_solution_ftr/services/timeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
DeleteTimelinesResponse,
GetDraftTimelinesResponse,
PatchTimelineResponse,
SavedTimeline,
} from '@kbn/security-solution-plugin/common/api/timeline';
import { TimelineInput } from '@kbn/security-solution-plugin/common/search_strategy';
import moment from 'moment';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { FtrService } from '../../../functional/ftr_provider_context';
Expand Down Expand Up @@ -75,15 +75,15 @@ export class TimelineTestService extends FtrService {

const { savedObjectId: timelineId, version } = createdTimeline;

const timelineUpdate: TimelineInput = {
const timelineUpdate: SavedTimeline = {
title,
// Set date range to the last 1 year
dateRange: {
start: moment().subtract(1, 'year').toISOString(),
end: moment().toISOString(),
// Not sure why `start`/`end` are defined as numbers in the type, but looking at the
// UI's use of it, I can see they are being set to strings, so I'm forcing a cast here
} as unknown as TimelineInput['dateRange'],
} as unknown as SavedTimeline['dateRange'],

// Not sure why, but the following fields are not in the created timeline, which causes
// the timeline to not be able to pull in the event for display
Expand Down Expand Up @@ -111,7 +111,7 @@ export class TimelineTestService extends FtrService {

async updateTimeline(
timelineId: string,
updates: TimelineInput,
updates: SavedTimeline,
version: string
): Promise<PatchTimelineResponse> {
return await this.supertest
Expand Down

0 comments on commit 2acec55

Please sign in to comment.