-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
380 additions
and
102 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
30 changes: 30 additions & 0 deletions
30
packages/kbn-investigation-shared/src/rest_specs/update_note.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,30 @@ | ||
/* | ||
* 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 updateInvestigationNoteParamsSchema = t.type({ | ||
path: t.type({ | ||
investigationId: t.string, | ||
noteId: t.string, | ||
}), | ||
body: t.type({ | ||
content: t.string, | ||
}), | ||
}); | ||
|
||
const updateInvestigationNoteResponseSchema = investigationNoteResponseSchema; | ||
|
||
type UpdateInvestigationNoteParams = t.TypeOf< | ||
typeof updateInvestigationNoteParamsSchema.props.body | ||
>; | ||
type UpdateInvestigationNoteResponse = t.OutputOf<typeof updateInvestigationNoteResponseSchema>; | ||
|
||
export { updateInvestigationNoteParamsSchema, updateInvestigationNoteResponseSchema }; | ||
export type { UpdateInvestigationNoteParams, UpdateInvestigationNoteResponse }; |
46 changes: 46 additions & 0 deletions
46
...gins/observability_solution/investigate_app/public/hooks/use_update_investigation_note.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 { UpdateInvestigationNoteParams } from '@kbn/investigation-shared'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
type ServerError = IHttpFetchError<ResponseErrorBody>; | ||
|
||
export function useUpdateInvestigationNote() { | ||
const { | ||
core: { | ||
http, | ||
notifications: { toasts }, | ||
}, | ||
} = useKibana(); | ||
|
||
return useMutation< | ||
void, | ||
ServerError, | ||
{ investigationId: string; noteId: string; note: UpdateInvestigationNoteParams }, | ||
{ investigationId: string } | ||
>( | ||
['deleteInvestigationNote'], | ||
({ investigationId, noteId, note }) => { | ||
const body = JSON.stringify(note); | ||
return http.put<void>( | ||
`/api/observability/investigations/${investigationId}/notes/${noteId}`, | ||
{ body, version: '2023-10-31' } | ||
); | ||
}, | ||
{ | ||
onSuccess: (response, {}) => { | ||
toasts.addSuccess('Note 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
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
88 changes: 88 additions & 0 deletions
88
...on/investigate_app/public/pages/details/components/investigation_notes/edit_note_form.tsx
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,88 @@ | ||
/* | ||
* 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 { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { InvestigationNoteResponse } from '@kbn/investigation-shared'; | ||
import React, { useState } from 'react'; | ||
import { ResizableTextInput } from './resizable_text_input'; | ||
import { useUpdateInvestigationNote } from '../../../../hooks/use_update_investigation_note'; | ||
|
||
interface Props { | ||
investigationId: string; | ||
note: InvestigationNoteResponse; | ||
onCancel: () => void; | ||
onUpdate: () => void; | ||
} | ||
|
||
export function EditNoteForm({ investigationId, note, onCancel, onUpdate }: Props) { | ||
const [noteInput, setNoteInput] = useState(note.content); | ||
const { mutateAsync: updateNote, isLoading: isUpdating } = useUpdateInvestigationNote(); | ||
|
||
const handleUpdateNote = async () => { | ||
await updateNote({ investigationId, noteId: note.id, note: { content: noteInput.trim() } }); | ||
onUpdate(); | ||
}; | ||
|
||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem> | ||
<ResizableTextInput | ||
disabled={isUpdating} | ||
value={noteInput} | ||
onChange={(value) => { | ||
setNoteInput(value); | ||
}} | ||
onSubmit={() => { | ||
handleUpdateNote(); | ||
}} | ||
placeholder={note.content} | ||
/> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexGroup direction="row" gutterSize="s" justifyContent="flexEnd"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
disabled={isUpdating} | ||
data-test-subj="cancelEditNoteButton" | ||
color="text" | ||
aria-label={i18n.translate( | ||
'xpack.investigateApp.investigationNotes.cancelEditButtonLabel', | ||
{ defaultMessage: 'Cancel' } | ||
)} | ||
size="m" | ||
onClick={() => onCancel()} | ||
> | ||
{i18n.translate('xpack.investigateApp.investigationNotes.cancelEditButtonLabel', { | ||
defaultMessage: 'Cancel', | ||
})} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
data-test-subj="updateNoteButton" | ||
color="primary" | ||
aria-label={i18n.translate( | ||
'xpack.investigateApp.investigationNotes.updateNoteButtonLabel', | ||
{ defaultMessage: 'Update note' } | ||
)} | ||
disabled={isUpdating || noteInput.trim() === ''} | ||
isLoading={isUpdating} | ||
size="m" | ||
onClick={() => { | ||
handleUpdateNote(); | ||
}} | ||
> | ||
{i18n.translate('xpack.investigateApp.investigationNotes.updateNoteButtonLabel', { | ||
defaultMessage: 'Update note', | ||
})} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexGroup> | ||
); | ||
} |
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.