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-15480] widget assignee #3412

Merged
merged 29 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
03170ab
feat: widget assignee
simonadomnisoru Sep 13, 2023
fa263d7
Merge branch 'master' into DHIS2-15480
simonadomnisoru Sep 13, 2023
0282008
chore: improve displaymodel types
simonadomnisoru Oct 11, 2023
0170414
Merge branch 'master' into DHIS2-15480
simonadomnisoru Oct 11, 2023
4cf93f5
feat: remove redux and use app runtime hooks and callbacks
simonadomnisoru Nov 1, 2023
929c7e7
Merge branch 'master' into DHIS2-15480
simonadomnisoru Nov 1, 2023
e0d91ad
chore: split enrollment event page
simonadomnisoru Nov 1, 2023
fdf9f23
Merge branch 'master' into DHIS2-15480
simonadomnisoru Nov 1, 2023
af609d0
chore: improve converters
simonadomnisoru Nov 3, 2023
fac65a1
chore: simplify widget assignee props
simonadomnisoru Nov 14, 2023
fd3974e
chore: disable action buttons in the read-only mode
simonadomnisoru Nov 14, 2023
52ae166
feat: add delete assigned user functionality
simonadomnisoru Nov 15, 2023
f353687
Merge branch 'master' into DHIS2-15480
simonadomnisoru Nov 15, 2023
95453dd
chore: clean trackedEntityInstance
simonadomnisoru Dec 4, 2023
feb615a
Merge branch 'master' into DHIS2-15480
simonadomnisoru Dec 4, 2023
7a5ffe3
chore: clean trackedEntityInstance from payload
simonadomnisoru Dec 4, 2023
667b1cb
fix: hide assignee in form when rescheaduling an event
simonadomnisoru Dec 4, 2023
97588ac
Merge branch 'master' into DHIS2-15480
simonadomnisoru Jan 8, 2024
6ee56dd
Merge branch 'master' into DHIS2-15480
simonadomnisoru Jan 22, 2024
6aac3b8
chore: remove on prefix
simonadomnisoru Jan 22, 2024
2bcd8e3
feat: use UserAvatar component
simonadomnisoru Jan 22, 2024
3bd6cd0
chore: remove eventIdSelector
simonadomnisoru Jan 22, 2024
da212bc
feat: get the user avatar id with react query
simonadomnisoru Jan 23, 2024
c96bac8
fix: wait for the user avatar to load
simonadomnisoru Jan 23, 2024
27d4ce2
chore: apply mockup css properties
simonadomnisoru Jan 23, 2024
1290bfc
Merge branch 'master' into DHIS2-15480
simonadomnisoru Jan 23, 2024
8529d35
test: fix 2.38 cypress failures
simonadomnisoru Jan 23, 2024
c272d46
test: scenario for removing the assigned user
simonadomnisoru Jan 23, 2024
094b32e
fix: fallback to firstname and surname
simonadomnisoru Jan 25, 2024
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
@@ -0,0 +1,33 @@
When('you assign the user Geetha in the view mode', () => {
cy.get('[data-test="widget-assignee"]').within(() => {
cy.get('[data-test="widget-assignee-edit"]').click();
cy.get('[data-test="capture-ui-input"]').type('Geetha');
cy.contains('Geetha Alwan').click();
});
});

When('you assign the user Tracker demo User in the edit mode', () => {
cy
.get('[data-test="widget-enrollment-event"]')
.find('[data-test="dhis2-uicore-button"]')
.eq(1)
.click();

cy.get('[data-test="widget-assignee"]').within(() => {
cy.get('[data-test="widget-assignee-edit"]').click();
cy.get('[data-test="capture-ui-input"]').type('Tracker demo');
cy.contains('Tracker demo User').click();
});
});

Then('the event has the user Geetha Alwan assigned', () => {
cy.get('[data-test="widget-assignee"]').within(() => {
cy.get('[data-test="widget-contents"]').contains('Geetha Alwan').should('exist');
});
});

Then('the event has the user Tracker demo User assigned', () => {
cy.get('[data-test="widget-assignee"]').within(() => {
cy.get('[data-test="widget-contents"]').contains('Tracker demo User').should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ Feature: The user interacts with the widgets on the enrollment edit event
Given you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=XGLkLlOXgmE&orgUnitId=DiszpKrYNg8
Then the enrollment widget should be loaded
When you click edit mode
Then list should contain the new comment: new test comment
Then list should contain the new comment: new test comment

Scenario: You can assign a user to a event
Given you land on the enrollment edit event page by having typed /#/enrollmentEventEdit?eventId=SObENdEf76z&orgUnitId=g8upMTyEZGZ
When you assign the user Geetha in the view mode
Then the event has the user Geetha Alwan assigned
When you assign the user Tracker demo User in the edit mode
Then the event has the user Tracker demo User assigned
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ import '../sharedSteps';
import '../WidgetEnrollment';
import '../WidgetProfile';
import '../WidgetEventComment';
import '../WidgetAssignee';

25 changes: 14 additions & 11 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-09-29T14:14:34.330Z\n"
"PO-Revision-Date: 2023-09-29T14:14:34.330Z\n"
"POT-Creation-Date: 2023-10-11T07:28:55.943Z\n"
"PO-Revision-Date: 2023-10-11T07:28:55.943Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -923,15 +923,6 @@ msgstr ""
"Leaving this page will discard any selections you made for a new "
"relationship"

msgid "No one is assigned to this event"
msgstr "No one is assigned to this event"

msgid "Assign"
msgstr "Assign"

msgid "Event assigned to {{name}}"
msgstr "Event assigned to {{name}}"

msgid "Feedbacks"
msgstr "Feedbacks"

Expand Down Expand Up @@ -1104,6 +1095,15 @@ msgstr "To work with the selected program,"
msgid "open the Tracker Capture app"
msgstr "open the Tracker Capture app"

msgid "Event assigned to {{name}}"
msgstr "Event assigned to {{name}}"

msgid "Assign"
msgstr "Assign"

msgid "No one is assigned to this event"
msgstr "No one is assigned to this event"

msgid "This program is protected"
msgstr "This program is protected"

Expand Down Expand Up @@ -1512,6 +1512,9 @@ msgstr "Error deleting the enrollment event"
msgid "Error editing the event, the changes made were not saved"
msgstr "Error editing the event, the changes made were not saved"

msgid "Error updating the Assignee"
msgstr "Error updating the Assignee"

msgid "Set coordinate"
msgstr "Set coordinate"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// @flow
export { UserField } from './UserField.component';
export { UserSearch } from './UserSearch.component';
export type { User as UserFormField } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { WidgetFeedback } from '../../WidgetFeedback';
import { WidgetIndicator } from '../../WidgetIndicator';
import { WidgetProfile } from '../../WidgetProfile';
import { WidgetEnrollment } from '../../WidgetEnrollment';
import { WidgetAssignee } from '../../WidgetAssignee';
import { IncompleteSelectionsMessage } from '../../IncompleteSelectionsMessage';
import { WidgetEventComment } from '../../WidgetEventComment';
import { OrgUnitFetcher } from '../../OrgUnitFetcher';
Expand Down Expand Up @@ -66,11 +67,14 @@ const EnrollmentEditEventPagePain = ({
eventDate,
scheduleDate,
eventStatus,
eventAccess,
assignee,
pageStatus,
onEnrollmentError,
onEnrollmentSuccess,
onCancelEditEvent,
onHandleScheduleSave,
onGetAssignedUserSaveContext,
}: PlainProps) => (
<OrgUnitFetcher orgUnitId={orgUnitId}>
<TopBar
Expand Down Expand Up @@ -118,6 +122,12 @@ const EnrollmentEditEventPagePain = ({
)}
</div>
<div className={classes.rightColumn}>
<WidgetAssignee
programStage={programStage}
assignee={assignee}
onGetSaveContext={onGetAssignedUserSaveContext}
eventAccess={eventAccess}
/>
<WidgetEventComment dataEntryKey={mode} dataEntryId={dataEntryIds.ENROLLMENT_EVENT} />
<WidgetError error={widgetEffects.errors} />
<WidgetWarning warning={widgetEffects.warnings} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import { changeEventFromUrl } from '../ViewEvent/ViewEventComponent/viewEvent.ac
import { buildEnrollmentsAsOptions } from '../../ScopeSelector';
import { convertDateWithTimeForView, convertValue } from '../../../converters/clientToView';
import { dataElementTypes } from '../../../metaData/DataElement';
import { useEvent } from './hooks';
import { useEvent, useAssignee, useAssignedUserSaveContext } from './hooks';
import type { Props } from './EnrollmentEditEventPage.types';
import { LoadingMaskForPage } from '../../LoadingMasks';
import { cleanUpDataEntry } from '../../DataEntry';
import { pageKeys } from '../../App/withAppUrlSync';
import { withErrorMessageHandler } from '../../../HOC';
import { getProgramEventAccess } from '../../../metaData';

const getEventDate = (event) => {
const eventDataConvertValue = convertDateWithTimeForView(event?.occurredAt || event?.scheduledAt);
Expand Down Expand Up @@ -134,6 +135,7 @@ const EnrollmentEditEventPageWithContextPlain = ({
const { currentPageMode } = useEnrollmentEditEventPageMode(event?.status);
const dataEntryKey = `${dataEntryIds.ENROLLMENT_EVENT}-${currentPageMode}`;
const outputEffects = useWidgetDataFromStore(dataEntryKey);
const eventAccess = getProgramEventAccess(programId, programStage?.id);

const pageStatus = getPageStatus({
orgUnitId,
Expand All @@ -143,6 +145,8 @@ const EnrollmentEditEventPageWithContextPlain = ({
programStage,
event,
});
const assignee = useAssignee(event);
const onGetAssignedUserSaveContext = useAssignedUserSaveContext(enrollmentSite, event, eventId);

return (
<EnrollmentEditEventPageComponent
Expand All @@ -162,12 +166,15 @@ const EnrollmentEditEventPageWithContextPlain = ({
onAddNew={onAddNew}
orgUnitId={orgUnitId}
eventDate={eventDate}
assignee={assignee}
onEnrollmentError={onEnrollmentError}
onEnrollmentSuccess={onEnrollmentSuccess}
eventStatus={event?.status}
eventAccess={eventAccess}
scheduleDate={scheduleDate}
onCancelEditEvent={onCancelEditEvent}
onHandleScheduleSave={onHandleScheduleSave}
onGetAssignedUserSaveContext={onGetAssignedUserSaveContext}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import type { ProgramStage } from '../../../metaData';
import type { WidgetEffects, HideWidgets } from '../common/EnrollmentOverviewDomain';
import type { UserFormField } from '../../FormFields/UserField';

export type PlainProps = {|
programStage: ?ProgramStage,
Expand All @@ -25,6 +26,16 @@ export type PlainProps = {|
onHandleScheduleSave: (eventData: Object) => void,
pageStatus: string,
eventStatus?: string,
eventAccess: {|
read: boolean,
write: boolean,
|} | null,
onGetAssignedUserSaveContext: (assignee: UserFormField) => {
eventId: string,
events: Array<ApiEnrollmentEvent>,
assignedUser?: ApiAssignedUser,
},
assignee: UserFormField | null,
...CssClasses,
|};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// @flow
export { useEvent } from './useEvent';
export { useAssignee, useAssignedUserSaveContext } from './useAssignedUserSaveContext';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
import { useCallback, useMemo } from 'react';
import { convertServerToClient, convertClientToServer } from '../../../WidgetAssignee';
import type { EnrollmentData } from '../../common/EnrollmentOverviewDomain/useCommonEnrollmentDomainData';
import type { UserFormField } from '../../../FormFields/UserField';

export const useAssignee = (event?: ApiEnrollmentEvent) =>
useMemo(() => convertServerToClient(event?.assignedUser), [event?.assignedUser]);

export const useAssignedUserSaveContext = (
enrollmentSite?: EnrollmentData,
event?: ApiEnrollmentEvent,
eventId: string,
) =>
useCallback(
(newAssignee: UserFormField) => ({
eventId,
assignedUser: event?.assignedUser,
events: enrollmentSite?.events
// $FlowFixMe[missing-annot]
? enrollmentSite.events.map(e => (
e.event === eventId ? { ...e, assignedUser: convertClientToServer(newAssignee) } : e
))
: [],
}),
[enrollmentSite?.events, event?.assignedUser, eventId],
);

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading