|
1 |
|
2 import _ from 'lodash'; |
|
3 |
|
4 import React from 'react'; |
|
5 import PropTypes from 'prop-types'; |
|
6 |
|
7 import { FormattedMessage } from 'react-intl'; |
|
8 |
|
9 import DocumentAnnotations from './DocumentAnnotations'; |
|
10 |
|
11 const AnnotationsCards = ({ |
|
12 annotations, |
|
13 viaBaseUrl, |
|
14 metacategories, |
|
15 categories, |
|
16 children, |
|
17 }) => { |
|
18 const documents = _(annotations).groupBy('uri'); |
|
19 |
|
20 const documentAnnotations = documents.map((docAnnotations, uri) => { |
|
21 const document = { |
|
22 uri, |
|
23 title: docAnnotations[0].document.title, |
|
24 annotations: docAnnotations, |
|
25 }; |
|
26 |
|
27 return ( |
|
28 <DocumentAnnotations |
|
29 key={document.uri} |
|
30 document={document} |
|
31 viaBaseUrl={viaBaseUrl} |
|
32 metacategories={metacategories} |
|
33 categories={categories} |
|
34 /> |
|
35 ); |
|
36 }).value(); |
|
37 |
|
38 let noAnnotationContent = <FormattedMessage id="ui.annotationsCards.noAnnotation" defaultMessage="No annotation" />; |
|
39 if (React.Children.count(children) > 0) { |
|
40 noAnnotationContent = children; |
|
41 } |
|
42 |
|
43 return ( |
|
44 <div className="card-columns"> |
|
45 { annotations.length === 0 ? noAnnotationContent : documentAnnotations } |
|
46 </div> |
|
47 ); |
|
48 }; |
|
49 |
|
50 AnnotationsCards.propTypes = { |
|
51 annotations: PropTypes.arrayOf(PropTypes.object), |
|
52 viaBaseUrl: PropTypes.string.isRequired, |
|
53 metacategories: PropTypes.arrayOf(PropTypes.object).isRequired, |
|
54 categories: PropTypes.arrayOf(PropTypes.string).isRequired, |
|
55 children: PropTypes.node, |
|
56 }; |
|
57 |
|
58 AnnotationsCards.defaultProps = { |
|
59 annotations: [], |
|
60 children: null, |
|
61 }; |
|
62 |
|
63 export default AnnotationsCards; |