import { localized, React, ReactDOM, Actions, PropTypes } from 'mailspring-exports'; import { RetinaImg } from 'mailspring-component-kit'; import OpenTrackingMessagePopover from './open-tracking-message-popover'; import { PLUGIN_ID } from './open-tracking-constants'; export default class OpenTrackingMessageStatus extends React.Component { static displayName = 'OpenTrackingMessageStatus'; static propTypes = { message: PropTypes.object.isRequired, }; static containerStyles = { paddingTop: 4, }; onMouseDown = () => { const rect = ReactDOM.findDOMNode(this).getBoundingClientRect(); Actions.openPopover( , { originRect: rect, direction: 'down' } ); }; _getDataFromMessage() { const metadata = this.props.message.metadataForPluginId(PLUGIN_ID); if (!metadata || metadata.open_count == null) { return { hasMetadata: false, openCount: null, opened: false, }; } return { hasMetadata: true, openCount: metadata.open_count, opened: metadata.open_count > 0, }; } render() { const { hasMetadata, openCount, opened } = this._getDataFromMessage(); if (!hasMetadata) return false; const noun = openCount === 1 ? localized('Open') : localized('Opens'); let count = openCount; if (openCount > 999) { count = '999+'; } const text = opened ? `${count} ${noun.toLocaleLowerCase()}` : localized('No opens'); return ( { }  {text} ); } }