2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-07-27 20:07:50 +00:00
|
|
|
import {ipcRenderer} from 'electron';
|
2016-07-19 16:15:03 +00:00
|
|
|
import ReactDOM from 'react-dom';
|
2016-07-19 16:59:26 +00:00
|
|
|
import {connect} from 'react-redux';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {bindActionCreators} from 'redux';
|
2016-07-19 16:59:26 +00:00
|
|
|
import HTML5Backend from 'react-dnd-html5-backend';
|
|
|
|
import {DragDropContext} from 'react-dnd';
|
2016-07-16 02:06:10 +00:00
|
|
|
import Mousetrap from '../lib/mousetrap';
|
2016-08-15 17:04:36 +00:00
|
|
|
import {addModal} from '../components/modals';
|
|
|
|
import WorkspaceEnvironmentsEditModal from '../components/modals/WorkspaceEnvironmentsEditModal';
|
|
|
|
import CookiesModal from '../components/modals/CookiesModal';
|
2016-07-22 22:27:04 +00:00
|
|
|
import EnvironmentEditModal from '../components/modals/EnvironmentEditModal';
|
|
|
|
import RequestSwitcherModal from '../components/modals/RequestSwitcherModal';
|
2016-08-15 17:04:36 +00:00
|
|
|
import GenerateCodeModal from '../components/modals/GenerateCodeModal';
|
2016-07-22 22:27:04 +00:00
|
|
|
import PromptModal from '../components/modals/PromptModal';
|
|
|
|
import AlertModal from '../components/modals/AlertModal';
|
|
|
|
import ChangelogModal from '../components/modals/ChangelogModal';
|
|
|
|
import SettingsModal from '../components/modals/SettingsModal';
|
2016-07-16 02:06:10 +00:00
|
|
|
import RequestPane from '../components/RequestPane';
|
|
|
|
import ResponsePane from '../components/ResponsePane';
|
2016-07-22 22:27:04 +00:00
|
|
|
import Sidebar from '../components/sidebar/Sidebar';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {PREVIEW_MODE_FRIENDLY} from '../lib/previewModes';
|
2016-07-06 20:18:26 +00:00
|
|
|
import {
|
2016-09-10 18:30:50 +00:00
|
|
|
MAX_PANE_WIDTH,
|
|
|
|
MIN_PANE_WIDTH,
|
2016-07-06 20:18:26 +00:00
|
|
|
DEFAULT_PANE_WIDTH,
|
|
|
|
MAX_SIDEBAR_REMS,
|
|
|
|
MIN_SIDEBAR_REMS,
|
2016-09-10 18:30:50 +00:00
|
|
|
DEFAULT_SIDEBAR_WIDTH,
|
|
|
|
CHECK_FOR_UPDATES_INTERVAL
|
|
|
|
} from '../lib/constants';
|
2016-07-27 20:07:50 +00:00
|
|
|
import * as GlobalActions from '../redux/modules/global';
|
2016-07-16 02:06:10 +00:00
|
|
|
import * as RequestActions from '../redux/modules/requests';
|
2016-09-10 18:30:50 +00:00
|
|
|
import * as WorkspaceActions from '../redux/modules/workspaces';
|
2016-07-16 02:06:10 +00:00
|
|
|
import * as db from '../database';
|
2016-07-19 16:59:26 +00:00
|
|
|
import {importCurl} from '../lib/export/curl';
|
2016-07-25 22:27:29 +00:00
|
|
|
import {trackEvent} from '../lib/analytics';
|
|
|
|
import {getAppVersion} from '../lib/appInfo';
|
2016-08-15 17:04:36 +00:00
|
|
|
import {getModal} from '../components/modals/index';
|
|
|
|
|
2016-03-20 04:47:43 +00:00
|
|
|
|
|
|
|
class App extends Component {
|
2016-07-07 20:10:55 +00:00
|
|
|
constructor (props) {
|
2016-04-18 04:39:15 +00:00
|
|
|
super(props);
|
2016-07-06 20:18:26 +00:00
|
|
|
|
|
|
|
const workspace = this._getActiveWorkspace(props);
|
2016-04-18 04:39:15 +00:00
|
|
|
this.state = {
|
|
|
|
activeResponse: null,
|
2016-06-19 00:08:14 +00:00
|
|
|
activeRequest: null,
|
|
|
|
draggingSidebar: false,
|
|
|
|
draggingPane: false,
|
2016-07-19 16:59:26 +00:00
|
|
|
sidebarWidth: workspace.metaSidebarWidth || DEFAULT_SIDEBAR_WIDTH, // rem
|
|
|
|
paneWidth: workspace.metaPaneWidth || DEFAULT_PANE_WIDTH // % (fr)
|
2016-07-06 20:18:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.globalKeyMap = {
|
|
|
|
|
|
|
|
// Show Settings
|
|
|
|
'mod+,': () => {
|
2016-08-22 20:05:42 +00:00
|
|
|
// NOTE: This is controlled via a global menu shortcut in app.js
|
|
|
|
// getModal(SettingsModal).toggle();
|
2016-07-06 20:18:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Show Request Switcher
|
2016-07-25 22:27:29 +00:00
|
|
|
'mod+p': () => {
|
2016-08-15 17:04:36 +00:00
|
|
|
getModal(RequestSwitcherModal).toggle();
|
2016-07-06 20:18:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Request Send
|
2016-07-21 21:34:38 +00:00
|
|
|
'mod+enter': () => {
|
2016-07-06 20:18:26 +00:00
|
|
|
const request = this._getActiveRequest();
|
|
|
|
if (request) {
|
|
|
|
this.props.actions.requests.send(request);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
// Edit Workspace Environments
|
|
|
|
'mod+e': () => {
|
|
|
|
getModal(WorkspaceEnvironmentsEditModal).toggle(this._getActiveWorkspace());
|
|
|
|
},
|
|
|
|
|
2016-09-12 20:04:15 +00:00
|
|
|
// Toggle Sidebar
|
|
|
|
'mod+\\': () => {
|
|
|
|
this._handleToggleSidebar();
|
|
|
|
},
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
// Edit Cookies
|
|
|
|
'mod+k': () => {
|
2016-08-15 22:31:30 +00:00
|
|
|
getModal(CookiesModal).toggle(this._getActiveWorkspace());
|
2016-08-15 17:04:36 +00:00
|
|
|
},
|
|
|
|
|
2016-09-10 03:50:45 +00:00
|
|
|
// Request Create
|
|
|
|
'mod+n': () => {
|
|
|
|
const workspace = this._getActiveWorkspace();
|
|
|
|
const request = this._getActiveRequest();
|
|
|
|
|
|
|
|
if (!workspace) {
|
|
|
|
// Nothing to do if no workspace
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const parentId = request ? request.parentId : workspace._id;
|
|
|
|
this._requestCreate(parentId);
|
|
|
|
},
|
|
|
|
|
2016-07-06 20:18:26 +00:00
|
|
|
// Request Duplicate
|
|
|
|
'mod+d': () => {
|
|
|
|
const request = this._getActiveRequest();
|
2016-07-25 22:27:29 +00:00
|
|
|
const workspace = this._getActiveWorkspace();
|
2016-07-06 20:18:26 +00:00
|
|
|
|
|
|
|
if (!request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-08 06:54:35 +00:00
|
|
|
db.requestDuplicateAndActivate(workspace, request);
|
2016-07-25 22:27:29 +00:00
|
|
|
}
|
2016-04-18 04:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:07:50 +00:00
|
|
|
_importFile () {
|
|
|
|
const workspace = this._getActiveWorkspace();
|
|
|
|
this.props.actions.global.importFile(workspace);
|
|
|
|
}
|
|
|
|
|
2016-07-19 16:59:26 +00:00
|
|
|
_moveRequestGroup (requestGroupToMove, requestGroupToTarget, targetOffset) {
|
|
|
|
// Oh God, this function is awful...
|
|
|
|
|
|
|
|
if (requestGroupToMove._id === requestGroupToTarget._id) {
|
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: using requestToTarget's parentId so we can switch parents!
|
|
|
|
db.requestGroupFindByParentId(requestGroupToTarget.parentId).then(requestGroups => {
|
|
|
|
requestGroups = requestGroups.sort((a, b) => a.metaSortKey < b.metaSortKey ? -1 : 1);
|
|
|
|
|
|
|
|
// Find the index of request B so we can re-order and save everything
|
|
|
|
for (let i = 0; i < requestGroups.length; i++) {
|
|
|
|
const request = requestGroups[i];
|
|
|
|
|
|
|
|
if (request._id === requestGroupToTarget._id) {
|
|
|
|
let before, after;
|
|
|
|
if (targetOffset < 0) {
|
|
|
|
// We're moving to below
|
|
|
|
before = requestGroups[i];
|
|
|
|
after = requestGroups[i + 1];
|
|
|
|
} else {
|
|
|
|
// We're moving to above
|
|
|
|
before = requestGroups[i - 1];
|
|
|
|
after = requestGroups[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
const beforeKey = before ? before.metaSortKey : requestGroups[0].metaSortKey - 100;
|
|
|
|
const afterKey = after ? after.metaSortKey : requestGroups[requestGroups.length - 1].metaSortKey + 100;
|
|
|
|
|
|
|
|
if (Math.abs(afterKey - beforeKey) < 0.000001) {
|
|
|
|
// If sort keys get too close together, we need to redistribute the list. This is
|
|
|
|
// not performant at all (need to update all siblings in DB), but it is extremely rare
|
|
|
|
// anyway
|
|
|
|
console.warn('-- Recreating Sort Keys --');
|
|
|
|
|
|
|
|
requestGroups.map((r, i) => {
|
2016-07-20 18:35:08 +00:00
|
|
|
db.requestGroupUpdate(r, {
|
|
|
|
metaSortKey: i * 100,
|
|
|
|
parentId: requestGroupToTarget.parentId
|
|
|
|
});
|
2016-07-19 16:59:26 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const metaSortKey = afterKey - (afterKey - beforeKey) / 2;
|
2016-07-20 18:35:08 +00:00
|
|
|
db.requestGroupUpdate(requestGroupToMove, {
|
|
|
|
metaSortKey,
|
|
|
|
parentId: requestGroupToTarget.parentId
|
|
|
|
});
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-21 03:58:52 +00:00
|
|
|
_moveRequest (requestToMove, parentId, targetId, targetOffset) {
|
2016-07-19 16:59:26 +00:00
|
|
|
// Oh God, this function is awful...
|
|
|
|
|
2016-07-21 03:58:52 +00:00
|
|
|
if (requestToMove._id === targetId) {
|
|
|
|
// Nothing to do. We are in the same spot as we started
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targetId === null) {
|
|
|
|
// We are moving to an empty area. No sorting required
|
|
|
|
db.requestUpdate(requestToMove, {parentId});
|
2016-07-19 16:59:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: using requestToTarget's parentId so we can switch parents!
|
2016-07-21 03:58:52 +00:00
|
|
|
db.requestFindByParentId(parentId).then(requests => {
|
2016-07-19 16:59:26 +00:00
|
|
|
requests = requests.sort((a, b) => a.metaSortKey < b.metaSortKey ? -1 : 1);
|
|
|
|
|
|
|
|
// Find the index of request B so we can re-order and save everything
|
|
|
|
for (let i = 0; i < requests.length; i++) {
|
|
|
|
const request = requests[i];
|
|
|
|
|
2016-07-21 03:58:52 +00:00
|
|
|
if (request._id === targetId) {
|
2016-07-19 16:59:26 +00:00
|
|
|
let before, after;
|
|
|
|
if (targetOffset < 0) {
|
|
|
|
// We're moving to below
|
|
|
|
before = requests[i];
|
|
|
|
after = requests[i + 1];
|
|
|
|
} else {
|
|
|
|
// We're moving to above
|
|
|
|
before = requests[i - 1];
|
|
|
|
after = requests[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
const beforeKey = before ? before.metaSortKey : requests[0].metaSortKey - 100;
|
|
|
|
const afterKey = after ? after.metaSortKey : requests[requests.length - 1].metaSortKey + 100;
|
|
|
|
|
|
|
|
if (Math.abs(afterKey - beforeKey) < 0.000001) {
|
|
|
|
// If sort keys get too close together, we need to redistribute the list. This is
|
|
|
|
// not performant at all (need to update all siblings in DB), but it is extremely rare
|
|
|
|
// anyway
|
2016-07-23 08:22:52 +00:00
|
|
|
console.warn(`-- Recreating Sort Keys ${beforeKey} ${afterKey} --`);
|
2016-07-19 16:59:26 +00:00
|
|
|
|
|
|
|
requests.map((r, i) => {
|
2016-07-21 03:58:52 +00:00
|
|
|
db.requestUpdate(r, {metaSortKey: i * 100, parentId});
|
2016-07-19 16:59:26 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const metaSortKey = afterKey - (afterKey - beforeKey) / 2;
|
2016-07-21 03:58:52 +00:00
|
|
|
db.requestUpdate(requestToMove, {metaSortKey, parentId});
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
_requestGroupCreate (parentId) {
|
|
|
|
getModal(PromptModal).show({
|
|
|
|
headerName: 'Create New Folder',
|
|
|
|
defaultValue: 'My Folder',
|
|
|
|
selectText: true
|
|
|
|
}).then(name => {
|
|
|
|
db.requestGroupCreate({parentId, name})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-19 16:59:26 +00:00
|
|
|
_requestCreate (parentId) {
|
2016-08-15 17:04:36 +00:00
|
|
|
getModal(PromptModal).show({
|
|
|
|
headerName: 'Create New Request',
|
|
|
|
defaultValue: 'My Request',
|
|
|
|
selectText: true
|
|
|
|
}).then(name => {
|
|
|
|
const workspace = this._getActiveWorkspace();
|
|
|
|
db.requestCreateAndActivate(workspace, {parentId, name})
|
|
|
|
});
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_generateSidebarTree (parentId, entities) {
|
2016-07-19 16:59:26 +00:00
|
|
|
const children = entities.filter(
|
|
|
|
e => e.parentId === parentId
|
|
|
|
).sort((a, b) => {
|
|
|
|
if (a.metaSortKey === b.metaSortKey) {
|
|
|
|
return a._id > b._id ? -1 : 1;
|
|
|
|
} else {
|
2016-07-20 18:35:08 +00:00
|
|
|
return a.metaSortKey < b.metaSortKey ? -1 : 1;
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
if (children.length > 0) {
|
|
|
|
return children.map(c => ({
|
|
|
|
doc: c,
|
|
|
|
children: this._generateSidebarTree(c._id, entities)
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
return children;
|
2016-03-22 03:22:45 +00:00
|
|
|
}
|
2016-04-17 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
_handleUrlChanged (url) {
|
|
|
|
// TODO: Should this be moved elsewhere?
|
|
|
|
const requestPatch = importCurl(url);
|
|
|
|
|
|
|
|
if (requestPatch) {
|
|
|
|
// If the user typed in a curl cmd, dissect it and update the whole request
|
2016-09-09 17:57:26 +00:00
|
|
|
db.requestUpdate(this._getActiveRequest(), requestPatch).then(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
})
|
|
|
|
});
|
2016-07-14 22:48:56 +00:00
|
|
|
} else {
|
|
|
|
db.requestUpdate(this._getActiveRequest(), {url});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_startDragSidebar () {
|
2016-06-19 00:08:14 +00:00
|
|
|
this.setState({
|
|
|
|
draggingSidebar: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_resetDragSidebar () {
|
2016-07-06 22:11:37 +00:00
|
|
|
// TODO: Remove setTimeout need be not triggering drag on double click
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
sidebarWidth: DEFAULT_SIDEBAR_WIDTH
|
2016-07-19 16:59:26 +00:00
|
|
|
});
|
2016-06-19 00:40:14 +00:00
|
|
|
|
2016-07-06 22:11:37 +00:00
|
|
|
this._saveSidebarWidth();
|
|
|
|
}, 50);
|
2016-06-19 00:08:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_startDragPane () {
|
2016-07-06 20:18:26 +00:00
|
|
|
this.setState({
|
|
|
|
draggingPane: true
|
2016-06-19 00:08:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_resetDragPane () {
|
2016-07-06 22:11:37 +00:00
|
|
|
// TODO: Remove setTimeout need be not triggering drag on double click
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
paneWidth: DEFAULT_PANE_WIDTH
|
|
|
|
})
|
2016-06-19 00:08:14 +00:00
|
|
|
|
2016-07-06 22:11:37 +00:00
|
|
|
this._savePaneWidth();
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_savePaneWidth () {
|
2016-07-19 16:59:26 +00:00
|
|
|
const metaPaneWidth = this.state.paneWidth;
|
|
|
|
db.workspaceUpdate(this._getActiveWorkspace(), {metaPaneWidth});
|
2016-07-06 22:11:37 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_saveSidebarWidth () {
|
2016-07-19 16:59:26 +00:00
|
|
|
const metaSidebarWidth = this.state.sidebarWidth;
|
|
|
|
db.workspaceUpdate(this._getActiveWorkspace(), {metaSidebarWidth});
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_getActiveWorkspace (props) {
|
2016-04-26 07:29:24 +00:00
|
|
|
// TODO: Factor this out into a selector
|
2016-07-06 20:18:26 +00:00
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
const {entities, workspaces, actions} = props || this.props;
|
2016-04-26 07:29:24 +00:00
|
|
|
let workspace = entities.workspaces[workspaces.activeId];
|
|
|
|
if (!workspace) {
|
|
|
|
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
2016-04-17 20:35:35 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 20:18:26 +00:00
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_getActiveRequest (props) {
|
2016-08-15 22:31:30 +00:00
|
|
|
// TODO: Factor this out into a selector
|
|
|
|
|
2016-07-06 20:18:26 +00:00
|
|
|
props = props || this.props;
|
|
|
|
const {entities} = props;
|
2016-07-19 16:59:26 +00:00
|
|
|
let activeRequestId = this._getActiveWorkspace(props).metaActiveRequestId;
|
2016-07-06 20:18:26 +00:00
|
|
|
return activeRequestId ? entities.requests[activeRequestId] : null;
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_handleMouseMove (e) {
|
2016-07-06 20:18:26 +00:00
|
|
|
if (this.state.draggingPane) {
|
2016-09-03 04:32:45 +00:00
|
|
|
const requestPane = ReactDOM.findDOMNode(this._requestPane);
|
|
|
|
const responsePane = ReactDOM.findDOMNode(this._responsePane);
|
2016-07-06 20:18:26 +00:00
|
|
|
|
|
|
|
const requestPaneWidth = requestPane.offsetWidth;
|
|
|
|
const responsePaneWidth = responsePane.offsetWidth;
|
|
|
|
const pixelOffset = e.clientX - requestPane.offsetLeft;
|
|
|
|
let paneWidth = pixelOffset / (requestPaneWidth + responsePaneWidth);
|
|
|
|
paneWidth = Math.min(Math.max(paneWidth, MIN_PANE_WIDTH), MAX_PANE_WIDTH);
|
|
|
|
this.setState({paneWidth});
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-07-06 20:18:26 +00:00
|
|
|
} else if (this.state.draggingSidebar) {
|
2016-09-03 04:32:45 +00:00
|
|
|
const currentPixelWidth = ReactDOM.findDOMNode(this._sidebar).offsetWidth;
|
2016-07-06 20:18:26 +00:00
|
|
|
const ratio = e.clientX / currentPixelWidth;
|
|
|
|
const width = this.state.sidebarWidth * ratio;
|
2016-08-15 17:04:36 +00:00
|
|
|
let sidebarWidth = Math.max(Math.min(width, MAX_SIDEBAR_REMS), MIN_SIDEBAR_REMS);
|
2016-07-06 20:18:26 +00:00
|
|
|
this.setState({sidebarWidth})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
_handleMouseUp () {
|
2016-07-06 20:18:26 +00:00
|
|
|
if (this.state.draggingSidebar) {
|
|
|
|
this.setState({
|
|
|
|
draggingSidebar: false
|
2016-07-14 22:48:56 +00:00
|
|
|
});
|
2016-07-06 22:11:37 +00:00
|
|
|
|
|
|
|
this._saveSidebarWidth();
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
2016-03-22 05:01:58 +00:00
|
|
|
|
2016-07-06 20:18:26 +00:00
|
|
|
if (this.state.draggingPane) {
|
|
|
|
this.setState({
|
|
|
|
draggingPane: false
|
2016-07-14 22:48:56 +00:00
|
|
|
});
|
2016-07-06 22:11:37 +00:00
|
|
|
|
|
|
|
this._savePaneWidth();
|
2016-06-19 07:21:43 +00:00
|
|
|
}
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:04:15 +00:00
|
|
|
_handleToggleSidebar () {
|
|
|
|
const workspace = this._getActiveWorkspace();
|
|
|
|
const metaSidebarHidden = !workspace.metaSidebarHidden;
|
|
|
|
db.workspaceUpdate(workspace, {metaSidebarHidden});
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2016-07-19 16:59:26 +00:00
|
|
|
const sidebarWidth = this._getActiveWorkspace(nextProps).metaSidebarWidth;
|
2016-07-06 20:18:26 +00:00
|
|
|
this.setState({sidebarWidth});
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
componentDidMount () {
|
2016-07-06 20:18:26 +00:00
|
|
|
// Bind handlers before we use them
|
|
|
|
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
|
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
|
|
|
|
|
|
// Bind mouse handlers
|
|
|
|
document.addEventListener('mouseup', this._handleMouseUp);
|
|
|
|
document.addEventListener('mousemove', this._handleMouseMove);
|
|
|
|
|
|
|
|
// Map global keyboard shortcuts
|
|
|
|
Object.keys(this.globalKeyMap).map(key => {
|
|
|
|
Mousetrap.bindGlobal(key.split('|'), this.globalKeyMap[key]);
|
|
|
|
});
|
2016-07-25 22:27:29 +00:00
|
|
|
|
|
|
|
// Do The Analytics
|
|
|
|
trackEvent('App Launched');
|
|
|
|
|
|
|
|
// Update Stats Object
|
|
|
|
db.statsGet().then(({lastVersion, launches}) => {
|
|
|
|
const firstLaunch = !lastVersion;
|
|
|
|
if (firstLaunch) {
|
|
|
|
// TODO: Show a welcome message
|
|
|
|
} else if (lastVersion !== getAppVersion()) {
|
2016-08-15 17:04:36 +00:00
|
|
|
getModal(ChangelogModal).show();
|
2016-07-25 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db.statsUpdate({
|
|
|
|
launches: launches + 1,
|
|
|
|
lastLaunch: Date.now(),
|
|
|
|
lastVersion: getAppVersion()
|
|
|
|
});
|
|
|
|
});
|
2016-07-27 20:07:50 +00:00
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
ipcRenderer.send('check-for-updates');
|
|
|
|
}, CHECK_FOR_UPDATES_INTERVAL);
|
2016-08-22 19:05:17 +00:00
|
|
|
|
2016-08-22 20:05:42 +00:00
|
|
|
ipcRenderer.on('toggle-preferences', () => {
|
|
|
|
getModal(SettingsModal).toggle();
|
2016-09-12 20:04:15 +00:00
|
|
|
});
|
|
|
|
|
2016-09-12 21:16:55 +00:00
|
|
|
|
2016-09-12 20:04:15 +00:00
|
|
|
ipcRenderer.on('toggle-sidebar', this._handleToggleSidebar.bind(this));
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
componentWillUnmount () {
|
2016-07-06 20:18:26 +00:00
|
|
|
// Remove mouse handlers
|
|
|
|
document.removeEventListener('mouseup', this._handleMouseUp);
|
|
|
|
document.removeEventListener('mousemove', this._handleMouseMove);
|
|
|
|
|
|
|
|
// Unbind global keyboard shortcuts
|
|
|
|
Mousetrap.unbind();
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2016-07-25 22:27:29 +00:00
|
|
|
// throw new Error('Test Exception');
|
2016-07-06 22:11:37 +00:00
|
|
|
const {actions, entities, requests} = this.props;
|
2016-07-19 19:13:51 +00:00
|
|
|
const settings = entities.settings[Object.keys(entities.settings)[0]];
|
2016-07-06 20:18:26 +00:00
|
|
|
|
|
|
|
const workspace = this._getActiveWorkspace();
|
|
|
|
|
2016-07-19 16:15:03 +00:00
|
|
|
const activeRequest = this._getActiveRequest();
|
2016-07-06 20:18:26 +00:00
|
|
|
const activeRequestId = activeRequest ? activeRequest._id : null;
|
2016-06-19 07:21:43 +00:00
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
const allRequests = Object.keys(entities.requests).map(id => entities.requests[id]);
|
|
|
|
const allRequestGroups = Object.keys(entities.requestGroups).map(id => entities.requestGroups[id]);
|
|
|
|
|
|
|
|
const children = this._generateSidebarTree(
|
|
|
|
workspace._id,
|
|
|
|
allRequests.concat(allRequestGroups)
|
|
|
|
);
|
2016-03-22 03:22:45 +00:00
|
|
|
|
2016-06-19 00:40:14 +00:00
|
|
|
const {sidebarWidth, paneWidth} = this.state;
|
2016-09-12 20:04:15 +00:00
|
|
|
const realSidebarWidth = workspace.metaSidebarHidden ? 0 : sidebarWidth;
|
|
|
|
const gridTemplateColumns = `${realSidebarWidth}rem 0 ${paneWidth}fr 0 ${1 - paneWidth}fr`;
|
2016-06-19 00:40:14 +00:00
|
|
|
|
2016-03-20 04:47:43 +00:00
|
|
|
return (
|
2016-09-10 18:30:50 +00:00
|
|
|
<div id="wrapper" className="wrapper"
|
|
|
|
style={{gridTemplateColumns: gridTemplateColumns}}>
|
2016-04-17 22:46:17 +00:00
|
|
|
<Sidebar
|
2016-09-03 04:32:45 +00:00
|
|
|
ref={n => this._sidebar = n}
|
2016-08-15 17:04:36 +00:00
|
|
|
showEnvironmentsModal={() => getModal(WorkspaceEnvironmentsEditModal).show(workspace)}
|
2016-08-15 22:31:30 +00:00
|
|
|
showCookiesModal={() => getModal(CookiesModal).show(workspace)}
|
2016-07-19 16:59:26 +00:00
|
|
|
activateRequest={r => db.workspaceUpdate(workspace, {metaActiveRequestId: r._id})}
|
2016-08-15 22:31:30 +00:00
|
|
|
changeFilter={metaFilter => db.workspaceUpdate(workspace, {metaFilter})}
|
2016-07-19 16:59:26 +00:00
|
|
|
moveRequest={this._moveRequest.bind(this)}
|
|
|
|
moveRequestGroup={this._moveRequestGroup.bind(this)}
|
|
|
|
addRequestToRequestGroup={requestGroup => this._requestCreate(requestGroup._id)}
|
2016-08-15 22:31:30 +00:00
|
|
|
addRequestToWorkspace={() => this._requestCreate(workspace._id)}
|
2016-07-19 16:59:26 +00:00
|
|
|
toggleRequestGroup={requestGroup => db.requestGroupUpdate(requestGroup, {metaCollapsed: !requestGroup.metaCollapsed})}
|
2016-09-12 20:04:15 +00:00
|
|
|
activeRequestId={activeRequestId}
|
2016-08-15 22:31:30 +00:00
|
|
|
requestCreate={() => this._requestCreate(activeRequest ? activeRequest.parentId : workspace._id)}
|
2016-08-15 17:04:36 +00:00
|
|
|
requestGroupCreate={() => this._requestGroupCreate(workspace._id)}
|
2016-08-15 22:31:30 +00:00
|
|
|
filter={workspace.metaFilter || ''}
|
2016-09-12 20:04:15 +00:00
|
|
|
hidden={workspace.metaSidebarHidden}
|
2016-04-26 07:29:24 +00:00
|
|
|
children={children}
|
2016-08-15 17:04:36 +00:00
|
|
|
width={sidebarWidth}
|
2016-04-26 07:29:24 +00:00
|
|
|
/>
|
2016-05-07 17:29:24 +00:00
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
<div className="drag drag--sidebar">
|
2016-09-10 18:30:50 +00:00
|
|
|
<div onMouseDown={e => {
|
|
|
|
e.preventDefault();
|
|
|
|
this._startDragSidebar()
|
|
|
|
}}
|
2016-07-14 22:48:56 +00:00
|
|
|
onDoubleClick={() => this._resetDragSidebar()}>
|
|
|
|
</div>
|
2016-06-19 00:08:14 +00:00
|
|
|
</div>
|
|
|
|
|
2016-05-01 19:56:30 +00:00
|
|
|
<RequestPane
|
2016-09-03 04:32:45 +00:00
|
|
|
ref={n => this._requestPane = n}
|
2016-07-27 20:07:50 +00:00
|
|
|
importFile={this._importFile.bind(this)}
|
2016-05-01 19:56:30 +00:00
|
|
|
request={activeRequest}
|
|
|
|
sendRequest={actions.requests.send}
|
2016-07-19 19:13:51 +00:00
|
|
|
showPasswords={settings.showPasswords}
|
2016-08-22 20:05:42 +00:00
|
|
|
useBulkHeaderEditor={settings.useBulkHeaderEditor}
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize={settings.editorFontSize}
|
|
|
|
editorLineWrapping={settings.editorLineWrapping}
|
2016-08-15 17:04:36 +00:00
|
|
|
requestCreate={() => db.requestCreateAndActivate(workspace, {parentId: workspace._id})}
|
2016-05-01 19:56:30 +00:00
|
|
|
updateRequestBody={body => db.requestUpdate(activeRequest, {body})}
|
2016-07-14 22:48:56 +00:00
|
|
|
updateRequestUrl={url => this._handleUrlChanged(url)}
|
2016-05-01 19:56:30 +00:00
|
|
|
updateRequestMethod={method => db.requestUpdate(activeRequest, {method})}
|
2016-07-19 04:01:31 +00:00
|
|
|
updateRequestParameters={parameters => db.requestUpdate(activeRequest, {parameters})}
|
2016-05-01 19:56:30 +00:00
|
|
|
updateRequestAuthentication={authentication => db.requestUpdate(activeRequest, {authentication})}
|
|
|
|
updateRequestHeaders={headers => db.requestUpdate(activeRequest, {headers})}
|
2016-07-22 20:02:17 +00:00
|
|
|
updateRequestContentType={contentType => db.requestUpdateContentType(activeRequest, contentType)}
|
2016-07-19 19:13:51 +00:00
|
|
|
updateSettingsShowPasswords={showPasswords => db.settingsUpdate(settings, {showPasswords})}
|
2016-08-22 20:05:42 +00:00
|
|
|
updateSettingsUseBulkHeaderEditor={useBulkHeaderEditor => db.settingsUpdate(settings, {useBulkHeaderEditor})}
|
2016-05-01 19:56:30 +00:00
|
|
|
/>
|
2016-05-07 17:29:24 +00:00
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
<div className="drag drag--pane">
|
2016-07-06 20:18:26 +00:00
|
|
|
<div onMouseDown={() => this._startDragPane()}
|
|
|
|
onDoubleClick={() => this._resetDragPane()}></div>
|
2016-06-19 00:08:14 +00:00
|
|
|
</div>
|
|
|
|
|
2016-05-01 19:56:30 +00:00
|
|
|
<ResponsePane
|
2016-09-03 04:32:45 +00:00
|
|
|
ref={n => this._responsePane = n}
|
2016-07-07 20:10:55 +00:00
|
|
|
request={activeRequest}
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize={settings.editorFontSize}
|
|
|
|
editorLineWrapping={settings.editorLineWrapping}
|
2016-07-19 16:59:26 +00:00
|
|
|
previewMode={activeRequest ? activeRequest.metaPreviewMode : PREVIEW_MODE_FRIENDLY}
|
2016-09-09 00:32:36 +00:00
|
|
|
responseFilter={activeRequest ? activeRequest.metaResponseFilter : ''}
|
2016-07-19 16:59:26 +00:00
|
|
|
updatePreviewMode={metaPreviewMode => db.requestUpdate(activeRequest, {metaPreviewMode})}
|
2016-09-09 00:32:36 +00:00
|
|
|
updateResponseFilter={metaResponseFilter => db.requestUpdate(activeRequest, {metaResponseFilter})}
|
2016-07-06 22:11:37 +00:00
|
|
|
loadingRequests={requests.loadingRequests}
|
2016-08-19 23:12:33 +00:00
|
|
|
showCookiesModal={() => getModal(CookiesModal).show(workspace)}
|
2016-05-01 19:56:30 +00:00
|
|
|
/>
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
<PromptModal ref={m => addModal(m)}/>
|
|
|
|
<AlertModal ref={m => addModal(m)}/>
|
|
|
|
<ChangelogModal ref={m => addModal(m)}/>
|
|
|
|
<SettingsModal ref={m => addModal(m)}/>
|
|
|
|
<GenerateCodeModal ref={m => addModal(m)}/>
|
2016-07-20 18:35:08 +00:00
|
|
|
<RequestSwitcherModal
|
2016-08-15 17:04:36 +00:00
|
|
|
ref={m => addModal(m)}
|
2016-07-20 18:35:08 +00:00
|
|
|
workspaceId={workspace._id}
|
2016-07-22 17:02:42 +00:00
|
|
|
activeRequestParentId={activeRequest ? activeRequest.parentId : workspace._id}
|
2016-07-20 18:35:08 +00:00
|
|
|
activateRequest={r => db.workspaceUpdate(workspace, {metaActiveRequestId: r._id})}
|
2016-09-10 18:30:50 +00:00
|
|
|
activateWorkspace={w => actions.workspaces.activate(w)}
|
2016-07-20 18:35:08 +00:00
|
|
|
/>
|
2016-08-15 17:04:36 +00:00
|
|
|
<EnvironmentEditModal
|
|
|
|
ref={m => addModal(m)}
|
|
|
|
onChange={rg => db.requestGroupUpdate(rg)}/>
|
|
|
|
<WorkspaceEnvironmentsEditModal
|
|
|
|
ref={m => addModal(m)}
|
|
|
|
onChange={w => db.workspaceUpdate(w)}/>
|
2016-09-10 18:30:50 +00:00
|
|
|
<CookiesModal ref={m => addModal(m)}/>
|
2016-08-15 17:04:36 +00:00
|
|
|
|
2016-07-21 19:15:35 +00:00
|
|
|
{/*<div className="toast toast--show">*/}
|
2016-07-25 22:27:29 +00:00
|
|
|
{/*<div className="toast__message">How's it going?</div>*/}
|
|
|
|
{/*<button className="toast__action">Great!</button>*/}
|
|
|
|
{/*<button className="toast__action">Horrible :(</button>*/}
|
2016-07-21 19:15:35 +00:00
|
|
|
{/*</div>*/}
|
2016-07-06 22:11:37 +00:00
|
|
|
</div>
|
2016-03-20 04:47:43 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
App.propTypes = {
|
2016-03-22 05:01:58 +00:00
|
|
|
actions: PropTypes.shape({
|
2016-04-16 23:24:57 +00:00
|
|
|
requests: PropTypes.shape({
|
2016-08-15 22:31:30 +00:00
|
|
|
send: PropTypes.func.isRequired
|
2016-09-03 05:14:48 +00:00
|
|
|
}).isRequired,
|
2016-09-10 18:30:50 +00:00
|
|
|
workspaces: PropTypes.shape({
|
|
|
|
activate: PropTypes.func.isRequired
|
|
|
|
}).isRequired,
|
2016-09-03 05:14:48 +00:00
|
|
|
global: PropTypes.shape({
|
|
|
|
importFile: PropTypes.func.isRequired
|
|
|
|
}).isRequired
|
2016-03-22 05:01:58 +00:00
|
|
|
}).isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
entities: PropTypes.shape({
|
|
|
|
requests: PropTypes.object.isRequired,
|
|
|
|
requestGroups: PropTypes.object.isRequired,
|
|
|
|
responses: PropTypes.object.isRequired
|
|
|
|
}).isRequired,
|
|
|
|
workspaces: PropTypes.shape({
|
|
|
|
activeId: PropTypes.string
|
2016-04-09 21:08:55 +00:00
|
|
|
}).isRequired,
|
2016-03-22 05:01:58 +00:00
|
|
|
requests: PropTypes.shape({
|
2016-07-06 22:11:37 +00:00
|
|
|
loadingRequests: PropTypes.object.isRequired
|
2016-09-03 05:14:48 +00:00
|
|
|
}).isRequired
|
2016-03-20 04:47:43 +00:00
|
|
|
};
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
function mapStateToProps (state) {
|
2016-03-20 04:47:43 +00:00
|
|
|
return {
|
|
|
|
actions: state.actions,
|
2016-04-26 07:29:24 +00:00
|
|
|
workspaces: state.workspaces,
|
2016-03-22 05:01:58 +00:00
|
|
|
requests: state.requests,
|
2016-09-03 05:14:48 +00:00
|
|
|
entities: state.entities
|
2016-03-20 04:47:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
function mapDispatchToProps (dispatch) {
|
2016-03-20 04:47:43 +00:00
|
|
|
return {
|
2016-04-16 23:24:57 +00:00
|
|
|
actions: {
|
2016-07-27 20:07:50 +00:00
|
|
|
global: bindActionCreators(GlobalActions, dispatch),
|
2016-09-10 18:30:50 +00:00
|
|
|
requests: bindActionCreators(RequestActions, dispatch),
|
|
|
|
workspaces: bindActionCreators(WorkspaceActions, dispatch)
|
2016-04-16 23:24:57 +00:00
|
|
|
}
|
2016-03-20 04:47:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 16:59:26 +00:00
|
|
|
const reduxApp = connect(
|
2016-03-20 04:47:43 +00:00
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(App);
|
|
|
|
|
2016-07-19 16:59:26 +00:00
|
|
|
export default DragDropContext(HTML5Backend)(reduxApp);
|
|
|
|
|