OverviewPage.tsx 1.76 KB
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
2
3
4
5
6
7
8
import * as React from 'react';
import { WithTranslation, withTranslation } from 'react-i18next';

// Models
import { AccessionService } from '@genesys/client/service';

// UI
import AccessionOverviewSection from './AccessionOverviewSection';
9
import AccessionFilter from '@genesys/client/model/accession/AccessionFilter';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
10
11

interface IOverviewPageProps extends React.ClassAttributes<any>, WithTranslation {
12
  filter: AccessionFilter;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
13
14
15
16
17
18
19
20
21
22
23
24
}

class BrowsePage extends React.Component<IOverviewPageProps, any> {

  public constructor(props: IOverviewPageProps, context: any) {
    super(props, context);

    this.state = {
      overviewData: null,
    }
  }

Matija Obreza's avatar
Matija Obreza committed
25
  private loadData = (): Promise<any> => {
Maksym Tishchenko's avatar
Maksym Tishchenko committed
26
    return AccessionService
Matija Obreza's avatar
Matija Obreza committed
27
      .listOverview(this.props.filter)
Maksym Tishchenko's avatar
Maksym Tishchenko committed
28
29
30
31
32
33
34
35
36
37
38
39
      .then((data) => {
        console.log('overview: ', data);
        this.setState({ overviewData: data });
        return data;
      })
      .catch((e) => {
        console.log('Api call failed: ', e);
      });
  };

  public componentDidMount() {
    if (typeof window !== 'undefined') { // Call should be started only on client side
Matija Obreza's avatar
Matija Obreza committed
40
      this.loadData();
Maksym Tishchenko's avatar
Maksym Tishchenko committed
41
42
43
44
45
46
47
48
49
50
51
52
53
    }
  }

  public render() {
    const { overviewData } = this.state
    const { t } = this.props

    return (
      // Accession overview
      // Summary information about selected accessions
      <div>
        { overviewData &&
        <>
54
55
56
57
58
          <h1>{t('accession.overview.title')}</h1>
          <p>
            { t('accession.overview.about', { count: overviewData.accessionCount, what: t('accession.model_plural', { count: overviewData.accessionCount }) }) }
          </p>
          <AccessionOverviewSection overview={ overviewData && overviewData.overview } />
Maksym Tishchenko's avatar
Maksym Tishchenko committed
59
60
61
62
63
64
65
66
        </>
        }
      </div>
    );
  }
}

export default withTranslation()(BrowsePage);