insomnia/packages/insomnia-app/app/ui/components/modals/setup-sync-modal.js
Gregory Schier 0a616fba6b
Version Control (beta) (#1439)
* VCS proof of concept underway!

* Stuff

* Some things

* Replace deprecated Electron makeSingleInstance

* Rename `window` variables so not to be confused with window object

* Don't unnecessarily update request when URL does not change

* Regenerate package-lock

* Fix tests + ESLint

* Publish

 - insomnia-app@1.0.49
 - insomnia-cookies@0.0.12
 - insomnia-httpsnippet@1.16.18
 - insomnia-importers@2.0.13
 - insomnia-libcurl@0.0.23
 - insomnia-prettify@0.1.7
 - insomnia-url@0.1.6
 - insomnia-xpath@1.0.9
 - insomnia-plugin-base64@1.0.6
 - insomnia-plugin-cookie-jar@1.0.8
 - insomnia-plugin-core-themes@1.0.5
 - insomnia-plugin-default-headers@1.1.9
 - insomnia-plugin-file@1.0.7
 - insomnia-plugin-hash@1.0.7
 - insomnia-plugin-jsonpath@1.0.12
 - insomnia-plugin-now@1.0.11
 - insomnia-plugin-os@1.0.13
 - insomnia-plugin-prompt@1.1.9
 - insomnia-plugin-request@1.0.18
 - insomnia-plugin-response@1.0.16
 - insomnia-plugin-uuid@1.0.10

* Broken but w/e

* Some tweaks

* Big refactor. Create local snapshots and push done

* POC merging and a lot of improvements

* Lots of work done on initial UI/UX

* Fix old tests

* Atomic writes and size-based batches

* Update StageEntry definition once again to be better

* Factor out GraphQL query logic

* Merge algorithm, history modal, other minor things

* Fix test

* Merge, checkout, revert w/ user changes now work

* Force UI to refresh when switching branches changes active request

* Rough draft pull() and some cleanup

* E2EE stuff and some refactoring

* Add ability to share project with team and fixed tests

* VCS now created in root component and better remote project handling

* Remove unused definition

* Publish

 - insomnia-account@0.0.2
 - insomnia-app@1.1.1
 - insomnia-cookies@0.0.14
 - insomnia-httpsnippet@1.16.20
 - insomnia-importers@2.0.15
 - insomnia-libcurl@0.0.25
 - insomnia-prettify@0.1.9
 - insomnia-sync@0.0.2
 - insomnia-url@0.1.8
 - insomnia-xpath@1.0.11
 - insomnia-plugin-base64@1.0.8
 - insomnia-plugin-cookie-jar@1.0.10
 - insomnia-plugin-core-themes@1.0.7
 - insomnia-plugin-file@1.0.9
 - insomnia-plugin-hash@1.0.9
 - insomnia-plugin-jsonpath@1.0.14
 - insomnia-plugin-now@1.0.13
 - insomnia-plugin-os@1.0.15
 - insomnia-plugin-prompt@1.1.11
 - insomnia-plugin-request@1.0.20
 - insomnia-plugin-response@1.0.18
 - insomnia-plugin-uuid@1.0.12

* Move some deps around

* Fix Flow errors

* Update package.json

* Fix eslint errors

* Fix tests

* Update deps

* bootstrap insomnia-sync

* TRy fixing appveyor

* Try something else

* Bump lerna

* try powershell

*  Try again

* Fix imports

* Fixed errors

* sync types refactor

* Show remote projects in workspace dropdown

* Improved pulling of non-local workspaces

* Loading indicators and some tweaks

* Clean up sync staging modal

* Some sync improvements:

- No longer store stage
- Upgrade Electron
- Sync UI/UX improvements

* Fix snyc tests

* Upgraded deps and hot loader tweaks (it's broken for some reason)

* Fix tests

* Branches dialog, network refactoring, some tweaks

* Fixed merging when other branch is empty

* A bunch of small fixes from real testing

* Fixed pull merge logic

* Fix tests

* Some bug fixes

* A few small tweaks

* Conflict resolution and other improvements

* Fix tests

* Add revert changes

* Deal with duplicate projects per workspace

* Some tweaks and accessibility improvements

* Tooltip accessibility

* Fix API endpoint

* Fix tests

* Remove jest dep from insomnia-importers
2019-04-17 17:50:03 -07:00

182 lines
5.5 KiB
JavaScript

// @flow
import * as React 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';
import * as sync from '../../../sync-legacy';
import {
SYNC_MODE_OFF,
SYNC_MODE_ON,
SYNC_MODE_NEVER,
SYNC_MODE_UNSET,
} from '../../../sync-legacy/storage';
import type { Workspace } from '../../../models/workspace';
import HelpTooltip from '../help-tooltip';
type Props = {
workspace: Workspace,
};
type State = {
syncMode: string,
selectedSyncMode: string,
syncDisableCookieJars: boolean,
syncDisableClientCertificates: boolean,
};
@autobind
class SetupSyncModal extends React.PureComponent<Props, State> {
modal: ?Modal;
_onSelectSyncMode: ?(selectedSyncMode: string) => void;
constructor(props: Props) {
super(props);
this.state = {
syncMode: SYNC_MODE_UNSET,
selectedSyncMode: SYNC_MODE_ON,
syncDisableCookieJars: false,
syncDisableClientCertificates: false,
};
}
_setModalRef(n: ?Modal) {
this.modal = n;
}
_handleToggleSyncCertificates(e: SyntheticEvent<HTMLInputElement>) {
this.setState({ syncDisableClientCertificates: !e.currentTarget.checked });
}
_handleToggleSyncCookieJars(e: SyntheticEvent<HTMLInputElement>) {
this.setState({ syncDisableCookieJars: !e.currentTarget.checked });
}
async _handleDone() {
const { workspace } = this.props;
const { selectedSyncMode, syncDisableClientCertificates, syncDisableCookieJars } = this.state;
const resource = await sync.getOrCreateResourceForDoc(workspace);
await sync.createOrUpdateConfig(resource.resourceGroupId, {
syncMode: selectedSyncMode,
syncDisableClientCertificates: !!syncDisableClientCertificates,
syncDisableCookieJars: !!syncDisableCookieJars,
});
this.hide();
this._onSelectSyncMode && this._onSelectSyncMode(selectedSyncMode);
}
_handleSyncModeChange(e: SyntheticEvent<HTMLSelectElement>) {
const selectedSyncMode = e.currentTarget.value;
this.setState({
selectedSyncMode,
});
}
async show(options: { onSelectSyncMode: (syncMode: string) => void }) {
const { workspace } = this.props;
const resource = await sync.getOrCreateResourceForDoc(workspace);
const config = await sync.getOrCreateConfig(resource.resourceGroupId);
const { syncMode, syncDisableCookieJars, syncDisableClientCertificates } = config;
// Set selected sync mode. If it's unset, default it to ON
const selectedSyncMode = syncMode !== SYNC_MODE_UNSET ? syncMode : SYNC_MODE_ON;
this.setState({
syncMode,
selectedSyncMode,
syncDisableCookieJars,
syncDisableClientCertificates,
});
this._onSelectSyncMode = options.onSelectSyncMode;
this.modal && this.modal.show();
}
hide() {
this.modal && this.modal.hide();
}
render() {
const { workspace } = this.props;
const {
syncMode,
selectedSyncMode,
syncDisableClientCertificates,
syncDisableCookieJars,
} = this.state;
return (
<Modal ref={this._setModalRef} noEscape>
<ModalHeader>Workspace Sync Setup</ModalHeader>
<ModalBody className="wide pad-left pad-right">
{syncMode === SYNC_MODE_UNSET ? (
<p className="notice info">
You have not yet configured sync for your <strong>{workspace.name}</strong> workspace.
</p>
) : null}
<br />
<div className="form-control form-control--outlined">
<label>
Sync mode
<HelpTooltip className="space-left">
Control how and when data for this workspace is synced with the server
</HelpTooltip>
<select onChange={this._handleSyncModeChange} value={selectedSyncMode}>
<option value={SYNC_MODE_ON}>Automatically sync changes</option>
<option value={SYNC_MODE_OFF}>Manually sync changes</option>
<option value={SYNC_MODE_NEVER}>Disable sync for this workspace</option>
</select>
</label>
</div>
<br />
<label className="bold">
Advanced Rules
<HelpTooltip className="space-left">
Customize sync for you or your team's needs by choosing which resources are synced for
this workspace
</HelpTooltip>
</label>
<div className="form-control form-control--thin">
<label>
Sync Cookie Jars
<input
type="checkbox"
checked={!syncDisableCookieJars}
onChange={this._handleToggleSyncCookieJars}
/>
</label>
</div>
<div className="form-control form-control--thin">
<label>
Sync SSL Client Certificates
<input
type="checkbox"
checked={!syncDisableClientCertificates}
onChange={this._handleToggleSyncCertificates}
/>
</label>
</div>
<br />
</ModalBody>
<ModalFooter>
<div className="margin-left faint italic txt-sm tall">
* This can be changed at any time
</div>
<button className="btn" onClick={this._handleDone}>
Continue
</button>
</ModalFooter>
</Modal>
);
}
}
export default SetupSyncModal;