Skip to content

Commit

Permalink
#1226 | Do not reuse live object when editing
Browse files Browse the repository at this point in the history
Objects being passed in to the form wizard should never be a live object.
One situation where this is not happening is when an enrolment is saved.
While I could not accurately recreate the reported issue, this change
will ensure that the program enrolment object is always a clone when it is
being edited.
  • Loading branch information
vinayvenu committed Dec 19, 2023
1 parent 113a147 commit 797d065
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class ProgramEnrolmentActions {
}

static onLoad(state: ProgramEnrolmentState, action, context) {
if (ProgramEnrolmentState.hasEnrolmentOrItsUsageChanged(state, action) || action.forceLoad) {
const enrolment = action.enrolment.cloneForEdit();
const formMappingService = context.get(FormMappingService);
const isProgramEnrolment = action.usage === ProgramEnrolmentState.UsageKeys.Enrol;
Expand Down Expand Up @@ -68,9 +67,6 @@ export class ProgramEnrolmentActions {
programEnrolmentState.groupAffiliation.removeMemberFromGroup();
}
return QuickFormEditingActions.moveToPage(programEnrolmentState, action, context, ProgramEnrolmentActions);
} else {
return state.clone();
}
}

static enrolmentDateTimeChanged(state, action, context) {
Expand Down
7 changes: 0 additions & 7 deletions packages/openchs-android/src/state/ProgramEnrolmentState.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ class ProgramEnrolmentState extends AbstractDataEntryState {
return this.wizard.isFirstPage() ? validationKeys : [];
}

static hasEnrolmentOrItsUsageChanged(state, action) {
return _.isNil(state) ||
_.isNil(state.enrolment) ||
state.enrolment.uuid !== action.enrolment.uuid ||
state.usage !== action.usage;
}

validateEntity(context) {
let validationResults;
if (this.usage === ProgramEnrolmentState.UsageKeys.Enrol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ class ProgramEnrolmentView extends AbstractComponent {
enrolment: this.props.enrolment,
usage: ProgramEnrolmentView.usageContext.usage,
workLists: this.props.workLists,
forceLoad: this.props.editing,
pageNumber: this.props.pageNumber,
});
return super.UNSAFE_componentWillMount();
}

onBack() {
this.dispatchAction(Actions.ON_LOAD, {enrolment: this.props.enrolment, usage: ProgramEnrolmentView.usageContext.usage, forceLoad: true});
this.dispatchAction(Actions.ON_LOAD, {enrolment: this.props.enrolment, usage: ProgramEnrolmentView.usageContext.usage});
this.goBack();
}

Expand Down

0 comments on commit 797d065

Please sign in to comment.