@@ -62,46 +62,66 @@ export default function Korrel8rPanel() {
6262 return new korrel8r . Constraint ( { start : pStart , end : pEnd } ) ;
6363 } , [ search . period ] ) ;
6464
65- const initialized = React . useRef ( false ) ;
65+ // Call korrel8r service to get results for the current search.
6666 React . useEffect ( ( ) => {
67- if ( initialized . current ) return ; // Run once on mount
68- initialized . current = true ;
69- if ( ! search ?. queryStr && locationQuery ) {
70- dispatch ( setSearch ( { ...defaultSearch , queryStr : locationQuery . toString ( ) } ) ) ;
71- }
72- } , [ search ?. queryStr , locationQuery , dispatch ] ) ;
73-
74- React . useEffect ( ( ) => {
75- // Leave stored result in place if there is one.
76- // Dispatching SetSearch clears result to null, triggering a new fetch.
67+ // If we already have a stored result, do nothing.
68+ // Dispatching SetSearch sets result=null, triggering a new fetch.
7769 if ( result ) return ;
7870
79- const queryStr = search ?. queryStr ?. trim ( ) ;
80- const start : api . Start = {
81- queries : queryStr ? [ queryStr ] : undefined ,
82- constraint : constraint ?. toAPI ( ) ,
83- } ;
8471 let cancelled = false ;
8572 const onResult = ( newResult : Result ) => {
8673 if ( ! cancelled ) dispatch ( setResult ( newResult ) ) ;
8774 } ;
75+
76+ const queryStr = ( search ?. queryStr ?? '' ) . trim ( ) ;
77+
78+ if ( ! queryStr ) {
79+ // Default query or empty result
80+ if ( locationQuery ?. toString ( ) ) {
81+ dispatch ( setSearch ( { ...defaultSearch , queryStr : locationQuery ?. toString ( ) } ) ) ;
82+ } else {
83+ dispatch (
84+ setResult ( {
85+ title : t ( 'Empty Query' ) ,
86+ message : t ( 'No starting point for correlation' ) ,
87+ } ) ,
88+ ) ;
89+ }
90+ return ;
91+ }
92+
93+ const start : api . Start = {
94+ queries : queryStr ? [ queryStr ] : undefined ,
95+ constraint : constraint ?. toAPI ( ) ,
96+ } ;
97+
8898 const fetch =
8999 search . searchType === SearchType . Goal
90100 ? getGoalsGraph ( { start, goals : [ search . goal ] } )
91101 : getNeighborsGraph ( { start, depth : search . depth } ) ;
92102 fetch
93- . then ( ( response : api . Graph ) => onResult ( { graph : new korrel8r . Graph ( response ) } ) )
103+ . then ( ( response : api . Graph ) => {
104+ if ( Array . isArray ( response ?. nodes ) && response . nodes . length > 0 ) {
105+ onResult ( { graph : new korrel8r . Graph ( response ) } ) ;
106+ } else {
107+ onResult ( {
108+ title : t ( 'Empty Result' ) ,
109+ message : t ( 'No correlated data was found' ) ,
110+ } ) ;
111+ }
112+ } )
94113 . catch ( ( e : api . ApiError ) => {
95114 onResult ( {
96115 title : e ?. body ?. error ? t ( 'Korrel8r Error' ) : t ( 'Request Failed' ) ,
97116 message : e ?. body ?. error || e . message || 'Unknown Error' ,
117+ isError : true ,
98118 } ) ;
99119 } ) ;
100120 return ( ) => {
101121 cancelled = true ;
102122 fetch . cancel ( ) ;
103123 } ;
104- } , [ search , t , result , constraint , dispatch ] ) ;
124+ } , [ search , t , result , constraint , dispatch , locationQuery ] ) ;
105125
106126 const advancedToggleID = 'query-toggle' ;
107127 const advancedContentID = 'query-content' ;
@@ -124,9 +144,9 @@ export default function Korrel8rPanel() {
124144 content = {
125145 locationQuery
126146 ? isFocused
127- ? t ( 'Correlation graph is focused on the main view.' )
128- : t ( 'Focus the correlation on the main view.' )
129- : t ( 'Current view does not allow correlation. ' )
147+ ? t ( 'Correlation graph is already focused on the current view.' )
148+ : t ( 'Focus the correlation on the current view.' )
149+ : t ( 'Current view does not provide a starting point for correlation' )
130150 }
131151 >
132152 < Button
0 commit comments