@@ -20,6 +20,7 @@ export const ApplicationContext = React.createContext<any>(null);
20
20
const ApplicationContextProvider : React . FC < AppContextProps > = React . memo ( props => {
21
21
const children = props . children ;
22
22
const [ servicesData , setServicesData ] = useState ( [ ] ) ;
23
+ // v10 note: there is not function for setApp so app is never updated.
23
24
const [ app , setApp ] = useState < string > ( '' ) ;
24
25
const [ savedMetrics , setSavedMetrics ] = useState ( { } ) ;
25
26
const [ appIndex , setAppIndex ] = useState < number > ( 0 ) ;
@@ -54,26 +55,38 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
54
55
* 4. Remove the listener for `servicesResponse`
55
56
* @param application - application name
56
57
*/
58
+ // v10: Invoked by connectToDB, passing in app (card title)
57
59
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 ) ;
59
62
// setApp(application);
60
63
61
64
ipcRenderer . send ( 'servicesRequest' ) ;
62
65
63
66
ipcRenderer . on ( 'servicesResponse' , ( event : Electron . Event , data : any ) => {
64
67
let result : any ;
65
68
// 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 ) ;
67
71
console . log ( 'result from ipcrenderer services response is: ' , result ) ;
72
+ console . log ( 'Calling setServicesData passing in above result. Current servicesData is the following: ' , servicesData ) ;
68
73
setServicesData ( result ) ;
74
+ console . log ( 'Leaving fetchedServicesNames function.' ) ;
69
75
ipcRenderer . removeAllListeners ( 'servicesResponse' ) ;
70
76
} ) ;
71
77
} , [ ] ) ;
72
78
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.' ) ;
74
88
ipcRenderer . removeAllListeners ( 'databaseConnected' ) ;
75
- ipcRenderer . send ( 'connect' , username , index , URI ) ;
76
-
89
+ ipcRenderer . send ( 'connect' , username , index , URI , databaseType ) ;
77
90
ipcRenderer . on ( 'databaseConnected' , ( event : Electron . Event , data : any ) => {
78
91
fetchServicesNames ( application ) ;
79
92
} ) ;
0 commit comments