2023-02-18 10:40:37 +01:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import { useEffect } from 'react';
|
2022-02-06 20:07:18 +01:00
|
|
|
import { Link, useNavigate } from 'react-router-dom';
|
2023-02-18 11:11:01 +01:00
|
|
|
import { Card, CardBody, CardHeader, Row } from 'reactstrap';
|
2023-07-16 08:47:10 +02:00
|
|
|
import type { ShlinkShortUrlsListParams } from '../../api/types';
|
|
|
|
import { boundToMercureHub } from '../../mercure/helpers/boundToMercureHub';
|
|
|
|
import { Topics } from '../../mercure/helpers/Topics';
|
|
|
|
import type { SelectedServer } from '../../servers/data';
|
|
|
|
import { getServerId } from '../../servers/data';
|
|
|
|
import { HighlightCard } from '../../servers/helpers/HighlightCard';
|
|
|
|
import { VisitsHighlightCard } from '../../servers/helpers/VisitsHighlightCard';
|
|
|
|
import type { Settings } from '../../settings/reducers/settings';
|
|
|
|
import { prettify } from '../../utils/helpers/numbers';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { CreateShortUrlProps } from '../short-urls/CreateShortUrl';
|
2023-02-18 10:40:37 +01:00
|
|
|
import type { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import { ITEMS_IN_OVERVIEW_PAGE } from '../short-urls/reducers/shortUrlsList';
|
|
|
|
import type { ShortUrlsTableType } from '../short-urls/ShortUrlsTable';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { TagsList } from '../tags/reducers/tagsList';
|
2023-07-16 22:54:49 +02:00
|
|
|
import { useFeature } from '../utils/features';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { VisitsOverview } from '../visits/reducers/visitsOverview';
|
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;
|
2023-03-18 10:55:07 +01:00
|
|
|
settings: Settings;
|
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,
|
2023-03-18 10:55:07 +01:00
|
|
|
settings: { visits },
|
2020-12-07 12:12:39 +01:00
|
|
|
}: OverviewConnectProps) => {
|
|
|
|
const { loading, shortUrls } = shortUrlsList;
|
2020-12-06 18:32:24 +01:00
|
|
|
const { loading: loadingTags } = tagsList;
|
2023-03-18 10:55:07 +01:00
|
|
|
const { loading: loadingVisits, nonOrphanVisits, orphanVisits } = visitsOverview;
|
2021-11-06 12:04:26 +01:00
|
|
|
const serverId = getServerId(selectedServer);
|
2023-07-16 22:54:49 +02:00
|
|
|
const linkToNonOrphanVisits = useFeature('nonOrphanVisits');
|
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">
|
2023-03-18 10:55:07 +01:00
|
|
|
<VisitsHighlightCard
|
|
|
|
title="Visits"
|
|
|
|
link={linkToNonOrphanVisits ? `/server/${serverId}/non-orphan-visits` : undefined}
|
|
|
|
excludeBots={visits?.excludeBots ?? false}
|
|
|
|
loading={loadingVisits}
|
|
|
|
visitsSummary={nonOrphanVisits}
|
|
|
|
/>
|
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">
|
2023-03-18 10:55:07 +01:00
|
|
|
<VisitsHighlightCard
|
|
|
|
title="Orphan visits"
|
|
|
|
link={`/server/${serverId}/orphan-visits`}
|
|
|
|
excludeBots={visits?.excludeBots ?? false}
|
|
|
|
loading={loadingVisits}
|
|
|
|
visitsSummary={orphanVisits}
|
|
|
|
/>
|
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]);
|