2016-07-07 20:10:55 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {shell} from 'electron';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
|
|
|
import * as querystring from '../../../common/querystring';
|
|
|
|
import {getAppVersion} from '../../../common/constants';
|
2016-11-23 23:12:32 +00:00
|
|
|
import {isDevelopment} from '../../../common/constants';
|
2016-07-07 20:10:55 +00:00
|
|
|
|
|
|
|
class Link extends Component {
|
2016-11-29 22:28:55 +00:00
|
|
|
_handleClick = e => {
|
2016-11-23 19:33:24 +00:00
|
|
|
e && e.preventDefault();
|
2016-11-29 22:28:55 +00:00
|
|
|
const {href, onClick} = this.props;
|
|
|
|
|
|
|
|
// Also call onClick that was passed to us if there was one
|
|
|
|
onClick && onClick(e);
|
|
|
|
|
2016-11-23 19:33:24 +00:00
|
|
|
if (href.match(/^http/i)) {
|
2016-11-23 23:12:32 +00:00
|
|
|
const appName = isDevelopment() ? 'Insomnia Dev' : 'Insomnia';
|
2016-12-05 22:42:40 +00:00
|
|
|
const qs = `utm_source=${appName}&utm_medium=app&utm_campaign=v${getAppVersion()}`;
|
2016-11-23 19:33:24 +00:00
|
|
|
const attributedHref = querystring.joinUrl(href, qs);
|
|
|
|
shell.openExternal(attributedHref);
|
|
|
|
} else {
|
|
|
|
// Don't modify non-http urls
|
|
|
|
shell.openExternal(href);
|
|
|
|
}
|
|
|
|
|
2016-11-29 22:28:55 +00:00
|
|
|
trackEvent('Link', 'Click', href);
|
|
|
|
};
|
2016-11-23 22:55:09 +00:00
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2016-11-23 20:10:53 +00:00
|
|
|
const {onClick, button, href, children, ...other} = this.props;
|
2016-11-29 22:28:55 +00:00
|
|
|
return button ?
|
|
|
|
<button onClick={this._handleClick} {...other}>{children}</button> :
|
|
|
|
<a href={href} onClick={this._handleClick} {...other}>{children}</a>
|
2016-07-07 20:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Link.propTypes = {
|
2016-08-25 17:06:01 +00:00
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
button: PropTypes.bool
|
2016-07-07 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Link;
|