summaryrefslogtreecommitdiff
path: root/client/table/citations.table.js
blob: 1ec2d10c15332da7bf2bc300d0d75b57b23978e0 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { ReactTabulator } from 'react-tabulator'
import { Loader } from '../common'
import { toArray, toTuples } from '../util'

export const citationsColumns = [
  { title: 'Title', field: 'title', sorter: 'string' },
  { title: 'Institution', field: 'institution', sorter: 'string' },
  { title: 'Country', field: 'country', sorter: 'string', width: 140 },
  { title: 'Year', field: 'year', sorter: 'number', width: 70 },
  { title: 'PDF', field: 'pdf_text', formatter: 'link',
    formatterParams: { target: "_blank", urlField: 'pdf_link', },
    sorter: 'string', width: 100 },
]

class CitationsTable extends Component {
  render() {
    const { payload } = this.props
    const { paper, citations } = payload.data
    console.log(this.props)
    if (!citations.length) return <Loader />

    const formattedCitations = citations.map(citation => ({
      title: citation.title,
      institution: citation.addresses[0].name,
      country: citation.addresses[0].country,
      year: citation.year,
      pdf: (citation.pdf && citation.pdf.length)
        ? citation.pdf[0]
        : (citation.doi && citation.doi.length)
          ? citation.doi[0]
          : "",
    }))

    console.log(formattedCitations)

    return (
      <ReactTabulator
        columns={citationsColumns}
        data={formattedCitations}
        options={{
          height: 311,
          layout: 'fitColumns',
          placeholder: 'No Data Set',
        }}
      />
    )
  }
}

export default CitationsTable