2018-06-15 22:49:25 +03:00
|
|
|
import React from 'react';
|
2018-06-16 12:24:42 +03:00
|
|
|
import Moment from 'react-moment';
|
2018-06-15 22:49:25 +03:00
|
|
|
import { connect } from 'react-redux';
|
2018-06-16 12:24:42 +03:00
|
|
|
import Tag from '../utils/Tag';
|
2018-06-15 22:49:25 +03:00
|
|
|
import { listShortUrls } from './reducers/shortUrlsList';
|
2018-06-15 22:51:50 +03:00
|
|
|
import { isEmpty } from 'ramda';
|
2018-06-15 22:49:25 +03:00
|
|
|
|
|
|
|
export class ShortUrlsList extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
const { match } = this.props;
|
2018-06-16 12:24:42 +03:00
|
|
|
this.props.listShortUrls(match.params.serverId, { page: match.params.page });
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-06-16 12:24:42 +03:00
|
|
|
<table className="table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Created at</th>
|
|
|
|
<th>Short URL</th>
|
|
|
|
<th>Original URL</th>
|
|
|
|
<th>Tags</th>
|
|
|
|
<th>Visits</th>
|
|
|
|
<th> - </th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.renderShortUrls()}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2018-06-15 22:49:25 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderShortUrls() {
|
2018-06-16 12:24:42 +03:00
|
|
|
const { shortUrlsList, selectedServer } = this.props;
|
2018-06-15 22:51:50 +03:00
|
|
|
if (isEmpty(shortUrlsList)) {
|
|
|
|
return <li><i>Loading...</i></li>;
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return shortUrlsList.map(shortUrl => (
|
2018-06-16 12:24:42 +03:00
|
|
|
<tr key={shortUrl.shortCode}>
|
|
|
|
<td className="nowrap"><Moment format="YYYY-MM-DD HH:mm" interval={0}>{shortUrl.dateCreated}</Moment></td>
|
|
|
|
<td>
|
|
|
|
<a href={`${selectedServer.url}/${shortUrl.shortCode}`} target="_blank">
|
|
|
|
{`${selectedServer.url}/${shortUrl.shortCode}`}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<a href={shortUrl.originalUrl} target="_blank">{shortUrl.originalUrl}</a>
|
|
|
|
</td>
|
|
|
|
<td>{ShortUrlsList.renderTags(shortUrl.tags)}</td>
|
|
|
|
<td>{shortUrl.visitsCount}</td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
2018-06-15 22:49:25 +03:00
|
|
|
));
|
|
|
|
}
|
2018-06-16 12:24:42 +03:00
|
|
|
|
|
|
|
static renderTags(tags) {
|
|
|
|
if (isEmpty(tags)) {
|
|
|
|
return <i className="nowrap"><small>No tags</small></i>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags.map(tag => <Tag text={tag} />);
|
|
|
|
}
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(state => ({
|
2018-06-16 12:24:42 +03:00
|
|
|
shortUrlsList: state.shortUrlsList,
|
|
|
|
selectedServer: state.selectedServer,
|
2018-06-15 22:49:25 +03:00
|
|
|
}), { listShortUrls })(ShortUrlsList);
|