Skip to content

Commit

Permalink
feat: image and file for event and tracked entity
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Nov 6, 2024
1 parent 292ff79 commit df7011f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -76,6 +77,7 @@ const EventDetailsSectionPlain = (props: Props) => {
const {
classes,
eventId,
eventData,
onOpenEditEvent,
showEditEvent,
programStage,
Expand Down Expand Up @@ -200,7 +202,7 @@ const EventDetailsSectionPlain = (props: Props) => {
<EventChangelogWrapper
isOpen
setIsOpen={setChangeLogIsOpen}
eventData={{}}
eventData={eventData}
eventId={eventId}
formFoundation={programStage.stageForm}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TrackedEntityChangelogWrapper } from './TrackedEntityChangelogWrapper';

export const OverflowMenuComponent = ({
trackedEntity,
trackedEntityData,
trackedEntityTypeName,
canWriteData,
canCascadeDeleteTei,
Expand Down Expand Up @@ -68,6 +69,7 @@ export const OverflowMenuComponent = ({
programAPI={programAPI}
isOpen={changelogIsOpen}
setIsOpen={setChangelogIsOpen}
trackedEntityData={trackedEntityData}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const OverflowMenu = ({
trackedEntityTypeName,
canWriteData,
trackedEntity,
trackedEntityData,
onDeleteSuccess,
displayChangelog,
teiId,
Expand All @@ -21,6 +22,7 @@ export const OverflowMenu = ({
canWriteData={canWriteData}
canCascadeDeleteTei={hasAuthority}
trackedEntity={trackedEntity}
trackedEntityData={trackedEntityData}
onDeleteSuccess={onDeleteSuccess}
displayChangelog={displayChangelog}
teiId={teiId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
export type Props = {|
trackedEntity: { trackedEntity: string },
trackedEntityTypeName: string,
trackedEntityData: Object,
canWriteData: boolean,
trackedEntityData: Object,
onDeleteSuccess?: () => void,
displayChangelog: boolean,
teiId: string,
Expand All @@ -13,6 +15,7 @@ export type Props = {|
export type PlainProps = {|
trackedEntity: { trackedEntity: string },
trackedEntityTypeName: string,
trackedEntityData: Object,
canWriteData: boolean,
canCascadeDeleteTei: boolean,
onDeleteSuccess?: () => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -58,6 +63,7 @@ export const TrackedEntityChangelogWrapper = ({ programAPI, teiId, setIsOpen, ..
close={() => setIsOpen(false)}
programId={programAPI.id}
dataItemDefinitions={dataItemDefinitions}
trackedEntityData={transformedTrackedEntityData}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type PassOnProps = {|
teiId: string,
isOpen: boolean,
setIsOpen: (boolean | boolean => boolean) => void,
trackedEntityData: Object,
|}

export type Props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const WidgetProfilePlain = ({
trackedEntity={trackedEntity}
onDeleteSuccess={onDeleteSuccess}
displayChangelog={displayChangelog}
trackedEntityData={trackedEntityInstanceAttributes}
teiId={teiId}
programAPI={program}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ type Props = {
dataItemDefinitions: ItemDefinitions,
isOpen: boolean,
close: () => void,
trackedEntityData: Object,
}

export const WidgetTrackedEntityChangelog = ({
teiId,
programId,
close,
trackedEntityData,
...passOnProps
}: Props) => (
<Changelog
{...passOnProps}
close={close}
entityData={{}}
entityData={trackedEntityData}
entityId={teiId}
programId={programId}
entityType={CHANGELOG_ENTITY_TYPES.TRACKED_ENTITY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const fetchFormattedValues = async ({

const getSubValue = subValueGetterByElementType[RECORD_TYPE[entityType]]?.[metadataElement.type];

const isLatestValue = entityData?.[change.dataElement]?.value === change.currentValue;
const isLatestValue = entityType === RECORD_TYPE.event
? entityData?.[change.dataElement]?.value === change.currentValue
: entityData?.[change.attribute] === change.currentValue;

const getValue = async (value, latestValue) => {
if (!getSubValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const buildTEAUrlByElementType: {|
const { id, displayName: name } = await querySingleResource({ resource: `fileResources/${value}` });

if (!latestValue) {
return 'name';
return 'File';
}

return {
Expand Down

0 comments on commit df7011f

Please sign in to comment.