summaryrefslogtreecommitdiff
path: root/client/table/citations.table.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/table/citations.table.js')
-rw-r--r--client/table/citations.table.js55
1 files changed, 39 insertions, 16 deletions
diff --git a/client/table/citations.table.js b/client/table/citations.table.js
index f9599f5d..bbc55047 100644
--- a/client/table/citations.table.js
+++ b/client/table/citations.table.js
@@ -2,10 +2,10 @@ import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { ReactTabulator } from 'react-tabulator'
-import MultiValueFormatter from "react-tabulator/lib/formatters/MultiValueFormatter"
+import { saveAs } from 'file-saver'
import { Loader } from '../common'
-import { toArray, toTuples } from '../util'
+import { toArray, toTuples, domainFromUrl } from '../util'
export const citationsColumns = [
{ title: 'Title', field: 'title', sorter: 'string' },
@@ -42,13 +42,7 @@ class CitationsTable extends Component {
: (citation.doi && citation.doi.length)
? citation.doi[0]
: 'https://www.semanticscholar.org/paper/' + citation.id
- let pdf_text
- const pdf_partz = pdf_link.split('/')[2].split('.')
- if (pdf_partz.length > 2 && pdf_partz[pdf_partz.length - 2].length == 2) {
- pdf_text = pdf_partz.slice(-3).join('.')
- } else {
- pdf_text = pdf_partz.slice(-2).join('.')
- }
+ let pdf_text = domainFromUrl(pdf_link)
return {
title: citation.title,
institution: citation.addresses.map(a => a.name).sort().join('; '),
@@ -78,18 +72,47 @@ class CitationsTable extends Component {
}
}
+ download() {
+ const { formattedCitations } = this.state
+ const fn = this.props.payload.data.paper.key + '.csv'
+ const titles = citationsColumns.map(c => c.title)
+ const fields = citationsColumns.map(c => c.formatterParams ? c.formatterParams.urlField : c.field)
+ const rows = formattedCitations.map(citation => {
+ const row = fields.map(field => citation[field]).map(data => {
+ switch (typeof data) {
+ case 'number':
+ return String(data)
+ default:
+ return '\"' + String(data) + '\"'
+ }
+ })
+ return row.join(",")
+ })
+
+ const blob = new Blob([
+ [
+ titles.join(','),
+ ...rows,
+ ].join('\n')
+ ], {type: "text/csv;charset=utf-8"});
+ saveAs(blob, fn);
+ }
+
render() {
const { formattedCitations, filteredCitations } = this.state
if (!formattedCitations.length) return <Loader />
return (
<div className='citationBrowser'>
- <input
- type="text"
- value={this.state.q}
- onChange={e => this.updateFilter(e.target.value)}
- className='q'
- placeholder='Enter text to search citations...'
- />
+ <div className='citationHeader'>
+ <input
+ type="text"
+ value={this.state.q}
+ onChange={e => this.updateFilter(e.target.value)}
+ className='q'
+ placeholder='Enter text to search citations...'
+ />
+ <span className='download' onClick={() => this.download()}>Download CSV</span>
+ </div>
<ReactTabulator
columns={citationsColumns}
data={filteredCitations}