2023-02-18 12:40:37 +03:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import { useEffect } from 'react';
|
2022-02-05 12:04:34 +03:00
|
|
|
import { Card, CardBody, CardHeader, Row } from 'reactstrap';
|
2022-02-06 22:07:18 +03:00
|
|
|
import { Link, useNavigate } from 'react-router-dom';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import { ITEMS_IN_OVERVIEW_PAGE } from '../short-urls/reducers/shortUrlsList';
|
2020-12-06 20:32:24 +03:00
|
|
|
import { prettify } from '../utils/helpers/numbers';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { TagsList } from '../tags/reducers/tagsList';
|
|
|
|
import type { ShortUrlsTableType } from '../short-urls/ShortUrlsTable';
|
2020-12-07 13:17:19 +03:00
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { CreateShortUrlProps } from '../short-urls/CreateShortUrl';
|
|
|
|
import type { VisitsOverview } from '../visits/reducers/visitsOverview';
|
2021-02-28 12:12:30 +03:00
|
|
|
import { Topics } from '../mercure/helpers/Topics';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ShlinkShortUrlsListParams } from '../api/types';
|
2022-05-01 11:50:06 +03:00
|
|
|
import { supportsNonOrphanVisits } from '../utils/helpers/features';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { SelectedServer } from './data';
|
|
|
|
import { getServerId } from './data';
|
2022-02-05 12:04:34 +03:00
|
|
|
import { HighlightCard } from './helpers/HighlightCard';
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
interface OverviewConnectProps {
|
|
|
|
shortUrlsList: ShortUrlsListState;
|
2021-11-11 23:28:17 +03:00
|
|
|
listShortUrls: (params: ShlinkShortUrlsListParams) => void;
|
2020-12-06 20:32:24 +03:00
|
|
|
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 = (
|
2022-12-18 12:12:34 +03:00
|
|
|
ShortUrlsTable: ShortUrlsTableType,
|
2020-12-07 22:37:03 +03:00
|
|
|
CreateShortUrl: FC<CreateShortUrlProps>,
|
|
|
|
) => 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;
|
2021-11-06 14:04:26 +03:00
|
|
|
const serverId = getServerId(selectedServer);
|
2022-02-05 12:04:34 +03:00
|
|
|
const linkToNonOrphanVisits = supportsNonOrphanVisits(selectedServer);
|
2022-02-06 22:07:18 +03:00
|
|
|
const navigate = useNavigate();
|
2020-12-06 20:32:24 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-01-08 12:51:34 +03:00
|
|
|
listShortUrls({ itemsPerPage: ITEMS_IN_OVERVIEW_PAGE, orderBy: { field: 'dateCreated', dir: '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
|
|
|
<>
|
2021-03-29 22:08:48 +03:00
|
|
|
<Row>
|
2022-02-05 12:04:34 +03:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
2022-02-05 15:37:49 +03:00
|
|
|
<HighlightCard title="Visits" link={linkToNonOrphanVisits && `/server/${serverId}/non-orphan-visits`}>
|
2022-02-05 12:04:34 +03:00
|
|
|
{loadingVisits ? 'Loading...' : prettify(visitsCount)}
|
|
|
|
</HighlightCard>
|
2020-12-07 13:17:19 +03:00
|
|
|
</div>
|
2022-02-05 12:04:34 +03:00
|
|
|
<div className="col-lg-6 col-xl-3 mb-3">
|
2022-05-01 11:50:06 +03:00
|
|
|
<HighlightCard title="Orphan visits" link={`/server/${serverId}/orphan-visits`}>
|
2022-05-02 20:28:07 +03:00
|
|
|
{loadingVisits ? 'Loading...' : prettify(orphanVisitsCount)}
|
2022-02-05 12:04:34 +03:00
|
|
|
</HighlightCard>
|
2021-02-21 22:55:39 +03:00
|
|
|
</div>
|
2022-02-05 12:04:34 +03: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 13:17:19 +03:00
|
|
|
</div>
|
2022-02-05 12:04:34 +03: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 13:17:19 +03:00
|
|
|
</div>
|
2021-03-29 22:08:48 +03:00
|
|
|
</Row>
|
2022-02-05 12:04:34 +03:00
|
|
|
|
2021-03-29 22:08:48 +03:00
|
|
|
<Card className="mb-3">
|
2020-12-07 13:17:19 +03:00
|
|
|
<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>
|
2022-03-05 15:26:28 +03:00
|
|
|
<Link className="float-end" 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>
|
2022-03-05 15:26:28 +03:00
|
|
|
<Link className="float-end" to={`/server/${serverId}/list-short-urls/1`}>See all »</Link>
|
2020-12-07 13:17:19 +03:00
|
|
|
</CardHeader>
|
|
|
|
<CardBody>
|
2020-12-20 00:49:11 +03:00
|
|
|
<ShortUrlsTable
|
|
|
|
shortUrlsList={shortUrlsList}
|
|
|
|
selectedServer={selectedServer}
|
|
|
|
className="mb-0"
|
2022-02-06 22:07:18 +03:00
|
|
|
onTagClick={(tag) => navigate(`/server/${serverId}/list-short-urls/1?tags=${encodeURIComponent(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
|
|
|
);
|
2022-03-26 14:17:42 +03:00
|
|
|
}, () => [Topics.visits, Topics.orphanVisits]);
|