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

feat: [DHIS2-17970] Auto-select orgUnit if there is only one available #3798

Merged

Conversation

henrikmv
Copy link
Contributor

@henrikmv henrikmv commented Sep 10, 2024

DHIS2-17970

  • Retrieving organization units from the organisationUnits resource
  • If the user has access to only one orgUnit and that orgUnit has no child units, it will be automatically selected in the Schedule option in the action widget.

@henrikmv henrikmv marked this pull request as ready for review September 10, 2024 14:00
@henrikmv henrikmv requested a review from a team as a code owner September 10, 2024 14:00
Copy link
Contributor

@eirikhaugstulen eirikhaugstulen left a 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 🏁

orgUnits: {
resource: 'me',
params: {
fields: ['organisationUnits[id,path,displayName,children::isNotEmpty]'],
Copy link
Contributor

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,
Copy link
Contributor

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!

Copy link
Contributor Author

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!

Copy link
Contributor

@simonadomnisoru simonadomnisoru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@henrikmv henrikmv requested review from eirikhaugstulen and removed request for eirikhaugstulen September 23, 2024 07:27
Copy link

github-actions bot commented Sep 23, 2024

…/fix/DHIS2-17970_AutoSelectOrgunitWhenOnlyOneAvailable
import { useApiMetadataQuery } from '../../../utils/reactQueryHelpers';

export const useOrgUnitAutoSelect = (setRelatedStageDataValues: any) => {
const queryKey = ['organisationUnits'];
Copy link
Contributor

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.

Copy link

@geethaalwan geethaalwan left a 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

@henrikmv henrikmv merged commit de06f8b into master Oct 14, 2024
39 checks passed
@henrikmv henrikmv deleted the hv/fix/DHIS2-17970_AutoSelectOrgunitWhenOnlyOneAvailable branch October 14, 2024 14:53
dhis2-bot added a commit that referenced this pull request Oct 14, 2024
# [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))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 101.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants