-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [DHIS2-17970] Auto-select orgUnit if there is only one available (
#3798) * feat: pre select * feat: review changes * fix: remove children check * fix: review change * feat: merge hooks for auto select * Revert "feat: merge hooks for auto select" This reverts commit 9b97d2e. * fix: review changes
- Loading branch information
Showing
4 changed files
with
46 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { useOrganisationUnit } from './useOrganisationUnit'; | ||
export { useOrgUnitAutoSelect } from './useOrgUnitsForAutoSelect'; |
26 changes: 26 additions & 0 deletions
26
src/core_modules/capture-core/dataQueries/useOrgUnitsForAutoSelect.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,26 @@ | ||
// @flow | ||
import { useApiMetadataQuery } from '../utils/reactQueryHelpers'; | ||
|
||
export const useOrgUnitAutoSelect = (customQueryOptions: Object) => { | ||
const queryKey = ['organisationUnits']; | ||
const queryFn = { | ||
resource: 'organisationUnits', | ||
params: { | ||
fields: ['id, displayName~rename(name), path'], | ||
withinUserHierarchy: true, | ||
pageSize: 2, | ||
}, | ||
}; | ||
const defaultQueryOptions = { | ||
select: ({ organisationUnits }) => organisationUnits, | ||
}; | ||
|
||
const queryOptions = { ...defaultQueryOptions, ...customQueryOptions }; | ||
|
||
const { data, isLoading } = useApiMetadataQuery(queryKey, queryFn, queryOptions); | ||
|
||
return { | ||
isLoading, | ||
data, | ||
}; | ||
}; |