2020-12-07 11:17:19 +01:00
|
|
|
import { FC, useEffect } from 'react';
|
2022-02-05 10:04:34 +01:00
|
|
|
import { Card, CardBody, CardHeader, Row } from 'reactstrap';
|
2022-02-06 20:07:18 +01:00
|
|
|
import { Link, useNavigate } from 'react-router-dom';
|
2022-01-08 10:51:34 +01:00
|
|
|
import { ITEMS_IN_OVERVIEW_PAGE, ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList';
|
2020-12-06 18:32:24 +01:00
|
|
|
import { prettify } from '../utils/helpers/numbers';
|
|
|
|
import { TagsList } from '../tags/reducers/tagsList';
|
2022-12-18 10:12:34 +01:00
|
|
|
import { ShortUrlsTableType } from '../short-urls/ShortUrlsTable';
|
2020-12-07 11:17:19 +01:00
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
2020-12-07 20:37:03 +01:00
|
|
|
import { CreateShortUrlProps } from '../short-urls/CreateShortUrl';
|
2020-12-07 12:12:39 +01:00
|
|
|
import { VisitsOverview } from '../visits/reducers/visitsOverview';
|
2021-02-28 10:12:30 +01:00
|
|
|
import { Topics } from '../mercure/helpers/Topics';
|
2021-11-11 21:28:17 +01:00
|
|
|
import { ShlinkShortUrlsListParams } from '../api/types';
|
2022-05-01 10:50:06 +02:00
|
|
|
import { supportsNonOrphanVisits } from '../utils/helpers/features';
|
2021-11-06 12:04:26 +01:00
|
|
|
import { getServerId, SelectedServer } from './data';
|
2022-02-05 10:04:34 +01:00
|
|
|
import { HighlightCard } from './helpers/HighlightCard';
|
2020-12-06 18:32:24 +01:00
|
|
|
|
|
|
|
interface OverviewConnectProps {
|
|
|
|
shortUrlsList: ShortUrlsListState;
|
2021-11-11 21:28:17 +01:00
|
|
|
listShortUrls: (params: ShlinkShortUrlsListParams) => void;
|
2020-12-06 18:32:24 +01:00
|
|
|
listTags: Function;
|
|
|
|
tagsList: TagsList;
|
2020-12-07 11:17:19 +01:00
|
|
|
selectedServer: SelectedServer;
|
2020-12-07 12:12:39 +01:00
|
|
|
visitsOverview: VisitsOverview;
|
|
|
|
loadVisitsOverview: Function;
|
2020-12-06 18:32:24 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 20:37:03 +01:00
|
|
|
export const Overview = (
|
2022-12-18 10:12:34 +01:00
|
|
|
ShortUrlsTable: ShortUrlsTableType,
|
2020-12-07 20:37:03 +01:00
|
|
|
CreateShortUrl: FC<CreateShortUrlProps>,
|
|
|
|
) => boundToMercureHub(({
|
2020-12-07 12:12:39 +01:00
|
|
|
shortUrlsList,
|
|
|
|
listShortUrls,
|
|
|
|
listTags,
|
|
|
|
tagsList,
|
|
|
|
selectedServer,
|
|
|
|
loadVisitsOverview,
|
|
|
|
visitsOverview,
|
|
|
|
}: OverviewConnectProps) => {
|
|
|
|
const { loading, shortUrls } = shortUrlsList;
|
2020-12-06 18:32:24 +01:00
|
|
|
const { loading: loadingTags } = tagsList;
|
2021-02-21 20:55:39 +01:00
|
|
|
const { loading: loadingVisits, visitsCount, orphanVisitsCount } = visitsOverview;
|
2021-11-06 12:04:26 +01:00
|
|
|
const serverId = getServerId(selectedServer);
|
2022-02-05 10:04:34 +01:00
|
|
|
const linkToNonOrphanVisits = supportsNonOrphanVisits(selectedServer);
|
2022-02-06 20:07:18 +01:00
|
|
|
const navigate = useNavigate();
|
2020-12-06 18:32:24 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-01-08 10:51:34 +01:00
|
|
|
listShortUrls({ itemsPerPage: ITEMS_IN_OVERVIEW_PAGE, orderBy: { field: 'dateCreated', dir: 'DESC' } });
|
2020-12-06 18:32:24 +01:00
|
|
|
listTags();
|
2020-12-07 12:12:39 +01:00
|
|
|
loadVisitsOverview();
|
2020-12-06 18:32:24 +01:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-12-07 11:17:19 +01:00
|
|
|
<>
|
2021-03-29 21:08:48 +02:00
|
|
|
<Row>
|
2022-02-05 10:04:34 +01:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
2022-02-05 13:37:49 +01:00
|
|
|
<HighlightCard title="Visits" link={linkToNonOrphanVisits && `/server/${serverId}/non-orphan-visits`}>
|
2022-02-05 10:04:34 +01:00
|
|
|
{loadingVisits ? 'Loading...' : prettify(visitsCount)}
|
|
|
|
</HighlightCard>
|
2020-12-07 11:17:19 +01:00
|
|
|
</div>
|
2022-02-05 10:04:34 +01:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
2022-05-01 10:50:06 +02:00
|
|
|
<HighlightCard title="Orphan visits" link={`/server/${serverId}/orphan-visits`}>
|
2022-05-02 19:28:07 +02:00
|
|
|
{loadingVisits ? 'Loading...' : prettify(orphanVisitsCount)}
|
2022-02-05 10:04:34 +01:00
|
|
|
</HighlightCard>
|
2021-02-21 20:55:39 +01:00
|
|
|
</div>
|
2022-02-05 10:04:34 +01:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
|
|
|
<HighlightCard title="Short URLs" link={`/server/${serverId}/list-short-urls/1`}>
|
|
|
|
{loading ? 'Loading...' : prettify(shortUrls?.pagination.totalItems ?? 0)}
|
|
|
|
</HighlightCard>
|
2020-12-07 11:17:19 +01:00
|
|
|
</div>
|
2022-02-05 10:04:34 +01:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
|
|
|
<HighlightCard title="Tags" link={`/server/${serverId}/manage-tags`}>
|
|
|
|
{loadingTags ? 'Loading...' : prettify(tagsList.tags.length)}
|
|
|
|
</HighlightCard>
|
2020-12-07 11:17:19 +01:00
|
|
|
</div>
|
2021-03-29 21:08:48 +02:00
|
|
|
</Row>
|
2022-02-05 10:04:34 +01:00
|
|
|
|
2021-03-29 21:08:48 +02:00
|
|
|
<Card className="mb-3">
|
2020-12-07 11:17:19 +01:00
|
|
|
<CardHeader>
|
2020-12-08 11:39:16 +01:00
|
|
|
<span className="d-sm-none">Create a short URL</span>
|
|
|
|
<h5 className="d-none d-sm-inline">Create a short URL</h5>
|
2022-03-05 13:26:28 +01:00
|
|
|
<Link className="float-end" to={`/server/${serverId}/create-short-url`}>Advanced options »</Link>
|
2020-12-07 11:17:19 +01:00
|
|
|
</CardHeader>
|
2020-12-07 20:37:03 +01:00
|
|
|
<CardBody>
|
|
|
|
<CreateShortUrl basicMode />
|
|
|
|
</CardBody>
|
2020-12-07 11:17:19 +01:00
|
|
|
</Card>
|
|
|
|
<Card>
|
|
|
|
<CardHeader>
|
2020-12-08 11:39:16 +01:00
|
|
|
<span className="d-sm-none">Recently created URLs</span>
|
|
|
|
<h5 className="d-none d-sm-inline">Recently created URLs</h5>
|
2022-03-05 13:26:28 +01:00
|
|
|
<Link className="float-end" to={`/server/${serverId}/list-short-urls/1`}>See all »</Link>
|
2020-12-07 11:17:19 +01:00
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
2020-12-19 22:49:11 +01:00
|
|
|
<ShortUrlsTable
|
|
|
|
shortUrlsList={shortUrlsList}
|
|
|
|
selectedServer={selectedServer}
|
|
|
|
className="mb-0"
|
2022-02-06 20:07:18 +01:00
|
|
|
onTagClick={(tag) => navigate(`/server/${serverId}/list-short-urls/1?tags=${encodeURIComponent(tag)}`)}
|
2020-12-19 22:49:11 +01:00
|
|
|
/>
|
2020-12-07 11:17:19 +01:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
</>
|
2020-12-06 18:32:24 +01:00
|
|
|
);
|
2022-03-26 12:17:42 +01:00
|
|
|
}, () => [Topics.visits, Topics.orphanVisits]);
|