mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Updated getOrphanVisits action so that it expects a signle DTO param
This commit is contained in:
parent
b9efdd69f1
commit
8e6b9c5afb
3 changed files with 15 additions and 16 deletions
|
@ -1,21 +1,17 @@
|
||||||
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
||||||
import { ShlinkVisitsParams } from '../api/types';
|
|
||||||
import { Topics } from '../mercure/helpers/Topics';
|
import { Topics } from '../mercure/helpers/Topics';
|
||||||
import { useGoBack } from '../utils/helpers/hooks';
|
import { useGoBack } from '../utils/helpers/hooks';
|
||||||
import { ReportExporter } from '../common/services/ReportExporter';
|
import { ReportExporter } from '../common/services/ReportExporter';
|
||||||
import { VisitsStats } from './VisitsStats';
|
import { VisitsStats } from './VisitsStats';
|
||||||
import { NormalizedVisit, OrphanVisitType, VisitsParams } from './types';
|
import { NormalizedVisit, VisitsParams } from './types';
|
||||||
import { CommonVisitsProps } from './types/CommonVisitsProps';
|
import { CommonVisitsProps } from './types/CommonVisitsProps';
|
||||||
import { toApiParams } from './types/helpers';
|
import { toApiParams } from './types/helpers';
|
||||||
import { VisitsHeader } from './VisitsHeader';
|
import { VisitsHeader } from './VisitsHeader';
|
||||||
import { VisitsInfo } from './reducers/types';
|
import { VisitsInfo } from './reducers/types';
|
||||||
|
import { LoadOrphanVisits } from './reducers/orphanVisits';
|
||||||
|
|
||||||
export interface OrphanVisitsProps extends CommonVisitsProps {
|
export interface OrphanVisitsProps extends CommonVisitsProps {
|
||||||
getOrphanVisits: (
|
getOrphanVisits: (params: LoadOrphanVisits) => void;
|
||||||
params?: ShlinkVisitsParams,
|
|
||||||
orphanVisitsType?: OrphanVisitType,
|
|
||||||
doIntervalFallback?: boolean,
|
|
||||||
) => void;
|
|
||||||
orphanVisits: VisitsInfo;
|
orphanVisits: VisitsInfo;
|
||||||
cancelGetOrphanVisits: () => void;
|
cancelGetOrphanVisits: () => void;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +25,9 @@ export const OrphanVisits = ({ exportVisits }: ReportExporter) => boundToMercure
|
||||||
}: OrphanVisitsProps) => {
|
}: OrphanVisitsProps) => {
|
||||||
const goBack = useGoBack();
|
const goBack = useGoBack();
|
||||||
const exportCsv = (visits: NormalizedVisit[]) => exportVisits('orphan_visits.csv', visits);
|
const exportCsv = (visits: NormalizedVisit[]) => exportVisits('orphan_visits.csv', visits);
|
||||||
const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) =>
|
const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) => getOrphanVisits(
|
||||||
getOrphanVisits(toApiParams(params), params.filter?.orphanVisitsType, doIntervalFallback);
|
{ query: toApiParams(params), orphanVisitsType: params.filter?.orphanVisitsType, doIntervalFallback },
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VisitsStats
|
<VisitsStats
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { ApiErrorAction } from '../../api/types/actions';
|
||||||
import { isBetween } from '../../utils/helpers/date';
|
import { isBetween } from '../../utils/helpers/date';
|
||||||
import { getVisitsWithLoader, lastVisitLoaderForLoader } from './common';
|
import { getVisitsWithLoader, lastVisitLoaderForLoader } from './common';
|
||||||
import { createNewVisits, CreateVisitsAction } from './visitCreation';
|
import { createNewVisits, CreateVisitsAction } from './visitCreation';
|
||||||
import { VisitsFallbackIntervalAction, VisitsInfo, VisitsLoadProgressChangedAction } from './types';
|
import { LoadVisits, VisitsFallbackIntervalAction, VisitsInfo, VisitsLoadProgressChangedAction } from './types';
|
||||||
|
|
||||||
const REDUCER_PREFIX = 'shlink/orphanVisits';
|
const REDUCER_PREFIX = 'shlink/orphanVisits';
|
||||||
export const GET_ORPHAN_VISITS_START = `${REDUCER_PREFIX}/getOrphanVisits/pending`;
|
export const GET_ORPHAN_VISITS_START = `${REDUCER_PREFIX}/getOrphanVisits/pending`;
|
||||||
|
@ -26,6 +26,10 @@ export interface OrphanVisitsAction extends Action<string> {
|
||||||
query?: ShlinkVisitsParams;
|
query?: ShlinkVisitsParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LoadOrphanVisits extends LoadVisits {
|
||||||
|
orphanVisitsType?: OrphanVisitType;
|
||||||
|
}
|
||||||
|
|
||||||
type OrphanVisitsCombinedAction = OrphanVisitsAction
|
type OrphanVisitsCombinedAction = OrphanVisitsAction
|
||||||
& VisitsLoadProgressChangedAction
|
& VisitsLoadProgressChangedAction
|
||||||
& VisitsFallbackIntervalAction
|
& VisitsFallbackIntervalAction
|
||||||
|
@ -68,9 +72,7 @@ const matchesType = (visit: OrphanVisit, orphanVisitsType?: OrphanVisitType) =>
|
||||||
!orphanVisitsType || orphanVisitsType === visit.type;
|
!orphanVisitsType || orphanVisitsType === visit.type;
|
||||||
|
|
||||||
export const getOrphanVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (
|
export const getOrphanVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (
|
||||||
query: ShlinkVisitsParams = {},
|
{ orphanVisitsType, query = {}, doIntervalFallback = false }: LoadOrphanVisits,
|
||||||
orphanVisitsType?: OrphanVisitType,
|
|
||||||
doIntervalFallback = false,
|
|
||||||
) => async (dispatch: Dispatch, getState: GetState) => {
|
) => async (dispatch: Dispatch, getState: GetState) => {
|
||||||
const { getOrphanVisits: getVisits } = buildShlinkApiClient(getState);
|
const { getOrphanVisits: getVisits } = buildShlinkApiClient(getState);
|
||||||
const visitsLoader = async (page: number, itemsPerPage: number) => getVisits({ ...query, page, itemsPerPage })
|
const visitsLoader = async (page: number, itemsPerPage: number) => getVisits({ ...query, page, itemsPerPage })
|
||||||
|
|
|
@ -147,7 +147,7 @@ describe('orphanVisitsReducer', () => {
|
||||||
it('dispatches start and error when promise is rejected', async () => {
|
it('dispatches start and error when promise is rejected', async () => {
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.reject({}));
|
const ShlinkApiClient = buildApiClientMock(Promise.reject({}));
|
||||||
|
|
||||||
await getOrphanVisits(() => ShlinkApiClient)()(dispatchMock, getState);
|
await getOrphanVisits(() => ShlinkApiClient)({})(dispatchMock, getState);
|
||||||
|
|
||||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
||||||
|
@ -169,7 +169,7 @@ describe('orphanVisitsReducer', () => {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await getOrphanVisits(() => ShlinkApiClient)(query)(dispatchMock, getState);
|
await getOrphanVisits(() => ShlinkApiClient)({ query })(dispatchMock, getState);
|
||||||
|
|
||||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
||||||
|
@ -201,7 +201,7 @@ describe('orphanVisitsReducer', () => {
|
||||||
.mockResolvedValueOnce(buildVisitsResult(lastVisits));
|
.mockResolvedValueOnce(buildVisitsResult(lastVisits));
|
||||||
const ShlinkApiClient = Mock.of<ShlinkApiClient>({ getOrphanVisits: getShlinkOrphanVisits });
|
const ShlinkApiClient = Mock.of<ShlinkApiClient>({ getOrphanVisits: getShlinkOrphanVisits });
|
||||||
|
|
||||||
await getOrphanVisits(() => ShlinkApiClient)({}, undefined, true)(dispatchMock, getState);
|
await getOrphanVisits(() => ShlinkApiClient)({ doIntervalFallback: true })(dispatchMock, getState);
|
||||||
|
|
||||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_ORPHAN_VISITS_START });
|
||||||
|
|
Loading…
Reference in a new issue