DisplayPage.tsx 15.5 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
import { loadAccession } from 'accessions/actions/public';
8
import {addAccessionToMyList, removeAccessionFromMyList} from 'list/actions/public';
9
10

// Models
11
import AccessionDetails from 'model/accession/AccessionDetails';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
12
import RepositoryFile from 'model/repository/RepositoryFile';
13
14

// UI
Matija Obreza's avatar
Matija Obreza committed
15
16
17
import { Link } from 'react-router-dom';
import PrettyDate from 'ui/common/time/PrettyDate';
import PageLayout, { PageContents, MainSection, PageSection } from 'ui/layout/PageLayout';
18
19
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
Matija Obreza's avatar
Matija Obreza committed
20
21
22
23
24
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
25
import ReduxCheckbox from 'ui/common/checkbox';
26
import CropChips from 'crop/ui/c/CropChips';
27
import LocationMap from 'ui/common/LocationMap';
28
29
30
import {CountryLink, DatasetLink, InstituteLink, SubsetLink} from 'ui/genesys/Links';
import PropertiesCard from 'ui/common/PropertiesCard';
import GridLayout from 'ui/layout/GridLayout';
31
import McpdDate from 'ui/common/time/McpdDate';
32
import PdciTable from './c/PdciTable';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
33
34
import ImageGalleryView from 'repository/ui/c/ImageGalleryView';
import Button from '@material-ui/core/Button/Button';
Matija Obreza's avatar
Matija Obreza committed
35

36
37

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

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

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

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

  public componentWillMount() {
62
63
64
    const { doi, uuid, loadAccession } = this.props;
    const accession = this.props.accession ? this.props.accession.details : null;

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

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

83
  public render() {
84
    const { t, error, uuid, doi, accessions } = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
85
    const {details: accession, pdci, datasets, subsets, files, imageGallery} = this.props.accession ?
86
87
      this.props.accession
      :
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
88
      {details: null, pdci: null, datasets: null, subsets: null, files: null, imageGallery: null};
89

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

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

98
    return (
Oleksii Savran's avatar
Oleksii Savran committed
99
      <PageLayout withFooter>
Matija Obreza's avatar
Matija Obreza committed
100
        <ScrollToTopOnMount />
Matija Obreza's avatar
Matija Obreza committed
101
        <ContentHeader title={ t('accessions.public.p.display.title') } subtitle={ t('accessions.public.p.display.subTitle') } />
Matija Obreza's avatar
Matija Obreza committed
102

103
104
105
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
106

107
108
109
110
            { accession &&
              <PageContents>
                <MainSection title={
                  <div>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
111
                    { t('accessions.common.modelName') }: { accession.accessionNumber }
112
113
114
115
                    <div className="float-right">
                        <ReduxCheckbox
                            label={
                                <b>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
116
                                    { isChecked ? t('accessions.public.p.display.removeFromMyList', {accessionNumber: accession.accessionNumber}) : t('accessions.public.p.display.addToMyList', {accessionNumber: accession.accessionNumber}) }
117
118
119
120
121
122
123
124
125
126
127
128
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
129
130
131
                    { accession.doi && <PropertiesItem title={ t('accessions.public.p.display.DOI') }><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
                    <PropertiesItem title={ t('accessions.common.acceNumb') } >{ accession.accessionNumber }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.holdingInstitute') }>
132
133
134
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
Matija Obreza's avatar
Matija Obreza committed
135
136
                      <span> &mdash; </span>
                      <CountryLink noflag country={ accession.institute.country }/>
137
                    </PropertiesItem>
138
139
140
141
142
                    <PropertiesItem title={ t('accessions.common.instituteCode') }>{ accession.institute.code }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.acquisitionDate') }><McpdDate value={ accession.acquisitionDate } /></PropertiesItem>
                    { accession.countryOfOrigin && <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
                    { accession.sampStat && <PropertiesItem title={ t('accessions.common.sampStat') }>{ t(`accessions.common.sampleStatus.${accession.sampStat}`) }</PropertiesItem> }
                    { accession.storage && accession.storage.length > 0 && <PropertiesItem title={ t('accessions.common.storageType') }>
143
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
144
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accessions.common.storage.${storage}`) }</div>
145
146
                      )) }
                    </PropertiesItem> }
147
148
149
150
                    <PropertiesItem title={ t('accessions.public.p.display.availability') } keepEmpty>{ t(`accessions.common.available.${accession.available}`) }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.ITPGRFAMLS') } keepEmpty>{ t(`accessions.common.mlsStatus.${accession.mlsStatus}`) }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.donorInstitute') }>{ accession.donorCode }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.donorAccessionNumber') }>{ accession.donorNumb }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
151

152
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title={ t('accessions.public.p.display.safetyDuplicationInstitute') }>
153
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
154
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
155
156
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
157

158
                    { accession.acceUrl && <PropertiesItem title={ t('accessions.public.p.display.accessionURL') }><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
159
160
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
161

162
                <PageSection title={ t('accessions.common.taxonomy') }>
163
                  <Properties>
164
165
                    <PropertiesItem title={ t('accessions.common.genus') }>{ accession.taxonomy.genus }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.common.species') }>
166
167
168
169
                      { accession.taxonomy.species }
                      { '' }
                      <Link to={ '/a' }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</Link>
                    </PropertiesItem>
170
171
172
                    <PropertiesItem title={ t('accessions.public.p.display.scientificName') }><SciName taxa={ accession.taxonomy.taxonNameHtml } /></PropertiesItem>
                    { accession.crop && <PropertiesItem title={ t('accessions.public.p.display.cropName') }><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
                    <PropertiesItem title={ t('accessions.public.p.display.providedCropName') }>{ accession.cropName }</PropertiesItem>
173
174
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Cleanup    
Matija Obreza committed
175
176

                { (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
177
                  <PageSection title={ t('accessions.public.p.display.accessionNames') }>
178
                    <Properties>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
179
                      { accession.donorCode && <PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
180
                      { accession.aliases && accession.aliases.map((alias) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
181
                        <PropertiesItem key={ alias.id } title={ t(`accessions.common.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
182
183
184
185
                      )) }
                    </Properties>
                  </PageSection>
                }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                { files &&
                  <PageSection title={ t('accessions.public.p.display.relatedResources') }>
                    <Properties>
                      { files.map((e: RepositoryFile) => (
                        <PropertiesItem key={ e.uuid } title={
                          <a href={ `/proxy/api/v1/repository/download/${e.uuid}` }>
                            <Button variant="raised" component="span">
                              { t('common:action.download') }
                            </Button>
                          </a>
                        }>
                          <b>{ e.originalFilename }</b>
                        </PropertiesItem>
                      )) }
                    </Properties>
                  </PageSection>
                }

                { imageGallery &&
                  <PageSection title={ t('accessions.public.p.display.imageGallery') }>
                    <ImageGalleryView imageGallery={ imageGallery }/>
                  </PageSection>
                }
209

210
                { accession.coll &&
211
                  <PageSection title={ t('accessions.public.p.display.collectingInformation') }>
212
                    <Properties>
213
                      { accession.countryOfOrigin && <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
214
                      { accession.coll.collDate && <PropertiesItem key="collDate" title={ t(`accessions.common.coll.collDate`) }><McpdDate value={ accession.coll.collDate } /></PropertiesItem> }
215
216
217
                      { accession.coll &&
                        [ 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                          .filter((prop) => accession.coll[prop] !== null).map((prop) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
218
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
219
                        ))
220
                      }
221
222
223
                      { accession.coll &&
                        [ 'collCode', 'collName' ]
                          .filter((prop) => accession.coll[prop].length).map((prop) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
224
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
225
226
227
228
229
                        ))
                      }
                      { accession.geo &&
                        [ 'latitude', 'longitude', 'datum', 'method', 'uncertainty', 'elevation' ]
                          .filter((prop) => accession.geo[prop] !== null).map((prop) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
230
                          <PropertiesItem key={ prop } title={ t(`accessions.common.geo.${prop}`) }>{ accession.geo[prop] }</PropertiesItem>
231
232
233
234
235
                        ))
                      }
                    </Properties>

                    { hasLatLon &&
Maxym Borodenko's avatar
Maxym Borodenko committed
236
                      <LocationMap locations={ [{ id: accession.geo.id, lat: accession.geo.latitude, lng: accession.geo.longitude }] }/>
237
238
239
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
240

241
                { accession.remarks && accession.remarks.length > 0 && <PageSection title={ t('accessions.public.p.display.remarks') }>
242
243
244
245
246
247
                  <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
248

249
                { pdci && <PdciTable pdci={ pdci } title={ t('accessions.public.p.display.pdci') }/> }
Matija Obreza's avatar
Matija Obreza committed
250

251
                <PageSection title={ t('accessions.public.p.display.metadata') }>
252
                  <Properties>
253
254
255
256
                    <PropertiesItem title={ t('common:label.UUID') }>{ `urn:uuid:${accession.uuid}` }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.permanentURL') }><ExternalLink link={ `https://purl.org/germplasm/id/${accession.uuid}` } /></PropertiesItem>
                    <PropertiesItem title={ t('common:label.lastUpdated') }><PrettyDate value={ accession.lastModifiedDate } /></PropertiesItem>
                    <PropertiesItem title={ t('common:label.created') }><PrettyDate value={ accession.createdDate } /></PropertiesItem>
257
258
                  </Properties>
                </PageSection>
259
260
261
262
263

                <GridLayout>
                  { datasets && datasets.length > 0 &&
                  <PropertiesCard
                    small
264
                    title={ t('accessions.public.p.display.associatedDatasets') }
265
                    propertyItemProps={ { keepEmpty: true } }
266
                    propertiesList={ datasets.map((dataset) => ({ title: t('dataset.common.modelName'), value: <DatasetLink to={ dataset } /> })) }
267
268
269
270
271
                  />
                  }
                  { subsets && subsets.length > 0 &&
                  <PropertiesCard
                    small
272
                    title={ t('accessions.public.p.display.associatedSubsets') }
273
                    propertyItemProps={ { keepEmpty: true } }
274
                    propertiesList={ subsets.map((subset) => ({ title: t('subset.common.modelName'), value: <SubsetLink to={ subset } /> })) }
275
276
277
                  />
                  }
                </GridLayout>
278
279
280
              </PageContents>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
281
        }
282
283
284
285
286
287
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
288
289
  accession: state.accessions.public.accession,
  error: state.accessions.public.accessionError,
290
  uuid: ownProps.match.params.uuid,
291
  doi: ownProps.match.params.doi,
292
  accessions: state.list.public.myList.accessions,
293
294
295
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
296
297
  addAccessionToMyList,
  removeAccessionFromMyList,
298
299
300
301
  loadAccession,
}, dispatch);


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