PropertiesCard.tsx 2.11 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
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 (
Maksym Tishchenko's avatar
Maksym Tishchenko committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
      <div className="col-sm-12 col-md-12 col-xl-6 pl-0 pr-5 pb-5">
        <div className="card col-sm-12 col-md-12 col-xl-12 p-0 h-100">
          <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}
                />
              )
            })}
Maksym Tishchenko's avatar
Maksym Tishchenko committed
64
65
66
67
68
69
70
71
          </div>
        </div>
      </div>
    );
  }
}

export default withTranslation()(PropertiesCard);