import React, { Component } from 'react'; import PropTypes from 'prop-types'; import SiteIcon from '../../ui/site-icon'; import { stripHttpSchemes } from '../../../helpers/utils/util'; export default class ConnectedSitesList extends Component { static contextTypes = { t: PropTypes.func, }; static propTypes = { connectedDomains: PropTypes.arrayOf( PropTypes.shape({ name: PropTypes.string, icon: PropTypes.string, origin: PropTypes.string, host: PropTypes.string, }), ).isRequired, onDisconnect: PropTypes.func.isRequired, domainHostCount: PropTypes.objectOf(PropTypes.number).isRequired, }; render() { const { connectedDomains, onDisconnect } = this.props; const { t } = this.context; return (
{connectedDomains.map((domain) => (
{this.getDomainDisplayName(domain)}
onDisconnect(domain.origin)} />
))}
); } getDomainDisplayName(domain) { if (domain.extensionId) { return this.context.t('externalExtension'); } return this.props.domainHostCount[domain.host] > 1 ? domain.origin : stripHttpSchemes(domain.origin); } }