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-17 11:59:04 +03:00
|
|
|
import { ButtonDropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap';
|
|
|
|
import { isEmpty } from 'ramda';
|
|
|
|
import pieChartIcon from '@fortawesome/fontawesome-free-solid/faChartPie';
|
|
|
|
import pictureIcon from '@fortawesome/fontawesome-free-solid/faImage';
|
|
|
|
import qrIcon from '@fortawesome/fontawesome-free-solid/faQrcode';
|
|
|
|
import copyIcon from '@fortawesome/fontawesome-free-solid/faCopy';
|
|
|
|
import menuIcon from '@fortawesome/fontawesome-free-solid/faEllipsisV';
|
|
|
|
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
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-17 11:59:04 +03:00
|
|
|
import './ShortUrlsList.scss';
|
2018-06-15 22:49:25 +03:00
|
|
|
|
|
|
|
export class ShortUrlsList extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
const { match } = this.props;
|
2018-06-17 18:12:16 +03:00
|
|
|
this.props.listShortUrls(match.params.serverId, {
|
|
|
|
...this.props.shortUrlsListParams,
|
|
|
|
page: match.params.page
|
|
|
|
});
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-06-17 11:59:04 +03:00
|
|
|
<table className="table table-striped table-hover">
|
2018-06-16 12:24:42 +03:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Created at</th>
|
|
|
|
<th>Short URL</th>
|
|
|
|
<th>Original URL</th>
|
|
|
|
<th>Tags</th>
|
|
|
|
<th>Visits</th>
|
2018-06-17 11:59:04 +03:00
|
|
|
<th> </th>
|
2018-06-16 12:24:42 +03:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.renderShortUrls()}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2018-06-15 22:49:25 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderShortUrls() {
|
2018-07-15 11:39:05 +03:00
|
|
|
const { shortUrlsList, selectedServer, loading } = this.props;
|
|
|
|
if (loading) {
|
2018-06-17 11:59:04 +03:00
|
|
|
return <tr><td colSpan="6" className="text-center">Loading...</td></tr>;
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
2018-07-15 11:39:05 +03:00
|
|
|
if (! loading && isEmpty(shortUrlsList)) {
|
|
|
|
return <tr><td colSpan="6" className="text-center">No results found</td></tr>;
|
|
|
|
}
|
|
|
|
|
2018-06-15 22:49:25 +03:00
|
|
|
return shortUrlsList.map(shortUrl => (
|
2018-06-17 11:59:04 +03:00
|
|
|
<Row shortUrl={shortUrl} selectedServer={selectedServer} key={shortUrl.shortCode} />
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
static renderTags(tags) {
|
|
|
|
if (isEmpty(tags)) {
|
|
|
|
return <i className="nowrap"><small>No tags</small></i>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags.map(tag => <Tag text={tag} />);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Row extends React.Component {
|
|
|
|
state = { displayMenu: false };
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { shortUrl, selectedServer } = this.props;
|
|
|
|
|
|
|
|
return (
|
2018-07-15 11:39:05 +03:00
|
|
|
<tr
|
|
|
|
onMouseEnter={() => this.setState({ displayMenu: true })}
|
|
|
|
onMouseLeave={() => this.setState({ displayMenu: false })}
|
2018-06-17 11:59:04 +03:00
|
|
|
>
|
|
|
|
<td className="nowrap short-urls-list__cell">
|
|
|
|
<Moment format="YYYY-MM-DD HH:mm" interval={0}>{shortUrl.dateCreated}</Moment>
|
|
|
|
</td>
|
|
|
|
<td className="short-urls-list__cell">
|
2018-06-16 12:24:42 +03:00
|
|
|
<a href={`${selectedServer.url}/${shortUrl.shortCode}`} target="_blank">
|
|
|
|
{`${selectedServer.url}/${shortUrl.shortCode}`}
|
|
|
|
</a>
|
|
|
|
</td>
|
2018-06-17 11:59:04 +03:00
|
|
|
<td className="short-urls-list__cell">
|
2018-06-16 12:24:42 +03:00
|
|
|
<a href={shortUrl.originalUrl} target="_blank">{shortUrl.originalUrl}</a>
|
|
|
|
</td>
|
2018-06-17 11:59:04 +03:00
|
|
|
<td className="short-urls-list__cell">{ShortUrlsList.renderTags(shortUrl.tags)}</td>
|
|
|
|
<td className="short-urls-list__cell text-right">{shortUrl.visitsCount}</td>
|
|
|
|
<td className="short-urls-list__cell">
|
|
|
|
<RowMenu display={this.state.displayMenu} />
|
|
|
|
</td>
|
2018-06-16 12:24:42 +03:00
|
|
|
</tr>
|
2018-06-17 11:59:04 +03:00
|
|
|
)
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
2018-06-17 11:59:04 +03:00
|
|
|
}
|
2018-06-16 12:24:42 +03:00
|
|
|
|
2018-06-17 11:59:04 +03:00
|
|
|
class RowMenu extends React.Component {
|
|
|
|
state = { isOpen: false };
|
|
|
|
toggle = () => this.setState({ isOpen: ! this.state.isOpen });
|
2018-06-16 12:24:42 +03:00
|
|
|
|
2018-06-17 11:59:04 +03:00
|
|
|
render () {
|
|
|
|
const determineClass = () => {
|
|
|
|
const baseClass = 'short-urls-list__dropdown-toggle';
|
|
|
|
return ! this.props.display ? `${baseClass} short-urls-list__dropdown-toggle--hidden` : baseClass;
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ButtonDropdown toggle={this.toggle} isOpen={this.state.isOpen} direction="left">
|
|
|
|
<DropdownToggle color="white" size="sm" caret className={determineClass()}>
|
|
|
|
<FontAwesomeIcon icon={menuIcon} />
|
|
|
|
</DropdownToggle>
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownItem>
|
|
|
|
<FontAwesomeIcon icon={pieChartIcon} /> Visit Stats
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem divider />
|
|
|
|
<DropdownItem>
|
|
|
|
<FontAwesomeIcon icon={pictureIcon} /> Preview
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem>
|
|
|
|
<FontAwesomeIcon icon={qrIcon} /> QR code
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem divider />
|
|
|
|
<DropdownItem>
|
|
|
|
<FontAwesomeIcon icon={copyIcon} /> Copy to clipboard
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</ButtonDropdown>
|
|
|
|
);
|
2018-06-16 12:24:42 +03:00
|
|
|
}
|
2018-06-15 22:49:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(state => ({
|
2018-06-16 12:24:42 +03:00
|
|
|
selectedServer: state.selectedServer,
|
2018-06-17 18:12:16 +03:00
|
|
|
shortUrlsListParams: state.shortUrlsListParams,
|
2018-06-15 22:49:25 +03:00
|
|
|
}), { listShortUrls })(ShortUrlsList);
|