@@ -3,15 +3,28 @@ import React, { Component } from 'react';
33import Overridable from 'react-overridable' ;
44import { Button , Table } from 'semantic-ui-react' ;
55import DocumentItemBody from './DocumentItemBody' ;
6+ import { invenioConfig } from '@config' ;
7+ import { vocabularyApi } from '@api/vocabularies' ;
68
79class 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 >
0 commit comments