Skip to content

Commit 8265e70

Browse files
[7.8] [SIEM] Refactor Timeline.timelineType draft to Timeline.status draft (#66864) (#67084)
1 parent 306e42f commit 8265e70

34 files changed

+324
-101
lines changed

x-pack/plugins/siem/common/types/timeline/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,42 @@ const SavedSortRuntimeType = runtimeTypes.partial({
130130
sortDirection: unionWithNullType(runtimeTypes.string),
131131
});
132132

133+
/*
134+
* Timeline Statuses
135+
*/
136+
137+
export enum TimelineStatus {
138+
active = 'active',
139+
draft = 'draft',
140+
}
141+
142+
export const TimelineStatusLiteralRt = runtimeTypes.union([
143+
runtimeTypes.literal(TimelineStatus.active),
144+
runtimeTypes.literal(TimelineStatus.draft),
145+
]);
146+
147+
const TimelineStatusLiteralWithNullRt = unionWithNullType(TimelineStatusLiteralRt);
148+
149+
export type TimelineStatusLiteral = runtimeTypes.TypeOf<typeof TimelineStatusLiteralRt>;
150+
export type TimelineStatusLiteralWithNull = runtimeTypes.TypeOf<
151+
typeof TimelineStatusLiteralWithNullRt
152+
>;
153+
133154
/*
134155
* Timeline Types
135156
*/
136157

137158
export enum TimelineType {
138159
default = 'default',
139-
draft = 'draft',
140160
template = 'template',
141161
}
142162

143163
export const TimelineTypeLiteralRt = runtimeTypes.union([
144164
runtimeTypes.literal(TimelineType.template),
145-
runtimeTypes.literal(TimelineType.draft),
146165
runtimeTypes.literal(TimelineType.default),
147166
]);
148167

149-
const TimelineTypeLiteralWithNullRt = unionWithNullType(TimelineTypeLiteralRt);
168+
export const TimelineTypeLiteralWithNullRt = unionWithNullType(TimelineTypeLiteralRt);
150169

151170
export type TimelineTypeLiteral = runtimeTypes.TypeOf<typeof TimelineTypeLiteralRt>;
152171
export type TimelineTypeLiteralWithNull = runtimeTypes.TypeOf<typeof TimelineTypeLiteralWithNullRt>;
@@ -167,6 +186,7 @@ export const SavedTimelineRuntimeType = runtimeTypes.partial({
167186
dateRange: unionWithNullType(SavedDateRangePickerRuntimeType),
168187
savedQueryId: unionWithNullType(runtimeTypes.string),
169188
sort: unionWithNullType(SavedSortRuntimeType),
189+
status: unionWithNullType(TimelineStatusLiteralRt),
170190
created: unionWithNullType(runtimeTypes.number),
171191
createdBy: unionWithNullType(runtimeTypes.string),
172192
updated: unionWithNullType(runtimeTypes.number),

x-pack/plugins/siem/public/components/open_timeline/helpers.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { KueryFilterQueryKind } from '../../store/model';
3636
import { Note } from '../../lib/note';
3737
import moment from 'moment';
3838
import sinon from 'sinon';
39-
import { TimelineType } from '../../../common/types/timeline';
39+
import { TimelineType, TimelineStatus } from '../../../common/types/timeline';
4040

4141
jest.mock('../../store/inputs/actions');
4242
jest.mock('../../store/timeline/actions');
@@ -299,8 +299,9 @@ describe('helpers', () => {
299299
columnId: '@timestamp',
300300
sortDirection: 'desc',
301301
},
302+
status: TimelineStatus.draft,
302303
title: '',
303-
timelineType: TimelineType.draft,
304+
timelineType: TimelineType.default,
304305
templateTimelineId: null,
305306
templateTimelineVersion: null,
306307
version: '1',
@@ -396,8 +397,9 @@ describe('helpers', () => {
396397
columnId: '@timestamp',
397398
sortDirection: 'desc',
398399
},
400+
status: TimelineStatus.draft,
399401
title: '',
400-
timelineType: TimelineType.draft,
402+
timelineType: TimelineType.default,
401403
templateTimelineId: null,
402404
templateTimelineVersion: null,
403405
version: '1',
@@ -517,7 +519,7 @@ describe('helpers', () => {
517519
},
518520
loadingEventIds: [],
519521
title: '',
520-
timelineType: TimelineType.draft,
522+
timelineType: TimelineType.default,
521523
templateTimelineId: null,
522524
templateTimelineVersion: null,
523525
noteIds: [],
@@ -535,6 +537,7 @@ describe('helpers', () => {
535537
columnId: '@timestamp',
536538
sortDirection: 'desc',
537539
},
540+
status: TimelineStatus.draft,
538541
width: 1100,
539542
id: 'savedObject-1',
540543
});
@@ -685,7 +688,7 @@ describe('helpers', () => {
685688
},
686689
loadingEventIds: [],
687690
title: '',
688-
timelineType: TimelineType.draft,
691+
timelineType: TimelineType.default,
689692
templateTimelineId: null,
690693
templateTimelineVersion: null,
691694
noteIds: [],
@@ -703,6 +706,7 @@ describe('helpers', () => {
703706
columnId: '@timestamp',
704707
sortDirection: 'desc',
705708
},
709+
status: TimelineStatus.draft,
706710
width: 1100,
707711
id: 'savedObject-1',
708712
});

x-pack/plugins/siem/public/containers/timeline/all/index.gql_query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const allTimelinesQuery = gql`
1212
$search: String
1313
$sort: SortTimeline
1414
$onlyUserFavorite: Boolean
15-
$timelineType: String
15+
$timelineType: TimelineType
1616
) {
1717
getAllTimeline(
1818
pageInfo: $pageInfo

x-pack/plugins/siem/public/containers/timeline/api.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { pipe } from 'fp-ts/lib/pipeable';
99

1010
import { throwErrors } from '../../../../case/common/api';
1111
import {
12-
SavedTimeline,
1312
TimelineResponse,
1413
TimelineResponseType,
15-
TimelineType,
14+
TimelineStatus,
1615
} from '../../../common/types/timeline';
16+
import { TimelineInput, TimelineType } from '../../graphql/types';
1717
import {
1818
TIMELINE_URL,
1919
TIMELINE_DRAFT_URL,
@@ -28,7 +28,7 @@ import { createToasterPlainError } from '../case/utils';
2828
import { ImportDataProps, ImportDataResponse } from '../detection_engine/rules';
2929

3030
interface RequestPostTimeline {
31-
timeline: SavedTimeline;
31+
timeline: TimelineInput;
3232
signal?: AbortSignal;
3333
}
3434

@@ -72,8 +72,8 @@ export const persistTimeline = async ({
7272
timeline,
7373
version,
7474
}: RequestPersistTimeline): Promise<TimelineResponse> => {
75-
if (timelineId == null && timeline.timelineType === TimelineType.draft) {
76-
const draftTimeline = await cleanDraftTimeline();
75+
if (timelineId == null && timeline.status === TimelineStatus.draft) {
76+
const draftTimeline = await cleanDraftTimeline({ timelineType: timeline.timelineType! });
7777
return patchTimeline({
7878
timelineId: draftTimeline.data.persistTimeline.timeline.savedObjectId,
7979
timeline,
@@ -130,14 +130,30 @@ export const exportSelectedTimeline: ExportSelectedData = async ({
130130
return response.body!;
131131
};
132132

133-
export const getDraftTimeline = async (): Promise<TimelineResponse> => {
134-
const response = await KibanaServices.get().http.get<TimelineResponse>(TIMELINE_DRAFT_URL);
133+
export const getDraftTimeline = async ({
134+
timelineType,
135+
}: {
136+
timelineType: TimelineType;
137+
}): Promise<TimelineResponse> => {
138+
const response = await KibanaServices.get().http.get<TimelineResponse>(TIMELINE_DRAFT_URL, {
139+
query: {
140+
timelineType,
141+
},
142+
});
135143

136144
return decodeTimelineResponse(response);
137145
};
138146

139-
export const cleanDraftTimeline = async (): Promise<TimelineResponse> => {
140-
const response = await KibanaServices.get().http.post<TimelineResponse>(TIMELINE_DRAFT_URL);
147+
export const cleanDraftTimeline = async ({
148+
timelineType,
149+
}: {
150+
timelineType: TimelineType;
151+
}): Promise<TimelineResponse> => {
152+
const response = await KibanaServices.get().http.post<TimelineResponse>(TIMELINE_DRAFT_URL, {
153+
body: JSON.stringify({
154+
timelineType,
155+
}),
156+
});
141157

142158
return decodeTimelineResponse(response);
143159
};

x-pack/plugins/siem/public/graphql/introspection.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
{
254254
"name": "timelineType",
255255
"description": "",
256-
"type": { "kind": "SCALAR", "name": "String", "ofType": null },
256+
"type": { "kind": "ENUM", "name": "TimelineType", "ofType": null },
257257
"defaultValue": null
258258
}
259259
],
@@ -9726,6 +9726,14 @@
97269726
"isDeprecated": false,
97279727
"deprecationReason": null
97289728
},
9729+
{
9730+
"name": "status",
9731+
"description": "",
9732+
"args": [],
9733+
"type": { "kind": "ENUM", "name": "TimelineStatus", "ofType": null },
9734+
"isDeprecated": false,
9735+
"deprecationReason": null
9736+
},
97299737
{
97309738
"name": "title",
97319739
"description": "",
@@ -10353,6 +10361,19 @@
1035310361
"enumValues": null,
1035410362
"possibleTypes": null
1035510363
},
10364+
{
10365+
"kind": "ENUM",
10366+
"name": "TimelineStatus",
10367+
"description": "",
10368+
"fields": null,
10369+
"inputFields": null,
10370+
"interfaces": null,
10371+
"enumValues": [
10372+
{ "name": "active", "description": "", "isDeprecated": false, "deprecationReason": null },
10373+
{ "name": "draft", "description": "", "isDeprecated": false, "deprecationReason": null }
10374+
],
10375+
"possibleTypes": null
10376+
},
1035610377
{
1035710378
"kind": "SCALAR",
1035810379
"name": "Int",
@@ -10377,7 +10398,6 @@
1037710398
"isDeprecated": false,
1037810399
"deprecationReason": null
1037910400
},
10380-
{ "name": "draft", "description": "", "isDeprecated": false, "deprecationReason": null },
1038110401
{
1038210402
"name": "template",
1038310403
"description": "",
@@ -10962,6 +10982,12 @@
1096210982
"description": "",
1096310983
"type": { "kind": "INPUT_OBJECT", "name": "SortTimelineInput", "ofType": null },
1096410984
"defaultValue": null
10985+
},
10986+
{
10987+
"name": "status",
10988+
"description": "",
10989+
"type": { "kind": "ENUM", "name": "TimelineStatus", "ofType": null },
10990+
"defaultValue": null
1096510991
}
1096610992
],
1096710993
"interfaces": null,

x-pack/plugins/siem/public/graphql/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export interface TimelineInput {
143143
savedQueryId?: Maybe<string>;
144144

145145
sort?: Maybe<SortTimelineInput>;
146+
147+
status?: Maybe<TimelineStatus>;
146148
}
147149

148150
export interface ColumnHeaderInput {
@@ -340,9 +342,13 @@ export enum TlsFields {
340342
_id = '_id',
341343
}
342344

345+
export enum TimelineStatus {
346+
active = 'active',
347+
draft = 'draft',
348+
}
349+
343350
export enum TimelineType {
344351
default = 'default',
345-
draft = 'draft',
346352
template = 'template',
347353
}
348354

@@ -1954,6 +1960,8 @@ export interface TimelineResult {
19541960

19551961
sort?: Maybe<SortTimelineResult>;
19561962

1963+
status?: Maybe<TimelineStatus>;
1964+
19571965
title?: Maybe<string>;
19581966

19591967
templateTimelineId?: Maybe<string>;
@@ -2237,7 +2245,7 @@ export interface GetAllTimelineQueryArgs {
22372245

22382246
onlyUserFavorite?: Maybe<boolean>;
22392247

2240-
timelineType?: Maybe<string>;
2248+
timelineType?: Maybe<TimelineType>;
22412249
}
22422250
export interface AuthenticationsSourceArgs {
22432251
timerange: TimerangeInput;
@@ -4015,7 +4023,7 @@ export namespace GetAllTimeline {
40154023
search?: Maybe<string>;
40164024
sort?: Maybe<SortTimeline>;
40174025
onlyUserFavorite?: Maybe<boolean>;
4018-
timelineType?: Maybe<string>;
4026+
timelineType?: Maybe<TimelineType>;
40194027
};
40204028

40214029
export type Query = {

x-pack/plugins/siem/public/mock/global_state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
DEFAULT_INTERVAL_TYPE,
2424
DEFAULT_INTERVAL_VALUE,
2525
} from '../../common/constants';
26-
import { TimelineType } from '../../common/types/timeline';
26+
import { TimelineType, TimelineStatus } from '../../common/types/timeline';
2727

2828
export const mockGlobalState: State = {
2929
app: {
@@ -221,6 +221,7 @@ export const mockGlobalState: State = {
221221
width: DEFAULT_TIMELINE_WIDTH,
222222
isSaving: false,
223223
version: null,
224+
status: TimelineStatus.active,
224225
},
225226
},
226227
},

x-pack/plugins/siem/public/mock/timeline_results.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { FilterStateStore } from '../../../../../src/plugins/data/common/es_query/filters/meta_filter';
77

8-
import { TimelineType } from '../../common/types/timeline';
8+
import { TimelineType, TimelineStatus } from '../../common/types/timeline';
99

1010
import { OpenTimelineResult } from '../components/open_timeline/types';
1111
import { GetAllTimeline, SortFieldTimeline, TimelineResult, Direction } from '../graphql/types';
@@ -2142,6 +2142,7 @@ export const mockTimelineModel: TimelineModel = {
21422142
columnId: '@timestamp',
21432143
sortDirection: Direction.desc,
21442144
},
2145+
status: TimelineStatus.active,
21452146
title: 'Test rule',
21462147
timelineType: TimelineType.default,
21472148
templateTimelineId: null,
@@ -2242,8 +2243,9 @@ export const defaultTimelineProps: CreateTimelineProps = {
22422243
showCheckboxes: false,
22432244
showRowRenderers: true,
22442245
sort: { columnId: '@timestamp', sortDirection: Direction.desc },
2246+
status: TimelineStatus.draft,
22452247
title: '',
2246-
timelineType: TimelineType.draft,
2248+
timelineType: TimelineType.default,
22472249
templateTimelineVersion: null,
22482250
templateTimelineId: null,
22492251
version: null,

x-pack/plugins/siem/public/pages/detection_engine/components/signals/actions.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../../../../mock/';
1616
import { CreateTimeline, UpdateTimelineLoading } from './types';
1717
import { Ecs } from '../../../../graphql/types';
18-
import { TimelineType } from '../../../../../common/types/timeline';
18+
import { TimelineType, TimelineStatus } from '../../../../../common/types/timeline';
1919

2020
jest.mock('apollo-client');
2121

@@ -215,6 +215,7 @@ describe('signals actions', () => {
215215
columnId: '@timestamp',
216216
sortDirection: 'desc',
217217
},
218+
status: TimelineStatus.draft,
218219
title: '',
219220
timelineType: TimelineType.default,
220221
templateTimelineId: null,

0 commit comments

Comments
 (0)