mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Security Solution] [Exceptions] fixes error not displaying when importing invalid exception list (#147143)
## Summary Ref: https://github.com/elastic/kibana/issues/146871 Also restores functionality where if a user tries to import an exception list that already exists within the system, they are offered up options as to how to proceed; either by overwriting the current list or importing this list as a different list.
This commit is contained in:
parent
170de2dcd4
commit
6d5b292638
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