-
Notifications
You must be signed in to change notification settings - Fork 7
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
Waitp 1224 overlay selector desktop #4685
Merged
alexd-bes
merged 7 commits into
epic-frontend-rewrite
from
waitp-1224-overlay-selector-desktop
Jun 28, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43d565a
WAITP-1224 initial working selector
alexd-bes b0fcb1f
WAITP-1244 Tidy up files
alexd-bes b410783
Merge branch 'epic-frontend-rewrite' into waitp-1224-overlay-selector…
alexd-bes a0b2de5
Update border radius
alexd-bes fd672eb
Update border radius logic
alexd-bes 7962aff
Tidy ups
alexd-bes 8ff9041
Merge branch 'epic-frontend-rewrite' into waitp-1224-overlay-selector…
alexd-bes 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { useQuery } from 'react-query'; | ||
import { get } from '../api'; | ||
import { EntityCode, ProjectCode, SingleMapOverlayItem } from '../../types'; | ||
|
||
export const useMapOverlayData = ( | ||
projectCode?: ProjectCode, | ||
entityCode?: EntityCode, | ||
mapOverlayCode?: SingleMapOverlayItem['code'], | ||
) => { | ||
return useQuery( | ||
['mapOverlayData', projectCode, entityCode, mapOverlayCode], | ||
async () => { | ||
return get('measureData', { | ||
params: { | ||
mapOverlayCode, | ||
organisationUnitCode: entityCode, | ||
projectCode, | ||
shouldShowAllParentCountryResults: projectCode !== entityCode, // TODO: figure out the logic here for shouldShowAllParentCountryResults | ||
}, | ||
}); | ||
}, | ||
{ | ||
enabled: !!projectCode && !!entityCode && !!mapOverlayCode, | ||
}, | ||
); | ||
}; |
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,77 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import { ChangeEvent } from 'react'; | ||
import { useParams, useSearchParams } from 'react-router-dom'; | ||
import { useQuery, UseQueryResult } from 'react-query'; | ||
import { get } from '../api'; | ||
import { MapOverlayGroup, SingleMapOverlayItem } from '../../types'; | ||
import { URL_SEARCH_PARAMS } from '../../constants'; | ||
|
||
const mapOverlayByCode = ( | ||
mapOverlayGroups: MapOverlayGroup[] = [], | ||
): Record<SingleMapOverlayItem['code'], SingleMapOverlayItem> => { | ||
return mapOverlayGroups.reduce( | ||
( | ||
result: Record<string, SingleMapOverlayItem>, | ||
mapOverlay: MapOverlayGroup | SingleMapOverlayItem, | ||
) => { | ||
if (mapOverlay.children) { | ||
return { ...result, ...mapOverlayByCode(mapOverlay.children) }; | ||
} | ||
return { | ||
...result, | ||
[mapOverlay.code]: mapOverlay, | ||
}; | ||
}, | ||
{}, | ||
); | ||
}; | ||
|
||
interface UseMapOverlaysResult { | ||
hasMapOverlays: boolean; | ||
mapOverlayGroups: MapOverlayGroup[]; | ||
isLoadingMapOverlays: boolean; | ||
errorLoadingMapOverlays: UseQueryResult['error']; | ||
selectedOverlayCode: string | null; | ||
selectedOverlay?: SingleMapOverlayItem; | ||
updateSelectedMapOverlay: (e: ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
/** | ||
* Gets the map overlays and returns useful utils and values associated with these | ||
*/ | ||
export const useMapOverlays = (): UseMapOverlaysResult => { | ||
const [urlSearchParams, setUrlParams] = useSearchParams(); | ||
const { projectCode, entityCode } = useParams(); | ||
const { data, isLoading, error } = useQuery( | ||
['mapOverlays', projectCode, entityCode], | ||
async () => { | ||
return get(`mapOverlays/${projectCode}/${entityCode}`); | ||
}, | ||
{ | ||
enabled: !!projectCode && !!entityCode, | ||
}, | ||
); | ||
|
||
const selectedOverlayCode = urlSearchParams.get(URL_SEARCH_PARAMS.MAP_OVERLAY); | ||
const codedOverlays = mapOverlayByCode(data?.mapOverlays); | ||
|
||
const selectedOverlay = codedOverlays[selectedOverlayCode!]; | ||
|
||
const updateSelectedMapOverlay = (e: ChangeEvent<HTMLInputElement>) => { | ||
urlSearchParams.set(URL_SEARCH_PARAMS.MAP_OVERLAY, e.target.value); | ||
setUrlParams(urlSearchParams); | ||
}; | ||
|
||
return { | ||
hasMapOverlays: !!data?.mapOverlays?.length, | ||
mapOverlayGroups: data?.mapOverlays, | ||
isLoadingMapOverlays: isLoading, | ||
errorLoadingMapOverlays: error, | ||
selectedOverlayCode, | ||
selectedOverlay, | ||
updateSelectedMapOverlay, | ||
}; | ||
}; |
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.
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.
probably should be rems, right?
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.
It should, but this is just a placeholder so I don't think it's important at this stage
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.
oh true. I just see px and I jump 😆