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

44 lines
1.6 KiB
TypeScript
Raw Normal View History

import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
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, VisitsParams } from './types';
import { CommonVisitsProps } from './types/CommonVisitsProps';
import { toApiParams } from './types/helpers';
import { VisitsHeader } from './VisitsHeader';
import { VisitsInfo } from './reducers/types';
import { LoadOrphanVisits } from './reducers/orphanVisits';
2022-02-06 22:07:18 +03:00
export interface OrphanVisitsProps extends CommonVisitsProps {
getOrphanVisits: (params: LoadOrphanVisits) => 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,
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(
{ query: toApiParams(params), orphanVisitsType: 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}
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]);