44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import { useEffect , useRef , useState } from 'react' ;
7+ import { useEffect , useRef , useState , useCallback } from 'react' ;
88import { HttpStart } from '../../../../../../../src/core/public' ;
99
1010import {
@@ -60,7 +60,19 @@ export const useAddOrUpdateException = ({
6060 onSuccess,
6161} : UseAddOrUpdateExceptionProps ) : ReturnUseAddOrUpdateException => {
6262 const [ isLoading , setIsLoading ] = useState ( false ) ;
63- const addOrUpdateException = useRef < AddOrUpdateExceptionItemsFunc | null > ( null ) ;
63+ const addOrUpdateExceptionRef = useRef < AddOrUpdateExceptionItemsFunc | null > ( null ) ;
64+ const addOrUpdateException = useCallback < AddOrUpdateExceptionItemsFunc > (
65+ async ( exceptionItemsToAddOrUpdate , alertIdToClose , bulkCloseIndex ) => {
66+ if ( addOrUpdateExceptionRef . current !== null ) {
67+ addOrUpdateExceptionRef . current (
68+ exceptionItemsToAddOrUpdate ,
69+ alertIdToClose ,
70+ bulkCloseIndex
71+ ) ;
72+ }
73+ } ,
74+ [ ]
75+ ) ;
6476
6577 useEffect ( ( ) => {
6678 let isSubscribed = true ;
@@ -114,6 +126,7 @@ export const useAddOrUpdateException = ({
114126 await updateAlertStatus ( {
115127 query : getUpdateAlertsQuery ( [ alertIdToClose ] ) ,
116128 status : 'closed' ,
129+ signal : abortCtrl . signal ,
117130 } ) ;
118131 }
119132
@@ -131,6 +144,7 @@ export const useAddOrUpdateException = ({
131144 query : filter ,
132145 } ,
133146 status : 'closed' ,
147+ signal : abortCtrl . signal ,
134148 } ) ;
135149 }
136150
@@ -148,12 +162,12 @@ export const useAddOrUpdateException = ({
148162 }
149163 } ;
150164
151- addOrUpdateException . current = addOrUpdateExceptionItems ;
165+ addOrUpdateExceptionRef . current = addOrUpdateExceptionItems ;
152166 return ( ) : void => {
153167 isSubscribed = false ;
154168 abortCtrl . abort ( ) ;
155169 } ;
156170 } , [ http , onSuccess , onError ] ) ;
157171
158- return [ { isLoading } , addOrUpdateException . current ] ;
172+ return [ { isLoading } , addOrUpdateException ] ;
159173} ;
0 commit comments