diff --git a/static/package.json b/static/package.json
index f22ae6a..63b40f6 100644
--- a/static/package.json
+++ b/static/package.json
@@ -24,6 +24,7 @@
"react-router": "4.2.0",
"react-router-dom": "4.2.2",
"react-scripts": "1.0.17",
+ "react-table": "^6.7.6",
"semantic-ui-css": "2.2.12",
"semantic-ui-react": "0.77.1",
"toastr": "2.1.4"
diff --git a/static/src/Recent/Recent.js b/static/src/Recent/Recent.js
index c9f133b..6d2e058 100644
--- a/static/src/Recent/Recent.js
+++ b/static/src/Recent/Recent.js
@@ -1,10 +1,14 @@
import React, { Component } from 'react'
-import { Container, Table, Button, Icon } from 'semantic-ui-react'
+import { Container, Button, Icon } from 'semantic-ui-react'
import Moment from 'react-moment';
+import ReactTable from 'react-table'
+import 'react-table/react-table.css'
+
import util from '../util/util'
+
export default class RecentComponent extends Component {
state = {
- recent: {}
+ recent: []
}
componentDidMount() {
@@ -12,46 +16,73 @@ export default class RecentComponent extends Component {
}
loadRecentURLs = () => {
- util.getRecentURLs(recent => this.setState({ recent }))
+ util.getRecentURLs(recent => {
+ let parsed = [];
+ for (let key in recent) {
+ let shorted = recent[key]
+ shorted.ID = key;
+ parsed.push(shorted);
+ }
+ this.setState({ recent: parsed })
+ })
}
onRowClick(id) {
this.props.history.push(`/visitors/${id}`)
}
- onEntryDeletion(entry) {
- util.deleteEntry(entry.DeletionURL, this.loadRecentURLs)
+ onEntryDeletion(deletionURL) {
+ util.deleteEntry(deletionURL, this.loadRecentURLs)
}
render() {
const { recent } = this.state
+
+ const columns = [{
+ Header: 'Original URL',
+ accessor: "Public.URL"
+ }, {
+ Header: 'Created',
+ accessor: 'Public.CreatedOn',
+ Cell: props => {props.value}
+ }, {
+ Header: 'Short URL',
+ accessor: "ID",
+ Cell: props => `${window.location.origin}/${props.value}`
+ }, {
+ Header: 'Visitor count',
+ accessor: "Public.VisitCount"
+
+ }, {
+ Header: 'Delete',
+ accessor: 'DeletionURL',
+ Cell: props => ,
+ style: { textAlign: "center" }
+ }]
+
return (
-
-
-
- Original URL
- Created
- Short URL
- All Clicks
- Delete
-
-
-
- {Object.keys(recent).map(key =>
- {recent[key].Public.URL}
- {recent[key].Public.CreatedOn}
- {`${window.location.origin}/${key}`}
- {recent[key].Public.VisitCount}
-
- )}
-
-
+ {
+ return {
+ onClick: (e, handleOriginal) => {
+ if (handleOriginal) {
+ handleOriginal()
+ }
+ if (!rowInfo) {
+ return
+ }
+ if (column.id === "DeletionURL") {
+ return
+ }
+ this.onRowClick(rowInfo.row.ID)
+ }
+ }
+ }} />
)
}