2016-02-20 04:30:24 +08:00
|
|
|
import {React} from 'nylas-exports'
|
2016-02-24 14:55:47 +08:00
|
|
|
import {PLUGIN_ID} from './link-tracking-constants'
|
|
|
|
|
2016-02-20 04:30:24 +08:00
|
|
|
|
|
|
|
export default class LinkTrackingPanel extends React.Component {
|
|
|
|
static displayName = 'LinkTrackingPanel';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
message: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = this._getStateFromMessage(props.message)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(newProps) {
|
|
|
|
this.setState(this._getStateFromMessage(newProps.message));
|
|
|
|
}
|
|
|
|
|
|
|
|
_getStateFromMessage(message) {
|
2016-02-24 11:19:43 +08:00
|
|
|
const metadata = message.metadataForPluginId(PLUGIN_ID);
|
2016-02-20 04:30:24 +08:00
|
|
|
return metadata ? {links: metadata.links} : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderContents() {
|
|
|
|
return this.state.links.map(link => {
|
|
|
|
return (<tr className="link-info">
|
2016-02-24 10:51:05 +08:00
|
|
|
<td className="link-url">{link.url}</td>
|
|
|
|
<td className="link-count">{link.click_count + " clicks"}</td>
|
2016-02-20 04:30:24 +08:00
|
|
|
</tr>)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.links) {
|
|
|
|
return (<div className="link-tracking-panel">
|
|
|
|
<h4>Link Tracking Enabled</h4>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
{this._renderContents()}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
return <div></div>;
|
|
|
|
}
|
|
|
|
}
|