-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only request dimensions when needed (#1654)
This fix decreases the initial api requests being made when the dashboard first loads. There's no need to request dimensions unless they are needed for filtering the dashboard or setting filter settings while editing a dashboard.
- Loading branch information
1 parent
b31124a
commit 36eec71
Showing
9 changed files
with
79 additions
and
53 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useEffect } from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { acSetDimensions } from '../actions/dimensions' | ||
import { apiFetchDimensions } from '@dhis2/analytics' | ||
import { useDataEngine } from '@dhis2/app-runtime' | ||
|
||
import getFilteredDimensions from './getFilteredDimensions' | ||
import { useUserSettings } from '../components/UserSettingsProvider' | ||
|
||
const useDimensions = doFetch => { | ||
const dataEngine = useDataEngine() | ||
const { userSettings } = useUserSettings() | ||
const dimensions = useSelector(state => state.dimensions) | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
const fetchDimensions = async () => { | ||
try { | ||
const unfilteredDimensions = await apiFetchDimensions( | ||
dataEngine, | ||
userSettings.keyAnalysisDisplayProperty | ||
) | ||
|
||
dispatch( | ||
acSetDimensions(getFilteredDimensions(unfilteredDimensions)) | ||
) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
if ( | ||
!dimensions.length && | ||
doFetch && | ||
userSettings.keyAnalysisDisplayProperty | ||
) { | ||
fetchDimensions() | ||
} | ||
}, [dimensions, doFetch, userSettings.keyAnalysisDisplayProperty]) | ||
|
||
return dimensions | ||
} | ||
|
||
export default useDimensions |
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