Skip to content

Commit

Permalink
Uiu 603 (#470)
Browse files Browse the repository at this point in the history
* Move loansHistory back to ViewUser component, refs UIU-602, UIU-603
  • Loading branch information
adi-mat committed Aug 16, 2018
1 parent ea1df1c commit 2238830
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
25 changes: 3 additions & 22 deletions LoansHistory.js
Expand Up @@ -17,18 +17,6 @@ import css from './LoansHistory.css';
* the loan's item-record.
*/
class LoansHistory extends React.Component {
static manifest = Object.freeze({
loansHistory: {
type: 'okapi',
path: 'circulation/loans',
records: 'loans',
params: {
query: '(userId=!{user.id}) sortby id',
limit: '100',
},
},
});

static propTypes = {
stripes: PropTypes.shape({
locale: PropTypes.string.isRequired,
Expand All @@ -41,11 +29,7 @@ class LoansHistory extends React.Component {
onClickViewClosedLoans: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
patronGroup: PropTypes.object.isRequired,
resources: PropTypes.shape({
loansHistory: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
})
loansHistory: PropTypes.arrayOf(PropTypes.object).isRequired,
};

constructor(props) {
Expand Down Expand Up @@ -79,12 +63,9 @@ class LoansHistory extends React.Component {
}

render() {
const { user, patronGroup, openLoans, resources, stripes: { intl } } = this.props;
const { user, patronGroup, openLoans, loansHistory, stripes: { intl } } = this.props;
const loanStatus = openLoans ? 'Open' : 'Closed';
const loans = _.filter(
_.get(resources, ['loansHistory', 'records'], []),
loan => loanStatus === _.get(loan, ['status', 'name'])
);
const loans = _.filter(loansHistory, loan => loanStatus === _.get(loan, ['status', 'name']));
if (!loans) return <div />;

return (
Expand Down
11 changes: 11 additions & 0 deletions ViewUser.js
Expand Up @@ -46,6 +46,12 @@ class ViewUser extends React.Component {
path: 'users/:{id}',
clear: false,
},
loansHistory: {
type: 'okapi',
records: 'loans',
path: 'circulation/loans?query=(userId=:{id}) sortby id&limit=100',
permissionsRequired: 'circulation.loans.collection.get',
},
patronGroups: {
type: 'okapi',
path: 'groups',
Expand Down Expand Up @@ -105,6 +111,9 @@ class ViewUser extends React.Component {
records: PropTypes.arrayOf(PropTypes.object),
}),
}),
loansHistory: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
mutator: PropTypes.shape({
selUser: PropTypes.shape({
PUT: PropTypes.func.isRequired,
Expand Down Expand Up @@ -431,6 +440,7 @@ class ViewUser extends React.Component {
const patronGroups = (resources.patronGroups || {}).records || [];
const permissions = (resources.permissions || {}).records || [];
const settings = (resources.settings || {}).records || [];
const loans = (resources.loansHistory || {}).records || [];
const sponsors = this.props.getSponsors();
const proxies = this.props.getProxies();
const servicePoints = this.props.getServicePoints();
Expand Down Expand Up @@ -484,6 +494,7 @@ class ViewUser extends React.Component {

const loansHistory = (<this.connectedLoansHistory
user={user}
loansHistory={loans}
patronGroup={patronGroup}
stripes={stripes}
history={this.props.history}
Expand Down

0 comments on commit 2238830

Please sign in to comment.