shlink-web-client/src/short-urls/ShortUrlsList.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-06-15 22:49:25 +03:00
import React from 'react';
import Moment from 'react-moment';
2018-06-15 22:49:25 +03:00
import { connect } from 'react-redux';
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;
this.props.listShortUrls(match.params.serverId, { page: match.params.page });
2018-06-15 22:49:25 +03:00
}
render() {
return (
<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() {
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 => (
<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
));
}
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 => ({
shortUrlsList: state.shortUrlsList,
selectedServer: state.selectedServer,
2018-06-15 22:49:25 +03:00
}), { listShortUrls })(ShortUrlsList);