From df7011f883d1bc5480acf36b8e50a0fb78952708 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Wed, 6 Nov 2024 12:56:16 +0100 Subject: [PATCH] feat: image and file for event and tracked entity --- .../EventDetailsSection/EventDetailsSection.component.js | 4 +++- .../EventDetailsSection/EventDetailsSection.container.js | 1 + .../WidgetProfile/OverflowMenu/OverflowMenu.component.js | 2 ++ .../WidgetProfile/OverflowMenu/OverflowMenu.container.js | 2 ++ .../WidgetProfile/OverflowMenu/OverflowMenu.types.js | 3 +++ .../TrackedEntityChangelogWrapper.component.js | 8 +++++++- .../TrackedEntityChangelogWrapper.types.js | 1 + .../components/WidgetProfile/WidgetProfile.component.js | 1 + .../WidgetTrackedEntityChangelog.js | 4 +++- .../WidgetsChangelog/common/hooks/useClientDataValues.js | 4 +++- .../common/utils/getSubValueForChangelogData.js | 2 +- 11 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.component.js b/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.component.js index ed8d5bff52..30af8fca67 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.component.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.component.js @@ -56,6 +56,7 @@ const getStyles = () => ({ type Props = { showEditEvent: ?boolean, eventId: string, + eventData: Object, onOpenEditEvent: (orgUnit: Object, programCategory: ?ProgramCategory) => void, programStage: ProgramStage, eventAccess: { read: boolean, write: boolean }, @@ -76,6 +77,7 @@ const EventDetailsSectionPlain = (props: Props) => { const { classes, eventId, + eventData, onOpenEditEvent, showEditEvent, programStage, @@ -200,7 +202,7 @@ const EventDetailsSectionPlain = (props: Props) => { diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.container.js b/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.container.js index e57972d6bc..46c97da75d 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.container.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/EventDetailsSection/EventDetailsSection.container.js @@ -10,6 +10,7 @@ import type { ProgramCategory } from '../../../WidgetEventSchedule/CategoryOptio const mapStateToProps = (state: ReduxState) => ({ showEditEvent: state.viewEventPage.eventDetailsSection && state.viewEventPage.eventDetailsSection.showEditEvent, eventId: state.viewEventPage.eventId, + eventData: state.viewEventPage.loadedValues?.eventContainer?.values || {}, programId: state.currentSelections.programId, }); diff --git a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.component.js b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.component.js index e711f1a1f7..faf83dfe91 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.component.js +++ b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.component.js @@ -9,6 +9,7 @@ import { TrackedEntityChangelogWrapper } from './TrackedEntityChangelogWrapper'; export const OverflowMenuComponent = ({ trackedEntity, + trackedEntityData, trackedEntityTypeName, canWriteData, canCascadeDeleteTei, @@ -68,6 +69,7 @@ export const OverflowMenuComponent = ({ programAPI={programAPI} isOpen={changelogIsOpen} setIsOpen={setChangelogIsOpen} + trackedEntityData={trackedEntityData} /> )} diff --git a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.container.js b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.container.js index 031f7fd462..38d17ad0c0 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.container.js +++ b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.container.js @@ -8,6 +8,7 @@ export const OverflowMenu = ({ trackedEntityTypeName, canWriteData, trackedEntity, + trackedEntityData, onDeleteSuccess, displayChangelog, teiId, @@ -21,6 +22,7 @@ export const OverflowMenu = ({ canWriteData={canWriteData} canCascadeDeleteTei={hasAuthority} trackedEntity={trackedEntity} + trackedEntityData={trackedEntityData} onDeleteSuccess={onDeleteSuccess} displayChangelog={displayChangelog} teiId={teiId} diff --git a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.types.js b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.types.js index ad3cc687d4..cfa6a518a3 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.types.js +++ b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/OverflowMenu.types.js @@ -3,7 +3,9 @@ export type Props = {| trackedEntity: { trackedEntity: string }, trackedEntityTypeName: string, + trackedEntityData: Object, canWriteData: boolean, + trackedEntityData: Object, onDeleteSuccess?: () => void, displayChangelog: boolean, teiId: string, @@ -13,6 +15,7 @@ export type Props = {| export type PlainProps = {| trackedEntity: { trackedEntity: string }, trackedEntityTypeName: string, + trackedEntityData: Object, canWriteData: boolean, canCascadeDeleteTei: boolean, onDeleteSuccess?: () => void, diff --git a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.component.js b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.component.js index 1dc3172af6..27db89634d 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.component.js +++ b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.component.js @@ -5,9 +5,14 @@ import { useFormFoundation } from '../../DataEntry/hooks'; import { WidgetTrackedEntityChangelog } from '../../../WidgetsChangelog'; import type { Props } from './TrackedEntityChangelogWrapper.types'; -export const TrackedEntityChangelogWrapper = ({ programAPI, teiId, setIsOpen, ...passOnProps }: Props) => { +export const TrackedEntityChangelogWrapper = ({ programAPI, teiId, setIsOpen, trackedEntityData, ...passOnProps }: Props) => { const formFoundation: RenderFoundation = useFormFoundation(programAPI); + const transformedTrackedEntityData = trackedEntityData.reduce((acc, item) => { + acc[item.attribute] = item.value; + return acc; + }, {}); + const dataItemDefinitions = useMemo(() => { if (!Object.keys(formFoundation)?.length) return {}; const elements = formFoundation.getElements(); @@ -58,6 +63,7 @@ export const TrackedEntityChangelogWrapper = ({ programAPI, teiId, setIsOpen, .. close={() => setIsOpen(false)} programId={programAPI.id} dataItemDefinitions={dataItemDefinitions} + trackedEntityData={transformedTrackedEntityData} /> ); }; diff --git a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.types.js b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.types.js index e0bb62461f..c2c5d726f4 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.types.js +++ b/src/core_modules/capture-core/components/WidgetProfile/OverflowMenu/TrackedEntityChangelogWrapper/TrackedEntityChangelogWrapper.types.js @@ -5,6 +5,7 @@ type PassOnProps = {| teiId: string, isOpen: boolean, setIsOpen: (boolean | boolean => boolean) => void, + trackedEntityData: Object, |} export type Props = { diff --git a/src/core_modules/capture-core/components/WidgetProfile/WidgetProfile.component.js b/src/core_modules/capture-core/components/WidgetProfile/WidgetProfile.component.js index 0204ac19a7..0775de1ef4 100644 --- a/src/core_modules/capture-core/components/WidgetProfile/WidgetProfile.component.js +++ b/src/core_modules/capture-core/components/WidgetProfile/WidgetProfile.component.js @@ -162,6 +162,7 @@ const WidgetProfilePlain = ({ trackedEntity={trackedEntity} onDeleteSuccess={onDeleteSuccess} displayChangelog={displayChangelog} + trackedEntityData={trackedEntityInstanceAttributes} teiId={teiId} programAPI={program} /> diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/WidgetTrackedEntityChangelog/WidgetTrackedEntityChangelog.js b/src/core_modules/capture-core/components/WidgetsChangelog/WidgetTrackedEntityChangelog/WidgetTrackedEntityChangelog.js index c76e01ee74..a28370ea35 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/WidgetTrackedEntityChangelog/WidgetTrackedEntityChangelog.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/WidgetTrackedEntityChangelog/WidgetTrackedEntityChangelog.js @@ -9,18 +9,20 @@ type Props = { dataItemDefinitions: ItemDefinitions, isOpen: boolean, close: () => void, + trackedEntityData: Object, } export const WidgetTrackedEntityChangelog = ({ teiId, programId, close, + trackedEntityData, ...passOnProps }: Props) => ( { if (!getSubValue) { diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/utils/getSubValueForChangelogData.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/utils/getSubValueForChangelogData.js index 07e0b598ce..ebf739818b 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/utils/getSubValueForChangelogData.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/utils/getSubValueForChangelogData.js @@ -38,7 +38,7 @@ const buildTEAUrlByElementType: {| const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` }); if (!latestValue) { - return 'name'; + return 'File'; } return {