@@ -57,7 +57,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
5757} ) => {
5858 const { breakpoints } = tokens ;
5959 const isTablet = useMediaQuery ( `(min-width:${ breakpoints . xs } ) and (max-width: ${ breakpoints . lg } )` ) ;
60- const [ activeTab , setActiveTab ] = useState < number > ( error . length ? 10 : mode === 'graph' ? 4 : 3 ) ;
60+ const [ activeTab , setActiveTab ] = useState < number > ( error ? .length ? 10 : mode === 'graph' ? 4 : 3 ) ;
6161 const [ infoEntities , setInfoEntities ] = useState < Entity [ ] > ( [ ] ) ;
6262 const [ communities , setCommunities ] = useState < Community [ ] > ( [ ] ) ;
6363 const [ loading , setLoading ] = useState < boolean > ( false ) ;
@@ -106,8 +106,30 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
106106 if ( response . data . status === 'Failure' ) {
107107 throw new Error ( response . data . error ) ;
108108 }
109- setInfoEntities ( response . data . data . nodes ) ;
110- setNodes ( response . data . data . nodes ) ;
109+ setInfoEntities (
110+ response . data . data . nodes . map ( ( n : Entity ) => {
111+ if ( ! n . labels . length && mode === 'entity search+vector' ) {
112+ return {
113+ ...n ,
114+ labels : [ 'Entity' ] ,
115+ } ;
116+ }
117+ return n ;
118+
119+ } )
120+ ) ;
121+ setNodes (
122+ response . data . data . nodes . map ( ( n : ExtendedNode ) => {
123+ if ( ! n . labels . length && mode === 'entity search+vector' ) {
124+ return {
125+ ...n ,
126+ labels : [ 'Entity' ] ,
127+ } ;
128+ }
129+ return n ;
130+
131+ } )
132+ ) ;
111133 setRelationships ( response . data . data . relationships ) ;
112134 setCommunities ( response . data . data . community_data ) ;
113135 const chunks = response . data . data . chunk_data . map ( ( chunk : any ) => {
@@ -132,15 +154,17 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
132154 } , [ chunk_ids , mode , error ] ) ;
133155
134156 const groupedEntities = useMemo < { [ key : string ] : GroupedEntity } > ( ( ) => {
135- return infoEntities . reduce ( ( acc , entity ) => {
157+ const items = infoEntities . reduce ( ( acc , entity ) => {
136158 const { label, text } = parseEntity ( entity ) ;
137159 if ( ! acc [ label ] ) {
160+ console . log ( { label, text } ) ;
138161 const newColor = calcWordColor ( label ) ;
139162 acc [ label ] = { texts : new Set ( ) , color : newColor } ;
140163 }
141164 acc [ label ] . texts . add ( text ) ;
142165 return acc ;
143166 } , { } as Record < string , { texts : Set < string > ; color : string } > ) ;
167+ return items ;
144168 } , [ infoEntities ] ) ;
145169
146170 const onChangeTabs = ( tabId : number ) => {
@@ -149,7 +173,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
149173
150174 const labelCounts = useMemo ( ( ) => {
151175 const counts : { [ label : string ] : number } = { } ;
152- for ( let index = 0 ; index < infoEntities . length ; index ++ ) {
176+ for ( let index = 0 ; index < infoEntities ? .length ; index ++ ) {
153177 const entity = infoEntities [ index ] ;
154178 const { labels } = entity ;
155179 const [ label ] = labels ;
@@ -205,7 +229,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
205229 ) : (
206230 < > </ >
207231 ) }
208- { mode === 'graph' && cypher_query ?. trim ( ) . length ? (
232+ { mode === 'graph' && cypher_query ?. trim ( ) ? .length ? (
209233 < Tabs . Tab tabId = { 6 } > Generated Cypher Query</ Tabs . Tab >
210234 ) : (
211235 < > </ >
@@ -219,10 +243,10 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
219243 < Box className = 'flex justify-center items-center' >
220244 < LoadingSpinner size = 'small' />
221245 </ Box >
222- ) : mode === 'entity search+vector' && chunks . length ? (
246+ ) : mode === 'entity search+vector' && chunks ? .length ? (
223247 < ul >
224248 { chunks
225- . map ( ( c ) => ( { fileName : c . fileName , fileSource : c . fileType } ) )
249+ . map ( ( c ) => ( { fileName : c . fileName , fileSource : c . fileSource } ) )
226250 . map ( ( s , index ) => {
227251 return (
228252 < li key = { index } className = 'flex flex-row inline-block justify-between items-center p-2' >
@@ -235,7 +259,6 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
235259 width = { 20 }
236260 height = { 20 }
237261 className = 'mr-2'
238- alt = 'S3 Logo'
239262 />
240263 ) }
241264 < Typography
@@ -249,7 +272,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
249272 ) ;
250273 } ) }
251274 </ ul >
252- ) : sources . length ? (
275+ ) : sources ? .length ? (
253276 < ul className = 'list-class list-none' >
254277 { sources . map ( ( link , index ) => {
255278 return (
@@ -351,7 +374,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
351374 < Box className = 'flex justify-center items-center' >
352375 < LoadingSpinner size = 'small' />
353376 </ Box >
354- ) : Object . keys ( groupedEntities ) . length > 0 || Object . keys ( graphonly_entities ) . length > 0 ? (
377+ ) : Object . keys ( groupedEntities ) ? .length > 0 || Object . keys ( graphonly_entities ) ? .length > 0 ? (
355378 < ul className = 'list-none p-4 max-h-80 overflow-auto' >
356379 { mode == 'graph'
357380 ? graphonly_entities . map ( ( label , index ) => (
@@ -367,26 +390,25 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
367390 </ div >
368391 </ li >
369392 ) )
370- : sortedLabels . map ( ( label , index ) => (
371- < li
372- key = { index }
373- className = 'flex items-center mb-2 text-ellipsis whitespace-nowrap max-w-[100%)] overflow-hidden'
374- >
375- < div
393+ : sortedLabels . map ( ( label , index ) => {
394+ const entity = groupedEntities [ label == 'undefined' ? 'Entity' : label ] ;
395+ return (
396+ < li
376397 key = { index }
377- style = { { backgroundColor : `${ groupedEntities [ label ] . color } ` } }
378- className = 'legend mr-2'
379- >
380- { label } ({ labelCounts [ label ] } )
381- </ div >
382- < Typography
383- className = 'entity-text text-ellipsis whitespace-nowrap max-w-[calc(100%-120px)] overflow-hidden'
384- variant = 'body-medium'
398+ className = 'flex items-center mb-2 text-ellipsis whitespace-nowrap max-w-[100%)] overflow-hidden'
385399 >
386- { Array . from ( groupedEntities [ label ] . texts ) . slice ( 0 , 3 ) . join ( ', ' ) }
387- </ Typography >
388- </ li >
389- ) ) }
400+ < div key = { index } style = { { backgroundColor : `${ entity . color } ` } } className = 'legend mr-2' >
401+ { label } ({ labelCounts [ label ] } )
402+ </ div >
403+ < Typography
404+ className = 'entity-text text-ellipsis whitespace-nowrap max-w-[calc(100%-120px)] overflow-hidden'
405+ variant = 'body-medium'
406+ >
407+ { Array . from ( entity . texts ) . slice ( 0 , 3 ) . join ( ', ' ) }
408+ </ Typography >
409+ </ li >
410+ ) ;
411+ } ) }
390412 </ ul >
391413 ) : (
392414 < span className = 'h6 text-center' > No Entities Found</ span >
@@ -397,7 +419,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
397419 < Box className = 'flex justify-center items-center' >
398420 < LoadingSpinner size = 'small' />
399421 </ Box >
400- ) : chunks . length > 0 ? (
422+ ) : chunks ? .length > 0 ? (
401423 < div className = 'p-4 h-80 overflow-auto' >
402424 < ul className = 'list-disc list-inside' >
403425 { chunks . map ( ( chunk ) => (
@@ -522,7 +544,7 @@ const ChatInfoModal: React.FC<chatInfoMessage> = ({
522544 < > </ >
523545 ) }
524546 </ Flex >
525- { activeTab == 4 && nodes . length && relationships . length ? (
547+ { activeTab == 4 && nodes ? .length && relationships ? .length ? (
526548 < Box className = 'button-container flex mt-2 justify-center' >
527549 < GraphViewButton nodeValues = { nodes } relationshipValues = { relationships } />
528550 </ Box >
0 commit comments