diff --git a/src/data/events/EventsD2ApiRepository.ts b/src/data/events/EventsD2ApiRepository.ts index b84038246..98b1fa643 100644 --- a/src/data/events/EventsD2ApiRepository.ts +++ b/src/data/events/EventsD2ApiRepository.ts @@ -96,7 +96,7 @@ export class EventsD2ApiRepository implements EventsRepository { .getData(); }; - const result: D2TrackerEvent[][] = await promiseMap(orgUnits, async orgUnit => { + const result = await promiseMap(orgUnits, async (orgUnit): Promise => { const { instances, total = 0, pageSize } = await fetchApi(orgUnit, 1); const pageCount = Math.ceil(total / pageSize); @@ -111,7 +111,7 @@ export class EventsD2ApiRepository implements EventsRepository { return _(result) .flatten() - .filter(({ programStage }) => programStageIds.includes(programStage || "")) + .filter(({ programStage }) => (programStage ? programStageIds.includes(programStage) : false)) .map(object => ({ ...object, id: object.event })) .map(object => cleanObjectDefault(object, defaults)) .value(); @@ -273,10 +273,6 @@ export class EventsD2ApiRepository implements EventsRepository { dataElementIdScheme: params.dataElementIdScheme ?? "UID", orgUnitIdScheme: params.orgUnitIdScheme ?? "UID", importMode: params.importMode ?? "COMMIT", - - // TODO: Check if these params exists in the new tracker endpoint - // preheatCache: params.preheatCache ?? false, - // skipExistingCheck: params.skipExistingCheck ?? false, }; const trackerPostRequest: TrackerPostRequest = { diff --git a/src/presentation/react/core/components/sync-params-selector/SyncParamsSelector.tsx b/src/presentation/react/core/components/sync-params-selector/SyncParamsSelector.tsx index 2da32b017..e00c3eff8 100644 --- a/src/presentation/react/core/components/sync-params-selector/SyncParamsSelector.tsx +++ b/src/presentation/react/core/components/sync-params-selector/SyncParamsSelector.tsx @@ -1,5 +1,7 @@ import { makeStyles, Typography } from "@material-ui/core"; import React from "react"; +import { DataSynchronizationParams } from "../../../../../domain/aggregated/entities/DataSynchronizationParams"; +import { MetadataSynchronizationParams } from "../../../../../domain/metadata/entities/MetadataSynchronizationParams"; import { SynchronizationRule } from "../../../../../domain/rules/entities/SynchronizationRule"; import i18n from "../../../../../locales"; import RadioButtonGroup from "../radio-button-group/RadioButtonGroup"; @@ -260,13 +262,7 @@ const SyncParamsSelector: React.FC = ({ syncRule, onCha @@ -298,3 +294,17 @@ const SyncParamsSelector: React.FC = ({ syncRule, onCha }; export default SyncParamsSelector; + +function isDryRunEnabled( + syncRule: SynchronizationRule, + syncParams: MetadataSynchronizationParams, + dataParams: DataSynchronizationParams +): boolean { + if (syncRule.type === "metadata" || syncRule.type === "deleted") { + return syncParams.importMode === "VALIDATE"; + } else if (syncRule.type === "events") { + return dataParams.importMode === "VALIDATE"; + } else { + return dataParams.dryRun || false; + } +}