Skip to content

Commit d43e3d9

Browse files
committed
frontside: added config to display selected item identifiers
1 parent 8306405 commit d43e3d9

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/lib/config/defaultConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ export const RECORDS_CONFIG = {
521521
},
522522
},
523523
ITEMS: {
524+
identifiersToDisplayInFrontside: [],
524525
circulationRestrictions: [
525526
{ value: 'NO_RESTRICTION', text: 'No restriction (4 weeks)' },
526527
{ value: 'ONE_WEEK', text: '1 week' },

src/lib/pages/frontsite/Documents/DocumentDetails/DocumentItems/DocumentItem.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ import React, { Component } from 'react';
33
import Overridable from 'react-overridable';
44
import { Button, Table } from 'semantic-ui-react';
55
import DocumentItemBody from './DocumentItemBody';
6+
import { invenioConfig } from '@config';
7+
import { vocabularyApi } from '@api/vocabularies';
68

79
class DocumentItem extends Component {
810
constructor(props) {
911
super(props);
1012

13+
const identifiersToDisplayInFrontside =
14+
invenioConfig.ITEMS.identifiersToDisplayInFrontside.map((identifier) => ({
15+
key: identifier,
16+
text: identifier,
17+
}));
18+
1119
this.state = {
1220
isShowingAll: false,
1321
itemAmountLimit: 5,
22+
identifiersToDisplayInFrontside,
1423
};
24+
25+
if (identifiersToDisplayInFrontside.length > 0) {
26+
this.fetchIdentifiersToDisplayInFrontsideTitles();
27+
}
1528
}
1629

1730
get moreItemsToLoad() {
@@ -21,6 +34,26 @@ class DocumentItem extends Component {
2134
return items.length > itemAmountLimit;
2235
}
2336

37+
fetchIdentifiersToDisplayInFrontsideTitles = () => {
38+
const query = vocabularyApi
39+
.query()
40+
.withType(invenioConfig.VOCABULARIES.item.identifier.scheme);
41+
vocabularyApi.list(query.qs()).then((response) => {
42+
const identifiersToDisplayInFrontside =
43+
this.state.identifiersToDisplayInFrontside.map((identifier) => {
44+
const vocabEntry = response.data.hits.find(
45+
(entry) => entry.metadata.key === identifier.key
46+
);
47+
return {
48+
...identifier,
49+
text: vocabEntry ? vocabEntry.metadata.text : identifier.text,
50+
};
51+
});
52+
53+
this.setState({ identifiersToDisplayInFrontside });
54+
});
55+
};
56+
2457
toggleItems = () => {
2558
const { isShowingAll } = this.state;
2659

@@ -30,7 +63,8 @@ class DocumentItem extends Component {
3063
render() {
3164
const { internalLocationName, items, documentDetails, showTitle } =
3265
this.props;
33-
const { isShowingAll, itemAmountLimit } = this.state;
66+
const { isShowingAll, itemAmountLimit, identifiersToDisplayInFrontside } =
67+
this.state;
3468

3569
const previewArrayOfItems = items.slice(0, itemAmountLimit);
3670
const completeArrayOfItems = items;
@@ -56,6 +90,11 @@ class DocumentItem extends Component {
5690
<Table.Row data-test="header">
5791
<Table.HeaderCell>Barcode</Table.HeaderCell>
5892
<Table.HeaderCell>Shelf</Table.HeaderCell>
93+
{identifiersToDisplayInFrontside.map((identifier) => (
94+
<Table.HeaderCell key={identifier.key}>
95+
{identifier.text}
96+
</Table.HeaderCell>
97+
))}
5998
<Table.HeaderCell>Status</Table.HeaderCell>
6099
<Table.HeaderCell>Medium</Table.HeaderCell>
61100
<Table.HeaderCell>Loan restriction</Table.HeaderCell>
@@ -68,6 +107,9 @@ class DocumentItem extends Component {
68107
<DocumentItemBody
69108
items={itemsToShow}
70109
documentDetails={documentDetails}
110+
identifiersToDisplayInFrontside={
111+
identifiersToDisplayInFrontside
112+
}
71113
/>
72114
</Overridable>
73115
</Table.Body>

src/lib/pages/frontsite/Documents/DocumentDetails/DocumentItems/DocumentItemBody.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export default class DocumentItemBody extends Component {
2727
};
2828

2929
render() {
30-
const { items, shelfLink, documentDetails } = this.props;
30+
const {
31+
items,
32+
shelfLink,
33+
documentDetails,
34+
identifiersToDisplayInFrontside,
35+
} = this.props;
3136

3237
return items.map((item) => (
3338
<Table.Row key={item.pid}>
@@ -37,13 +42,26 @@ export default class DocumentItemBody extends Component {
3742
>
3843
{item.barcode}
3944
</Table.Cell>
40-
4145
<Table.Cell data-label="Shelf" className="document-item-table-itemCell">
4246
{shelfLink !== null
4347
? shelfLink(item, documentDetails)
4448
: _get(item, 'shelf')}
4549
</Table.Cell>
4650

51+
{identifiersToDisplayInFrontside.map((identifier) => (
52+
<Table.Cell
53+
key={identifier}
54+
data-label={identifier.text}
55+
className="document-item-table-itemCell"
56+
>
57+
{
58+
item.identifiers?.find((entry) => {
59+
return entry.scheme === identifier.key;
60+
})?.value
61+
}
62+
</Table.Cell>
63+
))}
64+
4765
<Table.Cell data-label="Status">{this.statusLabel(item)}</Table.Cell>
4866
<Table.Cell data-label="Medium">
4967
{getDisplayVal('ITEMS.mediums', item.medium)}
@@ -63,6 +81,8 @@ DocumentItemBody.propTypes = {
6381
items: PropTypes.array.isRequired,
6482
documentDetails: PropTypes.object.isRequired,
6583
shelfLink: PropTypes.func,
84+
identifiersToDisplayInFrontside: PropTypes.arrayOf(PropTypes.object)
85+
.isRequired,
6686
};
6787

6888
DocumentItemBody.defaultProps = {

0 commit comments

Comments
 (0)