forked from folio-org/ui-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewHoldingsRecord.js
226 lines (206 loc) · 7.88 KB
/
ViewHoldingsRecord.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import queryString from 'query-string';
import Layer from '@folio/stripes-components/lib/Layer';
import Pane from '@folio/stripes-components/lib/Pane';
import PaneMenu from '@folio/stripes-components/lib/PaneMenu';
import { Accordion } from '@folio/stripes-components/lib/Accordion';
import KeyValue from '@folio/stripes-components/lib/KeyValue';
import { Row, Col } from '@folio/stripes-components/lib/LayoutGrid';
import Headline from '@folio/stripes-components/lib/Headline';
import IconButton from '@folio/stripes-components/lib/IconButton';
import transitionToParams from '@folio/stripes-components/util/transitionToParams';
import removeQueryParam from '@folio/stripes-components/util/removeQueryParam';
import craftLayerUrl from '@folio/stripes-components/util/craftLayerUrl';
import HoldingsForm from './edit/holdings/HoldingsForm';
class ViewHoldingsRecord extends React.Component {
static manifest = Object.freeze({
holdingsRecords: {
type: 'okapi',
path: 'holdings-storage/holdings/:{holdingsrecordid}',
},
instances1: {
type: 'okapi',
path: 'instance-storage/instances/:{id}',
},
shelfLocations: {
type: 'okapi',
records: 'shelflocations',
path: 'shelf-locations',
},
platforms: {
type: 'okapi',
path: 'platforms',
records: 'platforms',
},
});
constructor(props) {
super(props);
this.state = {
accordions: {
holdingsAccordion: true,
},
};
this.transitionToParams = transitionToParams.bind(this);
this.removeQueryParam = removeQueryParam.bind(this);
this.craftLayerUrl = craftLayerUrl.bind(this);
}
// Edit Holdings records handlers
onClickEditHoldingsRecord = (e) => {
if (e) e.preventDefault();
this.transitionToParams({ layer: 'editHoldingsRecord' });
}
onClickCloseEditHoldingsRecord = (e) => {
if (e) e.preventDefault();
this.removeQueryParam('layer');
}
updateHoldingsRecord = (holdingsRecord) => {
const holdings = holdingsRecord;
if (holdings.permanentLocationId === '') delete holdings.permanentLocationId;
if (holdings.platformId === '') delete holdings.platformId;
this.props.mutator.holdingsRecords.PUT(holdings).then(() => {
this.onClickCloseEditHoldingsRecord();
});
}
handleAccordionToggle = ({ id }) => {
this.setState((state) => {
const newState = _.cloneDeep(state);
newState.accordions[id] = !newState.accordions[id];
return newState;
});
}
render() {
const { location, resources: { holdingsRecords, instances1, shelfLocations, platforms }, referenceTables, okapi } = this.props;
if (!holdingsRecords || !holdingsRecords.hasLoaded
|| !instances1 || !instances1.hasLoaded
|| !shelfLocations || !shelfLocations.hasLoaded
|| !platforms || !platforms.hasLoaded) return <div>Awaiting resources</div>;
const holdingsRecord = holdingsRecords.records[0];
const instance = instances1.records[0];
const locations = shelfLocations.records;
referenceTables.shelfLocations = locations;
referenceTables.platforms = platforms.records;
const query = location.search ? queryString.parse(location.search) : {};
const that = this;
const detailMenu = (
<PaneMenu>
<IconButton
icon="edit"
id="clickable-edit-holdingsrecord"
style={{ visibility: !holdingsRecord ? 'hidden' : 'visible' }}
href={this.craftLayerUrl('editHoldingsRecord')}
onClick={this.onClickEditHoldingsRecord}
title="Edit Holdings"
/>
</PaneMenu>
);
return (
<div>
<Layer isOpen label="View Holdings Record">
<Pane
defaultWidth={this.props.paneWidth}
paneTitle={
<div style={{ textAlign: 'center' }}>
<strong>{holdingsRecord.permanentLocationId ? locations.find(loc => holdingsRecord.permanentLocationId === loc.id).name : null} > {_.get(holdingsRecord, ['callNumber'], '')}</strong>
<div>
Holdings
</div>
</div>
}
lastMenu={detailMenu}
dismissible
onClose={this.props.onCloseViewHoldingsRecord}
>
<Row center="xs">
<Col sm={6}>
Instance: {instance.title}
{(instance.publication && instance.publication.length > 0) &&
<span><em>, </em><em>{instance.publication[0].publisher}{instance.publication[0].dateOfPublication ? `, ${instance.publication[0].dateOfPublication}` : ''}</em></span>
}
</Col>
</Row>
<Accordion
open={this.state.accordions.holdingsAccordion}
id="holdingsAccordion"
onToggle={this.handleAccordionToggle}
label="Holdings data"
>
<Row>
<Col sm={12}>
Holdings record
</Col>
</Row>
<br />
<Row>
<Col sm={12}>
<Headline size="medium" margin="medium">
{holdingsRecord.permanentLocationId ? locations.find(loc => holdingsRecord.permanentLocationId === loc.id).name : null} > {_.get(holdingsRecord, ['callNumber'], '')}
</Headline>
</Col>
</Row>
{ (holdingsRecord.electronicLocation && holdingsRecord.electronicLocation.platformId) &&
<Row>
<Col smOffset={1} sm={4}>
<KeyValue label="Platform" value={_.get(holdingsRecord, ['electronicLocation', 'platformId'], '') ? platforms.records.find(platform => _.get(holdingsRecord, ['electronicLocation', 'platformId']) === platform.id).name : null} />
</Col>
</Row>
}
{ (holdingsRecord.electronicLocation && holdingsRecord.electronicLocation.uri) &&
<Row>
<Col smOffset={1} sm={4}>
<KeyValue label="URI" value={_.get(holdingsRecord, ['electronicLocation', 'uri'], '')} />
</Col>
</Row>
}
{ (holdingsRecord.holdingsStatements.length > 0) &&
<Row>
<Col smOffset={1} sm={4}>
<KeyValue label="Holdings statements" value={_.get(holdingsRecord, ['holdingsStatements'], []).map((line, i) => <div key={i}>{line}</div>)} />
</Col>
</Row>
}
</Accordion>
</Pane>
</Layer>
<Layer isOpen={query.layer ? (query.layer === 'editHoldingsRecord') : false} label="Edit Holdings Record Dialog">
<HoldingsForm
initialValues={holdingsRecord}
onSubmit={(record) => { that.updateHoldingsRecord(record); }}
onCancel={this.onClickCloseEditHoldingsRecord}
okapi={okapi}
instance={instance}
referenceTables={referenceTables}
/>
</Layer>
</div>
);
}
}
ViewHoldingsRecord.propTypes = {
resources: PropTypes.shape({
instances1: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
holdingsRecords: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
shelfLocations: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
platforms: PropTypes.shape({
records: PropTypes.arrayOf(PropTypes.object),
}),
}).isRequired,
okapi: PropTypes.object,
location: PropTypes.object,
paneWidth: PropTypes.string,
referenceTables: PropTypes.object.isRequired,
mutator: PropTypes.shape({
holdingsRecords: PropTypes.shape({
PUT: PropTypes.func.isRequired,
}),
}),
onCloseViewHoldingsRecord: PropTypes.func.isRequired,
};
export default ViewHoldingsRecord;