Skip to content

Commit a9bc618

Browse files
committed
updated addAWSApp in AWSModal.tsx and dashboard.ts to save data in db or locally depending on current user. Both cloud and local instances were tested and worked. Co-authored-by: Jon Cruz
<[email protected]> Co-authored-by: Elena Atencio <[email protected]> Co-authored-by: Iris Wong <[email protected]> Co-authored-by: John Donato <[email protected]>
1 parent 516fbd3 commit a9bc618

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

app/context/DashboardContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const DashboardContextProvider = React.memo((props: any) => {
6464

6565
const addAwsApp = useCallback((awsFields: AwsFields) => {
6666
const { typeOfService, instance, region, accessKey, secretAccessKey, name, description, awsUrl } = awsFields;
67+
// call to ipcRenderer returns an array consisting of name, 'AWS', region, 'AWS/(instance)', instance
6768
const result = ipcRenderer.sendSync(
6869
'addAwsApp', //"addApp"
6970
JSON.stringify([name, 'AWS', region, description, typeOfService, instance, accessKey, secretAccessKey, awsUrl])

app/modals/AwsModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type FormElement = React.FormEvent<HTMLFormElement>;
2828
const AwsModal: React.FC<AddModalProps> = React.memo(({ setOpen }) => {
2929
const { addAwsApp }: IDashboard = useContext(DashboardContext);
3030

31+
// instance is instanceID
3132
const [awsFields, setAwsFields] = useState<AwsFields>({
3233
typeOfService: 'AWS/EC2',
3334
instance: '',

electron/routes/dashboard.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,33 @@ ipcMain.on('addApp', (message: IpcMainEvent, application: any) => {
111111

112112
/**
113113
* @event addAwsApp
114+
* @param name, 'AWS', region, description, typeOfService, instanceID, accessKey, secretAccessKey, awsURL
114115
* @desc Adds an AWS application to the user's list in the settings.json with the provided fields
115116
* @return New list of applications
116117
*/
117118
ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
118119

119-
const newAWSApp = JSON.parse(application);
120-
console.log('parsed newApp: ', newAWSApp);
120+
const newAwsApp = JSON.parse(application);
121+
console.log('parsed newApp: ', newAwsApp);
121122
console.log('currentUser', currentUser);
122123
const createdOn = moment().format('lll');
123-
newAWSApp.push(createdOn);
124+
newAwsApp.push(createdOn);
124125

125126
if(currentUser !== 'guest'){
126-
127-
}
128-
129-
// if user is not guest, should not have to pull info from settings.json file
130-
127+
return User.findOneAndUpdate({ username: currentUser }, {
128+
$push: {services: newAwsApp}
129+
}, {new: true})
130+
.then((data) => {
131+
console.log('User updated', data);
132+
// returning each array element name, 'AWS', region, 'AWS/(instance)', Date
133+
message.returnValue = data.services.map((arr: string[]) => [arr[0], arr[1], arr[2], arr[4], arr[5]])
134+
})
135+
.catch((error) => {
136+
console.log(`addAWSApp failed : ${error}`)
137+
})
138+
} else {
139+
// if user is not guest, should not have to pull info from settings.json file
140+
console.log('current user is a guest, data will be saved locally...')
131141
// Retrieves file contents from settings.json
132142
const settings = JSON.parse(fs.readFileSync(settingsLocation).toString('utf8'));
133143
const services = settings[currentUser].services;
@@ -136,7 +146,7 @@ ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
136146
// name, instance, region, description, typeOfService, accessKey, secretAccessKey
137147

138148
// Add new applicaiton to list
139-
const newAwsApp = JSON.parse(application);
149+
// const newAwsApp = JSON.parse(application);
140150

141151
// Add a creation date to the application on the 5th index
142152
// const createdOn = moment().format('lll');
@@ -151,6 +161,7 @@ ipcMain.on('addAwsApp', (message: IpcMainEvent, application: any) => {
151161

152162
// Sync event - return new applications list
153163
message.returnValue = services.map((arr: string[]) => [arr[0], arr[1], arr[2], arr[4], arr[5]]);
164+
}
154165
});
155166

156167
/**

electron/routes/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const postgresFetch = fetchData.postgresFetch;
2525
const AWS = require('aws-sdk');
2626

2727
require('dotenv').config({
28-
path: path.join(__dirname, './.env'),
28+
path: path.join(__dirname, './.env'),
2929
});
3030
// Initiate pool variable for SQL setup
3131
let pool: any;

0 commit comments

Comments
 (0)