|
|
@ -1,10 +1,14 @@ |
|
|
import React, { Component } from 'react' |
|
|
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 Moment from 'react-moment'; |
|
|
|
|
|
import ReactTable from 'react-table' |
|
|
|
|
|
import 'react-table/react-table.css' |
|
|
|
|
|
|
|
|
import util from '../util/util' |
|
|
import util from '../util/util' |
|
|
|
|
|
|
|
|
export default class RecentComponent extends Component { |
|
|
export default class RecentComponent extends Component { |
|
|
state = { |
|
|
state = { |
|
|
recent: {} |
|
|
recent: [] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
componentDidMount() { |
|
|
@ -12,46 +16,73 @@ export default class RecentComponent extends Component { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
loadRecentURLs = () => { |
|
|
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) { |
|
|
onRowClick(id) { |
|
|
this.props.history.push(`/visitors/${id}`) |
|
|
this.props.history.push(`/visitors/${id}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onEntryDeletion(entry) { |
|
|
onEntryDeletion(deletionURL) { |
|
|
util.deleteEntry(entry.DeletionURL, this.loadRecentURLs) |
|
|
util.deleteEntry(deletionURL, this.loadRecentURLs) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const { recent } = this.state |
|
|
const { recent } = this.state |
|
|
|
|
|
|
|
|
|
|
|
const columns = [{ |
|
|
|
|
|
Header: 'Original URL', |
|
|
|
|
|
accessor: "Public.URL" |
|
|
|
|
|
}, { |
|
|
|
|
|
Header: 'Created', |
|
|
|
|
|
accessor: 'Public.CreatedOn', |
|
|
|
|
|
Cell: props => <Moment fromNow>{props.value}</Moment> |
|
|
|
|
|
}, { |
|
|
|
|
|
Header: 'Short URL', |
|
|
|
|
|
accessor: "ID", |
|
|
|
|
|
Cell: props => `${window.location.origin}/${props.value}` |
|
|
|
|
|
}, { |
|
|
|
|
|
Header: 'Visitor count', |
|
|
|
|
|
accessor: "Public.VisitCount" |
|
|
|
|
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
Header: 'Delete', |
|
|
|
|
|
accessor: 'DeletionURL', |
|
|
|
|
|
Cell: props => <Button animated='vertical' onClick={this.onEntryDeletion.bind(this, props.value)}> |
|
|
|
|
|
<Button.Content hidden>Delete</Button.Content> |
|
|
|
|
|
<Button.Content visible> |
|
|
|
|
|
<Icon name='trash' /> |
|
|
|
|
|
</Button.Content> |
|
|
|
|
|
</Button>, |
|
|
|
|
|
style: { textAlign: "center" } |
|
|
|
|
|
}] |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Container> |
|
|
<Container> |
|
|
<Table celled selectable> |
|
|
<ReactTable data={recent} columns={columns} getTdProps={(state, rowInfo, column, instance) => { |
|
|
<Table.Header> |
|
|
return { |
|
|
<Table.Row> |
|
|
onClick: (e, handleOriginal) => { |
|
|
<Table.HeaderCell>Original URL</Table.HeaderCell> |
|
|
if (handleOriginal) { |
|
|
<Table.HeaderCell>Created</Table.HeaderCell> |
|
|
handleOriginal() |
|
|
<Table.HeaderCell>Short URL</Table.HeaderCell> |
|
|
} |
|
|
<Table.HeaderCell>All Clicks</Table.HeaderCell> |
|
|
if (!rowInfo) { |
|
|
<Table.HeaderCell>Delete</Table.HeaderCell> |
|
|
return |
|
|
</Table.Row> |
|
|
} |
|
|
</Table.Header> |
|
|
if (column.id === "DeletionURL") { |
|
|
<Table.Body> |
|
|
return |
|
|
{Object.keys(recent).map(key => <Table.Row key={key} title="Click to view visitor statistics"> |
|
|
} |
|
|
<Table.Cell onClick={this.onRowClick.bind(this, key)}>{recent[key].Public.URL}</Table.Cell> |
|
|
this.onRowClick(rowInfo.row.ID) |
|
|
<Table.Cell onClick={this.onRowClick.bind(this, key)}><Moment>{recent[key].Public.CreatedOn}</Moment></Table.Cell> |
|
|
} |
|
|
<Table.Cell>{`${window.location.origin}/${key}`}</Table.Cell> |
|
|
} |
|
|
<Table.Cell onClick={this.onRowClick.bind(this, key)}>{recent[key].Public.VisitCount}</Table.Cell> |
|
|
}} /> |
|
|
<Table.Cell><Button animated='vertical' onClick={this.onEntryDeletion.bind(this, recent[key])}> |
|
|
|
|
|
<Button.Content hidden>Delete</Button.Content> |
|
|
|
|
|
<Button.Content visible> |
|
|
|
|
|
<Icon name='trash' /> |
|
|
|
|
|
</Button.Content> |
|
|
|
|
|
</Button></Table.Cell> |
|
|
|
|
|
</Table.Row>)} |
|
|
|
|
|
</Table.Body> |
|
|
|
|
|
</Table> |
|
|
|
|
|
</Container> |
|
|
</Container> |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|