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

// Actions
Matija Obreza's avatar
Matija Obreza committed
8
import { loadAccession, applyFilters } 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
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
import {CountryLink, DatasetLink, InstituteLink, SubsetLink} from 'ui/genesys/Links';
import PropertiesCard from 'ui/common/PropertiesCard';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
30
import GridContainer from 'ui/layout/GridContainer';
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
38
39
const styles = (theme) => ({
  pageSection: {
    marginBottom: '1em',
  },
Matija Obreza's avatar
Matija Obreza committed
40
41
42
43
44
45
  selected: {
    background: '#c9e2cb',
  },
  historic: {
    background: '#ffe2e2 !important',
  },
46
47
});

48

49
50
51
interface IBrowsePageProps {
  t?: any;
  classes?: any;
52

53
  uuid: string;
54
  doi: string; // DOI comes from the route without the '10.'
55
  accession: AccessionDetails;
56
57
  error: any;
  loadAccession: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
58
59
60
  accessions: any;
  addAccessionToMyList: any;
  removeAccessionFromMyList: any;
Matija Obreza's avatar
Matija Obreza committed
61
  applyFilters: any;
62
63
64
65
66
}

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

  protected static needs = [
67
    ({ params: { uuid, doi } }) => {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
68
        return doi ? loadAccession({ doi: `10.${doi}` }) :  loadAccession({ uuid });
69
70
71
72
73
74
75
76
    },
  ];

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

  public componentWillMount() {
77
78
79
    const { doi, uuid, loadAccession } = this.props;
    const accession = this.props.accession ? this.props.accession.details : null;

80
81
82
83
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
84
    if (uuid && (! accession || uuid !== accession.uuid)) {
85
      loadAccession({ uuid });
86
87
88
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
89
  private onCheckboxChange = (event, checked) => {
90
      const {accession: {details: accession}, addAccessionToMyList, removeAccessionFromMyList} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
91
92
93
94
95
96
97
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

Matija Obreza's avatar
Matija Obreza committed
98
99
100
101
102
103
104
105

  private applyFilterForInstituteSpecies = () => {
    const { accession: {details: accession}, applyFilters } = this.props;
    const filter = {holder: {code: [ accession.institute.code ]}, taxa: { genus: [ accession.taxonomy.genus ], species: [ accession.taxonomy.species ] }};
    applyFilters(filter);
  }


106
  public render() {
107
108
    const { t, error, uuid, doi, accessions, classes } = this.props;
    const { details: accession, pdci, datasets, subsets, files, imageGallery } = this.props.accession ?
109
110
      this.props.accession
      :
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
111
      {details: null, pdci: null, datasets: null, subsets: null, files: null, imageGallery: null};
112

Matija Obreza's avatar
Matija Obreza committed
113
    const isChecked  =  accession && accessions && accessions.includes(accession.uuid);
114
115
116
117
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
118

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

121
    return (
Oleksii Savran's avatar
Oleksii Savran committed
122
      <PageLayout withFooter>
Matija Obreza's avatar
Matija Obreza committed
123
        <ScrollToTopOnMount />
Matija Obreza's avatar
Matija Obreza committed
124
        <ContentHeader title={ t('accessions.public.p.display.title') } subtitle={ t('accessions.public.p.display.subTitle') } />
Matija Obreza's avatar
Matija Obreza committed
125

126
127
128
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
129

130
            { accession &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
131
              <PageContents className="pt-1rem">
Matija Obreza's avatar
Matija Obreza committed
132
                <MainSection className={ isChecked ? classes.selected : accession.historic ?  classes.historic : '' } title={
133
                  <div>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
134
                    { t('accessions.common.modelName') }: { accession.accessionNumber }
135
136
137
138
                    <div className="float-right">
                        <ReduxCheckbox
                            label={
                                <b>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
139
                                    { isChecked ? t('accessions.public.p.display.removeFromMyList', {accessionNumber: accession.accessionNumber}) : t('accessions.public.p.display.addToMyList', {accessionNumber: accession.accessionNumber}) }
140
141
142
143
144
145
146
147
148
149
150
151
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
152
153
154
                    { 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') }>
155
156
157
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
Matija Obreza's avatar
Matija Obreza committed
158
159
                      <span> &mdash; </span>
                      <CountryLink noflag country={ accession.institute.country }/>
160
                    </PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
161
                    { accession.historic && <PropertiesItem className={ accession.historic ?  classes.historic : '' } title={ t('accessions.public.p.display.historic') }>{ t('accessions.public.p.display.isHistoric') }</PropertiesItem> }
162
163
164
165
166
                    <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') }>
167
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
168
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accessions.common.storage.${storage}`) }</div>
169
170
                      )) }
                    </PropertiesItem> }
171
172
173
174
                    <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
175

176
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title={ t('accessions.public.p.display.safetyDuplicationInstitute') }>
177
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
178
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
179
180
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
181

182
                    { accession.acceUrl && <PropertiesItem title={ t('accessions.public.p.display.accessionURL') }><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
183
184
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
185

186
187
188
189
                { imageGallery &&
                  <ImageGalleryView className={ classes.pageSection } imageGallery={ imageGallery }/>
                }

190
                <PageSection title={ t('accessions.common.taxonomy') }>
191
                  <Properties>
192
193
                    <PropertiesItem title={ t('accessions.common.genus') }>{ accession.taxonomy.genus }</PropertiesItem>
                    <PropertiesItem title={ t('accessions.common.species') }>
194
195
                      { accession.taxonomy.species }
                      { '' }
Matija Obreza's avatar
Matija Obreza committed
196
                      <a onClick={ this.applyFilterForInstituteSpecies }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</a>
197
                    </PropertiesItem>
198
199
200
                    <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>
201
202
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Cleanup    
Matija Obreza committed
203
204

                { (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
205
                  <PageSection title={ t('accessions.public.p.display.accessionNames') }>
206
                    <Properties>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
207
                      { accession.donorCode && <PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
208
                      { accession.aliases && accession.aliases.map((alias) => (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
209
                        <PropertiesItem key={ alias.id } title={ t(`accessions.common.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
210
211
212
213
                      )) }
                    </Properties>
                  </PageSection>
                }
214

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

                    { hasLatLon &&
Maxym Borodenko's avatar
Maxym Borodenko committed
241
                      <LocationMap locations={ [{ id: accession.geo.id, lat: accession.geo.latitude, lng: accession.geo.longitude }] }/>
242
243
244
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
245

246
                { accession.remarks && accession.remarks.length > 0 && <PageSection title={ t('accessions.public.p.display.remarks') }>
247
248
249
250
251
252
                  <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
253

254
255
256
257
258
259
                { 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}` }>
260
                            <Button variant="contained" component="span">
261
262
263
264
265
266
267
268
269
270
271
                              { t('common:action.download') }
                            </Button>
                          </a>
                        }>
                          <b>{ e.originalFilename }</b>
                        </PropertiesItem>
                      )) }
                    </Properties>
                  </PageSection>
                }

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

274
                <PageSection title={ t('accessions.public.p.display.metadata') }>
275
                  <Properties>
276
277
278
279
                    <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>
280
281
                  </Properties>
                </PageSection>
282

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
283
                <GridContainer className="mb-15">
284
285
286
                  { datasets && datasets.length > 0 &&
                  <PropertiesCard
                    small
287
                    title={ t('accessions.public.p.display.associatedDatasets') }
288
                    propertyItemProps={ { keepEmpty: true } }
Matija Obreza's avatar
Matija Obreza committed
289
                    propertiesList={ datasets.map((dataset) => ({ value: <DatasetLink to={ dataset } /> })) }
290
291
292
293
294
                  />
                  }
                  { subsets && subsets.length > 0 &&
                  <PropertiesCard
                    small
295
                    title={ t('accessions.public.p.display.associatedSubsets') }
296
                    propertyItemProps={ { keepEmpty: true } }
Matija Obreza's avatar
Matija Obreza committed
297
                    propertiesList={ subsets.map((subset) => ({ value: <SubsetLink to={ subset } /> })) }
298
299
                  />
                  }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
300
                </GridContainer>
301
302
303
              </PageContents>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
304
        }
305
306
307
308
309
310
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
311
312
  accession: state.accessions.public.accession,
  error: state.accessions.public.accessionError,
313
  uuid: ownProps.match.params.uuid,
314
  doi: ownProps.match.params.doi,
315
  accessions: state.list.public.myList.accessions,
316
317
318
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
319
320
  addAccessionToMyList,
  removeAccessionFromMyList,
321
  loadAccession,
Matija Obreza's avatar
Matija Obreza committed
322
  applyFilters,
323
324
325
}, dispatch);


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