mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[8.6] [Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143) (#147192)
# Backport This will backport the following commits from `main` to `8.6`: - [[Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143)](https://github.com/elastic/kibana/pull/147143) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Devin W. Hurley","email":"devin.hurley@elastic.co"},"sourceCommit":{"committedDate":"2022-12-07T15:06:24Z","message":"[Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143)\n\n## Summary\r\n\r\nRef: https://github.com/elastic/kibana/issues/146871\r\n\r\nAlso restores functionality where if a user tries to import an exception\r\nlist that already exists within the system, they are offered up options\r\nas to how to proceed; either by overwriting the current list or\r\nimporting this list as a different list.","sha":"6d5b29263821b96ab2fdba8c92d59e0a264b91c1","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:skip","impact:critical","Feature:Rule Exceptions","Team:Security Solution Platform","v8.6.0","v8.7.0"],"number":147143,"url":"https://github.com/elastic/kibana/pull/147143","mergeCommit":{"message":"[Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143)\n\n## Summary\r\n\r\nRef: https://github.com/elastic/kibana/issues/146871\r\n\r\nAlso restores functionality where if a user tries to import an exception\r\nlist that already exists within the system, they are offered up options\r\nas to how to proceed; either by overwriting the current list or\r\nimporting this list as a different list.","sha":"6d5b29263821b96ab2fdba8c92d59e0a264b91c1"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/147143","number":147143,"mergeCommit":{"message":"[Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143)\n\n## Summary\r\n\r\nRef: https://github.com/elastic/kibana/issues/146871\r\n\r\nAlso restores functionality where if a user tries to import an exception\r\nlist that already exists within the system, they are offered up options\r\nas to how to proceed; either by overwriting the current list or\r\nimporting this list as a different list.","sha":"6d5b29263821b96ab2fdba8c92d59e0a264b91c1"}}]}] BACKPORT--> Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
This commit is contained in:
parent
b16ce7f6d4
commit
f9f1c86186
1 changed files with 25 additions and 8 deletions
|
@ -55,6 +55,7 @@ export const ImportExceptionListFlyout = React.memo(
|
|||
const [file, setFile] = useState<File | null>(null);
|
||||
const [overwrite, setOverwrite] = useState(false);
|
||||
const [asNewList, setAsNewList] = useState(false);
|
||||
const [alreadyExistingItem, setAlreadyExistingItem] = useState(false);
|
||||
|
||||
const resetForm = useCallback(() => {
|
||||
if (filePickerRef.current?.fileInput) {
|
||||
|
@ -97,7 +98,8 @@ export const ImportExceptionListFlyout = React.memo(
|
|||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[resetForm, addSuccess, handleRefresh]
|
||||
);
|
||||
const handleImportError = useCallback(
|
||||
|
||||
const handleImportErrors = useCallback(
|
||||
(errors: BulkErrorSchema[]) => {
|
||||
errors.forEach((error) => {
|
||||
if (!error.error.message.includes('AbortError')) {
|
||||
|
@ -107,23 +109,38 @@ export const ImportExceptionListFlyout = React.memo(
|
|||
},
|
||||
[addError]
|
||||
);
|
||||
const [alreadyExistingItem, setAlreadyExistingItem] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!importExceptionListState.loading) {
|
||||
if (importExceptionListState?.result?.success) {
|
||||
handleImportSuccess(importExceptionListState?.result);
|
||||
} else if (importExceptionListState?.result?.errors) {
|
||||
handleImportError(importExceptionListState?.result?.errors);
|
||||
} else {
|
||||
const errorsToDisplay: BulkErrorSchema[] = [];
|
||||
// @ts-expect-error
|
||||
if (importExceptionListState?.error?.body) {
|
||||
errorsToDisplay.push({
|
||||
// @ts-expect-error
|
||||
error: { ...importExceptionListState?.error?.body },
|
||||
});
|
||||
}
|
||||
if (importExceptionListState?.result?.errors) {
|
||||
importExceptionListState?.result?.errors.forEach((err) => {
|
||||
if (err.error.message.includes('already exists')) {
|
||||
setAlreadyExistingItem(true);
|
||||
}
|
||||
errorsToDisplay.push(err);
|
||||
});
|
||||
}
|
||||
handleImportErrors(errorsToDisplay);
|
||||
}
|
||||
}
|
||||
}, [
|
||||
handleImportError,
|
||||
handleImportErrors,
|
||||
handleImportSuccess,
|
||||
importExceptionListState.error,
|
||||
importExceptionListState?.error,
|
||||
importExceptionListState.loading,
|
||||
importExceptionListState.result,
|
||||
setAlreadyExistingItem,
|
||||
importExceptionListState?.result,
|
||||
importExceptionListState?.result?.errors,
|
||||
]);
|
||||
const handleFileChange = useCallback((files: FileList | null) => {
|
||||
setFile(files?.item(0) ?? null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue