diff -r 000000000000 -r 5f4fcbc80b37 clientjs/packages/dashboard-components/src/ui/TermEntry.jsx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clientjs/packages/dashboard-components/src/ui/TermEntry.jsx Fri Sep 14 17:57:34 2018 +0200 @@ -0,0 +1,84 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { NavLink } from 'react-router-dom'; +import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; +import md5 from 'md5'; + +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; + +import './TermEntry.scss'; + + +function getTermDefinition(annotation) { + if (annotation.text) { + return annotation.text; + } + + let selector; + + if (annotation.target[0].selector) { + selector = annotation.target[0].selector.find(s => s.type === 'TextQuoteSelector'); + } + + if (selector) { + return selector.exact; + } + return ''; +} + +const TermEntry = ({ term, termDef, intl }) => { + const key = `${md5(term)}-term-entry`; + + let firstDefinition = ''; + + if (termDef.definitions.length > 0) { + firstDefinition = getTermDefinition(termDef.definitions[0]); + } + if (!firstDefinition) { + firstDefinition = ; + } + + const definitionsTitle = intl.formatMessage({ id: 'ui.termEntry.nbDefinitions', defaultMessage: 'Nb. definitions' }); + const referencesTitle = intl.formatMessage({ id: 'ui.termEntry.nbReferences', defaultMessage: 'Nb. references' }); + const commentsTitle = intl.formatMessage({ id: 'ui.termEntry.nbComments', defaultMessage: 'Nb. comments' }); + + return ( + + {term} + +

{firstDefinition}

+

+ + + + {' '} + { termDef.definitions.length } + + + + + + {' '} + { termDef.references.length } + + + + + + {' '} + { termDef.messagesCount || 0 } + + +

+ + + ); +}; + +TermEntry.propTypes = { + term: PropTypes.string.isRequired, + termDef: PropTypes.object.isRequired, + intl: intlShape.isRequired, +}; + +export default injectIntl(TermEntry);