forked from folio-org/ui-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstanceItems.js
56 lines (45 loc) · 1.47 KB
/
InstanceItems.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import MultiColumnList from '@folio/stripes-components/lib/MultiColumnList';
const emptyObj = {};
const emptyArr = [];
class InstanceItems extends React.Component {
static manifest = Object.freeze({
instanceId: {},
items: {
type: 'okapi',
records: 'items',
path: 'inventory/items?query=(instanceId=:{instanceid})',
},
});
render() {
const { resources: { items } } = this.props;
if (!items || !items.hasLoaded) return <div />;
const instanceItems = (items || emptyObj).records || emptyArr;
const itemsFormatter = {
'Material Type': x => _.get(x, ['materialType', 'name']),
location: x => _.get(x, ['location', 'name']),
'Permanent Loan Type': x => _.get(x, ['permanentLoanType', 'name']),
status: x => _.get(x, ['status', 'name']) || '--',
};
return (
<MultiColumnList
id="list-instance-items"
contentData={instanceItems}
rowMetadata={['id', 'instanceId']}
formatter={itemsFormatter}
visibleColumns={['Material Type', 'location', 'Permanent Loan Type', 'status', 'barcode']}
ariaLabel={'Instance\'s items'}
containerRef={(ref) => { this.resultsList = ref; }}
/>);
}
}
InstanceItems.propTypes = {
resources: PropTypes.shape({
items: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
}),
};
export default InstanceItems;