forked from folio-org/ui-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemsPerHoldingsRecord.js
177 lines (162 loc) · 6 KB
/
ItemsPerHoldingsRecord.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import { Accordion } from '@folio/stripes-components/lib/Accordion';
import Layer from '@folio/stripes-components/lib/Layer';
import { Row, Col } from '@folio/stripes-components/lib/LayoutGrid';
import KeyValue from '@folio/stripes-components/lib/KeyValue';
import Button from '@folio/stripes-components/lib/Button';
import Items from './Items';
import ItemForm from './edit/items/ItemForm';
class ItemsPerHoldingsRecord extends React.Component {
static manifest = Object.freeze({
addItemMode: { initialValue: { mode: false } },
materialTypes: {
type: 'okapi',
path: 'material-types',
records: 'mtypes',
},
loanTypes: {
type: 'okapi',
path: 'loan-types',
records: 'loantypes',
},
items: {
type: 'okapi',
records: 'items',
path: 'inventory/items',
fetch: false,
},
holdings: {
type: 'okapi',
records: 'holdingsRecords',
path: 'holdings-storage/holdings',
fetch: false,
},
});
constructor(props) {
super(props);
this.cItems = props.stripes.connect(Items, { dataKey: props.holdingsRecord.id });
this.addItemModeThisLayer = false;
}
// Add Item handlers
onClickAddNewItem = (e) => {
if (e) e.preventDefault();
if (e) e.stopPropagation();
this.props.mutator.addItemMode.replace({ mode: true });
this.addItemModeThisLayer = true;
}
onClickCloseNewItem = (e) => {
if (e) e.preventDefault();
this.props.mutator.addItemMode.replace({ mode: false });
this.addItemModeThisLayer = false;
}
createItem = (item) => {
// POST item record
this.props.mutator.items.POST(item);
this.onClickCloseNewItem();
}
viewHoldingsRecord = () => {
this.props.history.push(`/inventory/view/${this.props.instance.id}/${this.props.holdingsRecord.id}${this.props.location.search}`);
}
render() {
const { okapi, resources: { addItemMode, materialTypes, loanTypes }, instance, holdingsRecord, location, accordionToggle, accordionStates } = this.props;
const materialtypes = (materialTypes || {}).records || [];
const loantypes = (loanTypes || {}).records || [];
const referenceTables = this.props.referenceTables;
referenceTables.loanTypes = loantypes;
referenceTables.materialTypes = materialtypes;
const viewHoldingsButton = <Button id="clickable-view-holdings" onClick={this.viewHoldingsRecord}>View holdings</Button>;
const newItemButton = <Button id="clickable-new-item" onClick={this.onClickAddNewItem} title="+ Item" buttonStyle="primary paneHeaderNewButton">+ Add item</Button>;
const labelLocation = holdingsRecord.permanentLocationId ? referenceTables.shelfLocations.find(loc => holdingsRecord.permanentLocationId === loc.id).name : '';
const labelCallNumber = holdingsRecord.callNumber || '';
return (
<Accordion
open={accordionStates[holdingsRecord.id] === undefined || accordionStates[holdingsRecord.id]}
id={holdingsRecord.id}
onToggle={accordionToggle}
label={`Holdings: ${labelLocation} > ${labelCallNumber}`}
displayWhenOpen={<div>{viewHoldingsButton} {newItemButton}</div>}
>
<Row>
{ holdingsRecord.permanentLocationId ?
null
:
<Col sm={5}>
<KeyValue
label="Platform"
value={_.get(holdingsRecord, ['electronicLocation', 'platformId'], null) ?
(referenceTables.platforms.find(platform => _.get(holdingsRecord, ['electronicLocation', 'platformId'], '') === platform.id).name)
:
null}
/>
<KeyValue label="URI" value={_.get(holdingsRecord, ['electronicLocation', 'uri'], '')} />
</Col>
}
</Row>
<Row>
<Col sm={12}>
<this.cItems holdingsRecord={holdingsRecord} referenceTables={referenceTables} okapi={okapi} instance={instance} location={location} history={this.props.history} match={this.props.match} />
</Col>
</Row>
<br />
<Layer key={`itemformlayer_${holdingsRecord.id}`} isOpen={addItemMode ? (addItemMode.mode && this.addItemModeThisLayer) : false} label="Add New Item Dialog">
<ItemForm
form={`itemform_${holdingsRecord.id}`}
id={holdingsRecord.id}
key={holdingsRecord.id}
initialValues={{ status: { name: 'Available' }, holdingsRecordId: holdingsRecord.id }}
onSubmit={(record) => { this.createItem(record); }}
onCancel={this.onClickCloseNewItem}
okapi={okapi}
instance={instance}
holdingsRecord={holdingsRecord}
referenceTables={referenceTables}
/>
</Layer>
</Accordion>);
}
}
ItemsPerHoldingsRecord.propTypes = {
instance: PropTypes.object,
holdingsRecord: PropTypes.object.isRequired,
mutator: PropTypes.shape({
items: PropTypes.shape({
POST: PropTypes.func,
}),
holdings: PropTypes.shape({
PUT: PropTypes.func,
}),
addItemMode: PropTypes.shape({
replace: PropTypes.func,
}),
}),
resources: PropTypes.shape({
materialTypes: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
loanTypes: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
shelfLocations: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
}).isRequired,
referenceTables: PropTypes.object.isRequired,
stripes: PropTypes.shape({
connect: PropTypes.func.isRequired,
locale: PropTypes.string.isRequired,
}).isRequired,
match: PropTypes.shape({
params: PropTypes.object,
}),
history: PropTypes.object,
okapi: PropTypes.object,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired,
search: PropTypes.string,
}),
accordionToggle: PropTypes.func.isRequired,
accordionStates: PropTypes.object.isRequired,
};
export default ItemsPerHoldingsRecord;