mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Updated getNonOrphanVisits action so that it expects a signle DTO param
This commit is contained in:
parent
3b96b89492
commit
b9efdd69f1
3 changed files with 8 additions and 10 deletions
|
@ -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 (
|
||||
<VisitsStats
|
||||
|
|
|
@ -9,7 +9,7 @@ import { ApiErrorAction } from '../../api/types/actions';
|
|||
import { isBetween } from '../../utils/helpers/date';
|
||||
import { getVisitsWithLoader, lastVisitLoaderForLoader } from './common';
|
||||
import { createNewVisits, CreateVisitsAction } from './visitCreation';
|
||||
import { VisitsFallbackIntervalAction, VisitsInfo, VisitsLoadProgressChangedAction } from './types';
|
||||
import { LoadVisits, VisitsFallbackIntervalAction, VisitsInfo, VisitsLoadProgressChangedAction } from './types';
|
||||
|
||||
const REDUCER_PREFIX = 'shlink/orphanVisits';
|
||||
export const GET_NON_ORPHAN_VISITS_START = `${REDUCER_PREFIX}/getNonOrphanVisits/pending`;
|
||||
|
@ -66,8 +66,7 @@ export default buildReducer<VisitsInfo, NonOrphanVisitsCombinedAction>({
|
|||
}, 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) =>
|
||||
|
|
|
@ -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<ShlinkApiClient>({ 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 });
|
||||
|
|
Loading…
Reference in a new issue