1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { Map } from 'immutable' ;
4
- import { compose , withProps , setPropTypes } from 'recompose' ;
4
+ import { compose , setPropTypes , withProps } from 'recompose' ;
5
5
import { withModels } from 'ui/utils/hocs' ;
6
6
import SiteUserOrgItem from './SiteUserOrgItem' ;
7
7
@@ -11,12 +11,12 @@ const enhance = compose(
11
11
} ) ,
12
12
withProps ( ( { user } ) => {
13
13
const schema = 'organisation' ;
14
- const organisations = user
15
- . get ( 'organisations' )
16
- . map ( org => new Map ( { $oid : org } ) ) ;
14
+ const organisations = user . get ( 'organisations' ) . map ( org => new Map ( { $oid : org } ) ) ;
15
+ // Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642 )
16
+ // Need to change when we will have OrganisationUser model.
17
17
const filter = new Map ( {
18
18
_id : new Map ( {
19
- $in : organisations
19
+ $in : organisations . slice ( 0 , 10 )
20
20
} )
21
21
} ) ;
22
22
@@ -25,11 +25,37 @@ const enhance = compose(
25
25
withModels
26
26
) ;
27
27
28
- const SiteUserOrgItems = ( { models, user } ) => {
29
- const orgsItems = models
30
- . map ( org => < SiteUserOrgItem key = { org . get ( '_id' ) . toString ( ) } org = { org } user = { user } /> )
28
+ const SiteUserOrgItems = ( { models, user, filter } ) => {
29
+ // Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642)
30
+ // Need to change when we will have OrganisationUser model.
31
+ const orgItems = filter
32
+ . get ( '_id' )
33
+ . get ( '$in' )
34
+ . map ( ( org ) => {
35
+ const orgModel = models . find ( model =>
36
+ model . get ( '_id' ) . toString ( ) === org . get ( '$oid' ) . toString ( )
37
+ ) ;
38
+
39
+ if ( orgModel === undefined ) {
40
+ return (
41
+ < li key = { org . get ( '$oid' ) . toString ( ) } >
42
+ Sorry organisation with id { org . get ( '$oid' ) } was deleted!
43
+ </ li >
44
+ ) ;
45
+ }
46
+
47
+ return < SiteUserOrgItem key = { orgModel . get ( '_id' ) . toString ( ) } org = { orgModel } user = { user } /> ;
48
+ } )
31
49
. valueSeq ( ) ;
32
- return < ul > { orgsItems } </ ul > ;
50
+
51
+ const countOfRemainingOrganisations = user . get ( 'organisations' ) . count ( ) - orgItems . count ( ) ;
52
+
53
+ return (
54
+ < div >
55
+ < ul > { orgItems } </ ul >
56
+ { countOfRemainingOrganisations > 0 && < p > Plus { countOfRemainingOrganisations } more not displayed</ p > }
57
+ </ div >
58
+ ) ;
33
59
} ;
34
60
35
61
export default enhance ( SiteUserOrgItems ) ;
0 commit comments