SubsetCard.tsx 3.41 KB
Newer Older
Matija Obreza's avatar
Subsets  
Matija Obreza committed
1
import * as React from 'react';
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
2
import { translate } from 'react-i18next';
Matija Obreza's avatar
Subsets  
Matija Obreza committed
3

4
import Subset from 'model/subset/Subset';
5
import { SubsetLink, InstituteLink } from 'ui/genesys/Links';
Matija Obreza's avatar
Subsets  
Matija Obreza committed
6
import Card, {CardHeader, CardContent, CardActions} from 'ui/common/Card';
7
import Markdown from 'ui/common/markdown';
8
import Number from 'ui/common/Number';
Matija Obreza's avatar
Matija Obreza committed
9
import { ExternalLink } from 'ui/common/Links';
10
11

import { Properties, PropertiesItem } from 'ui/common/Properties';
12
13
import CropChips from 'crop/ui/c/CropChips';
import McpdDate from 'ui/common/time/McpdDate';
Oleksii Savran's avatar
Oleksii Savran committed
14
15
16
import DashboardCardDates from 'ui/catalog/dashboard/c/DashboardCardDates';
import DashboardCardStatus from 'ui/catalog/dashboard/c/DashboardCardStatus';
import Permissions from 'ui/common/permission/Permissions';
Matija Obreza's avatar
Subsets  
Matija Obreza committed
17

Oleksii Savran's avatar
Oleksii Savran committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const SubsetCard = (
  { subset,
    complete = false,
    compact = false,
    actions,
    index,
    dataClassName,
    t,
    ...other
  }: {
    subset: Subset,
    complete?: boolean,
    compact?: boolean,
    actions?: any,
    index: number,
    dataClassName: string;
    t: any
  } & React.ClassAttributes<any>) => {
36

Oleksii Savran's avatar
Oleksii Savran committed
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  return (
    compact ? (
      <Card>
        <CardContent>
          <div className="mb-15">
            <b>
              { index !== undefined && `${index + 1}. ` }
              <SubsetLink to={ subset }/>
            </b>
            <b></b>
            <span>{ subset.wiewsCode }</span>
            <b></b>
            <Number value={ subset.accessionCount }/>
            { ` ${t('accessions.common.modelName', {count: subset.accessionCount})}` }
            <DashboardCardDates item={ subset }/>
          </div>
          <div>
            { subset.state !== undefined && <DashboardCardStatus item={ subset }/> }
          </div>
        </CardContent>
        { subset._permissions.manage &&
          <CardActions>
            <div style={ {width: '100%', display: 'flex', flexDirection: 'row-reverse'} }>
              <Permissions clazz={ dataClassName } id={ subset.id }/>
            </div>
          </CardActions>
        }
      </Card>
    ) : (
      <Card>
        <CardHeader title={ <SubsetLink to={ subset }/> }/>
        <CardContent>
          <Markdown className="mb-20" firstParagraph={ !complete } source={ subset.description }/>
          <Properties>
            { subset.crops && subset.crops.length > 0 &&
            <PropertiesItem title={ t('subsets.public.c.subsetCard.crops') }>
              <CropChips crops={ subset.crops }/>
            </PropertiesItem> }
            <PropertiesItem title={ t('subsets.public.c.subsetCard.numberOfAccessions') }>
              <Number value={ subset.accessionCount }/>
            </PropertiesItem>
            <PropertiesItem title={ t('subsets.public.c.subsetCard.institute') }>
              <InstituteLink to={ subset.institute }>{ subset.institute.fullName }</InstituteLink>
            </PropertiesItem>
            { complete && <PropertiesItem title={ t('subsets.public.c.subsetCard.creationDate') }>
              <McpdDate value={ subset.date }/>
            </PropertiesItem> }
            { complete && subset.source &&
            <PropertiesItem title={ t('subsets.public.c.subsetCard.source') }>
              <ExternalLink link={ subset.source }/>
            </PropertiesItem> }
          </Properties>
        </CardContent>
        { actions &&
          <CardActions>
            { actions }
          </CardActions>
        }
      </Card>
    )
Matija Obreza's avatar
Subsets  
Matija Obreza committed
97
98
99
  );
};

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
100
export default translate()(SubsetCard);