DatasetDetailsPage.tsx 5.26 KB
Newer Older
1
2
import React from 'react';
import {useTranslation} from 'react-i18next';
Matija Obreza's avatar
Matija Obreza committed
3
// import {useSelector} from "react-redux";
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
import {Link} from "react-router-dom";

// model
import Dataset from "@genesys-pgr/client/model/catalog/Dataset";
import Accession from "@genesys-pgr/client/model/accession/Accession";
// service
import {AccessionService, DatasetService} from '@genesys-pgr/client/service';
// ui
import {Property} from 'ui/common/Property';
import Loading from 'ui/common/Loading';
import PageTitle from 'ui/common/PageTitle';

interface DatasetDetailsPageProps {
  match: any;
}

const DatasetDetailsPage = ({match}: DatasetDetailsPageProps) => {

  // util
  const {t} = useTranslation();

  // state
  const [dataset, setDataset] = React.useState<Dataset>();
  const [accessions, setAccessions] = React.useState<Accession[]>();

  const loadData = React.useCallback((uuid: string): Promise<void> => {
    return DatasetService
      .getDataset(uuid)
      .then((data) => {
        console.log('dataset: ', data);
        setDataset(data);
        AccessionService
          .list({datasets: [data.uuid]}, {page: 0})
          .then((accessions) => setAccessions(accessions.content));
      })
      .catch((e) => {
        console.log('Api call failed: ', e);
      });
  }, []);

  // redux
Matija Obreza's avatar
Matija Obreza committed
45
  // const publicWebsiteUrl = useSelector((state: any) => state?.apiInfo?.apiInfo?.publicWebsiteUrl);
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  React.useEffect(() => {
    loadData(match.params.uuid);
  }, [loadData, match.params])


  if (!dataset) {
    return (
      <>
        <PageTitle title={t('loading')}/>
        <Loading/>
      </>
    );
  }

  let propertyIndex = 0;

  return (
    <>
      <PageTitle title={t('pagetitle.dataset', {datasetTitle: dataset.title})}/>
      <div className="d-flex justify-content-between align-items-center">
        <h1>{dataset.title}</h1>
      </div>

Matija Obreza's avatar
Matija Obreza committed
70
      {dataset.description && <p>{dataset.description}</p> }
71
72
73
74

      {dataset.owner &&
      <Property
        title={t('dataset.dataProvider.title')}
Matija Obreza's avatar
Matija Obreza committed
75
        value={ dataset.owner.name }
76
77
78
        index={propertyIndex++}
      />
      }
Matija Obreza's avatar
Matija Obreza committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      {dataset.creators && dataset.creators.length > 0 && (
        <Property
          title={t('dataset.details.creators')}
          value={
            <>
              {dataset.creators.map((creat) => (
                <div key={creat.id}><b>{ creat.fullName }</b> ({ t(`creator.role.${creat.role }`) })</div>
              ))}
            </>
          }
          index={propertyIndex++}
        />
      )}

93
94
      {dataset.crops && dataset.crops.length > 0 &&
      <Property
Matija Obreza's avatar
Matija Obreza committed
95
        title={t('dataset.cropName')} value={ dataset.crops.join(', ') }
96
97
98
99
        index={propertyIndex++}
      />
      }

Matija Obreza's avatar
Matija Obreza committed
100
101
102
103
104
105
106
107
108
109
110
111
112
      { dataset.descriptors && dataset.descriptors.length > 0 &&
      <>
        {/* <h2 className="mt-4">{t('dataset.details.traits')}</h2>
        <ul>
          {dataset.descriptors.map((descr) => (
            <li key={descr.id}><a href={`${publicWebsiteUrl}/descriptors/${descr.uuid}`}>{`${descr.title}`}</a></li>
          ))}
        </ul> */}
        <Property
          title={t('dataset.details.traits')} value={ dataset.descriptors.map((descr) => descr.title).join(', ') }
          index={propertyIndex++}
        />
      </>
113
114
      }

Matija Obreza's avatar
Matija Obreza committed
115
      {!!dataset.accessionCount &&
116
      <Property
Matija Obreza's avatar
Matija Obreza committed
117
        title={t('dataset.accessionCount')} value={ dataset.accessionCount }
118
119
120
121
        index={propertyIndex++}
      />
      }

Matija Obreza's avatar
Matija Obreza committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      {dataset.locations && dataset.locations.length > 0 && (
        <>
          <Property
            title={t('dataset.locations')}
            value={ dataset.locations.map((location) => (
                <div key={location.id}>
                  <b>{ location.mapCountry || location.userCountry || ''}</b>
                  { location.decimalLatitude !== null && location.decimalLongitude != null ? <> ({location?.decimalLatitude?.toFixed(5)}, {location?.decimalLongitude?.toFixed(5)})</> : null }
                </div>
              )) }
            index={propertyIndex++}
          />
        </>
      )}

137
138
      {!!dataset.startDate &&
      <Property
Matija Obreza's avatar
Matija Obreza committed
139
        title={t('dataset.startDate')} value={ dataset.startDate }
140
141
142
143
144
145
        index={propertyIndex++}
      />
      }

      {!!dataset.endDate &&
      <Property
Matija Obreza's avatar
Matija Obreza committed
146
        title={t('dataset.endDate')} value={ dataset.endDate }
147
148
149
150
151
152
        index={propertyIndex++}
      />
      }

      {dataset.language &&
      <Property
Matija Obreza's avatar
Matija Obreza committed
153
        title={t('dataset.language')} value={ dataset.language }
154
155
156
157
158
159
160
        index={propertyIndex++}
      />
      }


      {dataset.format &&
      <Property
Matija Obreza's avatar
Matija Obreza committed
161
        title={t('dataset.format')} value={ dataset.format }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
        index={propertyIndex++}
      />
      }

      {dataset.source &&
      <Property
        title={t('dataset.source')} value={<a href={dataset.source}>{dataset.source}</a>}
        index={propertyIndex++}
      />
      }

      {accessions && accessions.length > 0 && (
        <>
          <h2 className="mt-4">{t('dataset.details.accessions')}</h2>
          <Property
            title={t('dataset.accessions')}
            value={(
              <ul>{accessions.map((acc) => (
                <li key={acc.id}><Link to={`/a/${acc.uuid}`}>{acc.accessionNumber}</Link></li>
              ))}
              </ul>
            )}
            index={propertyIndex++}
          />
        </>
      )}

    </>
  );
};

export default DatasetDetailsPage;