author | ymh <ymh.work@gmail.com> |
Mon, 17 Sep 2018 18:32:48 +0200 | |
changeset 8 | 24a3d661309f |
parent 0 | 5f4fcbc80b37 |
permissions | -rw-r--r-- |
0
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import React from 'react'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
import PropTypes from 'prop-types'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import { NavLink } from 'react-router-dom'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import md5 from 'md5'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
import './TermEntry.scss'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
function getTermDefinition(annotation) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
if (annotation.text) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
return annotation.text; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
let selector; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
if (annotation.target[0].selector) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
selector = annotation.target[0].selector.find(s => s.type === 'TextQuoteSelector'); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
if (selector) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
return selector.exact; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
return ''; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
const TermEntry = ({ term, termDef, intl }) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
const key = `${md5(term)}-term-entry`; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
let firstDefinition = ''; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
if (termDef.definitions.length > 0) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
firstDefinition = getTermDefinition(termDef.definitions[0]); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
if (!firstDefinition) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
firstDefinition = <span className="text-muted font-italic"><FormattedMessage id="ui.termEntry.noDefinition" defaultMessage="No definition yet" /></span>; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
const definitionsTitle = intl.formatMessage({ id: 'ui.termEntry.nbDefinitions', defaultMessage: 'Nb. definitions' }); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
const referencesTitle = intl.formatMessage({ id: 'ui.termEntry.nbReferences', defaultMessage: 'Nb. references' }); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
const commentsTitle = intl.formatMessage({ id: 'ui.termEntry.nbComments', defaultMessage: 'Nb. comments' }); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
return ( |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
<tr id={key}> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
<th scope="row" className="term-entry-term"><NavLink to={`/term/${encodeURIComponent(term)}`} className="term-entry-term-link">{term}</NavLink></th> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
<td className="term-entry-def"> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
<p>{firstDefinition}</p> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
<p className="glossary-table-counts align-text-bottom text-right text-muted small"> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
<span title={definitionsTitle}> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
<NavLink to={`/term/${encodeURIComponent(term)}`} className="term-entry-term-link"> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
<FontAwesomeIcon icon="file-alt" /> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
{' '} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
<span>{ termDef.definitions.length }</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
</NavLink> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
<span title={referencesTitle}> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
<NavLink to={`/term/${encodeURIComponent(term)}/1`} className="term-entry-term-link"> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
<FontAwesomeIcon icon="share-alt" /> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
{' '} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
<span>{ termDef.references.length }</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
</NavLink> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
<span title={commentsTitle}> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
<NavLink to={`/term/${encodeURIComponent(term)}/2`} className="term-entry-term-link"> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
<FontAwesomeIcon icon="comments" /> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
{' '} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
<span>{ termDef.messagesCount || 0 }</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
</NavLink> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
</span> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
</p> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
</td> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
</tr> |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
}; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
TermEntry.propTypes = { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
term: PropTypes.string.isRequired, |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
termDef: PropTypes.object.isRequired, |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
intl: intlShape.isRequired, |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
}; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
export default injectIntl(TermEntry); |