ClimateTable.tsx 1.14 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov 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
import * as React from 'react';
import { translate } from 'react-i18next';
import Table from '@material-ui/core/Table';
import { TableHead } from '@material-ui/core';
import TableRow from '@material-ui/core/TableRow';
import TableCell from '@material-ui/core/TableCell';
import TableBody from '@material-ui/core/TableBody';

const climateKeys = ['tmin', 'tmean', 'tmax', 'prec'];

const ClimateTable = ({ climate, t }) => {
  return (
    <Table padding="none">
      <TableHead>
        <TableRow>
          <TableCell/>
          { [...Array(12).keys()].map((i) => <TableCell key={ `month-${i}` }><b>{ t(`accessions.climate.month.${i + 1}`) }</b></TableCell>) }
        </TableRow>
      </TableHead>
      <TableBody>
        { climateKeys.map((key) => (
          <TableRow key={ key }>
            <TableCell>{ t(`accessions.climate.label.${key}`) }</TableCell>
            { [...Array(12).keys()].map((i) => <TableCell key={ `${key}-${i}` }>{ climate[`${key}${i + 1}`] ? Number(climate[`${key}${i + 1}`]).toFixed(1) : '' }</TableCell>) }
          </TableRow>
        )) }
      </TableBody>
    </Table>
  );
};

export default translate()(ClimateTable);