shlink-web-client/src/visits/OrphanVisits.tsx

49 lines
1.8 KiB
TypeScript
Raw Normal View History

import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
import { ShlinkVisitsParams } from '../api/types';
import { Topics } from '../mercure/helpers/Topics';
2022-02-06 22:07:18 +03:00
import { useGoBack } from '../utils/helpers/hooks';
2022-03-13 20:56:42 +03:00
import { ReportExporter } from '../common/services/ReportExporter';
import { VisitsStats } from './VisitsStats';
import { NormalizedVisit, OrphanVisitType, VisitsParams } from './types';
import { CommonVisitsProps } from './types/CommonVisitsProps';
import { toApiParams } from './types/helpers';
import { VisitsHeader } from './VisitsHeader';
import { VisitsInfo } from './reducers/types';
2022-02-06 22:07:18 +03:00
export interface OrphanVisitsProps extends CommonVisitsProps {
getOrphanVisits: (
params?: ShlinkVisitsParams,
orphanVisitsType?: OrphanVisitType,
doIntervalFallback?: boolean,
) => void;
2021-02-28 12:36:56 +03:00
orphanVisits: VisitsInfo;
cancelGetOrphanVisits: () => void;
}
2022-03-13 20:56:42 +03:00
export const OrphanVisits = ({ exportVisits }: ReportExporter) => boundToMercureHub(({
getOrphanVisits,
orphanVisits,
cancelGetOrphanVisits,
2021-03-06 12:56:49 +03:00
settings,
selectedServer,
2021-03-14 14:49:12 +03:00
}: OrphanVisitsProps) => {
2022-02-06 22:07:18 +03:00
const goBack = useGoBack();
2021-03-14 14:49:12 +03:00
const exportCsv = (visits: NormalizedVisit[]) => exportVisits('orphan_visits.csv', visits);
const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) =>
getOrphanVisits(toApiParams(params), params.filter?.orphanVisitsType, doIntervalFallback);
2021-03-14 14:49:12 +03:00
return (
<VisitsStats
getVisits={loadVisits}
2021-03-14 14:49:12 +03:00
cancelGetVisits={cancelGetOrphanVisits}
visitsInfo={orphanVisits}
settings={settings}
exportCsv={exportCsv}
selectedServer={selectedServer}
isOrphanVisits
2021-03-14 14:49:12 +03:00
>
<VisitsHeader title="Orphan visits" goBack={goBack} visits={orphanVisits.visits} />
2021-03-14 14:49:12 +03:00
</VisitsStats>
);
2022-03-26 14:17:42 +03:00
}, () => [Topics.orphanVisits]);