Skip to content

Commit

Permalink
Apply changes requested by Arnau
Browse files Browse the repository at this point in the history
  • Loading branch information
xurxodev committed Dec 27, 2024
1 parent dae6fb7 commit 320fe88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/data/events/EventsD2ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<D2TrackerEvent[]> => {
const { instances, total = 0, pageSize } = await fetchApi(orgUnit, 1);

const pageCount = Math.ceil(total / pageSize);
Expand All @@ -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();
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -260,13 +262,7 @@ const SyncParamsSelector: React.FC<SyncParamsSelectorProps> = ({ syncRule, onCha
<Toggle
label={i18n.t("Dry Run")}
onValueChange={changeDryRun}
value={
syncRule.type === "metadata" || syncRule.type === "deleted"
? syncParams.importMode === "VALIDATE"
: syncRule.type === "events"
? dataParams.importMode === "VALIDATE"
: dataParams.dryRun || false
}
value={isDryRunEnabled(syncRule, syncParams, dataParams)}
/>
</div>

Expand Down Expand Up @@ -298,3 +294,17 @@ const SyncParamsSelector: React.FC<SyncParamsSelectorProps> = ({ 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;
}
}

0 comments on commit 320fe88

Please sign in to comment.