Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/kbn-investigation-shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type * from './src/schema/find';
export type * from './src/schema/get';
export type * from './src/schema/get_notes';
export type * from './src/schema/origin';
export type * from './src/schema/delete_note';
export type * from './src/schema/investigation_note';

export * from './src/schema/create';
export * from './src/schema/create_notes';
Expand All @@ -21,3 +23,5 @@ export * from './src/schema/find';
export * from './src/schema/get';
export * from './src/schema/get_notes';
export * from './src/schema/origin';
export * from './src/schema/delete_note';
export * from './src/schema/investigation_note';
23 changes: 23 additions & 0 deletions packages/kbn-investigation-shared/src/schema/delete_note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as t from 'io-ts';

const deleteInvestigationNoteParamsSchema = t.type({
path: t.type({
id: t.string,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to investigationId

noteId: t.string,
}),
});

type DeleteInvestigationNoteParams = t.TypeOf<
typeof deleteInvestigationNoteParamsSchema.props.path
>; // Parsed payload used by the backend

export { deleteInvestigationNoteParamsSchema };
export type { DeleteInvestigationNoteParams };
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ export type {
} from './types';

export { mergePlainObjects } from './utils/merge_plain_objects';

export { InvestigateWidgetColumnSpan } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ export interface GlobalWidgetParameters {
};
}

export enum InvestigateWidgetColumnSpan {
One = 1,
Two = 2,
Three = 3,
Four = 4,
}

export interface Investigation {
id: string;
createdAt: number;
user: AuthenticatedUser;
title: string;
items: InvestigateWidget[];
notes: InvestigationNote[];
Expand All @@ -51,14 +43,11 @@ export interface InvestigateWidget<
parameters: GlobalWidgetParameters & TParameters;
data: TData;
title: string;
description?: string;
columns: InvestigateWidgetColumnSpan;
rows: number;
}

export type InvestigateWidgetCreate<TParameters extends Record<string, any> = {}> = Pick<
InvestigateWidget,
'title' | 'description' | 'columns' | 'rows' | 'type'
'title' | 'type'
> & {
parameters: DeepPartial<GlobalWidgetParameters> & TParameters;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/

import { DeepPartial } from 'utility-types';
import { InvestigateWidgetColumnSpan, InvestigateWidgetCreate } from '../common';
import { InvestigateWidgetCreate } from '../common';
import { GlobalWidgetParameters } from '../common/types';

type MakePartial<T extends Record<string, any>, K extends keyof T> = Omit<T, K> &
DeepPartial<Pick<T, K>>;

type PredefinedKeys = 'rows' | 'columns' | 'type';

type AllowedDefaultKeys = 'rows' | 'columns';
type PredefinedKeys = 'type';

export type WidgetFactory<TParameters extends Record<string, any>> = <
T extends MakePartial<InvestigateWidgetCreate<TParameters>, PredefinedKeys>
Expand All @@ -24,15 +22,11 @@ export type WidgetFactory<TParameters extends Record<string, any>> = <
Omit<T, 'parameters'> & { parameters: T['parameters'] & DeepPartial<GlobalWidgetParameters> };

export function createWidgetFactory<TParameters extends Record<string, any>>(
type: string,
defaults?: Pick<Partial<InvestigateWidgetCreate>, AllowedDefaultKeys>
type: string
): WidgetFactory<TParameters> {
const createWidget: WidgetFactory<TParameters> = (widgetCreate) => {
return {
rows: 12,
columns: InvestigateWidgetColumnSpan.Four,
type,
...defaults,
...widgetCreate,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { IconType } from '@elastic/eui';
import type { Ast } from '@kbn/interpreter';
import type { InvestigateWidgetCreate } from '../../common';

// copied over from the Lens plugin to prevent dependency hell
type TableChangeType = 'initial' | 'unchanged' | 'reduced' | 'extended' | 'reorder' | 'layers';
Expand All @@ -33,5 +32,3 @@ export interface EsqlWidgetParameters {
esql: string;
suggestion?: Suggestion;
}

export type EsqlWidgetCreate = InvestigateWidgetCreate<EsqlWidgetParameters>;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,43 @@
* 2.0.
*/

import type { AuthenticatedUser } from '@kbn/security-plugin/common';
import { v4 } from 'uuid';
import { i18n } from '@kbn/i18n';
import { GetInvestigationResponse } from '@kbn/investigation-shared';
import { v4 } from 'uuid';
import type { Investigation } from '../../../common';
import { GlobalWidgetParameters } from '../../../common/types';

export function createNewInvestigation({
id,
user,
globalWidgetParameters,
}: {
id?: string;
user: AuthenticatedUser;
globalWidgetParameters: GlobalWidgetParameters;
}): Investigation {
export function createNewInvestigation(): Investigation {
return {
id: v4(),
createdAt: new Date().getTime(),
user,
id: id ?? v4(),
title: i18n.translate('xpack.investigate.newInvestigationTitle', {
defaultMessage: 'New investigation',
}),
items: [],
notes: [],
parameters: globalWidgetParameters,
parameters: {
timeRange: {
from: new Date(Date.now() - 15 * 60 * 1000).toISOString(),
to: new Date().toISOString(),
},
},
};
}

export function fromInvestigationResponse(
investigationData: GetInvestigationResponse
): Investigation {
return {
id: investigationData.id,
createdAt: investigationData.createdAt,
title: investigationData.title,
items: [],
notes: investigationData.notes,
parameters: {
timeRange: {
from: new Date(investigationData.params.timeRange.from).toISOString(),
to: new Date(investigationData.params.timeRange.to).toISOString(),
},
},
};
}
Loading