insomnia/app/ui/components/base/Link.js
Gregory Schier 314daf155e Verify Before Syncing (#98)
* Added an UNSET sync mode

* Fixed tests

* Remove sync logs and adjusted dropdown

* Fixed duplication kve bug

* Added sync config modal

* AUtobind

* Autobind working

* Hot loading works again

* Remove express

* Fixed tests

* Fix one thing

* Fixed some hmr-related bugs
2017-03-02 17:44:07 -08:00

51 lines
1.4 KiB
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import autobind from 'autobind-decorator';
import {shell} from 'electron';
import {trackEvent} from '../../../analytics/index';
import * as querystring from '../../../common/querystring';
import {getAppVersion} from '../../../common/constants';
import {isDevelopment} from '../../../common/constants';
@autobind
class Link extends PureComponent {
constructor (props) {
super(props);
}
_handleClick (e) {
e && e.preventDefault();
const {href, onClick} = this.props;
// Also call onClick that was passed to us if there was one
onClick && onClick(e);
if (href.match(/^http/i)) {
const appName = isDevelopment() ? 'Insomnia Dev' : 'Insomnia';
const qs = `utm_source=${appName}&utm_medium=app&utm_campaign=v${getAppVersion()}`;
const attributedHref = querystring.joinUrl(href, qs);
shell.openExternal(attributedHref);
} else {
// Don't modify non-http urls
shell.openExternal(href);
}
trackEvent('Link', 'Click', href);
};
render () {
const {onClick, button, href, children, ...other} = this.props;
return button ?
<button onClick={this._handleClick} {...other}>{children}</button> :
<a href={href} onClick={this._handleClick} {...other}>{children}</a>
}
}
Link.propTypes = {
href: PropTypes.string.isRequired,
// Optional
button: PropTypes.bool
};
export default Link;