PropertiesCard.tsx 2 KB
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import { Property } from "ui/Property";
import { TreeMap } from "d3js";
import {WithTranslation, withTranslation} from "react-i18next";

interface IProperty extends React.ClassAttributes<any>, WithTranslation {
  title: string;
  propertiesList: {term: string, count: any}[];
  translationGroup?: string;
  countyCodes?: object;
  t: any;
  propertyItemProps?: any;
}

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

  private getTitle(property: {term: string, count: any}) {
    const {translationGroup, countyCodes, t} = this.props;
    if (countyCodes && countyCodes[property.term]) {
      return countyCodes[property.term];
    }
    if (translationGroup) {
      return t([
        `accession.${translationGroup}.${property.term}`,
        `accession.overview.${property.term}`,
        property.term,
      ]);
    }
    return t(property.term);
  }

  public render() {
    const {propertiesList, propertyItemProps, title, t} = this.props;

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

    return (
      <div className="card col-sm-11 col-md-11 col-xl-5 ml-auto mr-auto mb-5 p-0">
        <div className="card-header">
          <span className="card-title">{title}</span>
        </div>
        <div className="card-body">
          <div style={{height: "400px", width: "100%"}}>
            <TreeMap style={{height: "100%"}} data={{
              name: t("accession.overview.total"),
              children: propertiesList,
            }}/>
          </div>
          {propertiesList.map((property, i) => {
            property.term = this.getTitle(property);
            return (
              <Property
                key={`${i}-${property.term}`}
                title={property.term}
                value={property.count}
                index={i}
                {...propertyItemProps}
              />
            )
          })}
        </div>
      </div>
    );
  }
}

export default withTranslation()(PropertiesCard);