@@ -44,10 +44,11 @@ export default function Korrel8rPanel() {
4444 const search : Search = useSelector ( ( state : State ) => state . plugins ?. tp ?. get ( 'search' ) ) ;
4545 const result : Result | null = useSelector ( ( state : State ) => state . plugins ?. tp ?. get ( 'result' ) ) ;
4646
47- // Is the search panel already in focus on the main view?
47+ // Disable focus button if the panel is already focused on the current location,
48+ // or the current result is an error.
4849 const isFocused = React . useMemo (
49- ( ) => locationQuery ?. toString ( ) === search . queryStr ,
50- [ locationQuery , search . queryStr ] ,
50+ ( ) => locationQuery ?. toString ( ) === search . queryStr && ! result ?. isError ,
51+ [ locationQuery , search . queryStr , result ?. isError ] ,
5152 ) ;
5253
5354 // Showing advanced query
@@ -71,11 +72,22 @@ export default function Korrel8rPanel() {
7172 [ dispatch ] ,
7273 ) ;
7374
74- // Set up default locationQuery search on mount, when query is blank.
75+ // Create the initial result on startup.
76+ // Use the current location or an explicit "Empty" result.
77+ const initialized = React . useRef ( false ) ;
7578 React . useEffect ( ( ) => {
76- if ( ! search ?. queryStr && locationQuery ?. toString ( ) )
77- dispatchSearch ( { ...defaultSearch , queryStr : locationQuery . toString ( ) } ) ;
78- } , [ locationQuery , dispatchSearch , search ?. queryStr ] ) ;
79+ if ( initialized . current ) return ;
80+ initialized . current = true ;
81+ if ( ! search ?. queryStr && ! result ) {
82+ if ( locationQuery ?. toString ( ) )
83+ dispatchSearch ( { ...defaultSearch , queryStr : locationQuery . toString ( ) } ) ;
84+ else
85+ dispatchResult ( {
86+ title : t ( 'Empty Query' ) ,
87+ message : t ( 'No starting point for correlation' ) ,
88+ } ) ;
89+ }
90+ } , [ locationQuery , dispatchSearch , dispatchResult , search ?. queryStr , result , t ] ) ;
7991
8092 // Skip the first fetch if we already have a stored result.
8193 const useStoredResult = React . useRef ( result != null ) ;
@@ -87,10 +99,8 @@ export default function Korrel8rPanel() {
8799 return ;
88100 }
89101 const queryStr = search ?. queryStr ;
90- if ( ! queryStr ) {
91- dispatchResult ( { title : t ( 'Empty Query' ) , message : t ( 'No starting point for correlation' ) } ) ;
92- return ;
93- }
102+ if ( ! queryStr ) return ;
103+
94104 let cancelled = false ;
95105 const start : api . Start = {
96106 queries : [ queryStr ] ,
@@ -141,7 +151,7 @@ export default function Korrel8rPanel() {
141151 content = {
142152 locationQuery
143153 ? isFocused
144- ? t ( 'Correlation graph is already focused on the current view.' )
154+ ? t ( 'Correlation graph is focused on the current view.' )
145155 : t ( 'Focus the correlation on the current view.' )
146156 : t ( 'Current view does not provide a starting point for correlation' )
147157 }
0 commit comments