PropertiesCard.tsx 2.06 KB
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
import React from 'react';
Oleksii Savran's avatar
Oleksii Savran committed
2
import { Property } from 'ui/common/Property';
Oleksii Savran's avatar
Oleksii Savran committed
3
4
import { TreeMap } from 'd3js';
import { WithTranslation, withTranslation } from 'react-i18next';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
5
6
7
8
9

interface IProperty extends React.ClassAttributes<any>, WithTranslation {
  title: string;
  propertiesList: {term: string, count: any}[];
  translationGroup?: string;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
10
  countryCodes?: Record<string, string>;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
11
12
13
14
15
16
  t: any;
  propertyItemProps?: any;
}

class PropertiesCard extends React.Component<IProperty, any> {

Maksym Tishchenko's avatar
Maksym Tishchenko committed
17
18


Oleksii Savran's avatar
Oleksii Savran committed
19
  private getTitle(property: { term: string, count: any }) {
Maksym Tishchenko's avatar
Maksym Tishchenko committed
20
21
22
    const { translationGroup, countryCodes, t } = this.props;
    if (countryCodes && countryCodes[property.term]) {
      return countryCodes[property.term];
Maksym Tishchenko's avatar
Maksym Tishchenko committed
23
24
25
26
27
28
29
30
31
32
33
34
    }
    if (translationGroup) {
      return t([
        `accession.${translationGroup}.${property.term}`,
        `accession.overview.${property.term}`,
        property.term,
      ]);
    }
    return t(property.term);
  }

  public render() {
Oleksii Savran's avatar
Oleksii Savran committed
35
    const { propertiesList, propertyItemProps, title, t } = this.props;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
36
37
38
39
40
41

    if ((propertiesList && propertiesList.length === 0) || !propertiesList) {
      return null;
    }

    return (
42
43
      <div className="col-sm-12 col-md-12 col-xl-6 pb-5">
        <div className="col-sm-12 col-md-12 col-xl-12 p-0 h-100">
Oleksii Savran's avatar
Oleksii Savran committed
44
          <h4>{ title }</h4>
45
          <div className="">
Oleksii Savran's avatar
Oleksii Savran committed
46
47
48
            <div style={ { height: '300px', width: '100%' } }>
              <TreeMap style={ { height: '100%' } } data={ {
                name: t('accession.overview.total'),
Maksym Tishchenko's avatar
Maksym Tishchenko committed
49
                children: propertiesList,
Oleksii Savran's avatar
Oleksii Savran committed
50
              } }/>
Maksym Tishchenko's avatar
Maksym Tishchenko committed
51
52
53
54
55
            </div>
            {propertiesList.map((property, i) => {
              property.term = this.getTitle(property);
              return (
                <Property
Oleksii Savran's avatar
Oleksii Savran committed
56
57
58
59
60
                  key={ `${i}-${property.term}` }
                  title={ property.term }
                  value={ property.count }
                  index={ i }
                  { ...propertyItemProps }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
61
62
63
                />
              )
            })}
Maksym Tishchenko's avatar
Maksym Tishchenko committed
64
65
66
67
68
69
70
71
          </div>
        </div>
      </div>
    );
  }
}

export default withTranslation()(PropertiesCard);