Skip to content

Commit b2724a6

Browse files
authored
fix: [DHIS2-20495] Org unit not retained after “Save and add another” event (#4406)
* fix: add org unit * fix: typing * fix: expect org unit first * fix: review temp * fix: add program category from index db
1 parent bfd0929 commit b2724a6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/core_modules/capture-core-utils/types/global.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export type ReduxStore = {
88
programId: string;
99
orgUnitId?: string;
1010
complete?: boolean;
11+
trackedEntityTypeId?: string;
12+
categories?: Record<string, string>;
13+
categoriesMeta?: Record<string, { name: string; writeAccess: boolean }>;
1114
};
1215
possibleDuplicates: {
1316
isLoading: boolean;

src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/newEventDataEntry.epics.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,29 @@ type SelectionsCompletenessPayload = {
4545
triggeringActionType?: string;
4646
};
4747

48-
export const resetDataEntryForNewEventEpic = (action$: EpicAction<any>) =>
48+
export const resetDataEntryForNewEventEpic = (action$: EpicAction<any>, store: ReduxStore) =>
4949
action$.pipe(
5050
ofType(newEventDataEntryBatchActionTypes.SAVE_NEW_EVENT_ADD_ANOTHER_BATCH),
51-
map(() => (batchActions(getOpenDataEntryActions()))),
51+
map(() => {
52+
const state = store.value;
53+
const selectedCategories = state.currentSelections.categories;
54+
const orgUnitId = state.currentSelections.orgUnitId;
55+
const orgUnits = state.organisationUnits;
56+
const orgUnit = orgUnitId && orgUnits
57+
? orgUnits[orgUnitId]
58+
: undefined;
59+
const program = getEventProgramThrowIfNotFound(state.currentSelections.programId);
60+
const categoryCombination = program.categoryCombination;
61+
const programCategory = categoryCombination ? {
62+
displayName: categoryCombination.name,
63+
id: categoryCombination.id,
64+
categories: Array.from(categoryCombination.categories.values()).map(category => ({
65+
id: category.id,
66+
displayName: category.name,
67+
})),
68+
} : null;
69+
return batchActions(getOpenDataEntryActions(programCategory, selectedCategories, orgUnit));
70+
}),
5271
);
5372

5473
export const openNewEventInDataEntryEpic = (action$: EpicAction<SelectionsCompletenessPayload>, store: ReduxStore) =>

src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/helpers/getOpenDataEntryActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OrgUnit } from '@dhis2/rules-engine-javascript';
1+
import { CoreOrgUnit } from 'capture-core/metadataRetrieval/coreOrgUnit';
22
import { loadNewDataEntry } from '../../../../../DataEntry/actions/dataEntryLoadNew.actions';
33
import { getEventDateValidatorContainers, getOrgUnitValidatorContainers } from '../fieldValidators';
44
import { convertGeometryOut, convertStatusIn, convertStatusOut } from '../../../../index';
@@ -51,7 +51,7 @@ const dataEntryPropsToInclude: Array<DataEntryPropToInclude> = [
5151
export const getOpenDataEntryActions = (
5252
programCategory?: ProgramCategory | null,
5353
selectedCategories?: { [key: string]: string } | null,
54-
orgUnit?: OrgUnit & { path: string } | null,
54+
orgUnit?: CoreOrgUnit | null,
5555
) => {
5656
let defaultDataEntryValues = {
5757
orgUnit: orgUnit

0 commit comments

Comments
 (0)