Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DHIS2-17102] edit event navigation #3592

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ And the user see the following text: 11
When the user clicks on the edit button
And the user set the apgar score to 5
And the user clicks on the save button
Then you are redirected to the enrollment dashboard
And you open the Birth stage event
Then the user see the following text: Enrollment: View Event
And the user see the following text: 5
When the user clicks on the edit button
And the user set the apgar score to 11
And the user clicks on the save button
Then you are redirected to the enrollment dashboard
And you open the Birth stage event
Then the user see the following text: Enrollment: View Event
And the user see the following text: 11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,17 @@ Then('the user sees the enrollment status and recently edited event in Case outc
changeEnrollmentAndEventsStatus();
});

Then('you are redirected to the enrollment dashboard', () => {
cy.url().should('include', `${Cypress.config().baseUrl}/#/enrollment?`);
});

And('you open the Birth stage event', () => {
cy.get('[data-test="stage-content"]')
.eq(0)
.within(() => {
cy.get('[data-test="dhis2-uicore-datatablerow"]')
.eq(1)
.click();
});
});

10 changes: 10 additions & 0 deletions cypress/e2e/ViewPage/EditEventPageForm.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: User interacts with a single event page view/edit form

Scenario: The single event is edited and the changes are reflected in the working list
Given you open the main page with Ngelehun and antenatal care context
And you open the first event in the list
And you complete and save the event
Then you are redirected to the main page and the event status Completed is displayed in the list
And you open the first event in the list
And you incomplete and save the event
Then you are redirected to the main page and the event status Active is displayed in the list
40 changes: 40 additions & 0 deletions cypress/e2e/ViewPage/EditEventPageForm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Given, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../../sharedSteps';

Given('you open the main page with Ngelehun and antenatal care context', () => {
cy.visit('#/?programId=lxAQ7Zs9VYR&orgUnitId=DiszpKrYNg8');
});

And('you open the first event in the list', () => {
cy.get('[data-test="online-list-table"]').within(() => {
cy.get('[data-test="dhis2-uicore-tablebody"]')
.find('tr')
.eq(0)
.click();
});
});

And('you (incomplete)(complete) and save the event', () => {
cy.contains('Edit event')
.click();

cy.get('[data-test="dataentry-field-complete"]')
.find('input')
.click()
.blur();

cy.get('[data-test="dhis2-uicore-button"]')
.contains('Save')
.click();
});

Then(/^you are redirected to the main page and the event status (.*) is displayed in the list/, (status) => {
cy.url().should('include', 'programId=lxAQ7Zs9VYR');
cy.url().should('include', 'orgUnitId=DiszpKrYNg8');
cy.get('[data-test="online-list-table"]').within(() => {
cy.get('[data-test="dhis2-uicore-tablebody"]')
.find('tr')
.eq(0)
.contains(status);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const EnrollmentEditEventPageWithContextPlain = ({
const onSaveExternal = () => {
const queryKey = [ReactQueryAppNamespace, 'changelog', CHANGELOG_ENTITY_TYPES.EVENT, eventId];
queryClient.removeQueries(queryKey);
history.push(`enrollment?${buildUrlQueryString({ enrollmentId })}`);
};

const { teiDisplayName } = useTeiDisplayName(teiId, programId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Props = {
onOpenEditEvent: (orgUnit: Object) => void,
programStage: ProgramStage,
eventAccess: { read: boolean, write: boolean },
onBackToAllEvents: () => {},
classes: {
container: string,
headerContainer: string,
Expand All @@ -75,6 +76,7 @@ const EventDetailsSectionPlain = (props: Props) => {
showEditEvent,
programStage,
eventAccess,
onBackToAllEvents,
...passOnProps } = props;
const orgUnitId = useSelector(({ viewEventPage }) => viewEventPage.loadedValues?.orgUnit?.id);
const { orgUnit, error } = useCoreOrgUnit(orgUnitId);
Expand All @@ -86,6 +88,7 @@ const EventDetailsSectionPlain = (props: Props) => {
const onSaveExternal = () => {
const queryKey = [ReactQueryAppNamespace, 'changelog', CHANGELOG_ENTITY_TYPES.EVENT, eventId];
queryClient.removeQueries(queryKey);
onBackToAllEvents();
};

if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ViewEventPlain extends Component<Props, State> {
getAssignedUserSaveContext,
onSaveAssignee,
onSaveAssigneeError,
onBackToAllEvents,
} = this.props;

return (
Expand All @@ -98,6 +99,7 @@ class ViewEventPlain extends Component<Props, State> {
<EventDetails
eventAccess={eventAccess}
programStage={programStage}
onBackToAllEvents={onBackToAllEvents}
/>
<RightColumnWrapper
eventAccess={eventAccess}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import { actionCreator } from 'capture-core/actions/actions.utils';
import type { OrgUnit } from '@dhis2/rules-engine-javascript';
import type { UserFormField } from '../../../FormFields/UserField';

export const actionTypes = {
Expand All @@ -16,7 +15,6 @@ export const actionTypes = {
NO_WORKING_LIST_UPDATE_NEEDED_ON_BACK_TO_MAIN_PAGE: 'NoWorkingListUpdateNeededOnBackToMainPageForViewEvent',
START_GO_BACK_TO_MAIN_PAGE: 'StartGoBackToMainPageForViewEvent',
VIEW_EVENT_OPEN_NEW_RELATIONSHIP: 'ViewEventOpenAddRelationship',
UPDATE_EVENT_CONTAINER: 'UpdateEventContainerForViewEvent',
UPDATE_WORKING_LIST_PENDING_ON_BACK_TO_MAIN_PAGE: 'UpdateWorkingListPendingOnBackToMainPageForViewEvent',
OPEN_VIEW_EVENT_PAGE_FAILED: 'OpenViewEventPageFailed',
INITIALIZE_WORKING_LISTS_ON_BACK_TO_MAIN_PAGE: 'InitializeWorkingListsOnBackToMainPage',
Expand Down Expand Up @@ -72,9 +70,6 @@ export const updateWorkingListPendingOnBackToMainPage = () =>
export const openAddRelationship = () =>
actionCreator(actionTypes.VIEW_EVENT_OPEN_NEW_RELATIONSHIP)();

export const updateEventContainer = (eventContainer: Object, orgUnit: OrgUnit) =>
actionCreator(actionTypes.UPDATE_EVENT_CONTAINER)({ eventContainer, orgUnit });

export const openViewEventPageFailed = (error: string) =>
actionCreator(actionTypes.OPEN_VIEW_EVENT_PAGE_FAILED)({ error });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props): any => ({

dispatch(startAsyncUpdateFieldForEditEvent(innerAction, onAsyncUpdateSuccess, onAsyncUpdateError));
},
onSave: (orgUnit: OrgUnit) => (eventId: string, dataEntryId: string, formFoundation: RenderFoundation) => {
onSave: () => (eventId: string, dataEntryId: string, formFoundation: RenderFoundation) => {
const { onSaveExternal } = props;
window.scrollTo(0, 0);
onSaveExternal && onSaveExternal();
dispatch(requestSaveEditEventDataEntry(eventId, dataEntryId, formFoundation, orgUnit));
dispatch(requestSaveEditEventDataEntry(eventId, dataEntryId, formFoundation));
},
onSaveAndCompleteEnrollment: (orgUnit: OrgUnit) => (
onSaveAndCompleteEnrollment: () => (
eventId: string,
dataEntryId: string,
formFoundation: RenderFoundation,
Expand All @@ -113,7 +113,6 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props): any => ({
itemId: eventId,
dataEntryId,
formFoundation,
orgUnit,
onSaveAndCompleteEnrollmentExternal,
onSaveAndCompleteEnrollmentSuccessActionType,
onSaveAndCompleteEnrollmentErrorActionType,
Expand All @@ -139,14 +138,14 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props): any => ({
},
onCancelCreateNew: (itemId: string) => {
const { dataEntryId, formFoundation, orgUnit, enrollmentId, programId, teiId, availableProgramStages } = props;
dispatch(requestSaveEditEventDataEntry(itemId, dataEntryId, formFoundation, orgUnit));
dispatch(requestSaveEditEventDataEntry(itemId, dataEntryId, formFoundation));
dispatch(startCreateNewAfterCompleting({
enrollmentId, isCreateNew: false, orgUnitId: orgUnit.id, programId, teiId, availableProgramStages,
}));
},
onConfirmCreateNew: (itemId: string) => {
const { dataEntryId, formFoundation, orgUnit, enrollmentId, programId, teiId, availableProgramStages } = props;
dispatch(requestSaveEditEventDataEntry(itemId, dataEntryId, formFoundation, orgUnit));
dispatch(requestSaveEditEventDataEntry(itemId, dataEntryId, formFoundation));
dispatch(startCreateNewAfterCompleting({
enrollmentId, isCreateNew: true, orgUnitId: orgUnit.id, programId, teiId, availableProgramStages,
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @flow

import type { OrgUnit } from '@dhis2/rules-engine-javascript';
import { actionCreator } from '../../../actions/actions.utils';
import { effectMethods } from '../../../trackerOffline';

export const batchActionTypes = {
START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH: 'StartSaveEditEventDataEntryBatchForViewSingleEvent',
SAVE_EDIT_EVENT_DATA_ENTRY_FAILED: 'SaveEditEventDataEntryBatchFailed',
};


Expand All @@ -29,9 +28,11 @@ export const actionTypes = {
export const cancelEditEventDataEntry = () =>
actionCreator(actionTypes.CANCEL_EDIT_EVENT_DATA_ENTRY)();

export const requestSaveEditEventDataEntry = (itemId: string, dataEntryId: string, formFoundation: Object, orgUnit: OrgUnit) =>
actionCreator(actionTypes.REQUEST_SAVE_EDIT_EVENT_DATA_ENTRY)({ itemId, dataEntryId, formFoundation, orgUnit }, { skipLogging: ['formFoundation'] });

export const requestSaveEditEventDataEntry = (itemId: string, dataEntryId: string, formFoundation: Object) =>
actionCreator(actionTypes.REQUEST_SAVE_EDIT_EVENT_DATA_ENTRY)(
{ itemId, dataEntryId, formFoundation },
{ skipLogging: ['formFoundation'] },
);

export const startSaveEditEventDataEntry = (
eventId: string,
Expand Down Expand Up @@ -92,7 +93,6 @@ export const requestSaveAndCompleteEnrollment = ({
itemId,
dataEntryId,
formFoundation,
orgUnit,
onSaveAndCompleteEnrollmentExternal,
onSaveAndCompleteEnrollmentSuccessActionType,
onSaveAndCompleteEnrollmentErrorActionType,
Expand All @@ -101,7 +101,6 @@ export const requestSaveAndCompleteEnrollment = ({
itemId: string,
dataEntryId: string,
formFoundation: Object,
orgUnit: OrgUnit,
onSaveAndCompleteEnrollmentExternal?: (enrollmnet: ApiEnrollment) => void,
onSaveAndCompleteEnrollmentSuccessActionType?: string,
onSaveAndCompleteEnrollmentErrorActionType?: string,
Expand All @@ -112,7 +111,6 @@ export const requestSaveAndCompleteEnrollment = ({
itemId,
dataEntryId,
formFoundation,
orgUnit,
onSaveAndCompleteEnrollmentExternal,
onSaveAndCompleteEnrollmentSuccessActionType,
onSaveAndCompleteEnrollmentErrorActionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ import {
showEditEventDataEntry,
} from '../../Pages/ViewEvent/EventDetailsSection/eventDetails.actions';
import { buildUrlQueryString } from '../../../utils/routing/buildUrlQueryString';

import {
updateEventContainer,
} from '../../Pages/ViewEvent/ViewEventComponent/viewEvent.actions';
import { newEventWidgetActionTypes } from '../../WidgetEnrollmentEventNew/Validated/validated.actions';
import { enrollmentEditEventActionTypes } from '../../Pages/EnrollmentEditEvent';

Expand Down Expand Up @@ -90,7 +86,6 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore)
dataEntryId,
itemId,
formFoundation,
orgUnit,
} = action.payload;
const state = store.value;
const dataEntryKey = getDataEntryKey(dataEntryId, itemId);
Expand Down Expand Up @@ -149,29 +144,33 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore)

if (program instanceof TrackerProgram) {
return batchActions([
updateEventContainer(eventContainer, orgUnit),
updateEnrollmentEvent(eventId, serverData.events[0]),
startSaveEditEventDataEntry(eventId, serverData, enrollmentSiteActionTypes.COMMIT_ENROLLMENT_EVENT, enrollmentSiteActionTypes.ROLLBACK_ENROLLMENT_EVENT),
], batchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH);
}
return batchActions([
updateEventContainer(eventContainer, orgUnit),
startSaveEditEventDataEntry(eventId, serverData),
], batchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH);
}));

export const saveEditedEventSucceededEpic = (action$: InputObservable) =>
action$.pipe(
ofType(actionTypes.EDIT_EVENT_DATA_ENTRY_SAVED),
filter((action) => {
const {
meta: { triggerAction },
} = action;
return (
triggerAction === enrollmentSiteActionTypes.COMMIT_ENROLLMENT_EVENT ||
triggerAction === enrollmentEditEventActionTypes.EVENT_SAVE_ENROLLMENT_COMPLETE_SUCCESS
);
}),
map((action) => {
const meta = action.meta;
if (meta.triggerAction === enrollmentSiteActionTypes.COMMIT_ENROLLMENT_EVENT) {
return commitEnrollmentEvent(meta.eventId);
}
if (meta.triggerAction === enrollmentEditEventActionTypes.EVENT_SAVE_ENROLLMENT_COMPLETE_SUCCESS) {
return commitEnrollmentAndEvents();
}
return EMPTY;
return commitEnrollmentEvent(meta.eventId);
}));

export const saveEditedEventFailedEpic = (action$: InputObservable, store: ReduxStore) =>
Expand All @@ -189,20 +188,19 @@ export const saveEditedEventFailedEpic = (action$: InputObservable, store: Redux
const meta = action.meta;
const viewEventPage = state.viewEventPage;
const eventContainer = viewEventPage.loadedValues.eventContainer;
const orgUnit = state.organisationUnits[eventContainer.event.orgUnitId];
if (eventContainer.event && eventContainer.event.attributeCategoryOptions) {
eventContainer.event.attributeCategoryOptions =
convertCategoryOptionsToServer(eventContainer.event.attributeCategoryOptions);
}
let actions = [updateEventContainer(eventContainer, orgUnit)];
let actions = [];

if (meta.triggerAction === enrollmentSiteActionTypes.ROLLBACK_ENROLLMENT_EVENT) {
actions = [...actions, rollbackEnrollmentEvent(eventContainer.event.eventId)];
}
if (meta.triggerAction === enrollmentEditEventActionTypes.EVENT_SAVE_ENROLLMENT_COMPLETE_ERROR) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed into else if, which in turn let us avoid using spread syntax on actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the unnecessary spread syntax on actions. Thanks for the feedback!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more efficient to use else if as well here (because then the second condition will not get evaluated whenever the first one evaluates to true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The code should be updated now. Thanks!

actions = [...actions, rollbackEnrollmentAndEvents()];
}
return batchActions(actions);
return batchActions(actions, batchActionTypes.SAVE_EDIT_EVENT_DATA_ENTRY_FAILED);
}));

export const requestDeleteEventDataEntryEpic = (action$: InputObservable, store: ReduxStore, dependencies: any) =>
Expand Down Expand Up @@ -248,7 +246,6 @@ export const saveEventAndCompleteEnrollmentEpic = (action$: InputObservable, sto
itemId,
dataEntryId,
formFoundation,
orgUnit,
onSaveAndCompleteEnrollmentExternal,
onSaveAndCompleteEnrollmentSuccessActionType,
onSaveAndCompleteEnrollmentErrorActionType,
Expand Down Expand Up @@ -277,18 +274,6 @@ export const saveEventAndCompleteEnrollmentEpic = (action$: InputObservable, sto
mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment());
}

const { eventContainer: prevEventContainer } = state.viewEventPage.loadedValues;
const eventContainer = {
...prevEventContainer,
event: {
...prevEventContainer.event,
...dataEntryClientValues,
},
values: {
...formClientValues,
},
};

const editEvent = {
...mainDataServerValues,
attributeOptionCombo: undefined,
Expand All @@ -308,7 +293,6 @@ export const saveEventAndCompleteEnrollmentEpic = (action$: InputObservable, sto

onSaveAndCompleteEnrollmentExternal && onSaveAndCompleteEnrollmentExternal(enrollmentWithAllEvents);
return batchActions([
updateEventContainer(eventContainer, orgUnit),
startSaveEditEventDataEntry(
eventId,
serverData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@ export const loadViewEventDataEntryEpic = (action$: InputObservable, store: Redu
viewEventPageActionTypes.ORG_UNIT_RETRIEVED_ON_URL_UPDATE,
viewEventPageActionTypes.ORG_UNIT_RETRIEVAL_FAILED_ON_URL_UPDATE,
viewEventPageActionTypes.START_OPEN_EVENT_FOR_VIEW,
viewEventPageActionTypes.UPDATE_EVENT_CONTAINER,
editEventDataEntryBatchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH,
),
filter(action =>
filterByInnerAction(
action,
editEventDataEntryBatchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH,
viewEventPageActionTypes.UPDATE_EVENT_CONTAINER,
),
),
map(action =>
mapToInnerAction(
action,
editEventDataEntryBatchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH,
viewEventPageActionTypes.UPDATE_EVENT_CONTAINER,
),
),
filter((action) => {
Expand Down
Loading
Loading