Add prompt to export private environments (if any) (#343)

This commit is contained in:
Gregory Schier 2017-07-03 13:51:55 -07:00 committed by GitHub
parent 13365989a5
commit 5fbfbccd2a
5 changed files with 144 additions and 31 deletions

View File

@ -79,7 +79,6 @@ export async function importRaw (workspace, rawContent, generateNewIds = false)
}
const {data} = results;
console.log('IMPORTING', JSON.parse(rawContent));
// Fetch the base environment in case we need it
const baseEnvironment = await models.environment.getOrCreateForWorkspace(workspace);
@ -145,7 +144,7 @@ export async function importRaw (workspace, rawContent, generateNewIds = false)
};
}
export async function exportJSON (parentDoc = null) {
export async function exportJSON (parentDoc = null, includePrivateDocs = false) {
const data = {
_type: 'export',
__export_format: EXPORT_FORMAT,
@ -156,32 +155,37 @@ export async function exportJSON (parentDoc = null) {
const docs = await db.withDescendants(parentDoc);
data.resources = docs.filter(d => (
!d.isPrivate && (
data.resources = docs
.filter(d => (
// Don't include if private, except if we want to
!d.isPrivate || includePrivateDocs
))
.filter(d => (
// Only export these model types
d.type === models.request.type ||
d.type === models.requestGroup.type ||
d.type === models.workspace.type ||
d.type === models.cookieJar.type ||
d.type === models.environment.type
)
)).map(d => {
if (d.type === models.workspace.type) {
d._type = EXPORT_TYPE_WORKSPACE;
} else if (d.type === models.cookieJar.type) {
d._type = EXPORT_TYPE_COOKIE_JAR;
} else if (d.type === models.environment.type) {
d._type = EXPORT_TYPE_ENVIRONMENT;
} else if (d.type === models.requestGroup.type) {
d._type = EXPORT_TYPE_REQUEST_GROUP;
} else if (d.type === models.request.type) {
d._type = EXPORT_TYPE_REQUEST;
}
))
.map(d => {
if (d.type === models.workspace.type) {
d._type = EXPORT_TYPE_WORKSPACE;
} else if (d.type === models.cookieJar.type) {
d._type = EXPORT_TYPE_COOKIE_JAR;
} else if (d.type === models.environment.type) {
d._type = EXPORT_TYPE_ENVIRONMENT;
} else if (d.type === models.requestGroup.type) {
d._type = EXPORT_TYPE_REQUEST_GROUP;
} else if (d.type === models.request.type) {
d._type = EXPORT_TYPE_REQUEST;
}
// Delete the things we don't want to export
delete d.type;
delete d.isPrivate;
return d;
});
// Delete the things we don't want to export
delete d.type;
delete d.isPrivate;
return d;
});
return JSON.stringify(data, null, '\t');
}

View File

@ -49,15 +49,15 @@ class AuthWrapper extends PureComponent {
} else if (authentication.type === AUTH_OAUTH_1) {
return (
<div className="vertically-center text-center">
<p className="pad text-sm text-center">
<div className="pad text-sm text-center">
<i className="fa fa-commenting super-faint" style={{fontSize: '8rem', opacity: 0.3}}/>
<div className="faint pad-top">
Want OAuth 1.0? Please upvote
the <Link href="https://github.com/getinsomnia/insomnia/issues/197">
Issue on GitHub
</Link>
</div>
</p>
<p className="faint pad-top">
Want OAuth 1.0? Please upvote
the <Link href="https://github.com/getinsomnia/insomnia/issues/197">
Issue on GitHub
</Link>
</p>
</div>
</div>
);
} else if (authentication.type === AUTH_DIGEST) {

View File

@ -0,0 +1,83 @@
import React, {PureComponent} from 'react';
import autobind from 'autobind-decorator';
import Modal from '../base/modal';
import ModalBody from '../base/modal-body';
import ModalHeader from '../base/modal-header';
import ModalFooter from '../base/modal-footer';
@autobind
class AskModal extends PureComponent {
constructor (props) {
super(props);
this.state = {
title: '',
message: ''
};
}
_setModalRef (m) {
this.modal = m;
}
_handleYes () {
this.hide();
this._doneCallback && this._doneCallback(true);
this._promiseCallback(true);
}
_handleNo () {
this.hide();
this._doneCallback && this._doneCallback(false);
this._promiseCallback(false);
}
hide () {
this.modal.hide();
}
show (options = {}) {
const {
title,
message,
onDone
} = options;
this.modal.show();
this._doneCallback = onDone;
this.setState({title, message});
return new Promise(resolve => {
this._promiseCallback = resolve;
});
}
render () {
const {message, title} = this.state;
return (
<Modal noEscape ref={this._setModalRef} closeOnKeyCodes={[13]}>
<ModalHeader>{title || 'Confirm?'}</ModalHeader>
<ModalBody className="wide pad">
{message}
</ModalBody>
<ModalFooter>
<div>
<button className="btn" onClick={this._handleNo}>
No
</button>
<button className="btn" onClick={this._handleYes}>
Yes
</button>
</div>
</ModalFooter>
</Modal>
);
}
}
AskModal.propTypes = {};
export default AskModal;

View File

@ -11,6 +11,7 @@ import LoginModal from './modals/login-modal';
import PaymentNotificationModal from './modals/payment-notification-modal';
import NunjucksModal from './modals/nunjucks-modal';
import PromptModal from './modals/prompt-modal';
import AskModal from './modals/ask-modal';
import RequestCreateModal from './modals/request-create-modal';
import RequestPane from './request-pane';
import RequestSwitcherModal from './modals/request-switcher-modal';
@ -406,6 +407,7 @@ class Wrapper extends PureComponent {
<ChangelogModal ref={registerModal}/>
<LoginModal ref={registerModal}/>
<PromptModal ref={registerModal}/>
<AskModal ref={registerModal}/>
<RequestCreateModal ref={registerModal}/>
<PaymentNotificationModal ref={registerModal}/>
<FilterHelpModal ref={registerModal}/>

View File

@ -3,6 +3,7 @@ import React from 'react';
import {combineReducers} from 'redux';
import fs from 'fs';
import path from 'path';
import AskModal from '../../../ui/components/modals/ask-modal';
import * as moment from 'moment';
import * as importUtils from '../../../common/import';
@ -183,7 +184,30 @@ export function exportFile (workspaceId = null) {
dispatch(loadStart());
const workspace = await models.workspace.getById(workspaceId);
const json = await importUtils.exportJSON(workspace);
// Check if we want to export private environments
let environments;
if (workspace) {
const parentEnv = await models.environment.getOrCreateForWorkspace(workspace);
environments = [
parentEnv,
...await models.environment.findByParentId(parentEnv._id)
];
} else {
environments = await models.environment.all();
}
let exportPrivateEnvironments = false;
const privateEnvironments = environments.filter(e => e.isPrivate);
if (privateEnvironments.length) {
const names = privateEnvironments.map(e => e.name).join(', ');
exportPrivateEnvironments = await showModal(AskModal, {
title: 'Export Private Environments?',
message: `Do you want to include private environments (${names}) in your export?`
});
}
const json = await importUtils.exportJSON(workspace, exportPrivateEnvironments);
const date = moment().format('YYYY-MM-DD');
const name = (workspace ? workspace.name : 'Insomnia All').replace(/ /g, '-');