@@ -19,13 +19,13 @@ import { LegendsChip } from './LegendsChip';
1919import graphQueryAPI from '../../services/GraphQuery' ;
2020import {
2121 entityGraph ,
22+ graphQuery ,
2223 graphView ,
2324 intitalGraphType ,
2425 knowledgeGraph ,
2526 lexicalGraph ,
2627 mouseEventCallbacks ,
2728 nvlOptions ,
28- queryMap ,
2929} from '../../utils/Constants' ;
3030import { useFileContext } from '../../context/UsersFiles' ;
3131// import CheckboxSelection from './CheckboxSelection';
@@ -37,6 +37,7 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
3737 viewPoint,
3838 nodeValues,
3939 relationshipValues,
40+ processingCheck,
4041} ) => {
4142 const nvlRef = useRef < NVL > ( null ) ;
4243 const [ nodes , setNodes ] = useState < Node [ ] > ( [ ] ) ;
@@ -62,12 +63,15 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
6263 // }
6364 // setGraphType(newGraphSelected);
6465 // };
66+
6567 const handleZoomToFit = ( ) => {
6668 nvlRef . current ?. fit (
6769 allNodes . map ( ( node ) => node . id ) ,
6870 { }
6971 ) ;
7072 } ;
73+
74+ // Destroy the component
7175 useEffect ( ( ) => {
7276 const timeoutId = setTimeout ( ( ) => {
7377 handleZoomToFit ( ) ;
@@ -83,23 +87,52 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
8387 setAllRelationships ( [ ] ) ;
8488 } ;
8589 } , [ ] ) ;
86- const graphQuery : string = queryMap . DocChunkEntities ;
90+
91+ // To get nodes and relations on basis of view
8792 const fetchData = useCallback ( async ( ) => {
8893 try {
8994 const nodeRelationshipData =
9095 viewPoint === 'showGraphView'
9196 ? await graphQueryAPI (
92- userCredentials as UserCredentials ,
93- graphQuery ,
94- selectedRows . map ( ( f ) => JSON . parse ( f ) . name )
95- )
97+ userCredentials as UserCredentials ,
98+ graphQuery ,
99+ selectedRows . map ( ( f ) => JSON . parse ( f ) . name )
100+ )
96101 : await graphQueryAPI ( userCredentials as UserCredentials , graphQuery , [ inspectedName ?? '' ] ) ;
97102 return nodeRelationshipData ;
98103 } catch ( error : any ) {
99104 console . log ( error ) ;
100105 }
101106 } , [ viewPoint , selectedRows , graphQuery , inspectedName , userCredentials ] ) ;
102107
108+ // Api call to get the nodes and relations
109+ const graphApi = ( ) => {
110+ fetchData ( )
111+ . then ( ( result ) => {
112+ if ( result && result . data . data . nodes . length > 0 ) {
113+ const neoNodes = result . data . data . nodes . map ( ( f : Node ) => f ) ;
114+ const neoRels = result . data . data . relationships . map ( ( f : Relationship ) => f ) ;
115+ const { finalNodes, finalRels, schemeVal } = processGraphData ( neoNodes , neoRels ) ;
116+ setAllNodes ( finalNodes ) ;
117+ setAllRelationships ( finalRels ) ;
118+ setScheme ( schemeVal ) ;
119+ setNodes ( finalNodes ) ;
120+ setRelationships ( finalRels ) ;
121+ setNewScheme ( schemeVal ) ;
122+ setLoading ( false ) ;
123+ } else {
124+ setLoading ( false ) ;
125+ setStatus ( 'danger' ) ;
126+ setStatusMessage ( `No Nodes and Relations for the ${ inspectedName } file` ) ;
127+ }
128+ } )
129+ . catch ( ( error : any ) => {
130+ setLoading ( false ) ;
131+ setStatus ( 'danger' ) ;
132+ setStatusMessage ( error . message ) ;
133+ } ) ;
134+ } ;
135+
103136 useEffect ( ( ) => {
104137 if ( open ) {
105138 setLoading ( true ) ;
@@ -113,36 +146,11 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
113146 setNewScheme ( schemeVal ) ;
114147 setLoading ( false ) ;
115148 } else {
116- fetchData ( )
117- . then ( ( result ) => {
118- if ( result && result . data . data . nodes . length > 0 ) {
119- const neoNodes = result . data . data . nodes . map ( ( f : Node ) => f ) ;
120- const neoRels = result . data . data . relationships . map ( ( f : Relationship ) => f ) ;
121- const { finalNodes, finalRels, schemeVal } = processGraphData ( neoNodes , neoRels ) ;
122- setAllNodes ( finalNodes ) ;
123- setAllRelationships ( finalRels ) ;
124- setScheme ( schemeVal ) ;
125- setNodes ( finalNodes ) ;
126- setRelationships ( finalRels ) ;
127- setNewScheme ( schemeVal ) ;
128- setLoading ( false ) ;
129- } else {
130- setLoading ( false ) ;
131- setStatus ( 'danger' ) ;
132- setStatusMessage ( `Unable to retrieve document graph for ${ inspectedName } ` ) ;
133- }
134- } )
135- . catch ( ( error : any ) => {
136- setLoading ( false ) ;
137- setStatus ( 'danger' ) ;
138- setStatusMessage ( error . message ) ;
139- } ) ;
149+ graphApi ( ) ;
140150 }
141151 }
142152 } , [ open ] ) ;
143153
144- console . log ( 'nodes' , nodes ) ;
145-
146154 if ( ! open ) {
147155 return < > </ > ;
148156 }
@@ -151,24 +159,35 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
151159 viewPoint === 'showGraphView' || viewPoint === 'chatInfoView'
152160 ? 'Generated Graph'
153161 : `Inspect Generated Graph from ${ inspectedName } ` ;
154- const checkBoxView = viewPoint !== 'chatInfoView' ;
162+
163+ const dropDownView = viewPoint !== 'chatInfoView' ;
164+
155165 const nvlCallbacks = {
156166 onLayoutComputing ( isComputing : boolean ) {
157167 if ( ! isComputing ) {
158168 handleZoomToFit ( ) ;
159169 }
160170 } ,
161171 } ;
172+
173+ // To handle the current zoom in function of graph
162174 const handleZoomIn = ( ) => {
163175 nvlRef . current ?. setZoom ( nvlRef . current . getScale ( ) * 1.3 ) ;
164176 } ;
177+
178+ // To handle the current zoom out function of graph
165179 const handleZoomOut = ( ) => {
166180 nvlRef . current ?. setZoom ( nvlRef . current . getScale ( ) * 0.7 ) ;
167181 } ;
182+
183+ // Refresh the graph with nodes and relations if file is processing
168184 const handleRefresh = ( ) => {
169- // fetchData();
170- console . log ( 'hello' ) ;
185+ setLoading ( true ) ;
186+ setGraphType ( intitalGraphType ) ;
187+ graphApi ( ) ;
171188 } ;
189+
190+ // when modal closes reset all states to default
172191 const onClose = ( ) => {
173192 setStatus ( 'unknown' ) ;
174193 setStatusMessage ( '' ) ;
@@ -178,6 +197,8 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
178197 setNodes ( [ ] ) ;
179198 setRelationships ( [ ] ) ;
180199 } ;
200+
201+ // sort the legends in with Chunk and Document always the first two values
181202 const legendCheck = Object . keys ( newScheme ) . sort ( ( a , b ) => {
182203 if ( a === 'Document' || a === 'Chunk' ) {
183204 return - 1 ;
@@ -187,6 +208,7 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
187208 return a . localeCompare ( b ) ;
188209 } ) ;
189210
211+ // setting the default dropdown values
190212 const getDropdownDefaultValue = ( ) => {
191213 if ( graphType . includes ( 'Document' ) && graphType . includes ( 'Chunk' ) && graphType . includes ( 'Entities' ) ) {
192214 return knowledgeGraph ;
@@ -200,15 +222,22 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
200222 return '' ;
201223 } ;
202224
225+ // Make a function call to store the nodes and relations in their states
203226 const initGraph = ( graphType : GraphType [ ] , finalNodes : Node [ ] , finalRels : Relationship [ ] , schemeVal : Scheme ) => {
204227 if ( allNodes . length > 0 && allRelationships . length > 0 ) {
205- const { filteredNodes, filteredRelations, filteredScheme } = filterData ( graphType , finalNodes , finalRels , schemeVal ) ;
228+ const { filteredNodes, filteredRelations, filteredScheme } = filterData (
229+ graphType ,
230+ finalNodes ,
231+ finalRels ,
232+ schemeVal
233+ ) ;
206234 setNodes ( filteredNodes ) ;
207235 setRelationships ( filteredRelations ) ;
208236 setNewScheme ( filteredScheme ) ;
209237 }
210- }
238+ } ;
211239
240+ // handle dropdown value change and call the init graph method
212241 const handleDropdownChange = ( selectedOption : OptionType | null | void ) => {
213242 if ( selectedOption ?. value ) {
214243 const selectedValue = selectedOption . value ;
@@ -243,13 +272,16 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
243272 { /* {checkBoxView && (
244273 <CheckboxSelection graphType={graphType} loading={loading} handleChange={handleCheckboxChange} />
245274 )} */ }
246- { checkBoxView && ( < DropdownComponent
247- onSelect = { handleDropdownChange }
248- options = { graphView }
249- placeholder = 'Select Graph Type'
250- defaultValue = { getDropdownDefaultValue ( ) }
251- view = 'GraphView'
252- /> ) }
275+ { dropDownView && (
276+ < DropdownComponent
277+ onSelect = { handleDropdownChange }
278+ options = { graphView }
279+ placeholder = 'Select Graph Type'
280+ defaultValue = { getDropdownDefaultValue ( ) }
281+ view = 'GraphView'
282+ isDisabled = { nodes . length === 0 || allNodes . length === 0 }
283+ />
284+ ) }
253285 </ Flex >
254286 </ Dialog . Header >
255287 < Dialog . Content className = 'flex flex-col n-gap-token-4 w-full grow overflow-auto border border-palette-neutral-border-weak' >
@@ -278,14 +310,16 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
278310 nvlCallbacks = { nvlCallbacks }
279311 />
280312 < IconButtonArray orientation = 'vertical' floating className = 'absolute bottom-4 right-4' >
281- < IconButtonWithToolTip
282- label = 'Refresh'
283- text = 'Refresh graph'
284- onClick = { handleRefresh }
285- placement = 'left'
286- >
287- < ArrowPathIconOutline />
288- </ IconButtonWithToolTip >
313+ { viewPoint !== 'chatInfoView' && processingCheck && (
314+ < IconButtonWithToolTip
315+ label = 'Refresh'
316+ text = 'Refresh graph'
317+ onClick = { handleRefresh }
318+ placement = 'left'
319+ >
320+ < ArrowPathIconOutline />
321+ </ IconButtonWithToolTip >
322+ ) }
289323 < IconButtonWithToolTip label = 'Zoomin' text = 'Zoom in' onClick = { handleZoomIn } placement = 'left' >
290324 < MagnifyingGlassPlusIconOutline />
291325 </ IconButtonWithToolTip >
0 commit comments