@@ -3,7 +3,7 @@ import { IAnalysisDataProps } from "./analysis-data.interfaces";
33import { socket } from "../../../app.component" ;
44import { Chart } from "react-google-charts" ;
55import axios from "axios" ;
6- import { Dropdown , Modal , Button } from "react-bootstrap" ;
6+ import { Dropdown , Modal , Button , OverlayTrigger , Tooltip } from "react-bootstrap" ;
77import './analysis-data.component.css' ;
88
99const POLLING_INTERVAL_MS = 10000 ;
@@ -19,6 +19,7 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
1919 const [ showConfirmModal , setShowConfirmModal ] = useState ( false ) ;
2020 type TimeUnit = 'seconds' | 'minutes' | 'hours' | 'days' ;
2121 const [ timeUnit , setTimeUnit ] = useState < TimeUnit > ( 'seconds' ) ;
22+ const [ isDatabaseReady , setIsDatabaseReady ] = useState ( false ) ;
2223
2324 const threshold = data . data . queries [ 0 ] ?. threshold ? parseFloat ( data . data . queries [ 0 ] . threshold ) : 100 ;
2425
@@ -29,6 +30,18 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
2930 days : 'd'
3031 } ;
3132
33+ const checkDatabaseStatus = async ( projectId : string ) => {
34+ try {
35+ const res = await axios . get ( `http://localhost:5007/check_database_status?projectId=${ projectId } ` ) ;
36+ console . log ( "Database status response:" , res . data ) ;
37+ return res . data . is_ready ;
38+ } catch ( error ) {
39+ console . error ( "Error checking database status:" , error ) ;
40+ return false ; // Assume not ready if there's an error
41+ }
42+ } ;
43+
44+
3245 useEffect ( ( ) => {
3346 socket . emit ( 'check_fastq_file_listener' , { projectId : analysisData . data . projectId } ) ;
3447
@@ -89,6 +102,14 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
89102 setError ( "Failed to connect to the server. Please check your network connection." ) ;
90103 }
91104 }
105+
106+ // Check database status
107+ const checkStats = await checkDatabaseStatus ( analysisData . data . projectId ) ;
108+ setIsDatabaseReady ( checkStats ) ;
109+ if ( ! checkStats ) {
110+ setError ( "Database is not ready. Please wait for the database to be initialized." ) ;
111+ }
112+
92113 } ;
93114
94115 fetchData ( ) ;
@@ -237,11 +258,24 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
237258 < i className = "fas fa-stop" > </ i > Stop Analysis
238259 </ button >
239260 ) : (
240- < button className = "btn btn-primary nano-btn" onClick = { handleStartFileListener } >
241- < i className = "fas fa-play" > </ i > Start Analysis
242- </ button >
261+ isDatabaseReady ? (
262+ < button className = "btn btn-outline-primary nano-btn" onClick = { handleStartFileListener } >
263+ < i className = "fas fa-play" > </ i > Start Analysis
264+ </ button >
265+ ) : (
266+ < OverlayTrigger
267+ placement = "top"
268+ overlay = { < Tooltip id = "database-not-found-tooltip" > Database not found</ Tooltip > }
269+ >
270+ < span >
271+ < button className = "btn btn-outline-primary nano-btn" disabled >
272+ < i className = "fas fa-play" > </ i > Start Analysis
273+ </ button >
274+ </ span >
275+ </ OverlayTrigger >
276+ )
243277 ) }
244- < button className = "btn btn-outline-danger nano-btn " onClick = { handleRemoveAnalysis } >
278+ < button className = "btn btn-outline-danger" onClick = { handleRemoveAnalysis } >
245279 < i className = "fas fa-trash" > </ i > Remove Analysis
246280 </ button >
247281 </ div >
0 commit comments