diff --git a/src/visits/NonOrphanVisits.tsx b/src/visits/NonOrphanVisits.tsx index 9452167c..8c939558 100644 --- a/src/visits/NonOrphanVisits.tsx +++ b/src/visits/NonOrphanVisits.tsx @@ -1,5 +1,4 @@ import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub'; -import { ShlinkVisitsParams } from '../api/types'; import { Topics } from '../mercure/helpers/Topics'; import { useGoBack } from '../utils/helpers/hooks'; import { ReportExporter } from '../common/services/ReportExporter'; @@ -8,10 +7,10 @@ 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 { LoadVisits, VisitsInfo } from './reducers/types'; export interface NonOrphanVisitsProps extends CommonVisitsProps { - getNonOrphanVisits: (params?: ShlinkVisitsParams, doIntervalFallback?: boolean) => void; + getNonOrphanVisits: (params: LoadVisits) => void; nonOrphanVisits: VisitsInfo; cancelGetNonOrphanVisits: () => void; } @@ -26,7 +25,7 @@ export const NonOrphanVisits = ({ exportVisits }: ReportExporter) => boundToMerc const goBack = useGoBack(); const exportCsv = (visits: NormalizedVisit[]) => exportVisits('non_orphan_visits.csv', visits); const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) => - getNonOrphanVisits(toApiParams(params), doIntervalFallback); + getNonOrphanVisits({ query: toApiParams(params), doIntervalFallback }); return ( ({ }, initialState); export const getNonOrphanVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => ( - query: ShlinkVisitsParams = {}, - doIntervalFallback = false, + { query = {}, doIntervalFallback = false }: LoadVisits, ) => async (dispatch: Dispatch, getState: GetState) => { const { getNonOrphanVisits: shlinkGetNonOrphanVisits } = buildShlinkApiClient(getState); const visitsLoader = async (page: number, itemsPerPage: number) => diff --git a/test/visits/reducers/nonOrphanVisits.test.ts b/test/visits/reducers/nonOrphanVisits.test.ts index a5a4533c..0afde97e 100644 --- a/test/visits/reducers/nonOrphanVisits.test.ts +++ b/test/visits/reducers/nonOrphanVisits.test.ts @@ -147,7 +147,7 @@ describe('nonOrphanVisitsReducer', () => { it('dispatches start and error when promise is rejected', async () => { const ShlinkApiClient = buildApiClientMock(Promise.reject({})); - await getNonOrphanVisits(() => ShlinkApiClient)()(dispatchMock, getState); + await getNonOrphanVisits(() => ShlinkApiClient)({})(dispatchMock, getState); expect(dispatchMock).toHaveBeenCalledTimes(2); expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_NON_ORPHAN_VISITS_START }); @@ -169,7 +169,7 @@ describe('nonOrphanVisitsReducer', () => { }, })); - await getNonOrphanVisits(() => ShlinkApiClient)(query)(dispatchMock, getState); + await getNonOrphanVisits(() => ShlinkApiClient)({ query })(dispatchMock, getState); expect(dispatchMock).toHaveBeenCalledTimes(2); expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_NON_ORPHAN_VISITS_START }); @@ -201,7 +201,7 @@ describe('nonOrphanVisitsReducer', () => { .mockResolvedValueOnce(buildVisitsResult(lastVisits)); const ShlinkApiClient = Mock.of({ getNonOrphanVisits: getShlinkOrphanVisits }); - await getNonOrphanVisits(() => ShlinkApiClient)({}, true)(dispatchMock, getState); + await getNonOrphanVisits(() => ShlinkApiClient)({ doIntervalFallback: true })(dispatchMock, getState); expect(dispatchMock).toHaveBeenCalledTimes(2); expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_NON_ORPHAN_VISITS_START });