diff --git a/lib/models/plugins/addCRUDFunctions.js b/lib/models/plugins/addCRUDFunctions.js index e4e55cd780..75502c5575 100644 --- a/lib/models/plugins/addCRUDFunctions.js +++ b/lib/models/plugins/addCRUDFunctions.js @@ -181,7 +181,7 @@ async function getConnection({ query.where(cursorFilter); } else if (before) { const cursorFilter = paginationToFilter({ - cursor: after, + cursor: before, sort, paginationDirection: direction }); diff --git a/ui/src/pages/SiteUsersPage/SiteUserOrgItems.js b/ui/src/pages/SiteUsersPage/SiteUserOrgItems.js index 968c9bb6e5..50b94ae3b8 100644 --- a/ui/src/pages/SiteUsersPage/SiteUserOrgItems.js +++ b/ui/src/pages/SiteUsersPage/SiteUserOrgItems.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Map } from 'immutable'; -import { compose, withProps, setPropTypes } from 'recompose'; +import { compose, setPropTypes, withProps } from 'recompose'; import { withModels } from 'ui/utils/hocs'; import SiteUserOrgItem from './SiteUserOrgItem'; @@ -11,12 +11,12 @@ const enhance = compose( }), withProps(({ user }) => { const schema = 'organisation'; - const organisations = user - .get('organisations') - .map(org => new Map({ $oid: org })); + const organisations = user.get('organisations').map(org => new Map({ $oid: org })); + // Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642) + // Need to change when we will have OrganisationUser model. const filter = new Map({ _id: new Map({ - $in: organisations + $in: organisations.slice(0, 10) }) }); @@ -25,11 +25,37 @@ const enhance = compose( withModels ); -const SiteUserOrgItems = ({ models, user }) => { - const orgsItems = models - .map(org => ) +const SiteUserOrgItems = ({ models, user, filter }) => { + // Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642) + // Need to change when we will have OrganisationUser model. + const orgItems = filter + .get('_id') + .get('$in') + .map((org) => { + const orgModel = models.find(model => + model.get('_id').toString() === org.get('$oid').toString() + ); + + if (orgModel === undefined) { + return ( +
  • + Sorry organisation with id {org.get('$oid')} was deleted! +
  • + ); + } + + return ; + }) .valueSeq(); - return ; + + const countOfRemainingOrganisations = user.get('organisations').count() - orgItems.count(); + + return ( +
    +
      {orgItems}
    + {countOfRemainingOrganisations > 0 &&

    Plus { countOfRemainingOrganisations } more not displayed

    } +
    + ); }; export default enhance(SiteUserOrgItems);