forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rca): update items and investigation params (elastic#191766)
- Loading branch information
Showing
12 changed files
with
358 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/kbn-investigation-shared/src/rest_specs/update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 { investigationResponseSchema } from './investigation'; | ||
|
||
const updateInvestigationParamsSchema = t.type({ | ||
path: t.type({ | ||
investigationId: t.string, | ||
}), | ||
body: t.partial({ | ||
title: t.string, | ||
status: t.union([t.literal('ongoing'), t.literal('closed')]), | ||
params: t.type({ | ||
timeRange: t.type({ from: t.number, to: t.number }), | ||
}), | ||
}), | ||
}); | ||
|
||
const updateInvestigationResponseSchema = investigationResponseSchema; | ||
|
||
type UpdateInvestigationParams = t.TypeOf<typeof updateInvestigationParamsSchema.props.body>; | ||
type UpdateInvestigationResponse = t.OutputOf<typeof updateInvestigationResponseSchema>; | ||
|
||
export { updateInvestigationParamsSchema, updateInvestigationResponseSchema }; | ||
export type { UpdateInvestigationParams, UpdateInvestigationResponse }; |
29 changes: 29 additions & 0 deletions
29
packages/kbn-investigation-shared/src/rest_specs/update_item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 { investigationItemResponseSchema } from './investigation_item'; | ||
import { itemSchema } from '../schema'; | ||
|
||
const updateInvestigationItemParamsSchema = t.type({ | ||
path: t.type({ | ||
investigationId: t.string, | ||
itemId: t.string, | ||
}), | ||
body: itemSchema, | ||
}); | ||
|
||
const updateInvestigationItemResponseSchema = investigationItemResponseSchema; | ||
|
||
type UpdateInvestigationItemParams = t.TypeOf< | ||
typeof updateInvestigationItemParamsSchema.props.body | ||
>; | ||
type UpdateInvestigationItemResponse = t.OutputOf<typeof updateInvestigationItemResponseSchema>; | ||
|
||
export { updateInvestigationItemParamsSchema, updateInvestigationItemResponseSchema }; | ||
export type { UpdateInvestigationItemParams, UpdateInvestigationItemResponse }; |
46 changes: 46 additions & 0 deletions
46
...k/plugins/observability_solution/investigate_app/public/hooks/use_update_investigation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { IHttpFetchError, ResponseErrorBody } from '@kbn/core/public'; | ||
import { UpdateInvestigationParams, UpdateInvestigationResponse } from '@kbn/investigation-shared'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
type ServerError = IHttpFetchError<ResponseErrorBody>; | ||
|
||
export function useUpdateInvestigation() { | ||
const { | ||
core: { | ||
http, | ||
notifications: { toasts }, | ||
}, | ||
} = useKibana(); | ||
|
||
return useMutation< | ||
UpdateInvestigationResponse, | ||
ServerError, | ||
{ investigationId: string; payload: UpdateInvestigationParams }, | ||
{ investigationId: string } | ||
>( | ||
['updateInvestigation'], | ||
({ investigationId, payload }) => { | ||
const body = JSON.stringify(payload); | ||
return http.put<UpdateInvestigationResponse>( | ||
`/api/observability/investigations/${investigationId}`, | ||
{ body, version: '2023-10-31' } | ||
); | ||
}, | ||
{ | ||
onSuccess: (response, {}) => { | ||
toasts.addSuccess('Investigation updated'); | ||
}, | ||
onError: (error, {}, context) => { | ||
toasts.addError(new Error(error.body?.message ?? 'An error occurred'), { title: 'Error' }); | ||
}, | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.