DisplayPage.tsx 13.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

// Actions
7
8
import { loadAccession } from 'accessions/actions/public';
import {addAccessionToMyList, removeAccessionFromMyList} from 'user/actions/public';
9
10

// Models
11
import AccessionDetails from 'model/AccessionDetails';
12
13

// 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
28
29
import {CountryLink, DatasetLink, InstituteLink, SubsetLink} from 'ui/genesys/Links';
import PropertiesCard from 'ui/common/PropertiesCard';
import GridLayout from 'ui/layout/GridLayout';
30
import McpdDate from 'ui/common/time/McpdDate';
31
import PdciTable from './c/PdciTable';
Matija Obreza's avatar
Matija Obreza committed
32

33
34

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

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

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

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

  public componentWillMount() {
59
60
61
    const { doi, uuid, loadAccession } = this.props;
    const accession = this.props.accession ? this.props.accession.details : null;

62
63
64
65
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
66
    if (uuid && (! accession || uuid !== accession.uuid)) {
67
      loadAccession({ uuid });
68
69
70
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
71
  private onCheckboxChange = (event, checked) => {
72
      const {accession: {details: accession}, addAccessionToMyList, removeAccessionFromMyList} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
73
74
75
76
77
78
79
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

80
  public render() {
81
82
83
84
85
86
    const { t, error, uuid, doi, accessions } = this.props;
    const {details: accession, pdci, datasets, subsets} = this.props.accession ?
      this.props.accession
      :
      {details: null, pdci: null, datasets: null, subsets: null};

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
87
    const  isChecked  =  accession && accessions && accessions.includes(accession.uuid);
88
89
90
91
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
92

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

95
96
    return (
      <PageLayout>
Matija Obreza's avatar
Matija Obreza committed
97
98
99
        <ScrollToTopOnMount />
        <ContentHeader title="Accession details" subtitle="Passport data and everything else" />

100
101
102
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
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
            { 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>
Matija Obreza's avatar
Matija Obreza committed
132
133
                      <span> &mdash; </span>
                      <CountryLink noflag country={ accession.institute.country }/>
134
135
                    </PropertiesItem>
                    <PropertiesItem title="Institute code">{ accession.institute.code }</PropertiesItem>
136
                    <PropertiesItem title="Acquisition date"><McpdDate value={ accession.acquisitionDate } /></PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
137
                    { accession.countryOfOrigin && <PropertiesItem title="Country of origin">{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
138
                    { accession.sampStat && <PropertiesItem title="Biological status of accession">{ t(`accession.sampleStatus.${accession.sampStat}`) }</PropertiesItem> }
139
140
                    { accession.storage && accession.storage.length > 0 && <PropertiesItem title="Type of Germplasm storage">
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
141
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accession.storage.${storage}`) }</div>
142
143
                      )) }
                    </PropertiesItem> }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
144
                    <PropertiesItem title="Availability for distribution" keepEmpty>{ t(`accession.available.${accession.available}`) }</PropertiesItem>
Matija Obreza's avatar
Cleanup    
Matija Obreza committed
145
                    <PropertiesItem title="ITPGRFA MLS" keepEmpty>{ t(`accession.mlsStatus.${accession.mlsStatus}`) }</PropertiesItem>
146
147
                    <PropertiesItem title="Donor institute">{ accession.donorCode }</PropertiesItem>
                    <PropertiesItem title="Donor accession number">{ accession.donorNumb }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
148

149
150
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title="Safety duplication institute">
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
151
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
152
153
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
154

155
156
157
                    { accession.acceUrl && <PropertiesItem title="Accession URL"><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
158

159
160
161
162
163
164
165
166
167
168
169
170
171
                <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
Cleanup    
Matija Obreza committed
172
173

                { (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
174
175
                  <PageSection title="Accession names">
                    <Properties>
Matija Obreza's avatar
Cleanup    
Matija Obreza committed
176
                      { accession.donorCode && <PropertiesItem title={ t('accession.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
177
                      { accession.aliases && accession.aliases.map((alias) => (
Matija Obreza's avatar
Cleanup    
Matija Obreza committed
178
                        <PropertiesItem key={ alias.id } title={ t(`accession.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
179
180
181
182
                      )) }
                    </Properties>
                  </PageSection>
                }
183

184
185
186
                { accession.coll &&
                  <PageSection title="Collecting information">
                    <Properties>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
187
                      { accession.countryOfOrigin && <PropertiesItem title="Country of origin">{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
188
                      { accession.coll.collDate && <PropertiesItem key="collDate" title={ t(`accession.coll.collDate`) }><McpdDate value={ accession.coll.collDate } /></PropertiesItem> }
189
190
191
192
193
                      { accession.coll &&
                        [ 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                          .filter((prop) => accession.coll[prop] !== null).map((prop) => (
                          <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                        ))
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
                      { accession.coll &&
                        [ 'collCode', 'collName' ]
                          .filter((prop) => accession.coll[prop].length).map((prop) => (
                          <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                        ))
                      }
                      { 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,
                          }
                        }
                      />
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
222

223
224
225
226
227
228
229
                { 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
230

231
                { pdci && <PdciTable pdci={ pdci } title="Passport Data Completeness Index"/> }
Matija Obreza's avatar
Matija Obreza committed
232

233
234
235
236
237
238
239
240
                <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>
241
242
243
244
245
246

                <GridLayout>
                  { datasets && datasets.length > 0 &&
                  <PropertiesCard
                    small
                    title="Associated datasets"
247
248
                    propertyItemProps={ { keepEmpty: true } }
                    propertiesList={ datasets.map((dataset) => ({ title: 'Dataset', value: <DatasetLink to={ dataset } /> })) }
249
250
251
252
253
254
                  />
                  }
                  { subsets && subsets.length > 0 &&
                  <PropertiesCard
                    small
                    title="Associated Subsets"
255
256
                    propertyItemProps={ { keepEmpty: true } }
                    propertiesList={ subsets.map((subset) => ({ title: 'Subset', value: <SubsetLink to={ subset } /> })) }
257
258
259
                  />
                  }
                </GridLayout>
260
261
262
              </PageContents>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
263
        }
264
265
266
267
268
269
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
270
271
  accession: state.accessions.public.accession,
  error: state.accessions.public.accessionError,
272
  uuid: ownProps.match.params.uuid,
273
  doi: ownProps.match.params.doi,
274
  accessions: state.user.public.myList.accessions,
275
276
277
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
278
279
  addAccessionToMyList,
  removeAccessionFromMyList,
280
281
282
283
  loadAccession,
}, dispatch);


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