@@ -56,8 +56,9 @@ const WrappedTargetingHosts = () => {
5656 }
5757 } , [ dispatch , intervalExists ] ) ;
5858
59- // Use ref to avoid infinite loop from handleSearch depending on pagination.per_page
59+ // Use refs to avoid infinite loop from handleSearch depending on pagination.per_page and searchQuery
6060 const perPageRef = useRef ( pagination . per_page ) ;
61+ const searchQueryRef = useRef ( searchQuery ) ;
6162
6263 const handleSearch = useCallback (
6364 ( query , status ) => {
@@ -71,11 +72,15 @@ const WrappedTargetingHosts = () => {
7172 [ stopApiInterval ]
7273 ) ;
7374
74- // Keep ref in sync with pagination
75+ // Keep refs in sync with state
7576 useEffect ( ( ) => {
7677 perPageRef . current = pagination . per_page ;
7778 } , [ pagination . per_page ] ) ;
7879
80+ useEffect ( ( ) => {
81+ searchQueryRef . current = searchQuery ;
82+ } , [ searchQuery ] ) ;
83+
7984 const handlePagination = useCallback (
8085 args => {
8186 stopApiInterval ( ) ;
@@ -112,9 +117,19 @@ const WrappedTargetingHosts = () => {
112117 } ;
113118 } , [ dispatch , apiUrl , autoRefresh , getData ] ) ;
114119
120+ // Only respond to external statusFilter changes (from chart clicks)
121+ // searchQuery changes are handled directly by handleSearch calls from the UI
115122 useEffect ( ( ) => {
116- handleSearch ( searchQuery , statusFilter ) ;
117- } , [ statusFilter , searchQuery , handleSearch ] ) ;
123+ dispatch ( stopInterval ( TARGETING_HOSTS ) ) ;
124+ const defaultPagination = { page : 1 , per_page : perPageRef . current } ;
125+ setApiUrl (
126+ getApiUrl (
127+ buildSearchQuery ( searchQueryRef . current , statusFilter ) ,
128+ defaultPagination
129+ )
130+ ) ;
131+ setPagination ( defaultPagination ) ;
132+ } , [ statusFilter , dispatch ] ) ;
118133
119134 return (
120135 < TargetingHostsPage
0 commit comments