Response download and fix GA

This commit is contained in:
Gregory Schier committed 2016-10-28 10:51:08 -07:00
1 parent 1dc08efe39
commit 35c19ed305
6 files changed
+61 -14

No files matched your search

+7 -10
View File
@@ -1,7 +1,6 @@
import * as constants from './constants';
import {isDevelopment} from './appInfo';
let _ga = null;
let _sessionId = null;
export function initAnalytics () {
@@ -11,7 +10,7 @@ export function initAnalytics () {
}
if (!_sessionId) {
_ga = _initGA();
_injectGoogleAnalyticsScript();
}
if (!localStorage['gaClientId']) {
@@ -20,25 +19,25 @@ export function initAnalytics () {
const _sessionId = window.localStorage['gaClientId'];
_ga('create', constants.GA_ID, {'storage': 'none', 'clientId': _sessionId});
window.ga('create', constants.GA_ID, {'storage': 'none', 'clientId': _sessionId});
// Disable URL protocol check
_ga('set', 'checkProtocolTask', () => null);
window.ga('set', 'checkProtocolTask', () => null);
// Set a fake location
_ga('set', 'location', `https://${constants.GA_HOST}/`);
window.ga('set', 'location', `https://${constants.GA_HOST}/`);
// Track the initial page view
_ga('send', 'pageview');
window.ga('send', 'pageview');
console.log(`-- Analytics Initialized for ${_sessionId} --`);
}
export function trackEvent (category, action, label) {
_ga && _ga('send', 'event', category, action, label);
window.ga && window.ga('send', 'event', category, action, label);
}
function _initGA () {
function _injectGoogleAnalyticsScript () {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
@@ -50,6 +49,4 @@ function _initGA () {
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
return window.ga;
}
+3 -3
View File
@@ -81,9 +81,9 @@ export function allConfigs () {
return findConfigs({})
}
export function findInactiveConfigs (resourceGroupId = null) {
if (resourceGroupId) {
return findConfigs({syncMode: SYNC_MODE_OFF, $not: {resourceGroupId}})
export function findInactiveConfigs (excludedResourceGroupId = null) {
if (excludedResourceGroupId) {
return findConfigs({syncMode: SYNC_MODE_OFF, $not: {excludedResourceGroupId}})
} else {
return findConfigs({syncMode: SYNC_MODE_OFF})
}
+1
View File
@@ -17,6 +17,7 @@
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",
"json-lint": "^0.1.0",
"jsonpath-plus": "^0.15.0",
"mime-types": "^2.1.12",
"mkdirp": "^0.5.1",
"nedb": "^1.8.0",
"node-forge": "^0.6.43",
+42
View File
@@ -1,4 +1,7 @@
import React, {PropTypes, Component} from 'react';
import fs from 'fs';
import mime from 'mime-types';
import {remote} from 'electron';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
import ElmComponent from './ElmComponent';
import {ResponsePaneHeader} from './ResponsePaneHeader.elm';
@@ -18,6 +21,7 @@ import {
} from '../../backend/constants';
import {getSetCookieHeaders} from '../../backend/util';
import {cancelCurrentRequest} from '../../backend/network';
import {trackEvent} from '../../backend/ganalytics';
class ResponsePane extends Component {
constructor (props) {
@@ -37,6 +41,43 @@ class ResponsePane extends Component {
}
}
async _handleDownloadResponseBody () {
if (!this.state.response) {
// Should never happen
console.warn('No response to download');
return;
}
const {body, encoding, contentType} = this.state.response;
const bodyBuffer = new Buffer(body, encoding);
const extension = mime.extension(contentType) || '';
const options = {
title: 'Save Response',
buttonLabel: 'Save',
filters: [{
name: 'Download', extensions: [extension],
}]
};
remote.dialog.showSaveDialog(options, filename => {
if (!filename) {
trackEvent('Save Response', 'Cancel');
return;
}
fs.writeFile(filename, bodyBuffer, {}, err => {
if (err) {
console.warn('Failed to save response body', err);
trackEvent('Save Response', 'Failure');
} else {
trackEvent('Save Response', 'Success');
}
});
});
}
componentWillReceiveProps (nextProps) {
this._getResponse(nextProps.request);
}
@@ -171,6 +212,7 @@ class ResponsePane extends Component {
{getPreviewModeName(previewMode)}
</button>
<PreviewModeDropdown
download={this._handleDownloadResponseBody.bind(this)}
previewMode={previewMode}
updatePreviewMode={updatePreviewMode}
/>
@@ -1,8 +1,9 @@
import React, {PropTypes} from 'react';
import Dropdown from '../base/Dropdown';
import DropdownDivider from '../base/DropdownDivider';
import {PREVIEW_MODES, getPreviewModeName} from '../../../backend/previewModes';
const PreviewModeDropdown = ({updatePreviewMode}) => (
const PreviewModeDropdown = ({updatePreviewMode, download}) => (
<Dropdown>
<button className="tall">
<i className="fa fa-caret-down"></i>
@@ -15,6 +16,10 @@ const PreviewModeDropdown = ({updatePreviewMode}) => (
}}>{getPreviewModeName(previewMode)}</button>
</li>
))}
<DropdownDivider></DropdownDivider>
<li>
<button onClick={download}>Download</button>
</li>
</ul>
</Dropdown>
);
@@ -22,6 +27,7 @@ const PreviewModeDropdown = ({updatePreviewMode}) => (
PreviewModeDropdown.propTypes = {
// Functions
updatePreviewMode: PropTypes.func.isRequired,
download: PropTypes.func.isRequired,
// Required
previewMode: PropTypes.string.isRequired
+1
View File
@@ -67,6 +67,7 @@
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",
"json-lint": "^0.1.0",
"jsonpath-plus": "^0.15.0",
"mime-types": "^2.1.12",
"mkdirp": "^0.5.1",
"mousetrap": "^1.6.0",
"nedb": "^1.8.0",