Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DHIS2-6335] use custom map center point #3312

Merged
merged 82 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
7f8ab42
feat: [DHIS2-13237] add coordinate with map
jasminenguyennn Dec 6, 2022
c9e22f4
chore: minor fix
jasminenguyennn Dec 6, 2022
29b5ee9
feat: [DHIS2-13237] handle polygon in the map
jasminenguyennn Dec 7, 2022
02b7e6d
chore: fix flow
jasminenguyennn Dec 7, 2022
6e392c7
chore: [DHIS2-13237] convert coordinates
jasminenguyennn Dec 12, 2022
10c0237
feat: [DHIS2-13237] open on click and add new location
jasminenguyennn Dec 13, 2022
d610ef6
feat: [DHIS2-13237] handle add geometry
jasminenguyennn Dec 14, 2022
562e73c
feat: [DHIS2-13237] update locations
jasminenguyennn Dec 14, 2022
6e1ea40
chore: [DHIS2-13237] minor fix
jasminenguyennn Dec 14, 2022
c3d2cc0
Merge branch 'master' into DHIS2-13237
jasminenguyennn Dec 14, 2022
2d7f6f8
chore: [DHIS2-13237] minor fix
jasminenguyennn Dec 14, 2022
261dd92
Merge branch 'master' into DHIS2-13237
jasminenguyennn Jan 5, 2023
bab56da
Merge branch 'master' into DHIS2-13237
jasminenguyennn Jan 10, 2023
89f91b0
fix: minor fix
jasminenguyennn Jan 10, 2023
58cf3cf
Merge branch 'master' into DHIS2-13237
jasminenguyennn Jan 19, 2023
7c58207
chore: [DHIS2-13237] update review feedbacks
jasminenguyennn Jan 19, 2023
d94835e
chore: [DHIS2-13237] move folder
jasminenguyennn Jan 19, 2023
1054a57
Merge branch 'master' into DHIS2-13237
jasminenguyennn Jan 20, 2023
d6586c9
chore: [DHIS2-13237] minor add default value
jasminenguyennn Jan 25, 2023
ddb709d
chore: [DHIS2-13237] update edit polygon
jasminenguyennn Jan 25, 2023
aee5480
fix: [DHIS2-13237] minor fix
jasminenguyennn Jan 26, 2023
1321d38
Merge branch 'master' into DHIS2-13237
jasminenguyennn Jan 26, 2023
a31ec08
chore: [DHIS2-13237] fit bounds
jasminenguyennn Jan 27, 2023
8b7c0fa
fix: [DHIS2-13237] fix flow
jasminenguyennn Jan 27, 2023
d9a9f2e
fix: minor fix
jasminenguyennn Jan 27, 2023
a24b951
Merge branch 'master' into DHIS2-13237
jasminenguyennn Mar 21, 2023
64e5577
feat: [DHIS2-13237] add search feature
jasminenguyennn Mar 21, 2023
67da33c
feat: [DHIS2-13237] add input fields
jasminenguyennn Mar 21, 2023
1f29f52
fix: [DHIS2-13237] fix flow
jasminenguyennn Mar 22, 2023
a3a9dac
feat: [DHIS2-13237] update view/edit state
jasminenguyennn Mar 24, 2023
7341568
fix: minor update
jasminenguyennn Mar 27, 2023
0306946
Merge branch 'master' into DHIS2-13237
jasminenguyennn Mar 31, 2023
a84c8f9
Pressing enter should trigger search unique identifier returns results
jasminenguyennn Apr 18, 2023
9ae9423
fix: [DHIS2-13237] fix onChange
jasminenguyennn Apr 18, 2023
70628a1
fix: fix flow
jasminenguyennn Apr 18, 2023
ca68112
feat: [DHIS2-6335] add center by org unit coordinates
jasminenguyennn Apr 18, 2023
11de982
feat: [DHIS2-6335] use org unit coordinates as center point
jasminenguyennn Apr 19, 2023
1461509
fix: [DHIS2-13237] reset
jasminenguyennn Apr 20, 2023
280f130
fix: minor fix
jasminenguyennn Apr 20, 2023
fb90cbc
Merge branch 'master' into DHIS2-13237
simonadomnisoru Jun 2, 2023
4328c72
fix: validate coordinates
simonadomnisoru Jun 8, 2023
eb276a9
fix: delete polygon error
simonadomnisoru Jun 8, 2023
12e14fc
Merge branch 'master' into DHIS2-13237
simonadomnisoru Jun 9, 2023
4f5a328
Merge branch 'master' into DHIS2-13237
simonadomnisoru Jun 9, 2023
114254b
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Jun 9, 2023
869fb41
feat: [DHIS2-6335] use org unit coordinates as center point
simonadomnisoru Jun 13, 2023
af5dd73
chore: clean code
simonadomnisoru Jun 13, 2023
169e2cc
fix: close enrollment actions dropdown
simonadomnisoru Jul 4, 2023
d8582d9
fix: resetToDefaultValues and adjust height
simonadomnisoru Jul 4, 2023
c44f4a3
Merge branch 'master' into DHIS2-13237
simonadomnisoru Jul 4, 2023
23ca2d7
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Jul 4, 2023
9940b39
Merge branch 'master' into DHIS2-13237
simonadomnisoru Jul 24, 2023
e9d829b
chore: fix typo
simonadomnisoru Aug 8, 2023
4d23376
refactor: split MapCoordinatesModalComponent
simonadomnisoru Aug 10, 2023
120fa4e
Merge branch 'master' into DHIS2-13237
simonadomnisoru Aug 10, 2023
1919a26
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Aug 10, 2023
575bca7
chore: handle numbers with comma
simonadomnisoru Aug 16, 2023
0ebc464
fix: the map buttons are still displayed after closing the modal
simonadomnisoru Aug 17, 2023
941a9dd
chore: restructure MapModal folder
simonadomnisoru Aug 17, 2023
af48be5
chore: clean reactFGref
simonadomnisoru Aug 17, 2023
e7114cf
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Aug 17, 2023
ffa39ae
Merge branch 'master' into DHIS2-13237
simonadomnisoru Sep 7, 2023
c1674c7
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Sep 7, 2023
e5e9f38
Merge branch 'master' into DHIS2-13237
simonadomnisoru Sep 18, 2023
70973d4
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Sep 18, 2023
5aa0fcf
Merge branch 'master' into DHIS2-13237
simonadomnisoru Oct 18, 2023
cb72b5c
chore: disable the option to edit the polygon
simonadomnisoru Oct 19, 2023
f74091b
chore: improve the logic for Close without saving and Set Area buttons
simonadomnisoru Oct 23, 2023
da911ba
feat: return to previous state when canceling
simonadomnisoru Oct 23, 2023
2aea115
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Oct 25, 2023
c50adbf
Merge branch 'master' into DHIS2-13237
simonadomnisoru Nov 13, 2023
cd99514
fix: update enrollment mutation callback
simonadomnisoru Nov 13, 2023
abb8d9d
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru Nov 14, 2023
bb88f8d
feat: fetch the org unit only when the map is opened using useApiMeta…
simonadomnisoru Nov 30, 2023
3b195fa
Merge branch 'master' into DHIS2-6335
simonadomnisoru Nov 30, 2023
823d67c
Merge branch 'master' into DHIS2-6335
simonadomnisoru Jan 8, 2024
cd7c29f
Merge branch 'master' into DHIS2-6335
simonadomnisoru Feb 2, 2024
68a872a
Merge branch 'master' into DHIS2-6335
simonadomnisoru Feb 5, 2024
69aec56
Merge branch 'master' into DHIS2-6335
simonadomnisoru Feb 5, 2024
cdf150a
chore: change query key to reflect that we are just getting geometry
simonadomnisoru Mar 20, 2024
84b0bec
Merge branch 'master' into DHIS2-6335
simonadomnisoru Mar 20, 2024
78155ad
Merge branch 'master' into DHIS2-6335
simonadomnisoru Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const getGeometrySettings = () => ({
dialogLabel: i18n.t('Area'),
required: false,
orientation: getOrientation(props.formHorizontal),
orgUnit: props.orgUnit,
});
}

Expand All @@ -249,6 +250,7 @@ const getGeometrySettings = () => ({
required: false,
orientation: getOrientation(props.formHorizontal),
shrinkDisabled: props.formHorizontal,
orgUnit: props.orgUnit,
});
},
getPropName: () => 'geometry',
Expand Down Expand Up @@ -371,7 +373,6 @@ class FinalEnrollmentDataEntry extends React.Component<FinalTeiDataEntryProps> {
}
}


const AOCFieldBuilderHOC = withAOCFieldBuilder(getAOCSettingsFn())(
withDataEntryFields(
getCategoryOptionsSettingsFn(),
Expand Down Expand Up @@ -431,7 +432,6 @@ export class EnrollmentDataEntryComponent extends React.Component<PreEnrollmentD

render() {
const {
orgUnit,
onUpdateField,
onUpdateDataEntryField,
onStartAsyncUpdateField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const getStageGeometrySettings = () => ({
dialogLabel: i18n.t('Area'),
required: false,
orientation: getOrientation(props.formHorizontal),
orgUnit: props.orgUnit,
});
}

Expand All @@ -138,6 +139,7 @@ const getStageGeometrySettings = () => ({
required: false,
orientation: getOrientation(props.formHorizontal),
shrinkDisabled: props.formHorizontal,
orgUnit: props.orgUnit,
});
},
getPropName: () => stageMainDataIds.GEOMETRY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const buildGeometrySettingsFn = () => ({
dialogLabel: i18n.t('Area'),
required: false,
orientation: getOrientation(props.formHorizontal),
orgUnit: props.orgUnit,
});
}

Expand All @@ -241,6 +242,7 @@ const buildGeometrySettingsFn = () => ({
required: false,
orientation: getOrientation(props.formHorizontal),
shrinkDisabled: props.formHorizontal,
orgUnit: props.orgUnit,
});
},
getPropName: () => 'geometry',
Expand Down Expand Up @@ -579,6 +581,7 @@ class NewEventDataEntry extends Component<Props> {
fieldOptions={this.fieldOptions}
dataEntrySections={this.dataEntrySections}
relationshipsRef={this.setRelationshipsInstance}
orgUnit={orgUnit}
{...passOnProps}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import withStyles from '@material-ui/core/styles/withStyles';
import { CoordinateField as UICoordinateField } from 'capture-ui';
import { Modal, ModalTitle } from '@dhis2/ui';
import { typeof orientations } from '../../../New';
import { withCenterPoint } from '../../HOC';

const getStyles = (theme: Theme) => ({
inputWrapperFocused: {
Expand Down Expand Up @@ -93,4 +94,4 @@ class CoordinateFieldPlain extends React.Component<Props> {
}
}

export const CoordinateField = withStyles(getStyles)(CoordinateFieldPlain);
export const CoordinateField = withStyles(getStyles)(withCenterPoint()(CoordinateFieldPlain));
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import withStyles from '@material-ui/core/styles/withStyles';
import { PolygonField as UIPolygonField } from 'capture-ui';
import { Modal, ModalTitle } from '@dhis2/ui';
import { typeof orientations } from '../../../New';
import { withCenterPoint } from '../../HOC';

const getStyles = () => ({
dialogPaper: {
Expand Down Expand Up @@ -57,4 +58,4 @@ class PolygonFieldPlain extends React.Component<Props> {
}
}

export const PolygonField = withStyles(getStyles)(PolygonFieldPlain);
export const PolygonField = withStyles(getStyles)(withCenterPoint()(PolygonFieldPlain));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
export { withCenterPoint } from './withCenterPoint';
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @flow
import React, { type ComponentType, useMemo, useState } from 'react';
import { useApiMetadataQuery } from 'capture-core/utils/reactQueryHelpers';

const DEFAULT_CENTER = [51.505, -0.09];

const convertToClientCoordinates = ({ coordinates, type }: { coordinates: any[], type: string }) => {
switch (type) {
case 'Point':
return [coordinates[1], coordinates[0]];
case 'Polygon':
return coordinates[0][0];
default:
return DEFAULT_CENTER;
}
};

const getCenterPoint = (InnerComponent: ComponentType<any>) => (props: Object) => {
const { orgUnit, ...passOnProps } = props;
const [orgUnitKey, setOrgUnitKey] = useState(orgUnit.id);
const [shouldFetch, setShouldFetch] = useState(false);
const queryKey = ['organisationUnit', 'geometry', orgUnitKey];
const queryFn = {
resource: 'organisationUnits',
id: () => orgUnitKey,
params: {
fields: 'geometry,parent',
},
};
const queryOptions = useMemo(
() => ({ enabled: Boolean(orgUnit.id) && shouldFetch }),
[shouldFetch, orgUnit.id],
);
const { data } = useApiMetadataQuery<any>(queryKey, queryFn, queryOptions);

const center = useMemo(() => {
if (data) {
const { geometry, parent } = data;
if (geometry) {
return convertToClientCoordinates(geometry);
} else if (parent?.id) {
setOrgUnitKey(parent.id);
}
return DEFAULT_CENTER;
}
return undefined;
}, [data]);

const onOpenMap = (hasValue) => {
setShouldFetch(!hasValue);
};

return <InnerComponent {...passOnProps} center={center} onOpenMap={onOpenMap} />;
};

export const withCenterPoint = () => (InnerComponent: ComponentType<any>) => getCenterPoint(InnerComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { withLabel } from './HOC/withLabel';
export { withStyledContainer } from './HOC/withStyledContainer';
export { withOptionsIconElement } from './HOC/withOptionsIconElement';
export { withFocusSaver, withInternalChangeHandler } from 'capture-ui';
export { withCenterPoint } from './HOC/withCenterPoint';

// OrgUnit HOCs
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CoordinatesPlain = ({
onSetCoordinates,
}: CoordinatesProps) => {
const [position, setPosition] = useState(defaultValues);
const [center, setCenter] = useState(initialCenter);
const [center, setCenter] = useState();
const [tempLatitude, setTempLatitude] = useState(position?.[0]);
const [tempLongitude, setTempLongitude] = useState(position?.[1]);
const [isEditing, setEditing] = useState(!defaultValues);
Expand Down Expand Up @@ -92,7 +92,7 @@ const CoordinatesPlain = ({

const renderMap = () => (
<Map
center={center}
center={center ?? initialCenter}
zoom={13}
ref={(ref) => {
if (ref?.leafletElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import React, { useCallback } from 'react';
import { useGeometry } from '../hooks/useGeometry';
import type { MapModalProps } from './MapModal.types';
import { MapModal as MapModalComponent } from './MapModal.component';

const DEFAULT_CENTER = [51.505, -0.09];
import { useCenterPoint } from './hooks';

export const MapModal = ({
enrollment,
onUpdate,
setOpenMap,
defaultValues,
center,
center: storedCenter,
}: MapModalProps) => {
const { geometryType, dataElementType } = useGeometry(enrollment);
const { center } = useCenterPoint(enrollment.orgUnit, storedCenter);

const onSetCoordinates = useCallback((coordinates) => {
const geometry = coordinates ? { type: geometryType, coordinates } : null;
Expand All @@ -22,7 +22,7 @@ export const MapModal = ({

return (
<MapModalComponent
center={center || DEFAULT_CENTER}
center={center}
type={dataElementType}
setOpen={setOpenMap}
onSetCoordinates={onSetCoordinates}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PolygonPlain = ({
onSetCoordinates,
}: PolygonProps) => {
const [polygonArea, setPolygonArea] = useState(defaultValues);
const [center, setCenter] = useState(initialCenter);
const [center, setCenter] = useState();
const [drawingState, setDrawingState] = useState(undefined);
const prevDrawingState = useRef(undefined);

Expand Down Expand Up @@ -91,7 +91,7 @@ const PolygonPlain = ({

const renderMap = () => (
<Map
center={center}
center={center ?? initialCenter}
zoom={13}
ref={(ref) => {
if (ref?.leafletElement) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
export { useCenterPoint } from './useCenterPoint';
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @flow
import { useMemo, useState } from 'react';
import { useApiMetadataQuery } from 'capture-core/utils/reactQueryHelpers';

const DEFAULT_CENTER = [51.505, -0.09];

const convertToClientCoordinates = ({ coordinates, type }: { coordinates: any[], type: string }) => {
switch (type) {
case 'Point':
return [coordinates[1], coordinates[0]];
case 'Polygon':
return coordinates[0][0];
default:
return DEFAULT_CENTER;
}
};

export const useCenterPoint = (orgUnitId: string, storedCenter: ?[number, number]) => {
const [orgUnitKey, setOrgUnitKey] = useState(orgUnitId);
const queryKey = ['organisationUnit', 'geometry', orgUnitKey];
const queryFn = {
resource: 'organisationUnits',
id: () => orgUnitKey,
params: {
fields: 'geometry,parent',
},
};
const queryOptions = { enabled: !storedCenter && Boolean(orgUnitId) };
const { data, isLoading } = useApiMetadataQuery<any>(queryKey, queryFn, queryOptions);

const center = useMemo(() => {
if (data) {
const { geometry, parent } = data;
if (geometry) {
return convertToClientCoordinates(geometry);
} else if (parent?.id) {
setOrgUnitKey(parent.id);
}
return DEFAULT_CENTER;
}
return undefined;
}, [data]);

if (storedCenter) {
return {
center: storedCenter,
};
}

return {
center,
loading: isLoading,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const buildGeometrySettingsFn = () => ({
dialogLabel: i18n.t('Area'),
required: false,
orientation: getOrientation(props.formHorizontal),
orgUnit: props.orgUnit,
});
}

Expand All @@ -233,6 +234,7 @@ const buildGeometrySettingsFn = () => ({
required: false,
orientation: getOrientation(props.formHorizontal),
shrinkDisabled: props.formHorizontal,
orgUnit: props.orgUnit,
});
},
getPropName: () => 'geometry',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const DataEntry = ({ orgUnit, rulesExecutionDependenciesClientFormatted,
return (
<DataEntryComponent
{...passOnProps}
orgUnit={orgUnit}
orgUnitId={orgUnitId}
programId={programId}
onUpdateDataEntryField={onUpdateDataEntryField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ const buildGeometrySettingsFn = () => ({
label: i18n.t('Area'),
dialogLabel: i18n.t('Area'),
required: false,
orgUnit: props.orgUnit,
});
}
return createComponentProps(props, {
width: props && props.formHorizontal ? 150 : '100%',
label: i18n.t('Coordinate'),
dialogLabel: i18n.t('Coordinate'),
required: false,
orgUnit: props.orgUnit,
});
},
getPropName: () => 'geometry',
Expand Down Expand Up @@ -524,6 +526,7 @@ class EditEventDataEntryPlain extends Component<Props, State> {
onSaveAndCompleteEnrollment={onSaveAndCompleteEnrollment(orgUnit)}
fieldOptions={this.fieldOptions}
dataEntrySections={this.dataEntrySections}
orgUnit={orgUnit}
programId={programId}
selectedOrgUnitId={orgUnit?.id}
{...passOnProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const DataEntryComponent = ({
onGetValidationContext,
errorsMessages,
warningsMessages,
orgUnit,
}: PlainProps) => (
<Modal large onClose={onCancel} dataTest="modal-edit-profile">
<ModalTitle>{i18n.t(`Edit ${trackedEntityName}`)}</ModalTitle>
Expand All @@ -36,6 +37,7 @@ export const DataEntryComponent = ({
onUpdateFormField={onUpdateFormField}
onUpdateFormFieldAsync={onUpdateFormFieldAsync}
onGetValidationContext={onGetValidationContext}
orgUnit={orgUnit}
/>
<NoticeBoxes
dataEntryId={dataEntryId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const DataEntry = ({
onGetValidationContext={getValidationContext}
errorsMessages={errorsMessages}
warningsMessages={warningsMessages}
orgUnit={{ id: orgUnitId }}
/>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type PlainProps = {|
modalState: string,
errorsMessages: Array<{ id: string, message: string }>,
warningsMessages: Array<{ id: string, message: string }>,
center?: ?Array<number>,
orgUnit: { id: string },
|};

export type Props = {|
Expand Down
Loading
Loading