DisplayPage.tsx 12.3 KB
Newer Older
1
2
3
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
Matija Obreza's avatar
Matija Obreza committed
4
import { translate } from 'react-i18next';
5
6
7

// Actions
import { loadAccession } from 'actions/accessions';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
8
import {addAccessionToMyList, removeAccessionFromMyList} from 'actions/user';
9
10
11
12
13

// Models
import Accession from 'model/Accession';

// UI
Matija Obreza's avatar
Matija Obreza committed
14
15
16
import { Link } from 'react-router-dom';
import PrettyDate from 'ui/common/time/PrettyDate';
import PageLayout, { PageContents, MainSection, PageSection } from 'ui/layout/PageLayout';
17
18
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
Matija Obreza's avatar
Matija Obreza committed
19
20
21
22
23
import { Properties, PropertiesItem } from 'ui/common/Properties';
import DOI from 'ui/common/DOI';
import { ExternalLink } from 'ui/common/Links';
import SciName from 'ui/genesys/SciName';
import { ScrollToTopOnMount } from 'ui/common/page/scrollers';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
24
import ReduxCheckbox from 'ui/common/checkbox';
Matija Obreza's avatar
Matija Obreza committed
25
import CropChips from 'ui/genesys/crop/CropChips';
26
import LocationMap from 'ui/common/LocationMap';
27
import {InstituteLink} from 'ui/genesys/Links';
Matija Obreza's avatar
Matija Obreza committed
28

29
30

interface IBrowsePageProps extends React.ClassAttributes<any> {
Matija Obreza's avatar
Matija Obreza committed
31
  t: any;
32
  uuid: string;
33
  doi: string; // DOI comes from the route without the '10.'
34
35
36
  accession: Accession;
  error: any;
  loadAccession: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
37
38
39
  accessions: any;
  addAccessionToMyList: any;
  removeAccessionFromMyList: any;
40
41
42
43
44
}

class BrowsePage extends React.Component<IBrowsePageProps, any> {

  protected static needs = [
45
    ({ params: { uuid, doi } }) => {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
46
        return doi ? loadAccession({ doi: `10.${doi}` }) :  loadAccession({ uuid });
47
48
49
50
51
52
53
54
    },
  ];

  constructor(props: IBrowsePageProps, context: any) {
      super(props, context);
  }

  public componentWillMount() {
55
56
57
58
59
    const { accession, doi, uuid, loadAccession } = this.props;
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
60
    if (uuid && (! accession || uuid !== accession.uuid)) {
61
      loadAccession({ uuid });
62
63
64
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
65
66
67
68
69
70
71
72
73
  private onCheckboxChange = (event, checked) => {
      const {accession, addAccessionToMyList, removeAccessionFromMyList} = this.props;
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

74
  public render() {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
75
76
    const { t, error, accession, uuid, doi, accessions } = this.props;
    const  isChecked  =  accession && accessions && accessions.includes(accession.uuid);
77
78
79
80
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
81

Matija Obreza's avatar
Matija Obreza committed
82
83
    const hasLatLon = accession && accession.geo && accession.geo.latitude !== null && accession.geo.longitude !== null;

84
85
    return (
      <PageLayout>
Matija Obreza's avatar
Matija Obreza committed
86
87
88
        <ScrollToTopOnMount />
        <ContentHeader title="Accession details" subtitle="Passport data and everything else" />

89
90
91
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
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
            { accession &&
              <PageContents>
                <MainSection title={
                  <div>
                    Accession: { accession.accessionNumber }
                    <div className="float-right">
                        <ReduxCheckbox
                            label={
                                <b>
                                    { isChecked ? `Remove ${accession.accessionNumber} from my list` : `Add ${accession.accessionNumber} to my list` }
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
                    { accession.doi && <PropertiesItem title="DOI"><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
                    <PropertiesItem title="Accession number">{ accession.accessionNumber }</PropertiesItem>
                    <PropertiesItem title="Holding institute">
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
                    </PropertiesItem>
                    <PropertiesItem title="Country of holding institute">{ accession.institute.country.name }</PropertiesItem>
                    <PropertiesItem title="Institute code">{ accession.institute.code }</PropertiesItem>
                    <PropertiesItem title="Acquisition date">{ accession.acquisitionDate }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
125

126
127
                    <PropertiesItem title="Biological status of accession">{ accession.sampStat }</PropertiesItem>
                    <PropertiesItem title="Availability for distribution">{ t(`accession.available.${accession.available}`) }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
128

129
130
131
132
133
134
135
                    { accession.storage && accession.storage.length > 0 && <PropertiesItem title="Type of Germplasm storage">
                      { accession.storage.map((storage, i) => (
                        <div key={ storage }>{ t(`accession.storage.${storage}`) }</div>
                      )) }
                    </PropertiesItem> }
                    <PropertiesItem title="Donor institute">{ accession.donorCode }</PropertiesItem>
                    <PropertiesItem title="Donor accession number">{ accession.donorNumb }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
136

137
138
139
140
141
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title="Safety duplication institute">
                      { accession.duplSite.map((duplSite, i) => (
                        <div key={ duplSite }>{ duplSite }</div>
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
142

143
144
145
                    { accession.acceUrl && <PropertiesItem title="Accession URL"><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
146

147
148
149
150
151
152
153
154
155
156
157
158
159
                <PageSection title="Taxonomy">
                  <Properties>
                    <PropertiesItem title="Genus">{ accession.taxonomy.genus }</PropertiesItem>
                    <PropertiesItem title="Species">
                      { accession.taxonomy.species }
                      { '' }
                      <Link to={ '/a' }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</Link>
                    </PropertiesItem>
                    <PropertiesItem title="Scientific name"><SciName taxa={ accession.taxonomy.taxonNameHtml } /></PropertiesItem>
                    { accession.crop && <PropertiesItem title="Crop name"><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
                    <PropertiesItem title="Provided crop name">{ accession.cropName }</PropertiesItem>
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Matija Obreza committed
160

161
162
163
164
165
166
167
168
169
                <PageSection title="Accession names">
                  <Properties>
                    { accession.coll && accession.coll.collNumb && <PropertiesItem title={ t('accession.alias.COLLNUMB') }>{ accession.coll.collNumb } { accession.coll.collCode }</PropertiesItem> }
                    { accession.donorCode && <PropertiesItem title={ t('accession.alias.DONORNUMB') }>{ accession.donorNumb } { accession.donorCode }</PropertiesItem> }
                    { accession.aliases && accession.aliases.map((alias) => (
                      <PropertiesItem key={ alias.id } title={ t(`accession.alias.${alias.aliasType}`) }>{ alias.name } { alias.usedBy }</PropertiesItem>
                    )) }
                  </Properties>
                </PageSection>
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
                <PageSection title="Collecting information">
                  <Properties>
                    { accession.countryOfOrigin && <PropertiesItem title="Country of origin">{ accession.countryOfOrigin.name }</PropertiesItem> }
                    { accession.coll &&
                      [ 'collDate', 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                        .filter((prop) => accession.coll[prop] !== null).map((prop) => (
                        <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                      ))
                    }
                    { accession.coll &&
                      [ 'collCode', 'collName' ]
                        .filter((prop) => accession.coll[prop].length).map((prop) => (
                        <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                      ))
185
                    }
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
                    { accession.geo &&
                      [ 'latitude', 'longitude', 'datum', 'method', 'uncertainty', 'elevation' ]
                        .filter((prop) => accession.geo[prop] !== null).map((prop) => (
                        <PropertiesItem key={ prop } title={ t(`accession.geo.${prop}`) }>{ accession.geo[prop] }</PropertiesItem>
                      ))
                    }
                  </Properties>

                  { hasLatLon &&
                    <LocationMap
                      location={
                        {
                          id: accession.geo.id,
                          lat: accession.geo.latitude,
                          lng: accession.geo.longitude,
                        }
                      }
                    />
204
                  }
205
                </PageSection>
Matija Obreza's avatar
Matija Obreza committed
206

207
208
209
210
211
212
213
                { accession.remarks && accession.remarks.length > 0 && <PageSection title="Remarks">
                  <Properties>
                    { accession.remarks && accession.remarks.map((remark) => (
                      <PropertiesItem key={ remark.id } title={ remark.fieldName }>{ remark.remark }</PropertiesItem>
                    )) }
                  </Properties>
                </PageSection> }
Matija Obreza's avatar
Matija Obreza committed
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                { accession.pdci && <PageSection title="Passport Data Completeness Index">
                  <div style={ { marginBottom: '2em', padding: '2em', backgroundColor: '#b6c1b4', borderRadius: '6px' } }>
                    <span style={ { fontSize: '1.5em' } }>
                      { t('accession.pdciScore', { score: accession.pdci.score }) }
                      { /*<p>{ t(`accession.pdciInstitute`, { score: accession.pdci.score }) }</p>*/ }
                    </span>
                      { ' ' }
                      <a href="#">Read about Passport Data Completeness Index</a>
                  </div>
                  <Properties>
                    { accession.pdci.independentItems.map((item) => (
                      <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
                    )) }
                    { accession.pdci.dependentItems.map((item) => (
                      <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
                    )) }
                  </Properties>
                </PageSection> }
Matija Obreza's avatar
Matija Obreza committed
233

234
235
236
237
238
239
240
241
242
243
244
                <PageSection title="Metadata">
                  <Properties>
                    <PropertiesItem title="UUID">{ `urn:uuid:${accession.uuid}` }</PropertiesItem>
                    <PropertiesItem title="Permanent URL"><ExternalLink link={ `https://purl.org/germplasm/id/${accession.uuid}` } /></PropertiesItem>
                    <PropertiesItem title="Last updated"><PrettyDate value={ accession.lastModifiedDate } /></PropertiesItem>
                    <PropertiesItem title="Created"><PrettyDate value={ accession.createdDate } /></PropertiesItem>
                  </Properties>
                </PageSection>
              </PageContents>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
245
        }
246
247
248
249
250
251
252
253
254
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
  accession: state.accessions.accession,
  error: state.accessions.accessionError,
  uuid: ownProps.match.params.uuid,
255
  doi: ownProps.match.params.doi,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
256
  accessions: state.user.myList.accessions,
257
258
259
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
260
261
  addAccessionToMyList,
  removeAccessionFromMyList,
262
263
264
265
  loadAccession,
}, dispatch);


Matija Obreza's avatar
Matija Obreza committed
266
export default connect(mapStateToProps, mapDispatchToProps)(translate()(BrowsePage));