-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution][Exceptions] - Improve UX for missing exception list associated with rule #75898
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,14 @@ import { | |
} from '@elastic/eui'; | ||
import { useFetchIndexPatterns } from '../../../../detections/containers/detection_engine/rules'; | ||
import { useSignalIndex } from '../../../../detections/containers/detection_engine/alerts/use_signal_index'; | ||
import { useRuleAsync } from '../../../../detections/containers/detection_engine/rules/use_rule_async'; | ||
import { | ||
ExceptionListItemSchema, | ||
CreateExceptionListItemSchema, | ||
ExceptionListType, | ||
} from '../../../../../public/lists_plugin_deps'; | ||
import * as i18n from './translations'; | ||
import * as sharedI18n from '../translations'; | ||
import { useKibana } from '../../../lib/kibana'; | ||
import { useAppToasts } from '../../../hooks/use_app_toasts'; | ||
import { ExceptionBuilderComponent } from '../builder'; | ||
|
@@ -43,14 +45,17 @@ import { | |
lowercaseHashValues, | ||
} from '../helpers'; | ||
import { Loader } from '../../loader'; | ||
import { ErrorInfo, ErrorCallout } from '../error_callout'; | ||
|
||
interface EditExceptionModalProps { | ||
ruleName: string; | ||
ruleId: string; | ||
ruleIndices: string[]; | ||
exceptionItem: ExceptionListItemSchema; | ||
exceptionListType: ExceptionListType; | ||
onCancel: () => void; | ||
onConfirm: () => void; | ||
onRuleChange?: () => void; | ||
} | ||
|
||
const Modal = styled(EuiModal)` | ||
|
@@ -83,14 +88,18 @@ const ModalBodySection = styled.section` | |
|
||
export const EditExceptionModal = memo(function EditExceptionModal({ | ||
ruleName, | ||
ruleId, | ||
ruleIndices, | ||
exceptionItem, | ||
exceptionListType, | ||
onCancel, | ||
onConfirm, | ||
onRuleChange, | ||
}: EditExceptionModalProps) { | ||
const { http } = useKibana().services; | ||
const [comment, setComment] = useState(''); | ||
const { rule: maybeRule } = useRuleAsync(ruleId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may be able to refactor these modals to have a common parent, since they both repeat a good amount of logic, right now just doubling logic in each file. |
||
const [updateError, setUpdateError] = useState<ErrorInfo | null>(null); | ||
const [hasVersionConflict, setHasVersionConflict] = useState(false); | ||
const [shouldBulkCloseAlert, setShouldBulkCloseAlert] = useState(false); | ||
const [shouldDisableBulkClose, setShouldDisableBulkClose] = useState(false); | ||
|
@@ -108,27 +117,53 @@ export const EditExceptionModal = memo(function EditExceptionModal({ | |
'rules' | ||
); | ||
|
||
const onError = useCallback( | ||
(error) => { | ||
const handleExceptionUpdateError = useCallback( | ||
(error: Error, statusCode: number | null, message: string | null) => { | ||
if (error.message.includes('Conflict')) { | ||
setHasVersionConflict(true); | ||
} else { | ||
addError(error, { title: i18n.EDIT_EXCEPTION_ERROR }); | ||
onCancel(); | ||
setUpdateError({ | ||
reason: error.message, | ||
code: statusCode, | ||
details: message, | ||
listListId: exceptionItem.list_id, | ||
}); | ||
} | ||
}, | ||
[setUpdateError, setHasVersionConflict, exceptionItem.list_id] | ||
); | ||
|
||
const handleDissasociationSuccess = useCallback( | ||
(id: string): void => { | ||
addSuccess(sharedI18n.DISSASOCIATE_LIST_SUCCESS(id)); | ||
|
||
if (onRuleChange) { | ||
onRuleChange(); | ||
} | ||
|
||
onCancel(); | ||
}, | ||
[addSuccess, onCancel, onRuleChange] | ||
); | ||
|
||
const handleDissasociationError = useCallback( | ||
(error: Error): void => { | ||
addError(error, { title: sharedI18n.DISSASOCIATE_EXCEPTION_LIST_ERROR }); | ||
onCancel(); | ||
}, | ||
[addError, onCancel] | ||
); | ||
const onSuccess = useCallback(() => { | ||
|
||
const handleExceptionUpdateSuccess = useCallback((): void => { | ||
addSuccess(i18n.EDIT_EXCEPTION_SUCCESS); | ||
onConfirm(); | ||
}, [addSuccess, onConfirm]); | ||
|
||
const [{ isLoading: addExceptionIsLoading }, addOrUpdateExceptionItems] = useAddOrUpdateException( | ||
{ | ||
http, | ||
onSuccess, | ||
onError, | ||
onSuccess: handleExceptionUpdateSuccess, | ||
onError: handleExceptionUpdateError, | ||
} | ||
); | ||
|
||
|
@@ -222,11 +257,9 @@ export const EditExceptionModal = memo(function EditExceptionModal({ | |
{ruleName} | ||
</ModalHeaderSubtitle> | ||
</ModalHeader> | ||
|
||
{(addExceptionIsLoading || isIndexPatternLoading || isSignalIndexLoading) && ( | ||
<Loader data-test-subj="loadingEditExceptionModal" size="xl" /> | ||
)} | ||
|
||
{!isSignalIndexLoading && !addExceptionIsLoading && !isIndexPatternLoading && ( | ||
<> | ||
<ModalBodySection className="builder-section"> | ||
|
@@ -280,28 +313,40 @@ export const EditExceptionModal = memo(function EditExceptionModal({ | |
</ModalBodySection> | ||
</> | ||
)} | ||
|
||
{updateError != null && ( | ||
<ModalBodySection> | ||
<ErrorCallout | ||
http={http} | ||
errorInfo={updateError} | ||
rule={maybeRule} | ||
onCancel={onCancel} | ||
onSuccess={handleDissasociationSuccess} | ||
onError={handleDissasociationError} | ||
/> | ||
</ModalBodySection> | ||
)} | ||
{hasVersionConflict && ( | ||
<ModalBodySection> | ||
<EuiCallOut title={i18n.VERSION_CONFLICT_ERROR_TITLE} color="danger" iconType="alert"> | ||
<p>{i18n.VERSION_CONFLICT_ERROR_DESCRIPTION}</p> | ||
</EuiCallOut> | ||
</ModalBodySection> | ||
)} | ||
{updateError == null && ( | ||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={onCancel}>{i18n.CANCEL}</EuiButtonEmpty> | ||
|
||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={onCancel}>{i18n.CANCEL}</EuiButtonEmpty> | ||
|
||
<EuiButton | ||
data-test-subj="edit-exception-confirm-button" | ||
onClick={onEditExceptionConfirm} | ||
isLoading={addExceptionIsLoading} | ||
isDisabled={isSubmitButtonDisabled} | ||
fill | ||
> | ||
{i18n.EDIT_EXCEPTION_SAVE_BUTTON} | ||
</EuiButton> | ||
</EuiModalFooter> | ||
<EuiButton | ||
data-test-subj="edit-exception-confirm-button" | ||
onClick={onEditExceptionConfirm} | ||
isLoading={addExceptionIsLoading} | ||
isDisabled={isSubmitButtonDisabled} | ||
fill | ||
> | ||
{i18n.EDIT_EXCEPTION_SAVE_BUTTON} | ||
</EuiButton> | ||
</EuiModalFooter> | ||
)} | ||
</Modal> | ||
</EuiOverlayMask> | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this here to pull out the exception list details of the issue exception list. The error itself gives an
id
but no other info. Thought of reworkinguseFetchOrCreateRuleExceptionList
to pull out the call it makes to the rule, but wanted to minimize changes for backport to 7.9.1.