Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication + more #39

Merged
merged 18 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions public/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { app, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
const path = require('path');
const os = require('os');

if (isDev) {
console.log('Running in development');
Expand All @@ -15,11 +17,18 @@ function createWindow() {
height: 600,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
});

mainWindow.loadURL(isDev ? 'http://localhost:8080' : `file://${__dirname}/../dist/index.html`);


if (isDev) {
BrowserWindow.addDevToolsExtension(
path.join(os.homedir(), './Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.6.0_0'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, it’d probably be best to move this elsewhere for production, but looks fine for now 👌

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

);
}
mainWindow.on('closed', () => {
mainWindow = null;
});
Expand Down
29 changes: 29 additions & 0 deletions src/main/components/HeaderBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

const HeaderBar = (props) => {
const {
header, authType, handleChange,
} = props;

console.log(authType);
return (
<div>
<p>Headers</p>
<form>
<select name='Authentication' id='headerTypeInput' multiple={false} value={header}
onChange={handleChange} >
<option value='Authorization'>Authorization</option>
<option value='NONE'>none</option>
</select>
<select name='authType' id='typeInput' multiple={false} value={authType}
onChange={handleChange} >
<option value={authType}>{authType}</option>
</select>
<input name='headerKey' id='headerInput' type='text' onChange={handleChange}></input>
</form>
</div>
);

};

export default HeaderBar;
34 changes: 25 additions & 9 deletions src/main/components/RequestBar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import HeaderBar from './HeaderBar.jsx';

const RequestBar = (props) => {
const {
Expand All @@ -9,36 +10,50 @@ const RequestBar = (props) => {
const [selected, setSelected] = useState(method);
const [uri, setUri] = useState('');

// header info
const [headerType, setHeaderType] = useState('Authorization');
const [authType, setType] = useState('Bearer Token');
const [headerKey, setHeaderKey] = useState('');

const handleChange = (e) => {
const { name, value } = e.target;
if (name === 'method') setSelected(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned, @Donaldblanc let’s plan to refactor this to a switch statement on a future iteration. Created an issue so we don’t forget (#40)

else if (name === 'uri') setUri(value);

// header info
if (name === 'Authentication') setHeaderType(value);
if (name === 'headerKey') setHeaderKey(`Bearer ${value}`);

};

const runTest = (link, sendingObj, testsClone, i) => {
const test = testsClone;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this duplicates testsClone-- now tests is just a reference to testsClone. Not a prob bc presumably it isn't modifying state considering it's called "clone", just worth noting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree its point to a reference in memory, but for cleanliness we I did not want to mutate directly from a parameter passed in.

fetch(link, sendingObj)
.then((response) => {
test[i].status = response.status;
if (i === test.length - 1) setTests(test);
})
.catch(error => console.log(error));
};

function sendFetch(e) {
e.preventDefault();

if (SourceOrDest === 'source') {
const sendingObj = { method: selected, mode: 'cors' };
if (headerType !== 'NONE') sendingObj.headers = { [headerType]: headerKey };

fetch(uri, sendingObj)
.then(res => res.json())
.then(res => setData(res));
} else if (SourceOrDest === 'dest') {
const testsClone = [...tests];
const sendingObj = { method: selected, mode: 'cors' };
let counter = 0;
if (headerType !== 'NONE') sendingObj.headers = { [headerType]: headerKey };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should pull both the
const sendingObj = { method: selected, mode: 'cors' };
and the
if (headerType !== 'NONE') sendingObj.headers = { [headerType]: headerKey };
outside of the if-statement. I wrote the first one, no problems on getting approved bc it works just fine, just noticed it now.


for (let i = 0; i < testsClone.length; i += 1) {
sendingObj.body = JSON.stringify(testsClone[i].payload);

fetch(uri, sendingObj)
.then((response) => {
counter += 1;
testsClone[i].status = response.status;
if (counter === testsClone.length) setTests(testsClone);
})
.catch(error => console.log(error));
runTest(uri, sendingObj, testsClone, i);
}
}
}
Expand All @@ -65,6 +80,7 @@ const RequestBar = (props) => {
<input name='uri' id='urlInput' type='url' onChange={handleChange}></input>
<button type='submit' value='Submit'>Submit</button>
</form>
<HeaderBar header={headerType} authType={authType} handleChange={handleChange}/>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/main/components/ResponseComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ResponseComponent = (props) => {

return (
<div>
<p>{`${checkmark} ' - ' ${status}`}</p>
<p>{`${checkmark} - ${status}`}</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

<textarea cols='50' rows='5'>
{payload}
</textarea>
Expand Down