Browse Source

Added sorting and filtering for the recent table (#46)

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
b12af0bc79
  1. 1
      static/package.json
  2. 91
      static/src/Recent/Recent.js

1
static/package.json

@ -24,6 +24,7 @@
"react-router": "4.2.0", "react-router": "4.2.0",
"react-router-dom": "4.2.2", "react-router-dom": "4.2.2",
"react-scripts": "1.0.17", "react-scripts": "1.0.17",
"react-table": "^6.7.6",
"semantic-ui-css": "2.2.12", "semantic-ui-css": "2.2.12",
"semantic-ui-react": "0.77.1", "semantic-ui-react": "0.77.1",
"toastr": "2.1.4" "toastr": "2.1.4"

91
static/src/Recent/Recent.js

@ -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>
) )
} }

Loading…
Cancel
Save