Skip to content

Commit

Permalink
fix: [DHIS2-16994] Image and File DE and TEA not Displayed in Changel…
Browse files Browse the repository at this point in the history
…og (#3837)

* feat: temp

* fix: revert clienttolist changes

* fix: code clean up

* feat: temp

* fix: wrong else statement

* feat: add link for image and file data element

* fix: image and file for tea

* fix: show only latest image and file

* fix: revert change

* fix: update islatestvalue to check for fieldid

* feat: temp

* fix: caching

* fix: ensure text utilizes space without overflow

* fix: add try catch to all query calls

* fix: use storagestatus to find latest value

* fix: string improvement

* Revert "fix: string improvement"

This reverts commit d8a92bf.

* Revert "fix: use storagestatus to find latest value"

This reverts commit 877d489.

* feat: temp

* feat: compare with event data to find latest value

* feat: image and file for event and tracked entity

* fix: performance

* fix: review comments

* fix: review comments

* fix: latest value not shown

* fix: missing question mark
  • Loading branch information
henrikmv authored Nov 19, 2024
1 parent e518064 commit 9327210
Show file tree
Hide file tree
Showing 21 changed files with 414 additions and 110 deletions.
10 changes: 8 additions & 2 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: 2024-11-04T18:45:47.626Z\n"
"PO-Revision-Date: 2024-11-04T18:45:47.626Z\n"
"POT-Creation-Date: 2024-11-07T11:57:59.094Z\n"
"PO-Revision-Date: 2024-11-07T11:57:59.094Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -1547,6 +1547,12 @@ msgstr "Change"
msgid "Value"
msgstr "Value"

msgid "File"
msgstr "File"

msgid "Image"
msgstr "Image"

msgid "New {{trackedEntityTypeName}} relationship"
msgstr "New {{trackedEntityTypeName}} relationship"

Expand Down
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,6 +202,7 @@ const EventDetailsSectionPlain = (props: Props) => {
<EventChangelogWrapper
isOpen
setIsOpen={setChangeLogIsOpen}
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 @@ -5,7 +5,7 @@ import { dataElementTypes } from '../../../metaData';
import type { Props } from './EventChangelogWrapper.types';
import { WidgetEventChangelog } from '../../WidgetsChangelog';

export const EventChangelogWrapper = ({ formFoundation, eventId, ...passOnProps }: Props) => {
export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...passOnProps }: Props) => {
const dataItemDefinitions = useMemo(() => {
const elements = formFoundation.getElements();
const contextLabels = formFoundation.getLabels();
Expand Down Expand Up @@ -52,6 +52,7 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, ...passOnProps
<WidgetEventChangelog
{...passOnProps}
eventId={eventId}
eventData={eventData}
dataItemDefinitions={dataItemDefinitions}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ type PassOnProps = {|
export type Props = {
...PassOnProps,
formFoundation: RenderFoundation,
eventData: Object,
};
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const WidgetEventEditPlain = ({
isOpen
setIsOpen={setChangeLogIsOpen}
eventId={loadedValues.eventContainer.id}
eventData={loadedValues.eventContainer.values}
formFoundation={formFoundation}
/>
)}
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,6 +3,7 @@
export type Props = {|
trackedEntity: { trackedEntity: string },
trackedEntityTypeName: string,
trackedEntityData: Object,
canWriteData: boolean,
onDeleteSuccess?: () => void,
displayChangelog: boolean,
Expand All @@ -13,6 +14,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={clientAttributesWithSubvalues}
teiId={teiId}
programAPI={program}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import { Changelog, CHANGELOG_ENTITY_TYPES } from '../common/Changelog';

type Props = {
eventId: string,
eventData: Object,
dataItemDefinitions: ItemDefinitions,
isOpen: boolean,
setIsOpen: (boolean | boolean => boolean) => void,
}

export const WidgetEventChangelog = ({
eventId,
eventData,
setIsOpen,
...passOnProps
}: Props) => (
<Changelog
{...passOnProps}
close={() => setIsOpen(false)}
entityId={eventId}
entityData={eventData}
entityType={CHANGELOG_ENTITY_TYPES.EVENT}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +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={trackedEntityData}
entityId={teiId}
programId={programId}
entityType={CHANGELOG_ENTITY_TYPES.TRACKED_ENTITY}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
// @flow
import React from 'react';
import { Modal } from '@dhis2/ui';
import { useChangelogData } from '../hooks';
import { useChangelogData, useListDataValues } from '../hooks';
import { ChangelogComponent } from './Changelog.component';
import { CHANGELOG_ENTITY_TYPES } from './index';
import { LoadingMaskElementCenter } from '../../../LoadingMasks';
import type { ItemDefinitions } from './Changelog.types';

type Props = {
entityId: string,
entityData: Object,
entityType: $Values<typeof CHANGELOG_ENTITY_TYPES>,
isOpen: boolean,
close: () => void,
dataItemDefinitions: ItemDefinitions,
programId?: string,
}
};

export const Changelog = ({
entityId,
entityData,
entityType,
programId,
isOpen,
close,
dataItemDefinitions,
}: Props) => {
const {
records,
rawRecords,
pager,
isLoading,
isLoading: isChangelogLoading,
page,
pageSize,
setPage,
setPageSize,
sortDirection,
Expand All @@ -36,10 +40,24 @@ export const Changelog = ({
entityId,
entityType,
programId,
});

const {
processedRecords,
isLoading: isProcessingLoading,
} = useListDataValues({
rawRecords,
dataItemDefinitions,
entityId,
entityData,
entityType,
programId,
sortDirection,
page,
pageSize,
});

if (isLoading) {
if (isChangelogLoading || isProcessingLoading) {
return (
<Modal onClose={close}>
<LoadingMaskElementCenter />
Expand All @@ -51,7 +69,7 @@ export const Changelog = ({
<ChangelogComponent
isOpen={isOpen}
close={close}
records={records}
records={processedRecords}
pager={pager}
setPage={setPage}
setPageSize={setPageSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,36 @@ type Props = {
container: string,
previousValue: string,
currentValue: string,
updatePreviousValue: string,
updateCurrentValue: string,
updateArrow: string,
arrow: string,
}
}

const styles = {
container: {
alignItems: 'center',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
whiteSpace: 'normal',
height: '100%',
},
previousValue: {
color: colors.grey700,
wordBreak: 'break-word',
},
currentValue: {
color: colors.grey900,
wordBreak: 'break-word',
},
updatePreviousValue: {
color: colors.grey700,
maxWidth: '45%',
},
updateCurrentValue: {
color: colors.grey900,
maxWidth: '45%',
},
updateArrow: {
display: 'inline-flex',
alignItems: 'center',
margin: `${spacers.dp4}`,
arrow: {
margin: `0 ${spacers.dp4}`,
},
};

const Updated = ({ previousValue, currentValue, classes }) => (
<div className={classes.container}>
<span className={classes.updatePreviousValue}>{previousValue}</span>
<span className={classes.updateArrow}><IconArrowRight16 /></span>
<span className={classes.updateCurrentValue}>{currentValue}</span>
<div className={classes.previousValue}>{previousValue}</div>
<div className={classes.arrow}><IconArrowRight16 /></div>
<div className={classes.currentValue}>{currentValue}</div>
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ type Props = {
},
classes: {
dataItemColumn: string,
valueColumn: string,
},
};

const styles = {
dataItemColumn: { wordWrap: 'break-word', hyphens: 'auto' },
valueColumn: { wordWrap: 'break-word' },
};

const ChangelogTableRowPlain = ({ record, classes }: Props) => (
Expand All @@ -28,7 +26,7 @@ const ChangelogTableRowPlain = ({ record, classes }: Props) => (
<DataTableCell>{record.user}</DataTableCell>
<DataTableCell className={classes.dataItemColumn}>{record.dataItemLabel}</DataTableCell>
<DataTableCell><ChangelogChangeCell changeType={record.changeType} /></DataTableCell>
<DataTableCell className={classes.valueColumn}><ChangelogValueCell {...record} /></DataTableCell>
<DataTableCell><ChangelogValueCell {...record} /></DataTableCell>
</DataTableRow>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow

export { useChangelogData } from './useChangelogData';
export { useListDataValues } from './useListDataValues';
Loading

0 comments on commit 9327210

Please sign in to comment.