Skip to content

Commit

Permalink
fix and remove more types
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed Sep 26, 2024
1 parent 1ca9ef5 commit 3c19531
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 194 deletions.
143 changes: 8 additions & 135 deletions x-pack/plugins/security_solution/common/api/timeline/model/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
* 2.0.
*/

import type { Maybe } from '../../../search_strategy';
import type { DataProviderType } from './components.gen';
import {
BareNote,
BarePinnedEvent,
ColumnHeaderResult,
DataProviderTypeEnum,
DataProviderResult,
FavoriteTimelineResponse,
type FavoriteTimelineResult,
FilterTimelineResult,
ImportTimelineResult,
ImportTimelines,
type Note,
PinnedEvent,
PersistTimelineResponse,
QueryMatchResult,
ResolvedTimeline,
RowRendererId,
RowRendererIdEnum,
Expand All @@ -41,14 +43,18 @@ import {
export {
BareNote,
BarePinnedEvent,
ColumnHeaderResult,
DataProviderResult,
DataProviderType,
DataProviderTypeEnum,
FavoriteTimelineResponse,
FilterTimelineResult,
ImportTimelineResult,
ImportTimelines,
Note,
PinnedEvent,
PersistTimelineResponse,
QueryMatchResult,
ResolvedTimeline,
RowRendererId,
RowRendererIdEnum,
Expand Down Expand Up @@ -92,11 +98,6 @@ export interface ExportedNotes {
globalNotes: ExportedGlobalNotes;
}

export type ExportedTimelines = SavedTimeline &
ExportedNotes & {
pinnedEventIds: string[];
};

export interface ExportTimelineNotFoundError {
statusCode: number;
message: string;
Expand All @@ -107,134 +108,6 @@ export interface PageInfoTimeline {
pageSize: number;
}

export interface ColumnHeaderResult {
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 DataProviderResult {
id?: Maybe<string>;
name?: Maybe<string>;
enabled?: Maybe<boolean>;
excluded?: Maybe<boolean>;
kqlQuery?: Maybe<string>;
queryMatch?: Maybe<QueryMatchResult>;
type?: Maybe<DataProviderType>;
and?: Maybe<DataProviderResult[]>;
}

export interface QueryMatchResult {
field?: Maybe<string>;
displayField?: Maybe<string>;
value?: Maybe<string | string[]>;
displayValue?: Maybe<string>;
operator?: Maybe<string>;
}

export interface DateRangePickerResult {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
start?: Maybe<any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
end?: Maybe<any>;
}

export interface EqlOptionsResult {
eventCategoryField?: Maybe<string>;
tiebreakerField?: Maybe<string>;
timestampField?: Maybe<string>;
query?: Maybe<string>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
size?: Maybe<any>;
}

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

export interface FilterMetaTimelineResult {
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 SerializedFilterQueryResult {
filterQuery?: Maybe<SerializedKueryQueryResult>;
}

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

export interface SerializedKueryQueryResult {
kuery?: Maybe<KueryFilterQueryResult>;
serializedQuery?: Maybe<string>;
}

export interface TimelineResult {
columns?: Maybe<ColumnHeaderResult[]>;
created?: Maybe<number>;
createdBy?: Maybe<string>;
dataProviders?: Maybe<DataProviderResult[]>;
dataViewId?: Maybe<string>;
dateRange?: Maybe<DateRangePickerResult>;
description?: Maybe<string>;
eqlOptions?: Maybe<EqlOptionsResult>;
eventIdToNoteIds?: Maybe<Note[]>;
eventType?: Maybe<string>;
excludedRowRendererIds?: Maybe<RowRendererId[]>;
favorite?: Maybe<FavoriteTimelineResult[]>;
filters?: Maybe<FilterTimelineResult[]>;
kqlMode?: Maybe<string>;
kqlQuery?: Maybe<SerializedFilterQueryResult>;
indexNames?: Maybe<string[]>;
notes?: Maybe<Note[]>;
noteIds?: Maybe<string[]>;
pinnedEventIds?: Maybe<string[]>;
pinnedEventsSaveObject?: Maybe<PinnedEvent[]>;
savedQueryId?: Maybe<string>;
savedObjectId: string;
sort?: Maybe<Sort>;
status?: Maybe<TimelineStatus>;
title?: Maybe<string>;
templateTimelineId?: Maybe<string>;
templateTimelineVersion?: Maybe<number>;
timelineType?: Maybe<TimelineType>;
updated?: Maybe<number>;
updatedBy?: Maybe<string>;
version: string;
savedSearchId?: Maybe<string>;
}

export interface ResponseTimeline {
code?: Maybe<number>;
message?: Maybe<string>;
timeline: TimelineResult;
}

export interface SortTimeline {
sortField: SortFieldTimeline;
sortOrder: SortDirection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,3 @@ export const TimelineErrorResponse = z.union([
statusCode: z.number(),
}),
]);

export type ExportedTimelines = z.infer<typeof ExportedTimelines>;
export const ExportedTimelines = SavedTimeline.merge(
z.object({
globalNotes: z.array(Note).optional(),
eventNotes: z.array(Note).optional(),
pinnedEventIds: z.array(z.string()).optional(),
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -732,21 +732,3 @@ components:
type: string
statusCode:
type: number

ExportedTimelines:
allOf:
- $ref: '#/components/schemas/SavedTimeline'
- type: object
properties:
globalNotes:
type: array
items:
$ref: '#/components/schemas/Note'
eventNotes:
type: array
items:
$ref: '#/components/schemas/Note'
pinnedEventIds:
type: array
items:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { FilterStateStore } from '@kbn/es-query';

import type { DataTableModel } from '@kbn/securitysolution-data-table';
import { VIEW_SELECTION } from '../../../common/constants';
import type { TimelineResult } from '../../../common/api/timeline';
import { TimelineId, TimelineTabs } from '../../../common/types/timeline';
import type { TimelineResponse } from '../../../common/api/timeline';
import {
type ColumnHeaderResult,
RowRendererIdEnum,
Expand Down Expand Up @@ -1987,7 +1987,7 @@ export const mockDataTableModel: DataTableModel = {
},
};

export const mockGetOneTimelineResult: TimelineResult = {
export const mockGetOneTimelineResult: TimelineResponse = {
savedObjectId: 'ef579e40-jibber-jabber',
columns: timelineDefaults.columns.filter(
(column) => column.id !== 'event.action'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import {
isNewTermsRule,
isThresholdRule,
} from '../../../../common/detection_engine/utils';
import type { TimelineResult } from '../../../../common/api/timeline';
import { TimelineId } from '../../../../common/types/timeline';
import type { TimelineResponse } from '../../../../common/api/timeline';
import { TimelineStatusEnum, TimelineTypeEnum } from '../../../../common/api/timeline';
import type {
SendAlertToTimelineActionProps,
Expand All @@ -69,7 +69,7 @@ import { TimelineEventsQueries } from '../../../../common/search_strategy/timeli
import { timelineDefaults } from '../../../timelines/store/defaults';
import {
omitTypenameInTimeline,
formatTimelineResultToModel,
formatTimelineResponseToModel,
} from '../../../timelines/components/open_timeline/helpers';
import { convertKueryToElasticSearchQuery } from '../../../common/lib/kuery';
import { getField, getFieldKey } from '../../../helpers';
Expand Down Expand Up @@ -983,11 +983,15 @@ export const sendAlertToTimelineAction = async ({
),
]);

const resultingTimeline: TimelineResult = getOr({}, 'data.getOneTimeline', responseTimeline);
const resultingTimeline: TimelineResponse = getOr(
{},
'data.getOneTimeline',
responseTimeline
);
const eventData: TimelineEventsDetailsItem[] = eventDataResp.data ?? [];
if (!isEmpty(resultingTimeline)) {
const timelineTemplate: TimelineResult = omitTypenameInTimeline(resultingTimeline);
const { timeline, notes } = formatTimelineResultToModel(
const timelineTemplate = omitTypenameInTimeline(resultingTimeline);
const { timeline, notes } = formatTimelineResponseToModel(
timelineTemplate,
true,
timelineTemplate.timelineType ?? TimelineTypeEnum.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
isUntitled,
omitTypenameInTimeline,
useQueryTimelineById,
formatTimelineResultToModel,
formatTimelineResponseToModel,
} from './helpers';
import type { OpenTimelineResult } from './types';
import { TimelineId } from '../../../../common/types/timeline';
Expand Down Expand Up @@ -695,7 +695,7 @@ describe('helpers', () => {
});

test('Do not override daterange if TimelineStatus is active', () => {
const { timeline } = formatTimelineResultToModel(
const { timeline } = formatTimelineResponseToModel(
omitTypenameInTimeline(getOr({}, 'data.timeline', selectedTimeline)),
args.duplicate,
args.timelineType
Expand Down Expand Up @@ -748,7 +748,7 @@ describe('helpers', () => {
});

test('should not override daterange if TimelineStatus is active', () => {
const { timeline } = formatTimelineResultToModel(
const { timeline } = formatTimelineResponseToModel(
omitTypenameInTimeline(getOr({}, 'data.timeline', selectedTimeline)),
args.duplicate,
args.timelineType
Expand Down Expand Up @@ -822,7 +822,7 @@ describe('helpers', () => {
});

test('override daterange if TimelineStatus is immutable', () => {
const { timeline } = formatTimelineResultToModel(
const { timeline } = formatTimelineResponseToModel(
omitTypenameInTimeline(getOr({}, 'data.timeline', template)),
args.duplicate,
args.timelineType
Expand Down
Loading

0 comments on commit 3c19531

Please sign in to comment.