DisplayPage.tsx 15.6 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
import { withStyles } from '@material-ui/core/styles';
6
7

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

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

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

37
38
39
40
41
42
const styles = (theme) => ({
  pageSection: {
    marginBottom: '1em',
  },
});

43

44
45
46
interface IBrowsePageProps {
  t?: any;
  classes?: any;
47

48
  uuid: string;
49
  doi: string; // DOI comes from the route without the '10.'
50
  accession: AccessionDetails;
51
52
  error: any;
  loadAccession: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
53
54
55
  accessions: any;
  addAccessionToMyList: any;
  removeAccessionFromMyList: any;
56
57
58
59
60
}

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

  protected static needs = [
61
    ({ params: { uuid, doi } }) => {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
62
        return doi ? loadAccession({ doi: `10.${doi}` }) :  loadAccession({ uuid });
63
64
65
66
67
68
69
70
    },
  ];

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

  public componentWillMount() {
71
72
73
    const { doi, uuid, loadAccession } = this.props;
    const accession = this.props.accession ? this.props.accession.details : null;

74
75
76
77
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
78
    if (uuid && (! accession || uuid !== accession.uuid)) {
79
      loadAccession({ uuid });
80
81
82
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
83
  private onCheckboxChange = (event, checked) => {
84
      const {accession: {details: accession}, addAccessionToMyList, removeAccessionFromMyList} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
85
86
87
88
89
90
91
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

92
  public render() {
93
94
    const { t, error, uuid, doi, accessions, classes } = this.props;
    const { details: accession, pdci, datasets, subsets, files, imageGallery } = this.props.accession ?
95
96
      this.props.accession
      :
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
97
      {details: null, pdci: null, datasets: null, subsets: null, files: null, imageGallery: null};
98

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
99
    const  isChecked  =  accession && accessions && accessions.includes(accession.uuid);
100
101
102
103
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
104

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

107
    return (
Oleksii Savran's avatar
Oleksii Savran committed
108
      <PageLayout withFooter>
Matija Obreza's avatar
Matija Obreza committed
109
        <ScrollToTopOnMount />
Matija Obreza's avatar
Matija Obreza committed
110
        <ContentHeader title={ t('accessions.public.p.display.title') } subtitle={ t('accessions.public.p.display.subTitle') } />
Matija Obreza's avatar
Matija Obreza committed
111

112
113
114
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
115

116
117
118
119
            { accession &&
              <PageContents>
                <MainSection title={
                  <div>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
120
                    { t('accessions.common.modelName') }: { accession.accessionNumber }
121
122
123
124
                    <div className="float-right">
                        <ReduxCheckbox
                            label={
                                <b>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
125
                                    { isChecked ? t('accessions.public.p.display.removeFromMyList', {accessionNumber: accession.accessionNumber}) : t('accessions.public.p.display.addToMyList', {accessionNumber: accession.accessionNumber}) }
126
127
128
129
130
131
132
133
134
135
136
137
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
138
139
140
                    { 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') }>
141
142
143
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
Matija Obreza's avatar
Matija Obreza committed
144
145
                      <span> &mdash; </span>
                      <CountryLink noflag country={ accession.institute.country }/>
146
                    </PropertiesItem>
147
148
149
150
151
                    <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') }>
152
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
153
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accessions.common.storage.${storage}`) }</div>
154
155
                      )) }
                    </PropertiesItem> }
156
157
158
159
                    <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
160

161
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title={ t('accessions.public.p.display.safetyDuplicationInstitute') }>
162
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
163
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
164
165
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
166

167
                    { accession.acceUrl && <PropertiesItem title={ t('accessions.public.p.display.accessionURL') }><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
168
169
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
170

171
172
173
174
                { imageGallery &&
                  <ImageGalleryView className={ classes.pageSection } imageGallery={ imageGallery }/>
                }

175
                <PageSection title={ t('accessions.common.taxonomy') }>
176
                  <Properties>
177
178
                    <PropertiesItem title={ t('accessions.common.genus') }>{ accession.taxonomy.genus }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.common.species') }>
179
180
181
182
                      { accession.taxonomy.species }
                      { '' }
                      <Link to={ '/a' }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</Link>
                    </PropertiesItem>
183
184
185
                    <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>
186
187
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Cleanup  
Matija Obreza committed
188
189

                { (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
190
                  <PageSection title={ t('accessions.public.p.display.accessionNames') }>
191
                    <Properties>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
192
                      { accession.donorCode && <PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
193
                      { accession.aliases && accession.aliases.map((alias) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
194
                        <PropertiesItem key={ alias.id } title={ t(`accessions.common.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
195
196
197
198
                      )) }
                    </Properties>
                  </PageSection>
                }
199

200
                { accession.coll &&
201
                  <PageSection title={ t('accessions.public.p.display.collectingInformation') }>
202
                    <Properties>
203
                      { accession.countryOfOrigin && <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
204
                      { accession.coll.collDate && <PropertiesItem key="collDate" title={ t(`accessions.common.coll.collDate`) }><McpdDate value={ accession.coll.collDate } /></PropertiesItem> }
205
206
207
                      { accession.coll &&
                        [ 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                          .filter((prop) => accession.coll[prop] !== null).map((prop) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
208
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
209
                        ))
210
                      }
211
212
213
                      { accession.coll &&
                        [ 'collCode', 'collName' ]
                          .filter((prop) => accession.coll[prop].length).map((prop) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
214
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
215
216
217
218
219
                        ))
                      }
                      { accession.geo &&
                        [ 'latitude', 'longitude', 'datum', 'method', 'uncertainty', 'elevation' ]
                          .filter((prop) => accession.geo[prop] !== null).map((prop) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
220
                          <PropertiesItem key={ prop } title={ t(`accessions.common.geo.${prop}`) }>{ accession.geo[prop] }</PropertiesItem>
221
222
223
224
225
                        ))
                      }
                    </Properties>

                    { hasLatLon &&
Maxym Borodenko's avatar
Maxym Borodenko committed
226
                      <LocationMap locations={ [{ id: accession.geo.id, lat: accession.geo.latitude, lng: accession.geo.longitude }] }/>
227
228
229
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
230

231
                { accession.remarks && accession.remarks.length > 0 && <PageSection title={ t('accessions.public.p.display.remarks') }>
232
233
234
235
236
237
                  <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
238

239
240
241
242
243
244
                { 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}` }>
245
                            <Button variant="contained" component="span">
246
247
248
249
250
251
252
253
254
255
256
                              { t('common:action.download') }
                            </Button>
                          </a>
                        }>
                          <b>{ e.originalFilename }</b>
                        </PropertiesItem>
                      )) }
                    </Properties>
                  </PageSection>
                }

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

259
                <PageSection title={ t('accessions.public.p.display.metadata') }>
260
                  <Properties>
261
262
263
264
                    <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>
265
266
                  </Properties>
                </PageSection>
267
268
269
270
271

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

const mapStateToProps = (state, ownProps) => ({
296
297
  accession: state.accessions.public.accession,
  error: state.accessions.public.accessionError,
298
  uuid: ownProps.match.params.uuid,
299
  doi: ownProps.match.params.doi,
300
  accessions: state.list.public.myList.accessions,
301
302
303
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
304
305
  addAccessionToMyList,
  removeAccessionFromMyList,
306
307
308
309
  loadAccession,
}, dispatch);


310
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(translate()(BrowsePage)));