-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] - Fix bug of alerts not updating after closure from exceptions modal #76145
[Security Solution][Exceptions] - Fix bug of alerts not updating after closure from exceptions modal #76145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ interface Props { | |
utilityBar?: (refetch: inputsModel.Refetch, totalCount: number) => React.ReactNode; | ||
// If truthy, the graph viewer (Resolver) is showing | ||
graphEventId: string | undefined; | ||
exceptionsModal?: (refetch: inputsModel.Refetch) => React.ReactNode; | ||
} | ||
|
||
const EventsViewerComponent: React.FC<Props> = ({ | ||
|
@@ -134,6 +135,7 @@ const EventsViewerComponent: React.FC<Props> = ({ | |
toggleColumn, | ||
utilityBar, | ||
graphEventId, | ||
exceptionsModal, | ||
}) => { | ||
const { globalFullScreen } = useFullScreen(); | ||
const columnsHeader = isEmpty(columns) ? defaultHeaders : columns; | ||
|
@@ -259,6 +261,7 @@ const EventsViewerComponent: React.FC<Props> = ({ | |
</HeaderFilterGroupWrapper> | ||
)} | ||
</HeaderSection> | ||
{exceptionsModal && exceptionsModal(refetch)} | ||
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. This is the callback that the modal needed access to. I followed the pattern used for the utility bar here. |
||
{utilityBar && !resolverIsShowing(graphEventId) && ( | ||
<UtilityBar>{utilityBar?.(refetch, totalCountMinusDeleted)}</UtilityBar> | ||
)} | ||
|
@@ -335,5 +338,6 @@ export const EventsViewer = React.memo( | |
prevProps.start === nextProps.start && | ||
prevProps.sort === nextProps.sort && | ||
prevProps.utilityBar === nextProps.utilityBar && | ||
prevProps.graphEventId === nextProps.graphEventId | ||
prevProps.graphEventId === nextProps.graphEventId && | ||
prevProps.exceptionsModal === nextProps.exceptionsModal | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ export interface OwnProps { | |
headerFilterGroup?: React.ReactNode; | ||
pageFilters?: Filter[]; | ||
utilityBar?: (refetch: inputsModel.Refetch, totalCount: number) => React.ReactNode; | ||
exceptionsModal?: (refetch: inputsModel.Refetch) => React.ReactNode; | ||
} | ||
|
||
type Props = OwnProps & PropsFromRedux; | ||
|
@@ -74,6 +75,7 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({ | |
utilityBar, | ||
// If truthy, the graph viewer (Resolver) is showing | ||
graphEventId, | ||
exceptionsModal, | ||
}) => { | ||
const [ | ||
{ docValueFields, browserFields, indexPatterns, isLoading: isLoadingIndexPattern }, | ||
|
@@ -156,6 +158,7 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({ | |
toggleColumn={toggleColumn} | ||
utilityBar={utilityBar} | ||
graphEventId={graphEventId} | ||
exceptionsModal={exceptionsModal} | ||
/> | ||
</InspectButtonContainer> | ||
</FullScreenContainer> | ||
|
@@ -220,6 +223,7 @@ type PropsFromRedux = ConnectedProps<typeof connector>; | |
export const StatefulEventsViewer = connector( | ||
React.memo( | ||
StatefulEventsViewerComponent, | ||
// eslint-disable-next-line complexity | ||
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. 😢 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. The complexity warning is a good warning that we can use to track tech debt. Looking below, this indeed looks close to needing a refactor from someone soon-ish. |
||
(prevProps, nextProps) => | ||
prevProps.id === nextProps.id && | ||
deepEqual(prevProps.columns, nextProps.columns) && | ||
|
@@ -240,6 +244,7 @@ export const StatefulEventsViewer = connector( | |
prevProps.showCheckboxes === nextProps.showCheckboxes && | ||
prevProps.start === nextProps.start && | ||
prevProps.utilityBar === nextProps.utilityBar && | ||
prevProps.graphEventId === nextProps.graphEventId | ||
prevProps.graphEventId === nextProps.graphEventId && | ||
prevProps.exceptionsModal === nextProps.exceptionsModal | ||
) | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,7 +228,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({ | |
exceptionListType, | ||
alertData, | ||
}: AddExceptionModalBaseProps) => { | ||
if (alertData !== null && alertData !== undefined) { | ||
if (alertData != null) { | ||
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. Nice idiomatic JS fix using the |
||
setShouldShowAddExceptionModal(true); | ||
setAddExceptionModalState({ | ||
ruleName, | ||
|
@@ -441,9 +441,43 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({ | |
closeAddExceptionModal(); | ||
}, [closeAddExceptionModal]); | ||
|
||
const onAddExceptionConfirm = useCallback(() => closeAddExceptionModal(), [ | ||
closeAddExceptionModal, | ||
]); | ||
const onAddExceptionConfirm = useCallback( | ||
(refetch: inputsModel.Refetch) => (): void => { | ||
refetch(); | ||
closeAddExceptionModal(); | ||
}, | ||
[closeAddExceptionModal] | ||
); | ||
|
||
// Callback for creating the AddExceptionModal and allowing it | ||
// access to the refetchQuery to update the page | ||
const exceptionModalCallback = useCallback( | ||
(refetchQuery: inputsModel.Refetch) => { | ||
if (shouldShowAddExceptionModal) { | ||
return ( | ||
<AddExceptionModal | ||
ruleName={addExceptionModalState.ruleName} | ||
ruleId={addExceptionModalState.ruleId} | ||
ruleIndices={addExceptionModalState.ruleIndices} | ||
exceptionListType={addExceptionModalState.exceptionListType} | ||
alertData={addExceptionModalState.alertData} | ||
onCancel={onAddExceptionCancel} | ||
onConfirm={onAddExceptionConfirm(refetchQuery)} | ||
alertStatus={filterGroup} | ||
/> | ||
); | ||
} else { | ||
return <></>; | ||
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. Small nit. We could return 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. 👍 that's a good point. Since this file is being largely refactored for 7.10, I'm leaving here for now if that's ok. Happy to revisit too. 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. For clarity a react fragment However, returning null should be faster than a react fragment and when possible to return null I think we should. 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. Thanks for the info there @FrankHassanabad ! The code was reworked here so I think it's been updated - https://github.com/elastic/kibana/pull/73228/files#diff-2d4b35336b307ef04e3129bd4aecf10aL470 |
||
} | ||
}, | ||
[ | ||
addExceptionModalState, | ||
filterGroup, | ||
onAddExceptionCancel, | ||
onAddExceptionConfirm, | ||
shouldShowAddExceptionModal, | ||
] | ||
); | ||
|
||
if (loading || indexPatternsLoading || isEmpty(signalsIndex)) { | ||
return ( | ||
|
@@ -465,19 +499,8 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({ | |
id={timelineId} | ||
start={from} | ||
utilityBar={utilityBarCallback} | ||
exceptionsModal={exceptionModalCallback} | ||
/> | ||
{shouldShowAddExceptionModal === true && addExceptionModalState.alertData !== null && ( | ||
<AddExceptionModal | ||
ruleName={addExceptionModalState.ruleName} | ||
ruleId={addExceptionModalState.ruleId} | ||
ruleIndices={addExceptionModalState.ruleIndices} | ||
exceptionListType={addExceptionModalState.exceptionListType} | ||
alertData={addExceptionModalState.alertData} | ||
onCancel={onAddExceptionCancel} | ||
onConfirm={onAddExceptionConfirm} | ||
alertStatus={filterGroup} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
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 think for the future we might wanna take a look at the structure of these files so we can lessen the number of mounts we're using, especially in cases where this test block is identical to others in this file save for the expect function. Could be a way to speed up the tests
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.
That's a great point - @patrykkopycinski is working on refactoring this code, may be interesting to look at patterns there #73228