@@ -20,6 +20,7 @@ export const ApplicationContext = React.createContext<any>(null);
2020const ApplicationContextProvider : React . FC < AppContextProps > = React . memo ( props => {
2121 const children = props . children ;
2222 const [ servicesData , setServicesData ] = useState ( [ ] ) ;
23+ // v10 note: there is not function for setApp so app is never updated.
2324 const [ app , setApp ] = useState < string > ( '' ) ;
2425 const [ savedMetrics , setSavedMetrics ] = useState ( { } ) ;
2526 const [ appIndex , setAppIndex ] = useState < number > ( 0 ) ;
@@ -54,26 +55,38 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
5455 * 4. Remove the listener for `servicesResponse`
5556 * @param application - application name
5657 */
58+ // v10: Invoked by connectToDB, passing in app (card title)
5759 const fetchServicesNames = useCallback ( ( application : string ) => {
58- console . log ( 'app when fetch services name' , application ) ;
60+ console . log ( 'Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.' ) ;
61+ console . log ( 'app when fetch services name: ' , application ) ;
5962 // setApp(application);
6063
6164 ipcRenderer . send ( 'servicesRequest' ) ;
6265
6366 ipcRenderer . on ( 'servicesResponse' , ( event : Electron . Event , data : any ) => {
6467 let result : any ;
6568 // Parse JSON data into object
66- if ( tryParseJSON ( data ) ) result = JSON . parse ( data ) ;
69+ // if (tryParseJSON(data)) result = JSON.parse(data);
70+ result = JSON . parse ( data ) ;
6771 console . log ( 'result from ipcrenderer services response is: ' , result ) ;
72+ console . log ( 'Calling setServicesData passing in above result. Current servicesData is the following: ' , servicesData ) ;
6873 setServicesData ( result ) ;
74+ console . log ( 'Leaving fetchedServicesNames function.' ) ;
6975 ipcRenderer . removeAllListeners ( 'servicesResponse' ) ;
7076 } ) ;
7177 } , [ ] ) ;
7278
73- const connectToDB = useCallback ( ( username : string , index : number , application : string , URI : string ) => {
79+ /**
80+ * @function connectToTB - invoked in Services Modal when Service Modal component is first rendered or when useEffect invoked.
81+ * creates an event emitter that connects to the user provided URI for the service (should be the database URI...)
82+ * v10 notes: seems to only be set up for local instances, not when a cloud based service is clicked, causes an issue since a user provided
83+ * database should not exist...
84+ * @params application - is the name of the card taht was clicked on
85+ */
86+ const connectToDB = useCallback ( ( username : string , index : number , application : string , URI : string , databaseType : string ) => {
87+ console . log ( 'Hi, inside ApplicationContext, connectToDB function was invoked.' ) ;
7488 ipcRenderer . removeAllListeners ( 'databaseConnected' ) ;
75- ipcRenderer . send ( 'connect' , username , index , URI ) ;
76-
89+ ipcRenderer . send ( 'connect' , username , index , URI , databaseType ) ;
7790 ipcRenderer . on ( 'databaseConnected' , ( event : Electron . Event , data : any ) => {
7891 fetchServicesNames ( application ) ;
7992 } ) ;
0 commit comments