From 7f039d33280d345f7019544ebea2fcefe6bb76d4 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Wed, 20 Nov 2024 09:35:59 +0100 Subject: [PATCH 01/14] feat: geometry scheduledat occuredat in changelog --- .../EventChangelogWrapper.component.js | 10 ++ .../common/Changelog/Changelog.types.js | 3 + .../ChangelogChangeCell.js | 4 +- .../ChangelogChangeCell/index.js | 3 + .../ChangelogValueCell/ChangelogValueCell.js | 98 +++++++++++++++++++ .../ChangelogValueCellComponents.types.js | 13 +++ .../ChangelogValueCellDefault.js | 33 +++++++ .../ChangelogValueCellPolygon.js | 93 ++++++++++++++++++ .../ChangelogValueCellComponents/index.js | 6 ++ .../ChangelogValueCell/index.js | 3 + .../common/hooks/useListDataValues.js | 3 +- 11 files changed, 266 insertions(+), 3 deletions(-) rename src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/{ => ChangelogChangeCell}/ChangelogChangeCell.js (87%) create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js index e7041bdd74..4f3f931fbf 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js @@ -42,9 +42,19 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...p return acc; }, {}); + const additionalFields = { + geometry: { + id: 'geometry', + name: formFoundation.featureType, + type: formFoundation.featureType === 'Polygon' ? + dataElementTypes.POLYGON : dataElementTypes.COORDINATE, + }, + }; + return { ...fieldElementsById, ...fieldElementsContext, + ...additionalFields, }; }, [formFoundation]); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js index 56dccc68cd..d7173ddc1c 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js @@ -6,6 +6,7 @@ type CreatedChange = {| type: typeof CHANGE_TYPES.CREATED, dataElement?: string, attribute?: string, + property?: string, currentValue: any, |} @@ -13,6 +14,7 @@ type UpdatedChange = {| type: typeof CHANGE_TYPES.UPDATED, dataElement?: string, attribute?: string, + property?: string, previousValue: any, currentValue: any, |} @@ -21,6 +23,7 @@ type DeletedChange = {| type: typeof CHANGE_TYPES.DELETED, dataElement?: string, attribute?: string, + property?: string, previousValue: any, |} diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js similarity index 87% rename from src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js rename to src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js index 6f9a273d67..a5ce9256fe 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js @@ -3,8 +3,8 @@ import React from 'react'; import log from 'loglevel'; import { Tag } from '@dhis2/ui'; import i18n from '@dhis2/d2-i18n'; -import { CHANGE_TYPES } from '../../Changelog/Changelog.constants'; -import { errorCreator } from '../../../../../../capture-core-utils'; +import { CHANGE_TYPES } from '../../../Changelog/Changelog.constants'; +import { errorCreator } from '../../../../../../../capture-core-utils'; type Config = { label: string, diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js new file mode 100644 index 0000000000..f90d8203ee --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js @@ -0,0 +1,3 @@ +// @flow + +export { ChangelogChangeCell } from './ChangelogChangeCell'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js new file mode 100644 index 0000000000..18941872f0 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js @@ -0,0 +1,98 @@ +// @flow +import React from 'react'; +import { withStyles } from '@material-ui/core/styles'; +import { colors, spacers } from '@dhis2/ui'; +import { CHANGE_TYPES } from '../../../Changelog/Changelog.constants'; +import { + DefaultChangelogComponentsByChangeType, + PlygonChangelogComponentsByChangeType, +} from './ChangelogValueCellComponents'; + +type Props = { + dataItemId: string, + changeType: $Values, + previousValue?: string, + currentValue?: string, + classes: { + container: string, + valueContainer: string, + buttonContainer: string, + previousValue: string, + currentValue: string, + updatePreviousValue: string, + updateCurrentValue: string, + updateArrow: string, + viewButton: string, + }, +}; + +const styles = { + container: { + display: 'flex', + flexDirection: 'row', + alignItems: 'center', + whiteSpace: 'normal', + height: '100%', + }, + buttonContainer: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + previousValue: { + color: colors.grey700, + wordBreak: 'break-word', + }, + currentValue: { + color: colors.grey900, + wordBreak: 'break-word', + }, + updateArrow: { + display: 'inline-flex', + alignItems: 'center', + margin: spacers.dp4, + }, + viewButton: { + background: 'none', + border: 'none', + cursor: 'pointer', + color: colors.grey800, + display: 'flex', + alignItems: 'center', + '&:hover': { + textDecoration: 'underline', + color: 'black', + }, + }, +}; + +export const ChangelogValueCellPlain = ({ + dataItemId, + changeType, + currentValue, + previousValue, + classes, +}: Props) => { + if (!currentValue) { return null; } + const isPolygon = dataItemId === 'geometry' && currentValue.length > 2; + const ComponentsByChangeType = isPolygon + ? PlygonChangelogComponentsByChangeType + : DefaultChangelogComponentsByChangeType; + + const ChangelogComponent = ComponentsByChangeType[changeType]; + + if (!ChangelogComponent) { + console.error(`No component found for change type: ${changeType}`); + return null; + } + + return ( + + ); +}; + +export const ChangelogValueCell = withStyles(styles)(ChangelogValueCellPlain); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js new file mode 100644 index 0000000000..fa5261a085 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js @@ -0,0 +1,13 @@ +// @flow +export type ChangelogValueCellProps = { + previousValue?: string, + currentValue?: string, + classes: { + container: string, + buttonContainer: string, + previousValue: string, + currentValue: string, + updateArrow: string, + viewButton: string, + }, +}; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js new file mode 100644 index 0000000000..53d47340eb --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js @@ -0,0 +1,33 @@ +// @flow +import React from 'react'; +import { IconArrowRight16 } from '@dhis2/ui'; +import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; +import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; + +const Updated = ({ previousValue, currentValue, classes }: ChangelogValueCellProps) => ( +
+ {previousValue} + + + + {currentValue} +
+); + +const Created = ({ currentValue, classes }: ChangelogValueCellProps) => ( +
+ {currentValue} +
+); + +const Deleted = ({ previousValue, classes }: ChangelogValueCellProps) => ( +
+ {previousValue} +
+); + +export const DefaultChangelogComponentsByChangeType = Object.freeze({ + [CHANGE_TYPES.UPDATED]: Updated, + [CHANGE_TYPES.CREATED]: Created, + [CHANGE_TYPES.DELETED]: Deleted, +}); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js new file mode 100644 index 0000000000..2dd45fe46c --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js @@ -0,0 +1,93 @@ +// @flow +import React, { useState } from 'react'; +import { IconArrowRight16, IconChevronUp16, IconChevronDown16 } from '@dhis2/ui'; +import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; +import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; + +const ValueDisplay = ({ value, showMore, className }) => ( + {showMore ? value : value?.slice(0, 1)} +); + +const ViewMoreButton = ({ showMore, onClick, classes }) => ( + +); + +const Updated = ({ previousValue, currentValue, classes }: ChangelogValueCellProps) => { + const [showMore, setShowMore] = useState(false); + + return ( + <> +
+ + + + + +
+
+ setShowMore(!showMore)} + classes={classes} + /> +
+ + + ); +}; + + +const Created = ({ currentValue, classes }: ChangelogValueCellProps) => { + const [showMore, setShowMore] = useState(false); + + return ( +
+ + setShowMore(!showMore)} + classes={classes} + /> +
+ ); +}; + +const Deleted = ({ previousValue, classes }: ChangelogValueCellProps) => { + const [showMore, setShowMore] = useState(false); + + return ( +
+ + setShowMore(!showMore)} + classes={classes} + /> +
+ ); +}; + +export const PlygonChangelogComponentsByChangeType = Object.freeze({ + [CHANGE_TYPES.UPDATED]: Updated, + [CHANGE_TYPES.CREATED]: Created, + [CHANGE_TYPES.DELETED]: Deleted, +}); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js new file mode 100644 index 0000000000..fc72eca0e2 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js @@ -0,0 +1,6 @@ +// @flow + +export { DefaultChangelogComponentsByChangeType } from './ChangelogValueCellDefault'; +export { PlygonChangelogComponentsByChangeType } from './ChangelogValueCellPolygon'; + +export type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js new file mode 100644 index 0000000000..88dbf63fb0 --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js @@ -0,0 +1,3 @@ +// @flow + +export { ChangelogValueCell } from './ChangelogValueCell'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js index e94bf94a88..8bcce082d4 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js @@ -44,7 +44,8 @@ const fetchFormattedValues = async ({ elementKey: string, change: Change, ) => { - const fieldId = change.dataElement || change.attribute; + const { dataElement, attribute, property } = change; + const fieldId = dataElement ?? attribute ?? property; if (!fieldId) { log.error('Could not find fieldId in change:', change); return { metadataElement: null, fieldId: null }; From 056bb09814ea392dc459fc7238e5fb1880f7007c Mon Sep 17 00:00:00 2001 From: henrikmv Date: Wed, 20 Nov 2024 10:05:28 +0100 Subject: [PATCH 02/14] fix: clean up --- .../ChangelogChangeCell/index.js | 1 - .../ChangelogCells/ChangelogValueCell.js | 85 ------------------- .../ChangelogValueCellComponents/index.js | 1 - .../ChangelogValueCell/index.js | 1 - 4 files changed, 88 deletions(-) delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js index f90d8203ee..a221d08453 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js @@ -1,3 +1,2 @@ // @flow - export { ChangelogChangeCell } from './ChangelogChangeCell'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js deleted file mode 100644 index 4d6bd41b3e..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js +++ /dev/null @@ -1,85 +0,0 @@ -// @flow -import React from 'react'; -import log from 'loglevel'; -import { colors, IconArrowRight16, spacers } from '@dhis2/ui'; -import { withStyles } from '@material-ui/core/styles'; -import { CHANGE_TYPES } from '../../Changelog/Changelog.constants'; -import { errorCreator } from '../../../../../../capture-core-utils'; - -type Props = { - changeType: $Values, - previousValue?: string, - currentValue?: string, - classes: { - container: string, - previousValue: string, - currentValue: string, - arrow: string, - } -} - -const styles = { - container: { - display: 'flex', - flexDirection: 'row', - alignItems: 'center', - whiteSpace: 'normal', - height: '100%', - }, - previousValue: { - color: colors.grey700, - wordBreak: 'break-word', - }, - currentValue: { - color: colors.grey900, - wordBreak: 'break-word', - }, - arrow: { - margin: `0 ${spacers.dp4}`, - }, -}; - -const Updated = ({ previousValue, currentValue, classes }) => ( -
-
{previousValue}
-
-
{currentValue}
-
-); - -const Created = ({ currentValue, classes }) => ( -
- {currentValue} -
-); - -const Deleted = ({ previousValue, classes }) => ( -
- {previousValue} -
-); - -const ChangelogComponentsByType = { - [CHANGE_TYPES.UPDATED]: Updated, - [CHANGE_TYPES.CREATED]: Created, - [CHANGE_TYPES.DELETED]: Deleted, -}; - -const ChangelogValueCellPlain = ({ changeType, currentValue, previousValue, classes }: Props) => { - const ChangelogComponent = ChangelogComponentsByType[changeType]; - - if (!ChangelogComponent) { - log.error(errorCreator('Changelog component not found')({ changeType })); - return null; - } - - return ( - - ); -}; - -export const ChangelogValueCell = withStyles(styles)(ChangelogValueCellPlain); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js index fc72eca0e2..f6f80541ed 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js @@ -1,5 +1,4 @@ // @flow - export { DefaultChangelogComponentsByChangeType } from './ChangelogValueCellDefault'; export { PlygonChangelogComponentsByChangeType } from './ChangelogValueCellPolygon'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js index 88dbf63fb0..ceb08fff0f 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js @@ -1,3 +1,2 @@ // @flow - export { ChangelogValueCell } from './ChangelogValueCell'; From 684210bebbcda8ed7dd54456a65adb95609f3fb3 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Fri, 22 Nov 2024 15:07:03 +0100 Subject: [PATCH 03/14] fix: add check for featuretype --- .../EventChangelogWrapper/EventChangelogWrapper.component.js | 4 ++-- .../WidgetsChangelog/common/hooks/useListDataValues.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js index 4f3f931fbf..6dc1dd7970 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js @@ -42,14 +42,14 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...p return acc; }, {}); - const additionalFields = { + const additionalFields = formFoundation.featureType !== 'None' ? { geometry: { id: 'geometry', name: formFoundation.featureType, type: formFoundation.featureType === 'Polygon' ? dataElementTypes.POLYGON : dataElementTypes.COORDINATE, }, - }; + } : null; return { ...fieldElementsById, diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js index 8bcce082d4..479ff8d758 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js @@ -116,6 +116,7 @@ const fetchFormattedValues = async ({ reactKey: fieldId ? `${createdAt}-${fieldId}` : attributeOptionsKey, date: pipe(convertServerToClient, convertClientToList)(fromServerDate(createdAt), dataElementTypes.DATETIME), user: `${firstName} ${surname} (${username})`, + dataItemId: fieldId, changeType: type, dataItemLabel: metadataElement.name, previousValue, From cfb870de1cf7d89dd4405ce3861fb70889226fd7 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Wed, 27 Nov 2024 15:04:25 +0100 Subject: [PATCH 04/14] feat: style improvements --- .../ChangelogValueCell/ChangelogValueCell.js | 5 +- .../ChangelogValueCellDefault.js | 2 +- .../ChangelogValueCellPolygon.js | 60 +++++++++++-------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js index 18941872f0..d7f135aa88 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js @@ -31,12 +31,10 @@ const styles = { display: 'flex', flexDirection: 'row', alignItems: 'center', - whiteSpace: 'normal', height: '100%', }, buttonContainer: { display: 'flex', - alignItems: 'center', justifyContent: 'center', }, previousValue: { @@ -46,10 +44,9 @@ const styles = { currentValue: { color: colors.grey900, wordBreak: 'break-word', + maxWidth: '82%', }, updateArrow: { - display: 'inline-flex', - alignItems: 'center', margin: spacers.dp4, }, viewButton: { diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js index 53d47340eb..c0a502f4ed 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js @@ -16,7 +16,7 @@ const Updated = ({ previousValue, currentValue, classes }: ChangelogValueCellPro const Created = ({ currentValue, classes }: ChangelogValueCellProps) => (
- {currentValue} + {currentValue}
); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js index 2dd45fe46c..c7fd8ee6c3 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js @@ -4,8 +4,8 @@ import { IconArrowRight16, IconChevronUp16, IconChevronDown16 } from '@dhis2/ui' import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; -const ValueDisplay = ({ value, showMore, className }) => ( - {showMore ? value : value?.slice(0, 1)} +const ValueDisplay = ({ value, showMore }) => ( + {showMore ? value : value?.[0]} ); const ViewMoreButton = ({ showMore, onClick, classes }) => ( @@ -52,18 +52,21 @@ const Created = ({ currentValue, classes }: ChangelogValueCellProps) => { const [showMore, setShowMore] = useState(false); return ( -
- - setShowMore(!showMore)} - classes={classes} - /> -
+ <> +
+ +
+
+ setShowMore(!showMore)} + classes={classes} + /> +
+ ); }; @@ -71,18 +74,23 @@ const Deleted = ({ previousValue, classes }: ChangelogValueCellProps) => { const [showMore, setShowMore] = useState(false); return ( -
- - setShowMore(!showMore)} - classes={classes} - /> -
+ <> +
+ +
+
+ setShowMore(!showMore)} + classes={classes} + /> +
+ + ); }; From 732f04cf3d83d30ead4757c34886d6d35c230bc2 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 28 Nov 2024 11:02:18 +0100 Subject: [PATCH 05/14] fix: convert changelog data in servertoclient --- .../ChangelogValueCellPolygon.js | 5 ++-- .../capture-core/converters/serverToClient.js | 26 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js index c7fd8ee6c3..327a005914 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js @@ -4,8 +4,8 @@ import { IconArrowRight16, IconChevronUp16, IconChevronDown16 } from '@dhis2/ui' import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; -const ValueDisplay = ({ value, showMore }) => ( - {showMore ? value : value?.[0]} +const ValueDisplay = ({ value, showMore, className }) => ( + {showMore ? value : value?.[0]} ); const ViewMoreButton = ({ showMore, onClick, classes }) => ( @@ -57,6 +57,7 @@ const Created = ({ currentValue, classes }: ChangelogValueCellProps) => {
diff --git a/src/core_modules/capture-core/converters/serverToClient.js b/src/core_modules/capture-core/converters/serverToClient.js index 7a342c3aff..8da4b63d09 100644 --- a/src/core_modules/capture-core/converters/serverToClient.js +++ b/src/core_modules/capture-core/converters/serverToClient.js @@ -43,6 +43,25 @@ export function convertOptionSetValue(value: any, type: $Keys moment(d2Value).toISOString(), [dataElementTypes.TRUE_ONLY]: (d2Value: string) => ((d2Value === 'true') || null), [dataElementTypes.BOOLEAN]: (d2Value: string) => (d2Value === 'true'), - [dataElementTypes.COORDINATE]: (d2Value: string | Array) => { - const arr = typeof d2Value === 'string' ? JSON.parse(d2Value) : d2Value; - return { latitude: arr[1], longitude: arr[0] }; - }, - [dataElementTypes.POLYGON]: (d2Value: Array) => d2Value, + [dataElementTypes.COORDINATE]: (d2Value: any) => convertCoordinateToClient(d2Value), + [dataElementTypes.POLYGON]: (d2Value: any) => convertPolygonToClient(d2Value), [dataElementTypes.ASSIGNEE]: convertAssignedUserToClient, }; From 2cc1be85e58037366c3fca0d4ab7cbce8343e518 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 28 Nov 2024 14:59:14 +0100 Subject: [PATCH 06/14] feat: update clienttolist --- .../MinimalCoordinates/MinimalCoordinates.js | 16 +++--- .../MinimalCoordinates/index.js | 0 .../PolygonCoordinates/PolygonCoordinates.js | 50 +++++++++++++++++++ .../Coordinates/PolygonCoordinates/index.js | 2 + .../components/Coordinates/index.js | 3 ++ .../capture-core/converters/clientToList.js | 44 ++++++++-------- .../capture-core/converters/clientToView.js | 2 +- 7 files changed, 90 insertions(+), 27 deletions(-) rename src/core_modules/capture-core/components/{ => Coordinates}/MinimalCoordinates/MinimalCoordinates.js (51%) rename src/core_modules/capture-core/components/{ => Coordinates}/MinimalCoordinates/index.js (100%) create mode 100644 src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js create mode 100644 src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/index.js create mode 100644 src/core_modules/capture-core/components/Coordinates/index.js diff --git a/src/core_modules/capture-core/components/MinimalCoordinates/MinimalCoordinates.js b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js similarity index 51% rename from src/core_modules/capture-core/components/MinimalCoordinates/MinimalCoordinates.js rename to src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js index 36af51e4f5..7c9d38279d 100644 --- a/src/core_modules/capture-core/components/MinimalCoordinates/MinimalCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js @@ -3,14 +3,18 @@ import React from 'react'; type Props = $ReadOnly<{| latitude: number | string, - longitude: number | string, + longitude: number | string, |}>; const toSixDecimal = value => (parseFloat(value) ? parseFloat(value).toFixed(6) : null); -export const MinimalCoordinates = ({ latitude, longitude }: Props) => - (
- lat: {toSixDecimal(latitude)}
- long: {toSixDecimal(longitude)} -
); +export const MinimalCoordinates = ({ latitude, longitude }: Props) => { + console.log('MinimalCoordinates.js:', latitude); + return ( +
+ lat: {toSixDecimal(latitude)}
+ long: {toSixDecimal(longitude)} +
+ ); +}; diff --git a/src/core_modules/capture-core/components/MinimalCoordinates/index.js b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/index.js similarity index 100% rename from src/core_modules/capture-core/components/MinimalCoordinates/index.js rename to src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/index.js diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js new file mode 100644 index 0000000000..187ce98956 --- /dev/null +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js @@ -0,0 +1,50 @@ +// @flow +import React, { useState } from 'react'; +import { withStyles } from '@material-ui/core/styles'; +import { IconChevronUp16, IconChevronDown16, colors, spacers } from '@dhis2/ui'; + +type Props = $ReadOnly<{| + coordinates: Array>, + classes: { viewButton: string }, +|}>; + +const styles = { + viewButton: { + background: 'none', + border: 'none', + cursor: 'pointer', + color: colors.grey800, + marginTop: spacers.dp8, + display: 'flex', + alignItems: 'center', + '&:hover': { + textDecoration: 'underline', + color: 'black', + }, + }, +}; + +const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => { + const [showMore, setShowMore] = useState(false); + + return ( + <> +
+ {coordinates.slice(0, showMore ? coordinates.length : 1).map((coordinatePair, index) => ( + // eslint-disable-next-line react/no-array-index-key +
+ {`lat: ${coordinatePair[1]} long: ${coordinatePair[0]}`} +
+ ))} +
+ {coordinates.length > 3 && ( + + )} + + ); +}; + +export const PolygonCoordinates = withStyles(styles)(PolygonCoordinatesPlain); diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/index.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/index.js new file mode 100644 index 0000000000..0c85230d28 --- /dev/null +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/index.js @@ -0,0 +1,2 @@ +// @flow +export { PolygonCoordinates } from './PolygonCoordinates'; diff --git a/src/core_modules/capture-core/components/Coordinates/index.js b/src/core_modules/capture-core/components/Coordinates/index.js new file mode 100644 index 0000000000..a7549a63b6 --- /dev/null +++ b/src/core_modules/capture-core/components/Coordinates/index.js @@ -0,0 +1,3 @@ +// @flow +export { MinimalCoordinates } from './MinimalCoordinates'; +export { PolygonCoordinates } from './PolygonCoordinates'; diff --git a/src/core_modules/capture-core/converters/clientToList.js b/src/core_modules/capture-core/converters/clientToList.js index e72b837179..abbfbf6975 100644 --- a/src/core_modules/capture-core/converters/clientToList.js +++ b/src/core_modules/capture-core/converters/clientToList.js @@ -7,7 +7,7 @@ import { PreviewImage } from 'capture-ui'; import { dataElementTypes, type DataElement } from '../metaData'; import { convertMomentToDateFormatString } from '../utils/converters/date'; import { stringifyNumber } from './common/stringifyNumber'; -import { MinimalCoordinates } from '../components/MinimalCoordinates'; +import { MinimalCoordinates, PolygonCoordinates } from '../components/Coordinates'; import { TooltipOrgUnit } from '../components/Tooltips/TooltipOrgUnit'; function convertDateForListDisplay(rawValue: string): string { @@ -87,41 +87,45 @@ function convertStatusForDisplay(clientValue: Object) { ); } -function convertOrgUnitForDisplay(clientValue: string | {id: string}) { +function convertOrgUnitForDisplay(clientValue: string | { id: string }) { const orgUnitId = typeof clientValue === 'string' ? clientValue : clientValue.id; return ( ); } +function convertPolygonForDisplay(clientValue: Object) { + return ; +} const valueConvertersForType = { - [dataElementTypes.NUMBER]: stringifyNumber, - [dataElementTypes.INTEGER]: stringifyNumber, - [dataElementTypes.INTEGER_POSITIVE]: stringifyNumber, - [dataElementTypes.INTEGER_ZERO_OR_POSITIVE]: stringifyNumber, - [dataElementTypes.INTEGER_NEGATIVE]: stringifyNumber, - [dataElementTypes.INTEGER_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), - [dataElementTypes.INTEGER_POSITIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), - [dataElementTypes.INTEGER_ZERO_OR_POSITIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), - [dataElementTypes.INTEGER_NEGATIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), - [dataElementTypes.PERCENTAGE]: (value: number) => `${stringifyNumber(value)} %`, + [dataElementTypes.AGE]: convertDateForListDisplay, + [dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name} (${rawValue.username})`, + [dataElementTypes.BOOLEAN]: (rawValue: boolean) => (rawValue ? i18n.t('Yes') : i18n.t('No')), + [dataElementTypes.COORDINATE]: MinimalCoordinates, [dataElementTypes.DATE]: convertDateForListDisplay, [dataElementTypes.DATE_RANGE]: value => convertRangeForDisplay(convertDateForListDisplay, value), [dataElementTypes.DATETIME]: convertDateTimeForListDisplay, [dataElementTypes.DATETIME_RANGE]: value => convertRangeForDisplay(convertDateTimeForListDisplay, value), - [dataElementTypes.TIME]: convertTimeForListDisplay, - [dataElementTypes.TIME_RANGE]: value => convertRangeForDisplay(convertTimeForListDisplay, value), - [dataElementTypes.TRUE_ONLY]: () => i18n.t('Yes'), - [dataElementTypes.BOOLEAN]: (rawValue: boolean) => (rawValue ? i18n.t('Yes') : i18n.t('No')), - [dataElementTypes.COORDINATE]: MinimalCoordinates, - [dataElementTypes.AGE]: convertDateForListDisplay, [dataElementTypes.FILE_RESOURCE]: convertFileForDisplay, [dataElementTypes.IMAGE]: convertImageForDisplay, - [dataElementTypes.ORGANISATION_UNIT]: convertOrgUnitForDisplay, - [dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name} (${rawValue.username})`, + [dataElementTypes.INTEGER]: stringifyNumber, + [dataElementTypes.INTEGER_NEGATIVE]: stringifyNumber, + [dataElementTypes.INTEGER_NEGATIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), + [dataElementTypes.INTEGER_POSITIVE]: stringifyNumber, + [dataElementTypes.INTEGER_POSITIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), + [dataElementTypes.INTEGER_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), + [dataElementTypes.INTEGER_ZERO_OR_POSITIVE]: stringifyNumber, + [dataElementTypes.INTEGER_ZERO_OR_POSITIVE_RANGE]: value => convertRangeForDisplay(stringifyNumber, value), + [dataElementTypes.NUMBER]: stringifyNumber, [dataElementTypes.NUMBER_RANGE]: convertNumberRangeForDisplay, + [dataElementTypes.ORGANISATION_UNIT]: convertOrgUnitForDisplay, + [dataElementTypes.PERCENTAGE]: (value: number) => `${stringifyNumber(value)} %`, + [dataElementTypes.POLYGON]: convertPolygonForDisplay, [dataElementTypes.STATUS]: convertStatusForDisplay, + [dataElementTypes.TIME]: convertTimeForListDisplay, + [dataElementTypes.TIME_RANGE]: value => convertRangeForDisplay(convertTimeForListDisplay, value), + [dataElementTypes.TRUE_ONLY]: () => i18n.t('Yes'), }; export function convertValue(value: any, type: $Keys, dataElement?: ?DataElement) { diff --git a/src/core_modules/capture-core/converters/clientToView.js b/src/core_modules/capture-core/converters/clientToView.js index 2849a02b01..220e1906ef 100644 --- a/src/core_modules/capture-core/converters/clientToView.js +++ b/src/core_modules/capture-core/converters/clientToView.js @@ -6,7 +6,7 @@ import { PreviewImage } from 'capture-ui'; import { dataElementTypes, type DataElement } from '../metaData'; import { convertMomentToDateFormatString } from '../utils/converters/date'; import { stringifyNumber } from './common/stringifyNumber'; -import { MinimalCoordinates } from '../components/MinimalCoordinates'; +import { MinimalCoordinates } from '../components/Coordinates'; import { TooltipOrgUnit } from '../components/Tooltips/TooltipOrgUnit'; From 91c1890bd262ba0add12d115b3c8ed8cd46064c5 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 28 Nov 2024 15:05:54 +0100 Subject: [PATCH 07/14] fix: revert new folder structure --- .../ChangelogChangeCell.js | 5 +- .../ChangelogChangeCell/index.js | 2 - .../ChangelogCells/ChangelogValueCell.js | 89 +++++++++++++++ .../ChangelogValueCell/ChangelogValueCell.js | 95 ---------------- .../ChangelogValueCellComponents.types.js | 13 --- .../ChangelogValueCellDefault.js | 33 ------ .../ChangelogValueCellPolygon.js | 102 ------------------ .../ChangelogValueCellComponents/index.js | 5 - .../ChangelogValueCell/index.js | 2 - 9 files changed, 91 insertions(+), 255 deletions(-) rename src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/{ChangelogChangeCell => }/ChangelogChangeCell.js (87%) delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js create mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js delete mode 100644 src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js similarity index 87% rename from src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js rename to src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js index a5ce9256fe..ebd96bd80a 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/ChangelogChangeCell.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js @@ -3,8 +3,8 @@ import React from 'react'; import log from 'loglevel'; import { Tag } from '@dhis2/ui'; import i18n from '@dhis2/d2-i18n'; -import { CHANGE_TYPES } from '../../../Changelog/Changelog.constants'; -import { errorCreator } from '../../../../../../../capture-core-utils'; +import { CHANGE_TYPES } from '../../Changelog/Changelog.constants'; +import { errorCreator } from '../../../../../../capture-core-utils'; type Config = { label: string, @@ -40,4 +40,3 @@ export const ChangelogChangeCell = ({ changeType }: Object) => { ); }; - diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js deleted file mode 100644 index a221d08453..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell/index.js +++ /dev/null @@ -1,2 +0,0 @@ -// @flow -export { ChangelogChangeCell } from './ChangelogChangeCell'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js new file mode 100644 index 0000000000..eed9d19caf --- /dev/null +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js @@ -0,0 +1,89 @@ +// @flow +import React from 'react'; +import log from 'loglevel'; +import { colors, IconArrowRight16, spacers } from '@dhis2/ui'; +import { withStyles } from '@material-ui/core/styles'; +import { CHANGE_TYPES } from '../../Changelog/Changelog.constants'; +import { errorCreator } from '../../../../../../capture-core-utils'; + +type Props = { + changeType: $Values, + previousValue?: string, + currentValue?: string, + classes: { + container: string, + previousValue: string, + currentValue: string, + arrow: string, + } +} + +const styles = { + container: { + display: 'flex', + flexDirection: 'row', + alignItems: 'center', + height: '100%', + }, + buttonContainer: { + display: 'flex', + justifyContent: 'center', + }, + previousValue: { + color: colors.grey700, + wordBreak: 'break-word', + }, + currentValue: { + color: colors.grey900, + wordBreak: 'break-word', + maxWidth: '82%', + }, + updateArrow: { + margin: spacers.dp4, + }, +}; + +const Updated = ({ previousValue, currentValue, classes }) => ( +
+
{previousValue}
+
+
{currentValue}
+
+); + +const Created = ({ currentValue, classes }) => ( +
+ {currentValue} +
+); + +const Deleted = ({ previousValue, classes }) => ( +
+ {previousValue} +
+); + +const ChangelogComponentsByType = { + [CHANGE_TYPES.UPDATED]: Updated, + [CHANGE_TYPES.CREATED]: Created, + [CHANGE_TYPES.DELETED]: Deleted, +}; + +const ChangelogValueCellPlain = ({ changeType, currentValue, previousValue, classes }: Props) => { + const ChangelogComponent = ChangelogComponentsByType[changeType]; + + if (!ChangelogComponent) { + log.error(errorCreator('Changelog component not found')({ changeType })); + return null; + } + + return ( + + ); +}; + +export const ChangelogValueCell = withStyles(styles)(ChangelogValueCellPlain); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js deleted file mode 100644 index d7f135aa88..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCell.js +++ /dev/null @@ -1,95 +0,0 @@ -// @flow -import React from 'react'; -import { withStyles } from '@material-ui/core/styles'; -import { colors, spacers } from '@dhis2/ui'; -import { CHANGE_TYPES } from '../../../Changelog/Changelog.constants'; -import { - DefaultChangelogComponentsByChangeType, - PlygonChangelogComponentsByChangeType, -} from './ChangelogValueCellComponents'; - -type Props = { - dataItemId: string, - changeType: $Values, - previousValue?: string, - currentValue?: string, - classes: { - container: string, - valueContainer: string, - buttonContainer: string, - previousValue: string, - currentValue: string, - updatePreviousValue: string, - updateCurrentValue: string, - updateArrow: string, - viewButton: string, - }, -}; - -const styles = { - container: { - display: 'flex', - flexDirection: 'row', - alignItems: 'center', - height: '100%', - }, - buttonContainer: { - display: 'flex', - justifyContent: 'center', - }, - previousValue: { - color: colors.grey700, - wordBreak: 'break-word', - }, - currentValue: { - color: colors.grey900, - wordBreak: 'break-word', - maxWidth: '82%', - }, - updateArrow: { - margin: spacers.dp4, - }, - viewButton: { - background: 'none', - border: 'none', - cursor: 'pointer', - color: colors.grey800, - display: 'flex', - alignItems: 'center', - '&:hover': { - textDecoration: 'underline', - color: 'black', - }, - }, -}; - -export const ChangelogValueCellPlain = ({ - dataItemId, - changeType, - currentValue, - previousValue, - classes, -}: Props) => { - if (!currentValue) { return null; } - const isPolygon = dataItemId === 'geometry' && currentValue.length > 2; - const ComponentsByChangeType = isPolygon - ? PlygonChangelogComponentsByChangeType - : DefaultChangelogComponentsByChangeType; - - const ChangelogComponent = ComponentsByChangeType[changeType]; - - if (!ChangelogComponent) { - console.error(`No component found for change type: ${changeType}`); - return null; - } - - return ( - - ); -}; - -export const ChangelogValueCell = withStyles(styles)(ChangelogValueCellPlain); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js deleted file mode 100644 index fa5261a085..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellComponents.types.js +++ /dev/null @@ -1,13 +0,0 @@ -// @flow -export type ChangelogValueCellProps = { - previousValue?: string, - currentValue?: string, - classes: { - container: string, - buttonContainer: string, - previousValue: string, - currentValue: string, - updateArrow: string, - viewButton: string, - }, -}; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js deleted file mode 100644 index c0a502f4ed..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellDefault.js +++ /dev/null @@ -1,33 +0,0 @@ -// @flow -import React from 'react'; -import { IconArrowRight16 } from '@dhis2/ui'; -import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; -import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; - -const Updated = ({ previousValue, currentValue, classes }: ChangelogValueCellProps) => ( -
- {previousValue} - - - - {currentValue} -
-); - -const Created = ({ currentValue, classes }: ChangelogValueCellProps) => ( -
- {currentValue} -
-); - -const Deleted = ({ previousValue, classes }: ChangelogValueCellProps) => ( -
- {previousValue} -
-); - -export const DefaultChangelogComponentsByChangeType = Object.freeze({ - [CHANGE_TYPES.UPDATED]: Updated, - [CHANGE_TYPES.CREATED]: Created, - [CHANGE_TYPES.DELETED]: Deleted, -}); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js deleted file mode 100644 index 327a005914..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/ChangelogValueCellPolygon.js +++ /dev/null @@ -1,102 +0,0 @@ -// @flow -import React, { useState } from 'react'; -import { IconArrowRight16, IconChevronUp16, IconChevronDown16 } from '@dhis2/ui'; -import { CHANGE_TYPES } from '../../../../Changelog/Changelog.constants'; -import type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; - -const ValueDisplay = ({ value, showMore, className }) => ( - {showMore ? value : value?.[0]} -); - -const ViewMoreButton = ({ showMore, onClick, classes }) => ( - -); - -const Updated = ({ previousValue, currentValue, classes }: ChangelogValueCellProps) => { - const [showMore, setShowMore] = useState(false); - - return ( - <> -
- - - - - -
-
- setShowMore(!showMore)} - classes={classes} - /> -
- - - ); -}; - - -const Created = ({ currentValue, classes }: ChangelogValueCellProps) => { - const [showMore, setShowMore] = useState(false); - - return ( - <> -
- -
-
- setShowMore(!showMore)} - classes={classes} - /> -
- - ); -}; - -const Deleted = ({ previousValue, classes }: ChangelogValueCellProps) => { - const [showMore, setShowMore] = useState(false); - - return ( - <> -
- -
-
- setShowMore(!showMore)} - classes={classes} - /> -
- - - ); -}; - -export const PlygonChangelogComponentsByChangeType = Object.freeze({ - [CHANGE_TYPES.UPDATED]: Updated, - [CHANGE_TYPES.CREATED]: Created, - [CHANGE_TYPES.DELETED]: Deleted, -}); diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js deleted file mode 100644 index f6f80541ed..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/ChangelogValueCellComponents/index.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow -export { DefaultChangelogComponentsByChangeType } from './ChangelogValueCellDefault'; -export { PlygonChangelogComponentsByChangeType } from './ChangelogValueCellPolygon'; - -export type { ChangelogValueCellProps } from './ChangelogValueCellComponents.types'; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js deleted file mode 100644 index ceb08fff0f..0000000000 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell/index.js +++ /dev/null @@ -1,2 +0,0 @@ -// @flow -export { ChangelogValueCell } from './ChangelogValueCell'; From 194c20c004da26091f2a1a642e8e90b2a1896f48 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 28 Nov 2024 15:22:45 +0100 Subject: [PATCH 08/14] fix: code clean up --- .../MinimalCoordinates/MinimalCoordinates.js | 17 +++++++---------- .../PolygonCoordinates/PolygonCoordinates.js | 13 +++++-------- .../ChangelogCells/ChangelogChangeCell.js | 1 + .../capture-core/converters/serverToClient.js | 4 ++-- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js index 7c9d38279d..ed4dac51cc 100644 --- a/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js @@ -3,18 +3,15 @@ import React from 'react'; type Props = $ReadOnly<{| latitude: number | string, - longitude: number | string, + longitude: number | string, |}>; const toSixDecimal = value => (parseFloat(value) ? parseFloat(value).toFixed(6) : null); -export const MinimalCoordinates = ({ latitude, longitude }: Props) => { - console.log('MinimalCoordinates.js:', latitude); - return ( -
- lat: {toSixDecimal(latitude)}
- long: {toSixDecimal(longitude)} -
- ); -}; +export const MinimalCoordinates = ({ latitude, longitude }: Props) => ( +
+ lat: {toSixDecimal(latitude)}
+ long: {toSixDecimal(longitude)} +
+); diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js index 187ce98956..438b7a6bb9 100644 --- a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js @@ -5,7 +5,7 @@ import { IconChevronUp16, IconChevronDown16, colors, spacers } from '@dhis2/ui'; type Props = $ReadOnly<{| coordinates: Array>, - classes: { viewButton: string }, + classes: { viewButton: string }, |}>; const styles = { @@ -26,7 +26,6 @@ const styles = { const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => { const [showMore, setShowMore] = useState(false); - return ( <>
@@ -37,12 +36,10 @@ const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => {
))}
- {coordinates.length > 3 && ( - - )} + ); }; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js index ebd96bd80a..6f9a273d67 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogChangeCell.js @@ -40,3 +40,4 @@ export const ChangelogChangeCell = ({ changeType }: Object) => { ); }; + diff --git a/src/core_modules/capture-core/converters/serverToClient.js b/src/core_modules/capture-core/converters/serverToClient.js index 8da4b63d09..3ecedbe293 100644 --- a/src/core_modules/capture-core/converters/serverToClient.js +++ b/src/core_modules/capture-core/converters/serverToClient.js @@ -74,8 +74,8 @@ const valueConvertersForType = { [dataElementTypes.DATETIME]: (d2Value: string) => moment(d2Value).toISOString(), [dataElementTypes.TRUE_ONLY]: (d2Value: string) => ((d2Value === 'true') || null), [dataElementTypes.BOOLEAN]: (d2Value: string) => (d2Value === 'true'), - [dataElementTypes.COORDINATE]: (d2Value: any) => convertCoordinateToClient(d2Value), - [dataElementTypes.POLYGON]: (d2Value: any) => convertPolygonToClient(d2Value), + [dataElementTypes.COORDINATE]: (d2Value: string | Array) => convertCoordinateToClient(d2Value), + [dataElementTypes.POLYGON]: (d2Value: string | Array>) => convertPolygonToClient(d2Value), [dataElementTypes.ASSIGNEE]: convertAssignedUserToClient, }; From dba3800389c53cdc1ecbac2135036be658edc346 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Fri, 29 Nov 2024 14:07:57 +0100 Subject: [PATCH 09/14] fix: show coordinate --- .../capture-core/converters/serverToClient.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core_modules/capture-core/converters/serverToClient.js b/src/core_modules/capture-core/converters/serverToClient.js index 3ecedbe293..456e87d6af 100644 --- a/src/core_modules/capture-core/converters/serverToClient.js +++ b/src/core_modules/capture-core/converters/serverToClient.js @@ -44,11 +44,10 @@ export function convertOptionSetValue(value: any, type: $Keys Date: Fri, 29 Nov 2024 14:17:08 +0100 Subject: [PATCH 10/14] feat: style improvements --- .../PolygonCoordinates/PolygonCoordinates.js | 23 ++++++++++++++----- .../ChangelogCells/ChangelogValueCell.js | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js index 438b7a6bb9..306004242c 100644 --- a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js @@ -5,10 +5,18 @@ import { IconChevronUp16, IconChevronDown16, colors, spacers } from '@dhis2/ui'; type Props = $ReadOnly<{| coordinates: Array>, - classes: { viewButton: string }, + classes: { + buttonContainer: string, + viewButton: string, + }, |}>; const styles = { + buttonContainer: { + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + }, viewButton: { background: 'none', border: 'none', @@ -32,14 +40,17 @@ const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => { {coordinates.slice(0, showMore ? coordinates.length : 1).map((coordinatePair, index) => ( // eslint-disable-next-line react/no-array-index-key
- {`lat: ${coordinatePair[1]} long: ${coordinatePair[0]}`} + {`lat: ${coordinatePair[1]}`}
+ {`long: ${coordinatePair[0]}`}
))} - +
+ +
); }; diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js index eed9d19caf..3b43a13eba 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/ChangelogTable/ChangelogCells/ChangelogValueCell.js @@ -38,7 +38,7 @@ const styles = { wordBreak: 'break-word', maxWidth: '82%', }, - updateArrow: { + arrow: { margin: spacers.dp4, }, }; From 04117478f612248f4dc87d579f39721074d25e2c Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 12 Dec 2024 10:32:44 +0100 Subject: [PATCH 11/14] fix: change from property to fields --- .../WidgetsChangelog/common/Changelog/Changelog.types.js | 6 +++--- .../WidgetsChangelog/common/hooks/useListDataValues.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js index d7173ddc1c..ece01ab3a9 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/Changelog/Changelog.types.js @@ -6,7 +6,7 @@ type CreatedChange = {| type: typeof CHANGE_TYPES.CREATED, dataElement?: string, attribute?: string, - property?: string, + field?: string, currentValue: any, |} @@ -14,7 +14,7 @@ type UpdatedChange = {| type: typeof CHANGE_TYPES.UPDATED, dataElement?: string, attribute?: string, - property?: string, + field?: string, previousValue: any, currentValue: any, |} @@ -23,7 +23,7 @@ type DeletedChange = {| type: typeof CHANGE_TYPES.DELETED, dataElement?: string, attribute?: string, - property?: string, + field?: string, previousValue: any, |} diff --git a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js index 479ff8d758..16dcbe87f2 100644 --- a/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js +++ b/src/core_modules/capture-core/components/WidgetsChangelog/common/hooks/useListDataValues.js @@ -44,8 +44,8 @@ const fetchFormattedValues = async ({ elementKey: string, change: Change, ) => { - const { dataElement, attribute, property } = change; - const fieldId = dataElement ?? attribute ?? property; + const { dataElement, attribute, field } = change; + const fieldId = dataElement ?? attribute ?? field; if (!fieldId) { log.error('Could not find fieldId in change:', change); return { metadataElement: null, fieldId: null }; From 51add829d34a753d4b40128e2b65095a9d50cc89 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Fri, 13 Dec 2024 12:36:49 +0100 Subject: [PATCH 12/14] fix: review comments --- i18n/en.pot | 16 ++++++++++++++-- .../MinimalCoordinates/MinimalCoordinates.js | 5 +++-- .../PolygonCoordinates/PolygonCoordinates.js | 7 ++++--- .../EventChangelogWrapper.component.js | 5 +++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 8ba577cb6c..f5c1746865 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-07T11:57:59.094Z\n" -"PO-Revision-Date: 2024-11-07T11:57:59.094Z\n" +"POT-Creation-Date: 2024-12-13T11:35:42.356Z\n" +"PO-Revision-Date: 2024-12-13T11:35:42.356Z\n" msgid "Choose one or more dates..." msgstr "Choose one or more dates..." @@ -101,6 +101,18 @@ msgstr "Date of enrollment" msgid "Last updated" msgstr "Last updated" +msgid "Lat" +msgstr "Lat" + +msgid "Long" +msgstr "Long" + +msgid "Show less" +msgstr "Show less" + +msgid "Show more" +msgstr "Show more" + msgid "error encountered during field validation" msgstr "error encountered during field validation" diff --git a/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js index ed4dac51cc..39b23b672c 100644 --- a/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/MinimalCoordinates/MinimalCoordinates.js @@ -1,5 +1,6 @@ // @flow import React from 'react'; +import i18n from '@dhis2/d2-i18n'; type Props = $ReadOnly<{| latitude: number | string, @@ -10,8 +11,8 @@ const toSixDecimal = value => (parseFloat(value) ? parseFloat(value).toFixed(6) export const MinimalCoordinates = ({ latitude, longitude }: Props) => (
- lat: {toSixDecimal(latitude)}
- long: {toSixDecimal(longitude)} + {i18n.t('Lat')}: {toSixDecimal(latitude)}
+ {i18n.t('Long')}: {toSixDecimal(longitude)}
); diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js index 306004242c..a33f2cc976 100644 --- a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js @@ -1,5 +1,6 @@ // @flow import React, { useState } from 'react'; +import i18n from '@dhis2/d2-i18n'; import { withStyles } from '@material-ui/core/styles'; import { IconChevronUp16, IconChevronDown16, colors, spacers } from '@dhis2/ui'; @@ -40,14 +41,14 @@ const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => { {coordinates.slice(0, showMore ? coordinates.length : 1).map((coordinatePair, index) => ( // eslint-disable-next-line react/no-array-index-key
- {`lat: ${coordinatePair[1]}`}
- {`long: ${coordinatePair[0]}`} + {`${i18n('lat')}: ${coordinatePair[1]}`}
+ {`${i18n('long')}: ${coordinatePair[0]}`}
))}
diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js index 6dc1dd7970..d72ce6f045 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js @@ -1,5 +1,6 @@ // @flow import React, { useMemo } from 'react'; +import i18n from '@dhis2/d2-i18n'; import type { DataElement } from '../../../metaData'; import { dataElementTypes } from '../../../metaData'; import type { Props } from './EventChangelogWrapper.types'; @@ -36,7 +37,7 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...p acc[key] = { id: key, name: contextLabels[key], - type: dataElementTypes.DATE, + type: dataElementTypes.DATETIME, }; return acc; @@ -45,7 +46,7 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...p const additionalFields = formFoundation.featureType !== 'None' ? { geometry: { id: 'geometry', - name: formFoundation.featureType, + name: formFoundation.featureType === 'Polygon' ? i18n.t('Area') : i18n.t('Coordinate'), type: formFoundation.featureType === 'Polygon' ? dataElementTypes.POLYGON : dataElementTypes.COORDINATE, }, From 0c2a7342840136511d947c2771e7aa77fea7e5eb Mon Sep 17 00:00:00 2001 From: henrikmv Date: Sun, 15 Dec 2024 16:25:37 +0100 Subject: [PATCH 13/14] fix: translation --- i18n/en.pot | 10 ++++++++-- .../PolygonCoordinates/PolygonCoordinates.js | 4 ++-- .../Pages/NewRelationship/RegisterTei/open.epics.js | 2 +- .../TrackedEntityRelationshipsWrapper.epics.js | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index f5c1746865..aab5f47678 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-12-13T11:35:42.356Z\n" -"PO-Revision-Date: 2024-12-13T11:35:42.356Z\n" +"POT-Creation-Date: 2024-12-15T15:25:38.375Z\n" +"PO-Revision-Date: 2024-12-15T15:25:38.375Z\n" msgid "Choose one or more dates..." msgstr "Choose one or more dates..." @@ -107,6 +107,12 @@ msgstr "Lat" msgid "Long" msgstr "Long" +msgid "lat" +msgstr "lat" + +msgid "long" +msgstr "long" + msgid "Show less" msgstr "Show less" diff --git a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js index a33f2cc976..c019bdb5fe 100644 --- a/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js +++ b/src/core_modules/capture-core/components/Coordinates/PolygonCoordinates/PolygonCoordinates.js @@ -41,8 +41,8 @@ const PolygonCoordinatesPlain = ({ coordinates, classes }: Props) => { {coordinates.slice(0, showMore ? coordinates.length : 1).map((coordinatePair, index) => ( // eslint-disable-next-line react/no-array-index-key
- {`${i18n('lat')}: ${coordinatePair[1]}`}
- {`${i18n('long')}: ${coordinatePair[0]}`} + {`${i18n.t('lat')}: ${coordinatePair[1]}`}
+ {`${i18n.t('long')}: ${coordinatePair[0]}`}
))} diff --git a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/open.epics.js b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/open.epics.js index cfa4280b97..3244faf794 100644 --- a/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/open.epics.js +++ b/src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/open.epics.js @@ -30,7 +30,7 @@ function getTrackerProgram(suggestedProgramId: string) { log.error( errorCreator('tracker program for id not found')({ suggestedProgramId, error }), ); - throw Error(i18n('Metadata error. see log for details')); + throw Error(i18n.t('Metadata error. see log for details')); } return trackerProgram; } diff --git a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.epics.js b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.epics.js index 488faf8e6f..c752b65d0a 100644 --- a/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.epics.js +++ b/src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/TrackedEntityRelationshipsWrapper/TrackedEntityRelationshipsWrapper.epics.js @@ -30,7 +30,7 @@ function getTrackerProgram(suggestedProgramId: string) { log.error( errorCreator('tracker program for id not found')({ suggestedProgramId, error }), ); - throw Error(i18n('Metadata error. see log for details')); + throw Error(i18n.t('Metadata error. see log for details')); } return trackerProgram; } From b29d8bcbdd626b924956c7f4f0fcf07c6bf800e8 Mon Sep 17 00:00:00 2001 From: henrikmv <110386561+henrikmv@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:37:58 +0100 Subject: [PATCH 14/14] fix: revert type change --- .../EventChangelogWrapper/EventChangelogWrapper.component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js index d72ce6f045..2d7d294dd0 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/EventChangelogWrapper/EventChangelogWrapper.component.js @@ -37,7 +37,7 @@ export const EventChangelogWrapper = ({ formFoundation, eventId, eventData, ...p acc[key] = { id: key, name: contextLabels[key], - type: dataElementTypes.DATETIME, + type: dataElementTypes.DATE, }; return acc;