2020-12-07 13:17:19 +03:00
|
|
|
import { FC, useEffect } from 'react';
|
|
|
|
import { Card, CardBody, CardHeader, CardText, CardTitle } from 'reactstrap';
|
2020-12-20 00:49:11 +03:00
|
|
|
import { Link, useHistory } from 'react-router-dom';
|
2020-12-06 20:32:24 +03:00
|
|
|
import { ShortUrlsListParams } from '../short-urls/reducers/shortUrlsListParams';
|
|
|
|
import { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import { prettify } from '../utils/helpers/numbers';
|
|
|
|
import { TagsList } from '../tags/reducers/tagsList';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { ShortUrlsTableProps } from '../short-urls/ShortUrlsTable';
|
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
2020-12-07 22:37:03 +03:00
|
|
|
import { CreateShortUrlProps } from '../short-urls/CreateShortUrl';
|
2020-12-07 14:12:39 +03:00
|
|
|
import { VisitsOverview } from '../visits/reducers/visitsOverview';
|
2020-12-12 23:05:54 +03:00
|
|
|
import { Versions } from '../utils/helpers/version';
|
2021-02-28 12:12:30 +03:00
|
|
|
import { Topics } from '../mercure/helpers/Topics';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { isServerWithId, SelectedServer } from './data';
|
|
|
|
import './Overview.scss';
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
interface OverviewConnectProps {
|
|
|
|
shortUrlsList: ShortUrlsListState;
|
|
|
|
listShortUrls: (params: ShortUrlsListParams) => void;
|
|
|
|
listTags: Function;
|
|
|
|
tagsList: TagsList;
|
2020-12-07 13:17:19 +03:00
|
|
|
selectedServer: SelectedServer;
|
2020-12-07 14:12:39 +03:00
|
|
|
visitsOverview: VisitsOverview;
|
|
|
|
loadVisitsOverview: Function;
|
2020-12-06 20:32:24 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:37:03 +03:00
|
|
|
export const Overview = (
|
|
|
|
ShortUrlsTable: FC<ShortUrlsTableProps>,
|
|
|
|
CreateShortUrl: FC<CreateShortUrlProps>,
|
2020-12-12 15:22:11 +03:00
|
|
|
ForServerVersion: FC<Versions>,
|
2020-12-07 22:37:03 +03:00
|
|
|
) => boundToMercureHub(({
|
2020-12-07 14:12:39 +03:00
|
|
|
shortUrlsList,
|
|
|
|
listShortUrls,
|
|
|
|
listTags,
|
|
|
|
tagsList,
|
|
|
|
selectedServer,
|
|
|
|
loadVisitsOverview,
|
|
|
|
visitsOverview,
|
|
|
|
}: OverviewConnectProps) => {
|
|
|
|
const { loading, shortUrls } = shortUrlsList;
|
2020-12-06 20:32:24 +03:00
|
|
|
const { loading: loadingTags } = tagsList;
|
2021-02-21 22:55:39 +03:00
|
|
|
const { loading: loadingVisits, visitsCount, orphanVisitsCount } = visitsOverview;
|
2020-12-08 13:39:16 +03:00
|
|
|
const serverId = isServerWithId(selectedServer) ? selectedServer.id : '';
|
2020-12-20 00:49:11 +03:00
|
|
|
const history = useHistory();
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-12-07 13:17:19 +03:00
|
|
|
listShortUrls({ itemsPerPage: 5, orderBy: { dateCreated: 'DESC' } });
|
2020-12-06 20:32:24 +03:00
|
|
|
listTags();
|
2020-12-07 14:12:39 +03:00
|
|
|
loadVisitsOverview();
|
2020-12-06 20:32:24 +03:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-12-07 13:17:19 +03:00
|
|
|
<>
|
|
|
|
<div className="row mb-3">
|
2021-02-21 22:55:39 +03:00
|
|
|
<div className="col-md-6 col-xl-3">
|
2020-12-12 12:56:10 +03:00
|
|
|
<Card className="overview__card mb-2" body>
|
2020-12-07 13:17:19 +03:00
|
|
|
<CardTitle tag="h5" className="overview__card-title">Visits</CardTitle>
|
2020-12-12 15:22:11 +03:00
|
|
|
<CardText tag="h2">
|
|
|
|
<ForServerVersion minVersion="2.2.0">
|
|
|
|
{loadingVisits ? 'Loading...' : prettify(visitsCount)}
|
|
|
|
</ForServerVersion>
|
|
|
|
<ForServerVersion maxVersion="2.1.*">
|
|
|
|
<small className="text-muted"><i>Shlink 2.2 is needed</i></small>
|
|
|
|
</ForServerVersion>
|
|
|
|
</CardText>
|
2020-12-07 13:17:19 +03:00
|
|
|
</Card>
|
|
|
|
</div>
|
2021-02-21 22:55:39 +03:00
|
|
|
<div className="col-md-6 col-xl-3">
|
2021-02-28 11:50:01 +03:00
|
|
|
<Card className="overview__card mb-2" body tag={Link} to={`/server/${serverId}/orphan-visits`}>
|
2021-02-21 22:55:39 +03:00
|
|
|
<CardTitle tag="h5" className="overview__card-title">Orphan visits</CardTitle>
|
|
|
|
<CardText tag="h2">
|
|
|
|
<ForServerVersion minVersion="2.6.0">
|
|
|
|
{loadingVisits ? 'Loading...' : prettify(orphanVisitsCount ?? 0)}
|
|
|
|
</ForServerVersion>
|
|
|
|
<ForServerVersion maxVersion="2.5.*">
|
|
|
|
<small className="text-muted"><i>Shlink 2.6 is needed</i></small>
|
|
|
|
</ForServerVersion>
|
|
|
|
</CardText>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6 col-xl-3">
|
2021-02-28 11:50:01 +03:00
|
|
|
<Card className="overview__card mb-2" body tag={Link} to={`/server/${serverId}/list-short-urls/1`}>
|
2020-12-07 13:17:19 +03:00
|
|
|
<CardTitle tag="h5" className="overview__card-title">Short URLs</CardTitle>
|
|
|
|
<CardText tag="h2">
|
2020-12-07 14:12:39 +03:00
|
|
|
{loading ? 'Loading...' : prettify(shortUrls?.pagination.totalItems ?? 0)}
|
2020-12-07 13:17:19 +03:00
|
|
|
</CardText>
|
|
|
|
</Card>
|
|
|
|
</div>
|
2021-02-21 22:55:39 +03:00
|
|
|
<div className="col-md-6 col-xl-3">
|
2021-02-28 11:50:01 +03:00
|
|
|
<Card className="overview__card mb-2" body tag={Link} to={`/server/${serverId}/manage-tags`}>
|
2020-12-07 13:17:19 +03:00
|
|
|
<CardTitle tag="h5" className="overview__card-title">Tags</CardTitle>
|
2020-12-08 13:39:16 +03:00
|
|
|
<CardText tag="h2">{loadingTags ? 'Loading...' : prettify(tagsList.tags.length)}</CardText>
|
2020-12-07 13:17:19 +03:00
|
|
|
</Card>
|
|
|
|
</div>
|
2020-12-06 20:32:24 +03:00
|
|
|
</div>
|
2020-12-07 13:17:19 +03:00
|
|
|
<Card className="mb-4">
|
|
|
|
<CardHeader>
|
2020-12-08 13:39:16 +03:00
|
|
|
<span className="d-sm-none">Create a short URL</span>
|
|
|
|
<h5 className="d-none d-sm-inline">Create a short URL</h5>
|
2020-12-07 15:03:47 +03:00
|
|
|
<Link className="float-right" to={`/server/${serverId}/create-short-url`}>Advanced options »</Link>
|
2020-12-07 13:17:19 +03:00
|
|
|
</CardHeader>
|
2020-12-07 22:37:03 +03:00
|
|
|
<CardBody>
|
|
|
|
<CreateShortUrl basicMode />
|
|
|
|
</CardBody>
|
2020-12-07 13:17:19 +03:00
|
|
|
</Card>
|
|
|
|
<Card>
|
|
|
|
<CardHeader>
|
2020-12-08 13:39:16 +03:00
|
|
|
<span className="d-sm-none">Recently created URLs</span>
|
|
|
|
<h5 className="d-none d-sm-inline">Recently created URLs</h5>
|
2020-12-07 13:17:19 +03:00
|
|
|
<Link className="float-right" to={`/server/${serverId}/list-short-urls/1`}>See all »</Link>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
2020-12-20 00:49:11 +03:00
|
|
|
<ShortUrlsTable
|
|
|
|
shortUrlsList={shortUrlsList}
|
|
|
|
selectedServer={selectedServer}
|
|
|
|
className="mb-0"
|
2020-12-20 11:09:22 +03:00
|
|
|
onTagClick={(tag) => history.push(`/server/${serverId}/list-short-urls/1?tag=${tag}`)}
|
2020-12-20 00:49:11 +03:00
|
|
|
/>
|
2020-12-07 13:17:19 +03:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</>
|
2020-12-06 20:32:24 +03:00
|
|
|
);
|
2021-02-28 12:12:30 +03:00
|
|
|
}, () => [ Topics.visits(), Topics.orphanVisits() ]);
|