More flexible proxy setting and toggle sidebar

This commit is contained in:
Gregory Schier 2016-09-12 13:04:15 -07:00
parent 5d305ba8cd
commit 35a9e3ca9e
11 changed files with 72 additions and 40 deletions

View File

@ -372,6 +372,14 @@ function createWindow () {
saveZoomFactor(zoomFactor);
}
},
{
label: "Toggle Sidebar",
accelerator: "CmdOrCtrl+\\",
click: () => {
const window = BrowserWindow.getFocusedWindow();
window && window.webContents.send('toggle-sidebar');
}
}
]
}, {

View File

@ -16,9 +16,9 @@ const AuthEditor = ({request, showPasswords, onChange, ...other}) => {
valuePlaceholder="********"
valueInputType={showPasswords ? 'text' : 'password'}
onChange={pairs => onChange({
username: pairs.length ? pairs[0].name : '',
password: pairs.length ? pairs[0].value : ''
})}
username: pairs.length ? pairs[0].name : '',
password: pairs.length ? pairs[0].value : ''
})}
{...other}
/>
);

View File

@ -101,6 +101,7 @@ class Sidebar extends Component {
changeFilter,
filter,
children,
hidden,
requestCreate,
requestGroupCreate,
width
@ -108,6 +109,7 @@ class Sidebar extends Component {
return (
<aside className={classnames('sidebar', {
'sidebar--hidden': hidden,
'sidebar--skinny': width < SIDEBAR_SKINNY_REMS,
'sidebar--collapsed': width < COLLAPSE_SIDEBAR_REMS
})}>
@ -154,6 +156,7 @@ Sidebar.propTypes = {
showEnvironmentsModal: PropTypes.func.isRequired,
showCookiesModal: PropTypes.func.isRequired,
width: PropTypes.number.isRequired,
hidden: PropTypes.bool.isRequired,
// Other
children: PropTypes.array.isRequired,

View File

@ -79,6 +79,11 @@ class App extends Component {
getModal(WorkspaceEnvironmentsEditModal).toggle(this._getActiveWorkspace());
},
// Toggle Sidebar
'mod+\\': () => {
this._handleToggleSidebar();
},
// Edit Cookies
'mod+k': () => {
getModal(CookiesModal).toggle(this._getActiveWorkspace());
@ -393,6 +398,12 @@ class App extends Component {
}
}
_handleToggleSidebar () {
const workspace = this._getActiveWorkspace();
const metaSidebarHidden = !workspace.metaSidebarHidden;
db.workspaceUpdate(workspace, {metaSidebarHidden});
}
componentWillReceiveProps (nextProps) {
const sidebarWidth = this._getActiveWorkspace(nextProps).metaSidebarWidth;
this.setState({sidebarWidth});
@ -437,7 +448,9 @@ class App extends Component {
ipcRenderer.on('toggle-preferences', () => {
getModal(SettingsModal).toggle();
})
});
ipcRenderer.on('toggle-sidebar', this._handleToggleSidebar.bind(this));
}
componentWillUnmount () {
@ -468,7 +481,8 @@ class App extends Component {
);
const {sidebarWidth, paneWidth} = this.state;
const gridTemplateColumns = `${sidebarWidth}rem 0 ${paneWidth}fr 0 ${1 - paneWidth}fr`;
const realSidebarWidth = workspace.metaSidebarHidden ? 0 : sidebarWidth;
const gridTemplateColumns = `${realSidebarWidth}rem 0 ${paneWidth}fr 0 ${1 - paneWidth}fr`;
return (
<div id="wrapper" className="wrapper"
@ -484,10 +498,11 @@ class App extends Component {
addRequestToRequestGroup={requestGroup => this._requestCreate(requestGroup._id)}
addRequestToWorkspace={() => this._requestCreate(workspace._id)}
toggleRequestGroup={requestGroup => db.requestGroupUpdate(requestGroup, {metaCollapsed: !requestGroup.metaCollapsed})}
activeRequestId={activeRequest ? activeRequest._id : null}
activeRequestId={activeRequestId}
requestCreate={() => this._requestCreate(activeRequest ? activeRequest.parentId : workspace._id)}
requestGroupCreate={() => this._requestGroupCreate(workspace._id)}
filter={workspace.metaFilter || ''}
hidden={workspace.metaSidebarHidden}
children={children}
width={sidebarWidth}
/>

View File

@ -19,6 +19,9 @@
transition: opacity 0.5s;
}
&.sidebar--hidden {
display: none;
}
&:focus {
outline: none;

View File

@ -60,7 +60,8 @@ export const MODEL_DEFAULTS = {
metaSidebarWidth: DEFAULT_SIDEBAR_WIDTH,
metaActiveEnvironmentId: null,
metaActiveRequestId: null,
metaFilter: ''
metaFilter: '',
metaSidebarHidden: false
}),
[TYPE_ENVIRONMENT]: () => ({
name: 'New Environment',

View File

@ -123,25 +123,3 @@ describe('recursiveRender()', () => {
expect(fn).toThrowError('expected variable end');
})
});
describe('setDefaultProtocol()', () => {
it('correctly sets protocol for empty', () => {
const url = render.setDefaultProtocol('google.com');
expect(url).toBe('http://google.com');
});
it('does not set for valid url', () => {
const url = render.setDefaultProtocol('https://google.com');
expect(url).toBe('https://google.com');
});
it('does not set for valid url', () => {
const url = render.setDefaultProtocol('http://google.com');
expect(url).toBe('http://google.com');
});
it('does not set for invalid url', () => {
const url = render.setDefaultProtocol('httbad://google.com');
expect(url).toBe('httbad://google.com');
});
});

View File

@ -65,3 +65,25 @@ describe('generateId()', () => {
expect(id).toMatch(/^[a-zA-Z0-9]{24}$/);
});
});
describe('setDefaultProtocol()', () => {
it('correctly sets protocol for empty', () => {
const url = util.setDefaultProtocol('google.com');
expect(url).toBe('http://google.com');
});
it('does not set for valid url', () => {
const url = util.setDefaultProtocol('https://google.com');
expect(url).toBe('https://google.com');
});
it('does not set for valid url', () => {
const url = util.setDefaultProtocol('http://google.com');
expect(url).toBe('http://google.com');
});
it('does not set for invalid url', () => {
const url = util.setDefaultProtocol('httbad://google.com');
expect(url).toBe('httbad://google.com');
});
});

View File

@ -3,8 +3,9 @@ import {parse as urlParse, format as urlFormat} from 'url';
import * as db from '../database';
import * as querystring from './querystring';
import {DEBOUNCE_MILLIS, STATUS_CODE_PEBKAC} from './constants';
import {getRenderedRequest} from './render';
import {jarFromCookies, cookiesFromJar} from './cookies';
import {setDefaultProtocol} from './util';
import {getRenderedRequest} from './render';
export function _buildRequestConfig (renderedRequest, patch = {}) {
@ -59,7 +60,7 @@ export function _actuallySend (renderedRequest, settings) {
// NOTE: request does not have a separate settings for http/https proxies
const {protocol} = urlParse(renderedRequest.url);
const proxyHost = protocol === 'https:' ? settings.httpsProxy : settings.httpProxy;
const proxy = proxyHost ? `http://${proxyHost}` : null;
const proxy = proxyHost ? setDefaultProtocol(proxyHost) : null;
let config = _buildRequestConfig(renderedRequest, {
jar: jar,

View File

@ -3,6 +3,7 @@ import traverse from 'traverse';
import * as db from '../database';
import {TYPE_WORKSPACE} from '../database/index';
import {getBasicAuthHeader, hasAuthHeader} from './util';
import {setDefaultProtocol} from './util';
nunjucks.configure({
autoescape: false
@ -61,15 +62,6 @@ export function recursiveRender (obj, context) {
return newObj;
}
export function setDefaultProtocol (url, defaultProto = 'http:') {
// Default the proto if it doesn't exist
if (url.indexOf('://') === -1) {
url = `${defaultProto}//${url}`;
}
return url;
}
export function getRenderedRequest (request) {
return db.requestGetAncestors(request).then(ancestors => {
const workspace = ancestors.find(doc => doc.type === TYPE_WORKSPACE);

View File

@ -24,6 +24,15 @@ export function getSetCookieHeaders (headers) {
return filterHeaders(headers, 'set-cookie');
}
export function setDefaultProtocol (url, defaultProto = 'http:') {
// Default the proto if it doesn't exist
if (url.indexOf('://') === -1) {
url = `${defaultProto}//${url}`;
}
return url;
}
/**
* Generate an ID of the format "<MODEL_NAME>_<TIMESTAMP><RANDOM>"
* @param prefix