DisplayPage.tsx 19.5 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
import * as React from 'react';
2
import { withStyles } from '@material-ui/core/styles';
Matija Obreza's avatar
Matija Obreza committed
3 4
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
5
import { WithTranslation, withTranslation } from 'react-i18next';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
6
import { Link } from 'react-router-dom';
Oleksii Savran's avatar
Oleksii Savran committed
7
import * as _ from 'lodash';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
8 9

// Actions
Matija Obreza's avatar
Matija Obreza committed
10
import { loadInstitute } from 'institutes/actions/public';
11
import { applyFiltersAsync as applyFilters, applyOverviewFiltersAsync as applyOverviewFilters } from 'accessions/actions/public';
Oleksii Savran's avatar
Oleksii Savran committed
12
import { showSnackbar } from 'actions/snackbar';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
13 14

// Models
Oleksii Savran's avatar
Oleksii Savran committed
15 16
import FaoInstituteDetails from '@genesys/client/model/genesys/InstituteDetails';
import MapLayer from '@genesys/client/model/genesys/MapTileLayer';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
17 18

// UI
Matija Obreza's avatar
Matija Obreza committed
19
import PageLayout, { MainSection, PageContents, PageSection } from 'ui/layout/PageLayout';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
20
import GridContainer from 'ui/layout/GridContainer';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
21
import ContentHeader from 'ui/common/heading/ContentHeader';
22
import LocationMap from 'ui/common/LocationMap';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
23
import Loading from 'ui/common/Loading';
24
import Number from 'ui/common/Number';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
25
import { ScrollToTopOnMount } from 'ui/common/page/scrollers';
Matija Obreza's avatar
Matija Obreza committed
26
import { Properties, PropertiesItem } from 'ui/common/Properties';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
27
import PieChartCard from 'ui/common/pie-chart/PieChartCard';
28
import PrettyDate from 'ui/common/time/PrettyDate';
29
import {CountryLink, InstituteCodeLink, SubsetLink} from 'ui/genesys/Links';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
30
import BarChart from 'ui/common/bar-chart';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
31 32
import Button from '@material-ui/core/Button';
import Permissions from 'ui/common/permission/Permissions';
Oleksii Savran's avatar
Oleksii Savran committed
33
import FaoInstitute from '@genesys/client/model/genesys/FaoInstitute';
Oleksii Savran's avatar
Oleksii Savran committed
34
import ButtonBar from 'ui/common/buttons/ButtonBar';
35
import DownloadDialog, { DOWNLOAD_AUTH_SLUG, DOWNLOAD_ANON_SLUG } from 'ui/common/download-dialog';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
36
import PageTitle from 'ui/common/PageTitle';
Matija Obreza's avatar
Matija Obreza committed
37
import BlurbText from 'cms/ui/c/BlurbText';
Oleksii Savran's avatar
Oleksii Savran committed
38 39
import AccessionFilter from '@genesys/client/model/accession/AccessionFilter';
import { IPageRequest } from '@genesys/client/model/Page';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
40
import ErrorMessage from 'ui/common/error/ErrorMessage';
Oleksii Savran's avatar
Oleksii Savran committed
41
import { PartnerLink } from 'ui/catalog/Links';
42 43
import PropertiesCard from 'ui/common/PropertiesCard';
import { Grid } from '@material-ui/core';
Oleksii Savran's avatar
Oleksii Savran committed
44
import { ExternalInstituteLink, FaoWiewsLink } from 'ui/common/Links';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
45

46
/* eslint-disable*/
47 48 49
const styles = (theme) => ({
  italicProperties: {
    fontStyle: 'italic' as 'italic',
50
  },
51 52 53 54 55 56 57 58
  hasNewVersionPropLink: {
    '& > div': {
      backgroundColor: '#ffe2e2 !important',
    },
  },
  hasNewVersion: {
    backgroundColor: '#ffe2e2 !important',
  },
59 60 61 62 63
  pdciSubHeader: {
    fontSize: '1rem',
    color: 'black',
    marginTop: '15px',
  },
64
});
65
/* eslint-enable */
66 67


Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
68
interface IDisplayPageProps extends React.ClassAttributes<any>, WithTranslation {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
69
  t: any;
70
  classes: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
71
  code: string;
72
  institute: FaoInstituteDetails;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
73
  error: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
74
  loading: boolean;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
75
  loadInstitute: any;
Matija Obreza's avatar
Matija Obreza committed
76 77
  applyFilters: (filters: string | AccessionFilter, page?: IPageRequest) => any;
  applyOverviewFilters: (filters: string | AccessionFilter) => any;
78
  userRoles: string[];
Oleksii Savran's avatar
Oleksii Savran committed
79
  mapLayers: MapLayer[];
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
80
  apiUrl: string;
Oleksii Savran's avatar
Oleksii Savran committed
81
  showSnackbar: (snack: string) => void;
Oleksii Savran's avatar
Oleksii Savran committed
82
  lang: string;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
83 84
}

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
85

86
class DisplayPage extends React.Component<IDisplayPageProps, any> {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
87

88
  protected static needs = [
Matija Obreza's avatar
Matija Obreza committed
89
    ({ params: { wiewsCode } }) => loadInstitute(wiewsCode),
90 91
  ];

92
  public constructor(props: IDisplayPageProps, context: any) {
93
    super(props, context);
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
94 95
  }

96 97 98 99
  public state = {
    authenticated: false,
  };

100 101
  private applyInstituteCodeFilter = () => {
    const { institute, applyFilters} = this.props;
Matija Obreza's avatar
Matija Obreza committed
102
    const filter = { institute: { code: [institute.details.code] } };
103 104 105
    applyFilters(filter);
  }

Oleksii Savran's avatar
Oleksii Savran committed
106 107
  private applyFilterForOverview = () => {
    const { institute, applyOverviewFilters } = this.props;
Matija Obreza's avatar
Matija Obreza committed
108
    const filter = { institute: { code: [institute.details.code] } };
Oleksii Savran's avatar
Oleksii Savran committed
109 110 111
    applyOverviewFilters(filter);
  }

112 113 114 115 116 117 118 119
  private applyLastModifyDateFilter = (lastUpdateDate) => {
    const { institute, applyFilters} = this.props;
    const startOfDay = new Date(`${lastUpdateDate[0]}-${lastUpdateDate[1]}-${lastUpdateDate[2]}`);
    const endOfDay = new Date(`${lastUpdateDate[0]}-${lastUpdateDate[1]}-${lastUpdateDate[2]}`);
    startOfDay.setHours(0);
    endOfDay.setHours(23, 59, 59);

    const filter = {
120
      historic: null,
Matija Obreza's avatar
Matija Obreza committed
121
      institute: { code: [institute.details.code] },
122 123 124 125 126 127 128 129
      lastModifiedDate: {
        ge: startOfDay,
        le: endOfDay,
      },
    };
    applyFilters(filter);
  }

130
  public componentDidMount() {
131 132 133 134
    const { code, loadInstitute, institute, userRoles } = this.props;
    if (code && (! institute || code !== institute.details.code)) {
      loadInstitute(code);
    }
135 136 137

    const authenticated: boolean = userRoles.findIndex((role) => role === 'ROLE_USER') !== -1;
    this.setState({authenticated});
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
138 139
  }

Oleksii Savran's avatar
Oleksii Savran committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  private addTerm = (property, term) => {
    const { applyOverviewFilters, showSnackbar, institute } = this.props;

    const updatedFilter: AccessionFilter = {
      institute: { code: [institute.details.code] },
    };
    switch (property) {
      case 'crop':
      case 'taxonomy.genus':
      case 'taxonomy.genusSpecies':
        _.set(updatedFilter, property, _.concat(_.get(updatedFilter, property), term).filter((x) => x != null));
        break;

      default:
        _.set(updatedFilter, property, term);
    }

    showSnackbar('common.snackbar.applyingFilters');
    applyOverviewFilters(updatedFilter);
  }

  private renderLinkToOverview = (property) => (term) => {
    return (
      <a onClick={ () => this.addTerm(property, term.term) }>
        <Number value={ term.count }/>
      </a>
    );
  }

169 170
  public componentDidUpdate(prevProps: Readonly<IDisplayPageProps>): void {
    const { code: oldCode } = prevProps;
Matija Obreza's avatar
Bugs  
Matija Obreza committed
171 172
    const { loading, code, loadInstitute, institute } = this.props;
    if (code && !loading && (!institute || code !== institute.details.code) || code !== oldCode) {
173 174 175 176
      loadInstitute(code);
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
177
  public render() {
Oleksii Savran's avatar
Oleksii Savran committed
178
    const { error, loading, institute, code, userRoles, mapLayers, classes, apiUrl, t, lang } = this.props;
179
    const slug: string = this.state.authenticated ? DOWNLOAD_AUTH_SLUG : DOWNLOAD_ANON_SLUG;
180 181 182 183 184

    let cropShortNameOverview;
    let cropNameOverview;
    let taxonomyGenusOverview;
    let taxonomyGenusSpeciesOverview;
Matija Obreza's avatar
Bugs  
Matija Obreza committed
185
    if (!loading && institute) {
186 187 188 189 190 191 192 193 194
      const cropShortNameKey = 'crop.shortName';
      cropShortNameOverview = institute.overview[cropShortNameKey];
      const cropNameKey = 'cropName';
      cropNameOverview = institute.overview[cropNameKey];
      const taxonomyGenusKey = 'taxonomy.genus';
      taxonomyGenusOverview = institute.overview[taxonomyGenusKey];
      const taxonomyGenusSpeciesKey = 'taxonomy.genusSpecies';
      taxonomyGenusSpeciesOverview = institute.overview[taxonomyGenusSpeciesKey];
    }
195
    const hasNewVersion =  institute && institute.details && institute.details.vCode && institute.details.vCode !== code;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
196 197

    return (
Oleksii Savran's avatar
Oleksii Savran committed
198
      <PageLayout withFooter>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
199
        <ScrollToTopOnMount />
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
200
        <PageTitle title={ !loading && institute ? institute.details.fullName || institute.details.code : t('common:label.loading', { what: t('institutes.public.p.display.title') }) } />
Oleksii Savran's avatar
Oleksii Savran committed
201
        <ContentHeader title={ !loading && institute ? t('institutes.public.p.display.title') : t('common:label.loading', { what: t('institutes.public.p.display.title') }) } />
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
202

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
203
        { loading ? <Loading /> :
204
          <div>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
205
            { error && <ErrorMessage error={ error }/> }
206 207

            { institute &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
208
            <PageContents className="pt-1rem">
Oleksii Savran's avatar
Oleksii Savran committed
209
                <MainSection
210
                  className={ hasNewVersion ? classes.hasNewVersion : '' }
Oleksii Savran's avatar
Oleksii Savran committed
211
                  title={ institute.details.fullName || institute.details.code }
Oleksii Savran's avatar
Oleksii Savran committed
212 213 214 215 216 217 218 219 220
                  cardActions={
                    <ButtonBar barLabelText={ t('institutes.public.p.display.actions') }>
                      <Button onClick={ this.applyInstituteCodeFilter }>{ t('institutes.public.p.display.browseAccessions') }</Button>
                      { (userRoles.findIndex((role) => role === 'ROLE_ADMINISTRATOR') !== -1 || institute.details._permissions.manage) &&
                        <Link to={ `/dashboard/wiews/${institute.details.code}/files/` }>
                          <Button>{ t('institutes.public.p.display.browseFiles') }</Button>
                        </Link>
                      }
                      <Button onClick={ this.applyFilterForOverview }>{ t('accessions.tab.overview') }</Button>
221 222 223 224 225 226 227 228 229 230 231 232 233 234
                      <DownloadDialog
                        downloadUrl={ `${ apiUrl }/api/v1/wiews/${code}/download` }
                        slug={ slug }
                        postParams={ { mcpd: 'mcpd' } }
                        buttonTitle={ `${t('common:action.download')} ${t('institutes.public.p.display.MCPD')}` }
                        preventAction={ !this.state.authenticated }
                      />
                      <DownloadDialog
                        downloadUrl={ `${apiUrl}/api/v1/wiews/${code}/download` }
                        slug={ slug }
                        postParams={ { pdci: 'pdci' } }
                        buttonTitle={ `${t('common:action.download')} ${t('institutes.public.p.display.PDCI_short')}` }
                        preventAction={ !this.state.authenticated }
                      />
Oleksii Savran's avatar
Oleksii Savran committed
235
                      <DownloadDialog
236
                        downloadUrl={ `${apiUrl}/api/v1/wiews/${code}/download` }
Oleksii Savran's avatar
Oleksii Savran committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                        slug={ slug }
                        postParams={ { dwca: 'dwca' } }
                        buttonTitle={ `${t('common:action.download')} ${t('institutes.public.p.display.zip')}` }
                      />
                      { institute.details._permissions.manage &&
                        <Link to={ `/dashboard/wiews/${institute.details.code}/edit` }>
                          <Button>{ t('common:action.edit') }</Button>
                        </Link>
                      }
                      { institute.details._permissions.manage &&
                        <Permissions clazz={ FaoInstitute.clazz } id={ institute.details.id }/>
                      }
                    </ButtonBar>
                  }
                >
Matija Obreza's avatar
Matija Obreza committed
252
                  { institute.blurb && institute.blurb.body &&
Matija Obreza's avatar
Matija Obreza committed
253
                      <div className="mb-20">
Matija Obreza's avatar
Matija Obreza committed
254
                        <BlurbText body={ institute.blurb.body } />
Matija Obreza's avatar
Matija Obreza committed
255
                      </div>
Matija Obreza's avatar
Matija Obreza committed
256
                  }
257
                  <Properties>
Oleksii Savran's avatar
Oleksii Savran committed
258 259 260 261
                    <PropertiesItem title={ t('institutes.common.instituteCode') }>
                      <strong>{ institute.details.code }</strong>
                      <div className="float-right"><FaoWiewsLink lang={ lang } wiewsCode={ institute.details.code }>{ t('institutes.public.p.display.showWiewsPage') }</FaoWiewsLink></div>
                    </PropertiesItem>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
262 263
                    <PropertiesItem title={ t('institutes.public.p.display.type') }>{ institute.details.type }</PropertiesItem>
                    <PropertiesItem title={ t('geo.common.country') }>{ <CountryLink country={ institute.details.country }/> }</PropertiesItem>
264 265 266 267 268 269 270 271 272 273
                    {hasNewVersion &&
                      <PropertiesItem
                        className={ classes.hasNewVersionPropLink }
                        title={t('institutes.public.p.display.newCode')}
                      >
                        <InstituteCodeLink to={institute.details.vCode}>
                          { t('institutes.public.p.display.hasNewVersion', {instCode: institute.details.vCode}) }
                        </InstituteCodeLink>
                      </PropertiesItem>
                    }
274
                    { institute.details.url &&
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
275
                      <PropertiesItem title={ t('institutes.public.p.display.webLink') }>
Oleksii Savran's avatar
Oleksii Savran committed
276
                        <ExternalInstituteLink links={ institute.details.url }/>
277
                      </PropertiesItem>
278
                    }
279 280
                    { institute.details.owner &&
                      <PropertiesItem title={ t('accessions.public.p.display.partner') }>
Oleksii Savran's avatar
Oleksii Savran committed
281
                        <PartnerLink to={ institute.details.owner }/>
282 283
                      </PropertiesItem>
                    }
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
284
                    <PropertiesItem title={ t('institutes.common.accessionsInGenesys') }>
285 286
                      <a onClick={ this.applyInstituteCodeFilter }><Number value={ institute.details.accessionCount } /></a>
                    </PropertiesItem>
287 288
                  </Properties>
                </MainSection>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
289

290
                { institute.details.latitude !== null && institute.details.longitude !== null &&
Matija Obreza's avatar
Matija Obreza committed
291
                  <PageSection title={ t('geo.common.location') }>
292
                    <LocationMap
Maxym Borodenko's avatar
Maxym Borodenko committed
293
                      locations={ [{ id: institute.details.id, lat: institute.details.latitude, lng: institute.details.longitude }] }
Oleksii Savran's avatar
Oleksii Savran committed
294
                      mapLayers={ mapLayers }
295
                    />
Matija Obreza's avatar
Matija Obreza committed
296
                    <Properties>
Oleksii Savran's avatar
Oleksii Savran committed
297 298 299 300 301 302
                      <PropertiesItem title={ t('geo.common.latitude') }>
                        <Number value={ institute.details.latitude } />
                      </PropertiesItem>
                      <PropertiesItem title={ t('geo.common.longitude') }>
                        <Number value={ institute.details.longitude } />
                      </PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
303
                    </Properties>
304 305 306
                  </PageSection>
                }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
307
                <GridContainer className="mb-15">
308
                  { cropShortNameOverview && cropShortNameOverview.terms && cropShortNameOverview.terms.length > 0 &&
Matija Obreza's avatar
Matija Obreza committed
309
                    <PieChartCard
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
310
                      title={ t('institutes.public.p.display.representedCrops') }
Matija Obreza's avatar
Matija Obreza committed
311 312 313
                      terms={ cropShortNameOverview.terms }
                      missing={ cropShortNameOverview.missing }
                      total={ cropShortNameOverview.total }
Oleksii Savran's avatar
Oleksii Savran committed
314
                      valueHandler={ this.renderLinkToOverview('crop') }
315
                    />
316
                  }
317

318
                  { cropNameOverview && cropNameOverview.terms && cropNameOverview.terms.length > 0 &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
319
                    <PieChartCard
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
320
                      title={ t('institutes.public.p.display.representedCropNames') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
321 322 323 324
                      terms={ cropNameOverview.terms }
                      missing={ cropNameOverview.missing }
                      total={ cropNameOverview.total }
                    />
325 326 327
                  }

                  { taxonomyGenusOverview && taxonomyGenusOverview.terms && taxonomyGenusOverview.terms.length > 0 &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
328
                    <PieChartCard
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
329
                      title={ t('institutes.public.p.display.representedGenera') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
330 331 332
                      terms={ taxonomyGenusOverview.terms }
                      missing={ taxonomyGenusOverview.missing }
                      total={ taxonomyGenusOverview.total }
333
                      propertyItemProps={ {classes: {propertiesRowLabel: classes.italicProperties} } }
Oleksii Savran's avatar
Oleksii Savran committed
334
                      valueHandler={ this.renderLinkToOverview('taxonomy.genus') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
335
                    />
336 337 338
                  }

                  { taxonomyGenusSpeciesOverview && taxonomyGenusSpeciesOverview.terms && taxonomyGenusSpeciesOverview.terms.length > 0 &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
339
                    <PieChartCard
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
340
                      title={ t('institutes.public.p.display.representedSpecies') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
341 342 343
                      terms={ taxonomyGenusSpeciesOverview.terms }
                      missing={ taxonomyGenusSpeciesOverview.missing }
                      total={ taxonomyGenusSpeciesOverview.total }
344
                      propertyItemProps={ {classes: {propertiesRowLabel: classes.italicProperties} } }
Oleksii Savran's avatar
Oleksii Savran committed
345
                      valueHandler={ this.renderLinkToOverview('taxonomy.genusSpecies') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
346
                    />
347 348
                  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
349
                </GridContainer>
350 351 352 353 354
                <GridContainer className="mt-1rem mb-1rem">
                  { institute.recentSubsets && institute.recentSubsets.length > 0 &&
                  <Grid item xs={ 12 } style={ {minHeight: '100%'} }>
                    <PropertiesCard
                      style={ {height: '100%'} }
355
                      title={ t('recent.recentSubsets') }
356 357 358 359 360 361 362 363 364 365 366 367
                      propertyItemProps={ {keepEmpty: true} }
                      propertiesList={
                        institute.recentSubsets
                          .sort((a, b) => a.title.localeCompare(b.title))
                          .map((subset) => (
                            { value: <SubsetLink to={ subset }/> }
                          ))
                      }
                    />
                  </Grid>
                  }
                </GridContainer>
368

369
                { institute.lastUpdates && institute.lastUpdates.length > 0 &&
Matija Obreza's avatar
Matija Obreza committed
370
                <PageSection title={ t('institutes.public.p.display.lastUpdates') }>
371 372
                  <Properties>
                    { institute.lastUpdates.map((lastUpdate) => (
373
                      <PropertiesItem key={ `${lastUpdate[0]}-${lastUpdate[1]}=${lastUpdate[2]}` }
Matija Obreza's avatar
Matija Obreza committed
374
                        numeric title={ <PrettyDate value={ new Date(lastUpdate[0], lastUpdate[1] - 1, lastUpdate[2]) } /> }>
375 376
                          <a onClick={ () => this.applyLastModifyDateFilter(lastUpdate) }><Number value={ lastUpdate[3] } /></a>
                      </PropertiesItem>
377 378 379 380 381
                    )) }
                  </Properties>
                </PageSection>
                }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
382
                { institute.pdciStats && institute.pdciStats.histogram && institute.pdciStats.histogram.length > 0 &&
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
                  <PageSection
                    title={ t('institutes.public.p.display.PDCI') }
                    subheader={
                      <div className={ classes.pdciSubHeader }>
                        { t('institutes.public.p.display.pdciDescription1') }
                        <a href="https://www.cambridge.org/core/journals/plant-genetic-resources/article/quality-indicators-for-passport-data-in-ex-situ-genebanks/AD391E5CF32DD41BFB49C1FE1D457E2C">
                          { t('institutes.public.p.display.pdciDescriptionLink') }
                        </a>
                        { t('institutes.public.p.display.pdciDescription2') }
                      </div>
                    }
                  >
                    <BarChart
                      data={ institute.pdciStats.histogram.map((item, i) => ({key: i % 2 === 0 ? i / 2 : '', value: item })) }
                      yLabel={ t('institutes.public.p.display.pdciYLabel') }
                      xLabel={ t('institutes.public.p.display.pdciXLabel') }
                    />
                    <div className="mt-20">
                      { t('institutes.public.p.display.pdciScore', {
                        count: institute.pdciStats.count,
                        avg: institute.pdciStats.avg.toFixed(2),
                        min: institute.pdciStats.min.toFixed(2),
                        max: institute.pdciStats.max.toFixed(2),
                      }) }
                    </div>
408 409 410
                  </PageSection>
                }
              </PageContents>
411
            }
412
          </div>
413
        }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
414 415 416 417 418 419
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
420 421 422
  institute: state.institutes.public.institute ? state.institutes.public.institute.data : undefined,
  error:  state.institutes.public.institute ? state.institutes.public.institute.error : undefined,
  loading:  state.institutes.public.institute ? state.institutes.public.institute.loading : true,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
423
  code: ownProps.match.params.wiewsCode,
424
  userRoles: state.login.authorities,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
425
  apiUrl: state.applicationConfig.apiUrl,
Oleksii Savran's avatar
Oleksii Savran committed
426
  mapLayers: state.accessions.public.mapLayers,
Oleksii Savran's avatar
Oleksii Savran committed
427
  lang: state.applicationConfig.lang,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
428 429 430 431
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
  loadInstitute,
432
  applyFilters,
Oleksii Savran's avatar
Oleksii Savran committed
433
  applyOverviewFilters,
Oleksii Savran's avatar
Oleksii Savran committed
434
  showSnackbar,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
435 436 437
}, dispatch);


Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
438
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(withTranslation()(DisplayPage)));