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

feat: [DHIS2-17192] show related stages widget on registration page #3880

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

simonadomnisoru
Copy link
Contributor

@simonadomnisoru simonadomnisoru commented Nov 14, 2024

DHIS2-17192

Tech summary:

  • Add the Related Stages widget to the registration page and new relationship page. To enable it, the program's "First stage appears on registration page" option must be true, and the first stage should be the from part of a related stages relationship type.
  • Move to DataEntries some common logic and converters
  • The related stage event takes precedence over the openAfterEnrollment flag
  • The related stage event takes precedence over the autogenerate flag
  • Cypress tests will be added in DHIS2-17853

@simonadomnisoru simonadomnisoru changed the title feat: [DHIS2-17192] show related stages Widget on registration page feat: [DHIS2-17192] show related stages widget on registration page Nov 14, 2024
@simonadomnisoru simonadomnisoru marked this pull request as ready for review November 14, 2024 13:49
@simonadomnisoru simonadomnisoru requested a review from a team as a code owner November 14, 2024 13:49
@simonadomnisoru simonadomnisoru marked this pull request as draft November 26, 2024 11:17
@simonadomnisoru simonadomnisoru marked this pull request as ready for review December 2, 2024 14:49
Copy link
Contributor

@henrikmv henrikmv left a comment

Choose a reason for hiding this comment

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

Good work!

Comment on lines 16 to 17
'../../common/TEIRelationshipsWidget/RegisterTei/DataEntry/TrackedEntityInstance/dataEntryTrackedEntityInstance.types';

Copy link
Contributor

Choose a reason for hiding this comment

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

Can TeiPayload be exported through the existing index file in the folder?

errorMessages,
saveAttempted,
actionTypesOptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Not code implemented in this PR, but is it necessary to export the plain function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there is no need to export this function. I fixed it now. Good catch!

@@ -7,7 +7,7 @@ import { handleAPIResponse, REQUESTED_ENTITIES } from '../../../utils/api';

type Props = {
stageId: ?string,
enrollmentId: string,
enrollmentId?: string,
scheduledLabel: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

The property is always defined, but the value can be undefined.

Suggested change
scheduledLabel: string,
enrollmentId: ?string,

Copy link
Member

@JoakimSM JoakimSM left a comment

Choose a reason for hiding this comment

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

Looks really solid overall @simonadomnisoru! I have a few suggestions for adjustments here and there.

ref={relatedStageRef}
programId={passOnProps.programId}
programStageId={firstStageMetaData.stage?.id}
actionTypesOptions={relatedStageModesOptions}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to stick with either "action" or "mode" throughout? For this particular one, if we stick with actions: actionsOptions={relatedStageActionsOptions}

(I see that both mode and action are being used in code not introduced by this PR, would be great to fix those as well)

I do like the generic approach you have chosen here though 👍 Nice!

Comment on lines 186 to 189
programStageIdLinkedEventToRedirectTo:
relatedStageLinkedEvent && linkMode === RelatedStageModes.ENTER_DATA
? relatedStageLinkedEvent.programStage
: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a good time to simplify how we determine what event to redirect to. My suggestion would be that we in this function (buildTeiWithEnrollment) get the eventId for the event. For related stages we are generating the eventId on the client, we will have to do this for auto generated events too. Then we should be able to write the logic to determine the eventId (that we will redirect to). Having the related stage take precedence makes sense to me (like you already did).

This way we can simplify the epics in the chain quite a bit and the code would be easier to reason about.

Might be missing something of course. Happy to talk about it.

@@ -69,7 +68,7 @@ const getEventDetailsByLinkMode = ({
return ({
linkedEvent: {
...baseEventDetails,
scheduledAt: convertFn(clientRequestEvent.scheduledAt, dataElementTypes.DATE),
scheduledAt: clientRequestEvent.scheduledAt,
Copy link
Member

Choose a reason for hiding this comment

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

A bit worried about this change. Based on the naming it seems like we should have converted from clientToServer. Can you verify this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The naming was wrong as the data is in the server format. I renamed the variable to make it less confusing. Thanks for the feedback!

Comment on lines 25 to 28
deriveAutoGenerateEvents,
deriveFirstStageDuringRegistrationEvent,
deriveRelatedStageEvent,
} from '../../../Pages/New/RegistrationDataEntry/helpers';
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the opportunity to move these files to DataEntries/EnrollmentRegistrationEntry/helpers? From what I can see they belong in the DataEntries/EnrollmentRegistrationEntry folder and are only invoked from this file.


const toEntity = entity.id ? entity : getRelationshipNewTei(entity.dataEntryId, entity.itemId, state);
Copy link
Member

Choose a reason for hiding this comment

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

getRelationshipNewTei was dead code I presume? (yes, we need a clean up of relationships)

@simonadomnisoru
Copy link
Contributor Author

Looks really solid overall @simonadomnisoru! I have a few suggestions for adjustments here and there.

@JoakimSM the suggestions have been implemented. Can you have another look? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants