11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import { Map } from 'immutable' ;
4- import { compose , withProps , setPropTypes } from 'recompose' ;
4+ import { compose , setPropTypes , withProps } from 'recompose' ;
55import { withModels } from 'ui/utils/hocs' ;
66import SiteUserOrgItem from './SiteUserOrgItem' ;
77
@@ -11,12 +11,12 @@ const enhance = compose(
1111 } ) ,
1212 withProps ( ( { user } ) => {
1313 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.
1717 const filter = new Map ( {
1818 _id : new Map ( {
19- $in : organisations
19+ $in : organisations . slice ( 0 , 10 )
2020 } )
2121 } ) ;
2222
@@ -25,11 +25,37 @@ const enhance = compose(
2525 withModels
2626) ;
2727
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+ } )
3149 . 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+ ) ;
3359} ;
3460
3561export default enhance ( SiteUserOrgItems ) ;
0 commit comments