-
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.
[SIEM][Exceptions] - ExceptionsViewer UI component part 2 (#68294)
### Summary This PR is a follow up to #68027 . It brings it all together to complete the exceptions viewer component. This component is meant to display all exception items and allow a user to create, edit, delete, and search these exception items. - Moves ExceptionItem (from part 1) into its own folder - Adds exceptions_viewer_header component that includes the search, list toggle, and add exception buttons - Adds actual ExceptionViewer component - Updates the useExceptionList hook refresh function logic. Noticed that the previous version was creating some issues
- Loading branch information
Showing
30 changed files
with
2,266 additions
and
254 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
x-pack/plugins/lists/public/exceptions/hooks/use_api.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,111 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useMemo } from 'react'; | ||
|
||
import * as Api from '../api'; | ||
import { HttpStart } from '../../../../../../src/core/public'; | ||
import { ExceptionListItemSchema, ExceptionListSchema } from '../../../common/schemas'; | ||
import { ApiCallMemoProps } from '../types'; | ||
|
||
export interface ExceptionsApi { | ||
deleteExceptionItem: (arg: ApiCallMemoProps) => Promise<void>; | ||
deleteExceptionList: (arg: ApiCallMemoProps) => Promise<void>; | ||
getExceptionItem: ( | ||
arg: ApiCallMemoProps & { onSuccess: (arg: ExceptionListItemSchema) => void } | ||
) => Promise<void>; | ||
getExceptionList: ( | ||
arg: ApiCallMemoProps & { onSuccess: (arg: ExceptionListSchema) => void } | ||
) => Promise<void>; | ||
} | ||
|
||
export const useApi = (http: HttpStart): ExceptionsApi => { | ||
return useMemo( | ||
(): ExceptionsApi => ({ | ||
async deleteExceptionItem({ | ||
id, | ||
namespaceType, | ||
onSuccess, | ||
onError, | ||
}: ApiCallMemoProps): Promise<void> { | ||
const abortCtrl = new AbortController(); | ||
|
||
try { | ||
await Api.deleteExceptionListItemById({ | ||
http, | ||
id, | ||
namespaceType, | ||
signal: abortCtrl.signal, | ||
}); | ||
onSuccess(); | ||
} catch (error) { | ||
onError(error); | ||
} | ||
}, | ||
async deleteExceptionList({ | ||
id, | ||
namespaceType, | ||
onSuccess, | ||
onError, | ||
}: ApiCallMemoProps): Promise<void> { | ||
const abortCtrl = new AbortController(); | ||
|
||
try { | ||
await Api.deleteExceptionListById({ | ||
http, | ||
id, | ||
namespaceType, | ||
signal: abortCtrl.signal, | ||
}); | ||
onSuccess(); | ||
} catch (error) { | ||
onError(error); | ||
} | ||
}, | ||
async getExceptionItem({ | ||
id, | ||
namespaceType, | ||
onSuccess, | ||
onError, | ||
}: ApiCallMemoProps & { onSuccess: (arg: ExceptionListItemSchema) => void }): Promise<void> { | ||
const abortCtrl = new AbortController(); | ||
|
||
try { | ||
const item = await Api.fetchExceptionListItemById({ | ||
http, | ||
id, | ||
namespaceType, | ||
signal: abortCtrl.signal, | ||
}); | ||
onSuccess(item); | ||
} catch (error) { | ||
onError(error); | ||
} | ||
}, | ||
async getExceptionList({ | ||
id, | ||
namespaceType, | ||
onSuccess, | ||
onError, | ||
}: ApiCallMemoProps & { onSuccess: (arg: ExceptionListSchema) => void }): Promise<void> { | ||
const abortCtrl = new AbortController(); | ||
|
||
try { | ||
const list = await Api.fetchExceptionListById({ | ||
http, | ||
id, | ||
namespaceType, | ||
signal: abortCtrl.signal, | ||
}); | ||
onSuccess(list); | ||
} catch (error) { | ||
onError(error); | ||
} | ||
}, | ||
}), | ||
[http] | ||
); | ||
}; |
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.