Skip to content

Commit

Permalink
chore(rca): Add notes related APIs (elastic#190362)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Aug 14, 2024
1 parent 19e9bfb commit 47c41c1
Show file tree
Hide file tree
Showing 55 changed files with 587 additions and 258 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ test/interactive_setup_api_integration/plugins/test_endpoints @elastic/kibana-se
packages/kbn-interpreter @elastic/kibana-visualizations
x-pack/plugins/observability_solution/investigate_app @elastic/obs-ux-management-team
x-pack/plugins/observability_solution/investigate @elastic/obs-ux-management-team
packages/kbn-investigation-shared @elastic/obs-ux-management-team
packages/kbn-io-ts-utils @elastic/obs-knowledge-team
packages/kbn-ipynb @elastic/search-kibana
packages/kbn-jest-serializers @elastic/kibana-operations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
"@kbn/interpreter": "link:packages/kbn-interpreter",
"@kbn/investigate-app-plugin": "link:x-pack/plugins/observability_solution/investigate_app",
"@kbn/investigate-plugin": "link:x-pack/plugins/observability_solution/investigate",
"@kbn/investigation-shared": "link:packages/kbn-investigation-shared",
"@kbn/io-ts-utils": "link:packages/kbn-io-ts-utils",
"@kbn/ipynb": "link:packages/kbn-ipynb",
"@kbn/json-schemas": "link:x-pack/packages/ml/json_schemas",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-investigation-shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/investigation-shared

Empty package generated by @kbn/generate
23 changes: 23 additions & 0 deletions packages/kbn-investigation-shared/index.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.
*/

export type * from './src/schema/create';
export type * from './src/schema/create_notes';
export type * from './src/schema/delete';
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 * from './src/schema/create';
export * from './src/schema/create_notes';
export * from './src/schema/delete';
export * from './src/schema/find';
export * from './src/schema/get';
export * from './src/schema/get_notes';
export * from './src/schema/origin';
13 changes: 13 additions & 0 deletions packages/kbn-investigation-shared/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-investigation-shared'],
};
5 changes: 5 additions & 0 deletions packages/kbn-investigation-shared/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/investigation-shared",
"owner": "@elastic/obs-ux-management-team"
}
6 changes: 6 additions & 0 deletions packages/kbn-investigation-shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/investigation-shared",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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';
import { investigationResponseSchema } from './investigation';
import { alertOriginSchema, blankOriginSchema } from './origin';
Expand Down
36 changes: 36 additions & 0 deletions packages/kbn-investigation-shared/src/schema/create_notes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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';
import { investigationNoteResponseSchema } from './investigation_note';

const createInvestigationNoteParamsSchema = t.type({
path: t.type({
id: t.string,
}),
body: t.type({
content: t.string,
}),
});

const createInvestigationNoteResponseSchema = investigationNoteResponseSchema;

type CreateInvestigationNoteInput = t.OutputOf<
typeof createInvestigationNoteParamsSchema.props.body
>;
type CreateInvestigationNoteParams = t.TypeOf<
typeof createInvestigationNoteParamsSchema.props.body
>;
type CreateInvestigationNoteResponse = t.OutputOf<typeof createInvestigationNoteResponseSchema>;

export { createInvestigationNoteParamsSchema, createInvestigationNoteResponseSchema };
export type {
CreateInvestigationNoteInput,
CreateInvestigationNoteParams,
CreateInvestigationNoteResponse,
};
20 changes: 20 additions & 0 deletions packages/kbn-investigation-shared/src/schema/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 deleteInvestigationParamsSchema = t.type({
path: t.type({
id: t.string,
}),
});

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

export { deleteInvestigationParamsSchema };
export type { DeleteInvestigationParams };
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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';
import { investigationResponseSchema } from './investigation';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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';
import { investigationResponseSchema } from './investigation';

Expand Down
23 changes: 23 additions & 0 deletions packages/kbn-investigation-shared/src/schema/get_notes.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';
import { investigationNoteResponseSchema } from './investigation_note';

const getInvestigationNotesParamsSchema = t.type({
path: t.type({
id: t.string,
}),
});

const getInvestigationNotesResponseSchema = t.array(investigationNoteResponseSchema);

type GetInvestigationNotesResponse = t.OutputOf<typeof getInvestigationNotesResponseSchema>;

export { getInvestigationNotesParamsSchema, getInvestigationNotesResponseSchema };
export type { GetInvestigationNotesResponse };
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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';
import { alertOriginSchema, blankOriginSchema } from './origin';
import { investigationNoteResponseSchema } from './investigation_note';

const investigationResponseSchema = t.type({
id: t.string,
Expand All @@ -17,6 +20,7 @@ const investigationResponseSchema = t.type({
}),
origin: t.union([alertOriginSchema, blankOriginSchema]),
status: t.union([t.literal('ongoing'), t.literal('closed')]),
notes: t.array(investigationNoteResponseSchema),
});

type InvestigationResponse = t.OutputOf<typeof investigationResponseSchema>;
Expand Down
21 changes: 21 additions & 0 deletions packages/kbn-investigation-shared/src/schema/investigation_note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 investigationNoteResponseSchema = t.type({
id: t.string,
content: t.string,
createdAt: t.number,
createdBy: t.string,
});

type InvestigationNoteResponse = t.OutputOf<typeof investigationNoteResponseSchema>;

export { investigationNoteResponseSchema };
export type { InvestigationNoteResponse };
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 blankOriginSchema = t.type({ type: t.literal('blank') });
const alertOriginSchema = t.type({ type: t.literal('alert'), id: t.string });

type AlertOrigin = t.OutputOf<typeof alertOriginSchema>;
type BlankOrigin = t.OutputOf<typeof blankOriginSchema>;

export { alertOriginSchema, blankOriginSchema };

export type { AlertOrigin, BlankOrigin };
17 changes: 17 additions & 0 deletions packages/kbn-investigation-shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@
"@kbn/investigate-app-plugin/*": ["x-pack/plugins/observability_solution/investigate_app/*"],
"@kbn/investigate-plugin": ["x-pack/plugins/observability_solution/investigate"],
"@kbn/investigate-plugin/*": ["x-pack/plugins/observability_solution/investigate/*"],
"@kbn/investigation-shared": ["packages/kbn-investigation-shared"],
"@kbn/investigation-shared/*": ["packages/kbn-investigation-shared/*"],
"@kbn/io-ts-utils": ["packages/kbn-io-ts-utils"],
"@kbn/io-ts-utils/*": ["packages/kbn-io-ts-utils/*"],
"@kbn/ipynb": ["packages/kbn-ipynb"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ export type {
export { mergePlainObjects } from './utils/merge_plain_objects';

export { InvestigateWidgetColumnSpan } from './types';

export type { CreateInvestigationInput, CreateInvestigationResponse } from './schema/create';
export type { GetInvestigationParams } from './schema/get';
export type { FindInvestigationsResponse } from './schema/find';

export { createInvestigationParamsSchema } from './schema/create';
export { getInvestigationParamsSchema } from './schema/get';
export { findInvestigationsParamsSchema } from './schema/find';
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface Investigation {
export interface InvestigationNote {
id: string;
createdAt: number;
createdBy: AuthenticatedUser;
createdBy: string;
content: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { useContext, createContext } from 'react';
import { createContext } from 'react';
import type { InvestigateWidgetCreate } from '../../common';

export interface UseInvestigateWidgetApi<
Expand All @@ -17,9 +17,3 @@ export interface UseInvestigateWidgetApi<
const InvestigateWidgetApiContext = createContext<UseInvestigateWidgetApi | undefined>(undefined);

export const InvestigateWidgetApiContextProvider = InvestigateWidgetApiContext.Provider;

export function useInvestigateWidget(): UseInvestigateWidgetApi | undefined {
const context = useContext(InvestigateWidgetApiContext);

return context;
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function createInvestigationStore({
notes: prevInvestigation.notes.concat({
id: v4(),
createdAt: Date.now(),
createdBy: user,
createdBy: user.username,
content: note,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { CoreSetup, CoreStart, PluginInitializerContext, Plugin } from '@kbn/core/public';
import type { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public';
import type { Logger } from '@kbn/logging';
import { useMemo } from 'react';
import { useInvestigateWidget } from './hooks/use_investigate_widget';
import { createUseInvestigation } from './hooks/use_investigation';
import type {
ConfigSchema,
Expand Down Expand Up @@ -73,7 +72,6 @@ export class InvestigatePlugin
to,
});
},
useInvestigateWidget,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
*/

/* eslint-disable @typescript-eslint/no-empty-interface*/
import type { FromSchema } from 'json-schema-to-ts';
import type { CompatibleJSONSchema } from '@kbn/observability-ai-assistant-plugin/public';
import type { AuthenticatedUser } from '@kbn/core/public';
import type { CompatibleJSONSchema } from '@kbn/observability-ai-assistant-plugin/public';
import type { FromSchema } from 'json-schema-to-ts';
import type { InvestigateWidget } from '../common';
import type { GlobalWidgetParameters, InvestigateWidgetCreate } from '../common/types';
import type { UseInvestigationApi } from './hooks/use_investigation';
import type { UseInvestigateWidgetApi } from './hooks/use_investigate_widget';

export enum ChromeOption {
disabled = 'disabled',
Expand Down Expand Up @@ -84,5 +83,4 @@ export interface InvestigatePublicStart {
from: string;
to: string;
}) => UseInvestigationApi;
useInvestigateWidget: () => UseInvestigateWidgetApi | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"public/**/*",
"typings/**/*",
"public/**/*.json",
"server/**/*"
],
"server/**/*", ],
"kbn_references": [
"@kbn/core",
"@kbn/logging",
Expand Down
Loading

0 comments on commit 47c41c1

Please sign in to comment.