summaryrefslogtreecommitdiff
path: root/client/table/file.table.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-04-01 10:23:29 +0200
committerJules Laplace <julescarbon@gmail.com>2019-04-01 10:23:29 +0200
commit0bede27de3bcc0c7f03d16c7607a0ae693daebc7 (patch)
tree20646e82e6b608e452408ad1af24f70fa079387e /client/table/file.table.js
parentfd5d46b71af450fb582506dc8dd9c8d343d3a5c5 (diff)
citations table in react
Diffstat (limited to 'client/table/file.table.js')
-rw-r--r--client/table/file.table.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/client/table/file.table.js b/client/table/file.table.js
new file mode 100644
index 00000000..a7e25bbf
--- /dev/null
+++ b/client/table/file.table.js
@@ -0,0 +1,59 @@
+import React, { Component } from 'react'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+import { toArray, toTuples } from '../util'
+
+import { Loader } from '../common'
+
+import csv from 'parse-csv'
+
+class FileTable extends Component {
+ state = {
+ data: []
+ }
+
+ componentDidMount() {
+ fetch(payload.url, { mode: 'cors' })
+ .then(r => r.text())
+ .then(text => {
+ try {
+ const data = csv.toJSON(text, { headers: { included: true } })
+ this.setState({ data })
+ } catch (e) {
+ console.error("error making json:", payload.url)
+ console.error(e)
+ }
+ })
+ }
+
+ getColumns(payload) {
+ let { cmd, url, fields } = payload
+ return ((fields && fields.length) ? fields[0] : '').split(', ').map(field => {
+ switch (field) {
+ default:
+ return { title: field, field: field.toLowerCase(), sorter: 'string' }
+ }
+ })
+ }
+
+ render() {
+ const { payload } = this.props
+ const { paper, citations } = payload.data
+ const columns = getColumns(payload)
+ if (!this.state.data.length) {
+ return <Loader />
+ }
+ return (
+ <ReactTabulator
+ columns={citationsColumns}
+ data={this.state.data}
+ options={{
+ height: 311,
+ layout: 'fitColumns',
+ placeholder: 'No Data Set',
+ }}
+ />
+ )
+ }
+}
+export default FileTable