Links.tsx 2.8 KB
Newer Older
Matija Obreza's avatar
Subsets  
Matija Obreza committed
1
2
3
4
5
import * as React from 'react';
import { Link } from 'react-router-dom';
import Markdown from 'ui/common/markdown';

import Subset from 'model/Subset';
6
import Accession from 'model/Accession';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
7
8
import FaoInstitute from 'model/FaoInstitute';
import MaterialRequest from 'model/MaterialRequest';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
9
import Country from 'model/Country';
Matija Obreza's avatar
Subsets  
Matija Obreza committed
10
11
12
13
14
15
16

function SubsetLink({ to: subset, edit = false, children = null }
  : { to: Subset, edit?: boolean, children?: any }) {

  if (subset) {
    if (edit) {
      return (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
17
        <Link to={ `/subsets/${subset.uuid}/edit` }>
Matija Obreza's avatar
Subsets  
Matija Obreza committed
18
19
20
21
22
          { children || <Markdown basic source={ subset.title } /> }
        </Link>
      );
    } else {
      return (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
23
        <Link to={ `/subsets/${subset.uuid}` }>
Matija Obreza's avatar
Subsets  
Matija Obreza committed
24
25
26
27
28
29
30
31
32
          { children || <Markdown basic source={ subset.title } /> }
        </Link>
      );
    }
  } else {
    return null;
  }
}

33
34
35
36
37
function AccessionLink({ to: accession, edit = false, children = null }
  : { to: Accession, edit?: boolean, children?: any }) {

  if (accession) {
    return (
38
      <Link to={ accession.doi ? `/${accession.doi}` : `/a/${accession.uuid}` }>
39
40
41
42
43
44
45
46
        { children || accession.accessionNumber }
      </Link>
    );
  } else {
    return null;
  }
}

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
47
48
49
50
51
52
53
54
55
56
57
58
59
function InstituteLink({ to: institute, edit = false, children = null }
                           : { to: FaoInstitute, edit?: boolean, children?: any }) {

    if (institute) {
        return (
            <Link to={ `/wiews/${institute.code}` }>
                { children || institute.code }
            </Link>
        );
    } else {
        return null;
    }
}
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

function RequestLink({ to: request, edit = false, children = null }
                           : { to: MaterialRequest, edit?: boolean, children?: any }) {

    if (request) {
        return (
            <Link to={ `/admin/requests/${request.uuid}` }>
                { children || request.uuid }
            </Link>
        );
    } else {
        return null;
    }
}

Matija Obreza's avatar
Matija Obreza committed
75
76
77
78
79
const CountryLink = ({ country, noflag, children }: { country: Country, noflag?: boolean, children?: any }) => {
  if (! country) {
    return null;
  }
  return (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
80
81
    <Link to={ `/geo/${country.code3}` }>
        <div style={ {display: 'flex', alignItems: 'center'} }>
Matija Obreza's avatar
Matija Obreza committed
82
83
            { !noflag && <img src={ `images/flags/${country.code3}.png` } style={ {maxWidth: '1.25rem', padding: '0 0.25rem'} } /> }
            { children || country.name }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
84
85
        </div>
    </Link>
Matija Obreza's avatar
Matija Obreza committed
86
87
  );
};
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
const DatasetLink = ({ to: dataset, edit = false, children = null }
                       : { to: any, edit?: boolean, children?: any }) => {
  if (dataset) {
    return (
      <Link to={ `/datasets/${dataset.uuid}` }>
        { children || <Markdown basic source={ dataset.title } /> }
      </Link>
    );
  } else {
    return null;
  }
};

export { SubsetLink, AccessionLink, InstituteLink, RequestLink, CountryLink, DatasetLink};