AccessionDetailsPage.tsx 6.59 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
2
3
import React from 'react';

import { AccessionService } from '@genesys/client/service';
Oleksii Savran's avatar
Oleksii Savran committed
4
import { Property } from 'ui/common/Property';
Matija Obreza's avatar
Matija Obreza committed
5
import AccessionDetails from '@genesys/client/model/accession/AccessionDetails';
6
import { WithTranslation, withTranslation } from 'react-i18next';
Matija Obreza's avatar
Matija Obreza committed
7
8
9
10
11
12

interface IAccessionDetailsPage {
  match: any;
  apiUrl: string;
}

13
class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithTranslation, any> {
Matija Obreza's avatar
Matija Obreza committed
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
  public constructor(props) {
    super(props);
  }

  public state = {
    accession: null as AccessionDetails,
  };

  public componentDidMount() {
    this.loadData(this.props.match.params.uuid);
  }

  private loadData = (uuid: string): Promise<void> => {
    return AccessionService
      .getDetailsByUuid(uuid)
      .then((data) => {
        console.log('accession: ', data);
        this.setState({ accession: data });
      })
      .catch((e) => {
        console.log('Api call failed: ', e);
      });
  };

  public render() {
    const { accession } = this.state;
40
    const { apiUrl, t } = this.props;
Matija Obreza's avatar
Matija Obreza committed
41
42
43
44
45

    let propertyIndex = 0;

    if (accession === null) {
      return (
46
        <div>{ t('loading') }</div>
Matija Obreza's avatar
Matija Obreza committed
47
48
49
50
51
52
      );
    } else {
      const details = accession.details;
      return (
        <>
          <h1>{ details.accessionNumber }</h1>
Matija Obreza's avatar
Matija Obreza committed
53
54
          { details.doi && <Property title={ t('accession.doi') } value={ details.doi } index={ propertyIndex++ }/> }
          { details.accessionName && <Property title={ t('accession.accessionName') } value={ details.accessionName } index={ propertyIndex++ }/> }
Matija Obreza's avatar
Matija Obreza committed
55
          { details.taxonomy &&
Matija Obreza's avatar
Matija Obreza committed
56
            <Property title={ t('accession.taxonomy') } value={ <span dangerouslySetInnerHTML={ { __html: details.taxonomy.taxonNameHtml } } /> } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
57
58
          }
          { details.institute && details.institute.fullName &&
Matija Obreza's avatar
Matija Obreza committed
59
            <Property title={ t('accession.holdingInstitute') } value={ details.institute.fullName } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
60
61
62
63
64
          }
          { details.historic &&
            <Property title="Historic accession" value={ 'This is a historic record of an accession' } index={ propertyIndex++ }/>
          }
          { details.institute && details.institute.code &&
Matija Obreza's avatar
Matija Obreza committed
65
            <Property title={ t('accession.instituteCode') } value={ details.institute.code } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
66
67
68
69
          }
          { details.institute && details.institute.owner &&
            <Property title="Data provider" value={ details.institute.owner.name } index={ propertyIndex++ }/>
          }
Matija Obreza's avatar
Matija Obreza committed
70
71
72
          { details.sampStat &&
            <Property title={ t('accession.sampStat') } value={ t(`accession.sampleStatus.${details.sampStat}`) } index={ propertyIndex++ }/>
          }
Matija Obreza's avatar
Matija Obreza committed
73
          { details.countryOfOrigin &&
Matija Obreza's avatar
Matija Obreza committed
74
            <Property title={ t('accession.countryOfOrigin') } value={ details.countryOfOrigin.name } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
          }
          { details.ancest &&
            <Property title="Ancestral information (pedigree)" value={ details.ancest } index={ propertyIndex++ }/>
          }
          { details.aegis &&
            <Property title="AEGIS" value="Accession is part of the European Collection" index={ propertyIndex++ }/>
          }
          { (details.donorCode || details.donorName) &&
            <Property title="Donor institute" value={ <span>{ details.donorCode } { details.donorName }</span> } index={ propertyIndex++ }/>
          }
          { details.donorNumb &&
            <Property title="Donor accession number" value={ details.donorNumb } index={ propertyIndex++ }/>
          }
          { details.acceUrl &&
            <Property title="Accession URL" value={ <a href={ details.acceUrl } target="_blank" rel="nofollow">{ details.acceUrl }</a> } index={ propertyIndex++ }/>
          }

          { details.coll &&
            <>
              <h3 className="mt-4">Collecting site</h3>
Matija Obreza's avatar
Matija Obreza committed
95
96
97
98
99
              <Property title={ t('accession.coll.collSite') } value={ details.coll.collSite } index={ propertyIndex++ }/>
              <Property title={ t('accession.coll.collDate') } value={ details.coll.collDate } index={ propertyIndex++ }/>
              <Property title={ t('accession.coll.collMissId') } value={ details.coll.collMissId } index={ propertyIndex++ }/>
              <Property title={ t('accession.coll.collCode') } value={ details.coll.collCode } index={ propertyIndex++ }/>
              <Property title={ t('accession.coll.collName') } value={ details.coll.collName } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
100
101
102
103
104
            </>
          }
          { details.geo &&
            <>
              <h3 className="mt-4">Georeference</h3>
Matija Obreza's avatar
Matija Obreza committed
105
106
107
108
109
              <Property title={ t('accession.geo.latitude') } value={ details.geo.latitude } index={ propertyIndex++ }/>
              <Property title={ t('accession.geo.longitude') } value={ details.geo.longitude } index={ propertyIndex++ }/>
              <Property title={ t('accession.geo.datum') } value={ details.geo.datum } index={ propertyIndex++ }/>
              <Property title={ t('accession.geo.uncertainty') } value={ details.geo.uncertainty } index={ propertyIndex++ }/>
              <Property title={ t('accession.geo.elevation') } value={ details.geo.elevation } index={ propertyIndex++ }/>
Matija Obreza's avatar
Matija Obreza committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
            </>
          }

          { accession.imageGallery &&
            <>
              <h2 className="mt-4">Images</h2>
              <div>
                { accession.imageGallery.images.map((image, idx) => (
                  <span key={ idx }>
                    <a href={ `${apiUrl}/api/v1/repository/download/d${image.storagePath}` }><img className="img-thumbnail" src={ `${apiUrl}/api/v1/repository/download/d/_thumbs${image.thumbnailPath}/200x200.jpg` } alt={ image.subject } /></a>
                  </span>
                )) }
              </div>
            </>
          }

          { accession.subsets && accession.subsets.length > 0 &&
            <>
Matija Obreza's avatar
Matija Obreza committed
128
              <h2 className="mt-4">{ t('accession.subsets') }</h2>
Matija Obreza's avatar
Matija Obreza committed
129
130
131
132
133
134
135
136
137
138
139
              { accession.subsets.map((subset, idx) => (
                <div key={ idx }>
                  <h5>{ subset.title }</h5>
                  <p>{ subset.description }</p>
                </div>
              )) }
            </>
          }

          { accession.datasets && accession.datasets.length > 0 &&
            <>
Matija Obreza's avatar
Matija Obreza committed
140
              <h2 className="mt-4">{ t('accession.datasets') }</h2>
Matija Obreza's avatar
Matija Obreza committed
141
142
143
144
145
146
147
148
149
150
151
152
153
              { accession.datasets.map((dataset, idx) => (
                <div key={ idx }>
                  <h5>{ dataset.title }</h5>
                  <p>{ dataset.description }</p>
                </div>
              )) }
            </>
          }
        </>
      );
    }
  };
}
154
155

export default withTranslation()(AccessionDetailsPage);