-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: [DHIS2-17970] Auto-select orgUnit if there is only one available #3798
feat: [DHIS2-17970] Auto-select orgUnit if there is only one available #3798
Conversation
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.
Hey @henrikmv!
Some quick comments that you could look into, but you're on the right track 🏁
src/core_modules/capture-core/components/WidgetRelatedStages/WidgetRelatedStages.component.js
Outdated
Show resolved
Hide resolved
orgUnits: { | ||
resource: 'me', | ||
params: { | ||
fields: ['organisationUnits[id,path,displayName,children::isNotEmpty]'], |
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.
I think we might have misunderstood each other here - fetching orgunits through the /me
-endpoint does not necessarily filter the children array for whether you have access or not. Let's say a user only has access to the Bo
-orgunit. With this API-call, children would be present (true) as Bo does have a child. However, the user does not have access to this orgUnit.
When fetching through the /api/organisationUnits
-endpoint, there are filters to make sure you are searching for all orgunits withinUserScope
or withinUserSearchScope
. If this array is bigger than two, that means the user has more than two orgunits assigned.
params: { | ||
fields: 'id,path,displayName', | ||
withinUserSearchHierarchy: true, | ||
page: 2, |
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.
@henrikmv what is the reason for adding page: 2
? I am not able to get the only available orgUnit with these parameters combination. It works if I remove it or use page:1
instead. Thanks!
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.
I am sorry, it should have been pageSize
. Thanks!
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.
LGTM!
🚀 Deployed on https://deploy-preview-3798.capture.netlify.dhis2.org |
…/fix/DHIS2-17970_AutoSelectOrgunitWhenOnlyOneAvailable
import { useApiMetadataQuery } from '../../../utils/reactQueryHelpers'; | ||
|
||
export const useOrgUnitAutoSelect = (setRelatedStageDataValues: any) => { | ||
const queryKey = ['organisationUnits']; |
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 looks like this hook is basically the same as the on in MetadataAutoSelectInitializer
. Could we perhaps combine them and reuse it? I feel pretty certain that this will be used in multiple places. Make a new hook called useOrgUnitsForAutoSelect
which returns isLoading
and an array of max 2 orgunits called orgUnits
.
Keep the useEffect outside of the hook, so that the behavior can be customized for whichever use-case needed. (In this case, move the useEffect into the WidgetRelatedStages.component.js
-file). Put the hook in the src/core_modules/capture-core/dataQueries
folder.
This reverts commit 9b97d2e.
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.
Tested successfully on 2.42,2.41.2,2.40.6,2.39.8 versions
# [101.11.0](v101.10.2...v101.11.0) (2024-10-14) ### Features * [DHIS2-17970] Auto-select orgUnit if there is only one available ([#3798](#3798)) ([de06f8b](de06f8b))
🎉 This PR is included in version 101.11.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
DHIS2-17970
organisationUnits
resource