-
Notifications
You must be signed in to change notification settings - Fork 23
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
+155
−26
Merged
Changes from 79 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 c9e22f4
chore: minor fix
jasminenguyennn 29b5ee9
feat: [DHIS2-13237] handle polygon in the map
jasminenguyennn 02b7e6d
chore: fix flow
jasminenguyennn 6e392c7
chore: [DHIS2-13237] convert coordinates
jasminenguyennn 10c0237
feat: [DHIS2-13237] open on click and add new location
jasminenguyennn d610ef6
feat: [DHIS2-13237] handle add geometry
jasminenguyennn 562e73c
feat: [DHIS2-13237] update locations
jasminenguyennn 6e1ea40
chore: [DHIS2-13237] minor fix
jasminenguyennn c3d2cc0
Merge branch 'master' into DHIS2-13237
jasminenguyennn 2d7f6f8
chore: [DHIS2-13237] minor fix
jasminenguyennn 261dd92
Merge branch 'master' into DHIS2-13237
jasminenguyennn bab56da
Merge branch 'master' into DHIS2-13237
jasminenguyennn 89f91b0
fix: minor fix
jasminenguyennn 58cf3cf
Merge branch 'master' into DHIS2-13237
jasminenguyennn 7c58207
chore: [DHIS2-13237] update review feedbacks
jasminenguyennn d94835e
chore: [DHIS2-13237] move folder
jasminenguyennn 1054a57
Merge branch 'master' into DHIS2-13237
jasminenguyennn d6586c9
chore: [DHIS2-13237] minor add default value
jasminenguyennn ddb709d
chore: [DHIS2-13237] update edit polygon
jasminenguyennn aee5480
fix: [DHIS2-13237] minor fix
jasminenguyennn 1321d38
Merge branch 'master' into DHIS2-13237
jasminenguyennn a31ec08
chore: [DHIS2-13237] fit bounds
jasminenguyennn 8b7c0fa
fix: [DHIS2-13237] fix flow
jasminenguyennn d9a9f2e
fix: minor fix
jasminenguyennn a24b951
Merge branch 'master' into DHIS2-13237
jasminenguyennn 64e5577
feat: [DHIS2-13237] add search feature
jasminenguyennn 67da33c
feat: [DHIS2-13237] add input fields
jasminenguyennn 1f29f52
fix: [DHIS2-13237] fix flow
jasminenguyennn a3a9dac
feat: [DHIS2-13237] update view/edit state
jasminenguyennn 7341568
fix: minor update
jasminenguyennn 0306946
Merge branch 'master' into DHIS2-13237
jasminenguyennn a84c8f9
Pressing enter should trigger search unique identifier returns results
jasminenguyennn 9ae9423
fix: [DHIS2-13237] fix onChange
jasminenguyennn 70628a1
fix: fix flow
jasminenguyennn ca68112
feat: [DHIS2-6335] add center by org unit coordinates
jasminenguyennn 11de982
feat: [DHIS2-6335] use org unit coordinates as center point
jasminenguyennn 1461509
fix: [DHIS2-13237] reset
jasminenguyennn 280f130
fix: minor fix
jasminenguyennn fb90cbc
Merge branch 'master' into DHIS2-13237
simonadomnisoru 4328c72
fix: validate coordinates
simonadomnisoru eb276a9
fix: delete polygon error
simonadomnisoru 12e14fc
Merge branch 'master' into DHIS2-13237
simonadomnisoru 4f5a328
Merge branch 'master' into DHIS2-13237
simonadomnisoru 114254b
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru 869fb41
feat: [DHIS2-6335] use org unit coordinates as center point
simonadomnisoru af5dd73
chore: clean code
simonadomnisoru 169e2cc
fix: close enrollment actions dropdown
simonadomnisoru d8582d9
fix: resetToDefaultValues and adjust height
simonadomnisoru c44f4a3
Merge branch 'master' into DHIS2-13237
simonadomnisoru 23ca2d7
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru 9940b39
Merge branch 'master' into DHIS2-13237
simonadomnisoru e9d829b
chore: fix typo
simonadomnisoru 4d23376
refactor: split MapCoordinatesModalComponent
simonadomnisoru 120fa4e
Merge branch 'master' into DHIS2-13237
simonadomnisoru 1919a26
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru 575bca7
chore: handle numbers with comma
simonadomnisoru 0ebc464
fix: the map buttons are still displayed after closing the modal
simonadomnisoru 941a9dd
chore: restructure MapModal folder
simonadomnisoru af48be5
chore: clean reactFGref
simonadomnisoru e7114cf
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru ffa39ae
Merge branch 'master' into DHIS2-13237
simonadomnisoru c1674c7
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru e5e9f38
Merge branch 'master' into DHIS2-13237
simonadomnisoru 70973d4
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru 5aa0fcf
Merge branch 'master' into DHIS2-13237
simonadomnisoru cb72b5c
chore: disable the option to edit the polygon
simonadomnisoru f74091b
chore: improve the logic for Close without saving and Set Area buttons
simonadomnisoru da911ba
feat: return to previous state when canceling
simonadomnisoru 2aea115
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru c50adbf
Merge branch 'master' into DHIS2-13237
simonadomnisoru cd99514
fix: update enrollment mutation callback
simonadomnisoru abb8d9d
Merge branch 'DHIS2-13237' into DHIS2-6335
simonadomnisoru bb88f8d
feat: fetch the org unit only when the map is opened using useApiMeta…
simonadomnisoru 3b195fa
Merge branch 'master' into DHIS2-6335
simonadomnisoru 823d67c
Merge branch 'master' into DHIS2-6335
simonadomnisoru cd7c29f
Merge branch 'master' into DHIS2-6335
simonadomnisoru 68a872a
Merge branch 'master' into DHIS2-6335
simonadomnisoru 69aec56
Merge branch 'master' into DHIS2-6335
simonadomnisoru cdf150a
chore: change query key to reflect that we are just getting geometry
simonadomnisoru 84b0bec
Merge branch 'master' into DHIS2-6335
simonadomnisoru 78155ad
Merge branch 'master' into DHIS2-6335
simonadomnisoru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/core_modules/capture-core/components/FormFields/New/HOC/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @flow | ||
export { withCenterPoint } from './withCenterPoint'; |
56 changes: 56 additions & 0 deletions
56
src/core_modules/capture-core/components/FormFields/New/HOC/withCenterPoint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/core_modules/capture-core/components/WidgetEnrollment/MapModal/hooks/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @flow | ||
export { useCenterPoint } from './useCenterPoint'; |
54 changes: 54 additions & 0 deletions
54
src/core_modules/capture-core/components/WidgetEnrollment/MapModal/hooks/useCenterPoint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', 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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change the key to reflect that we are just getting geometry here (so we don't clash with other caches). Suggestion:
['organisationUnit', 'geometry', orgUnitKey]
And use same key in
useCenterPoint.js