From 7487a3ae594b3878b3c351a9a428ae10358fd6d7 Mon Sep 17 00:00:00 2001 From: Tony Valle Date: Mon, 30 Oct 2023 16:02:37 +0100 Subject: [PATCH] feat: display assigned users on the events in enrollment overview --- .../Stages/Stage/Stage.component.js | 3 ++- .../Stages/Stage/StageDetail/StageDetail.component.js | 3 ++- .../Stages/Stage/StageDetail/hooks/useEventList.js | 11 +++++++---- .../Stages/Stage/StageDetail/stageDetail.types.js | 1 + .../capture-core/converters/clientToList.js | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/Stage.component.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/Stage.component.js index f8a8908b20..55daffa89a 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/Stage.component.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/Stage.component.js @@ -30,7 +30,7 @@ const hideProgramStage = (ruleEffects, stageId) => ( export const StagePlain = ({ stage, events, classes, className, onCreateNew, ruleEffects, ...passOnProps }: Props) => { const [open, setOpenStatus] = useState(true); - const { id, name, icon, description, dataElements, hideDueDate, repeatable } = stage; + const { id, name, icon, description, dataElements, hideDueDate, repeatable, enableUserAssignment } = stage; const hiddenProgramStage = hideProgramStage(ruleEffects, id); return ( @@ -57,6 +57,7 @@ export const StagePlain = ({ stage, events, classes, className, onCreateNew, rul dataElements={dataElements} hideDueDate={hideDueDate} repeatable={repeatable} + enableUserAssignment={enableUserAssignment} onCreateNew={onCreateNew} hiddenProgramStage={hiddenProgramStage} {...passOnProps} diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/StageDetail.component.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/StageDetail.component.js index 6d5da181fa..633ed75b08 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/StageDetail.component.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/StageDetail.component.js @@ -66,6 +66,7 @@ const StageDetailPlain = (props: Props) => { dataElements, hideDueDate = false, repeatable = false, + enableUserAssignment = false, onEventClick, onViewAll, onCreateNew, @@ -76,7 +77,7 @@ const StageDetailPlain = (props: Props) => { sortDirection: SORT_DIRECTION.DESC, }; const { stage } = getProgramAndStageForProgram(programId, stageId); - const headerColumns = useComputeHeaderColumn(dataElements, hideDueDate, stage?.stageForm); + const headerColumns = useComputeHeaderColumn(dataElements, hideDueDate, enableUserAssignment, stage?.stageForm); const { loading, value: dataSource, error } = useComputeDataFromEvent(dataElements, events); diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js index ab47615397..a41287ad73 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js @@ -18,10 +18,11 @@ import { import { SORT_DIRECTION, MULIT_TEXT_WITH_NO_OPTIONS_SET } from './constants'; import { isNotValidOptionSet } from '../../../../../../utils/isNotValidOptionSet'; -const baseKeys = [{ id: 'status' }, { id: 'occurredAt' }, { id: 'orgUnitName' }, { id: 'scheduledAt' }, { id: 'comments' }]; +const baseKeys = [{ id: 'status' }, { id: 'occurredAt' }, { id: 'assignedUser' }, { id: 'orgUnitName' }, { id: 'scheduledAt' }, { id: 'comments' }]; const basedFieldTypes = [ { type: dataElementTypes.STATUS, resolveValue: convertStatusForView }, { type: dataElementTypes.DATE }, + { type: 'ASSIGNEE' }, { type: dataElementTypes.TEXT }, { type: dataElementTypes.DATE }, { type: dataElementTypes.UNKNOWN, resolveValue: convertCommentForView }, @@ -29,6 +30,7 @@ const basedFieldTypes = [ const getBaseColumnHeaders = props => [ { header: i18n.t('Status'), sortDirection: SORT_DIRECTION.DEFAULT, isPredefined: true }, { header: props.formFoundation.getLabel('occurredAt'), sortDirection: SORT_DIRECTION.DEFAULT, isPredefined: true }, + { header: i18n.t('Assigned to'), sortDirection: SORT_DIRECTION.DEFAULT, isPredefined: true }, { header: i18n.t('Registering unit'), sortDirection: SORT_DIRECTION.DEFAULT, isPredefined: true }, { header: props.formFoundation.getLabel('scheduledAt'), sortDirection: SORT_DIRECTION.DEFAULT, isPredefined: true }, { header: '', sortDirection: null, isPredefined: true }, @@ -110,7 +112,7 @@ const useComputeDataFromEvent = (dataElements: Array, events: }; -const useComputeHeaderColumn = (dataElements: Array, hideDueDate: boolean, formFoundation: Object) => { +const useComputeHeaderColumn = (dataElements: Array, hideDueDate: boolean, enableUserAssignment: boolean, formFoundation: Object) => { const headerColumns = useMemo(() => { const dataElementHeaders = dataElements.reduce((acc, currDataElement) => { const { id, name, formName, type, optionSet } = currDataElement; @@ -124,9 +126,10 @@ const useComputeHeaderColumn = (dataElements: Array, hideDueDa return acc; }, []); return [ - ...getBaseColumns({ formFoundation }).filter(col => (hideDueDate ? col.id !== 'scheduledAt' : true)), + ...getBaseColumns({ formFoundation }) + .filter(col => (enableUserAssignment || col.id !== 'assignedUser') && (!hideDueDate || col.id !== 'scheduledAt')), ...dataElementHeaders]; - }, [dataElements, hideDueDate, formFoundation]); + }, [dataElements, hideDueDate, enableUserAssignment, formFoundation]); return headerColumns; }; diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/stageDetail.types.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/stageDetail.types.js index a5edeeab75..31d8c79dea 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/stageDetail.types.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/stageDetail.types.js @@ -7,6 +7,7 @@ import type { StageDataElement, StageCommonProps } from '../../../types/common.t eventName: string, hideDueDate?: boolean, repeatable?: boolean, + enableUserAssignment?: boolean, stageId: string, hiddenProgramStage?: boolean, ...CssClasses, diff --git a/src/core_modules/capture-core/converters/clientToList.js b/src/core_modules/capture-core/converters/clientToList.js index ff6a7b3825..ff78d99f5c 100644 --- a/src/core_modules/capture-core/converters/clientToList.js +++ b/src/core_modules/capture-core/converters/clientToList.js @@ -92,7 +92,7 @@ const valueConvertersForType = { [dataElementTypes.FILE_RESOURCE]: convertResourceForDisplay, [dataElementTypes.IMAGE]: convertResourceForDisplay, [dataElementTypes.ORGANISATION_UNIT]: (rawValue: Object) => rawValue.name, - [dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name} (${rawValue.username})`, + [dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name || rawValue.displayName} (${rawValue.username})`, [dataElementTypes.NUMBER_RANGE]: convertNumberRangeForDisplay, [dataElementTypes.STATUS]: convertStatusForDisplay, };