-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
68 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
33 changes: 0 additions & 33 deletions
33
src/core_modules/capture-core/utils/api/useQueryStyleEvaluation.js
This file was deleted.
Oops, something went wrong.
30 changes: 17 additions & 13 deletions
30
src/core_modules/capture-core/utils/cachedDataHooks/useDataElementsFromIndexedDB.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 |
---|---|---|
@@ -1,28 +1,32 @@ | ||
// @flow | ||
import { useCallback } from 'react'; | ||
import type { UseQueryOptions } from 'react-query'; | ||
import { userStores, getUserStorageController } from '../../storageControllers'; | ||
import { useQueryStyleEvaluation } from '../api/useQueryStyleEvaluation'; | ||
import { useIndexedDBQuery } from '../reactQueryHelpers'; | ||
import type { CachedDataElement } from '../../storageControllers/'; | ||
|
||
export const useDataElementsFromIndexedDB = (dataElementIds: ?Set<string>): { | ||
export const useDataElementsFromIndexedDB = (queryKey: Array<string | number>, dataElementIds: ?Set<string>, queryOptions?: UseQueryOptions<>): { | ||
dataElements: ?Array<CachedDataElement>, | ||
loading: boolean, | ||
error: any, | ||
isLoading: boolean, | ||
isError: boolean, | ||
} => { | ||
const storageController = getUserStorageController(); | ||
const { enabled = !!dataElementIds } = queryOptions ?? {}; | ||
|
||
const getDataElements = useCallback(requestedIds => | ||
storageController.getAll( | ||
const { data, isLoading, isError } = useIndexedDBQuery( | ||
['dataElements', ...queryKey], | ||
() => storageController.getAll( | ||
userStores.DATA_ELEMENTS, { | ||
predicate: dataElement => requestedIds.has(dataElement.id), | ||
// $FlowIgnore - the enabled prop guarantees that dataElementIds will be defined | ||
predicate: dataElement => dataElementIds.has(dataElement.id), | ||
}, | ||
), [storageController]); | ||
|
||
const { loading, data, error } = useQueryStyleEvaluation(getDataElements, dataElementIds); | ||
), { | ||
enabled, | ||
}, | ||
); | ||
|
||
return { | ||
dataElements: data, | ||
loading, | ||
error, | ||
isLoading, | ||
isError, | ||
}; | ||
}; |
30 changes: 17 additions & 13 deletions
30
src/core_modules/capture-core/utils/cachedDataHooks/useOptionSetsFromIndexedDB.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 |
---|---|---|
@@ -1,28 +1,32 @@ | ||
// @flow | ||
import { useCallback } from 'react'; | ||
import type { UseQueryOptions } from 'react-query'; | ||
import { userStores, getUserStorageController } from '../../storageControllers'; | ||
import { useQueryStyleEvaluation } from '../api/useQueryStyleEvaluation'; | ||
import { useIndexedDBQuery } from '../reactQueryHelpers'; | ||
import type { CachedOptionSet } from '../../storageControllers/'; | ||
|
||
export const useOptionSetsFromIndexedDB = (optionSetIds: ?Set<string>): { | ||
export const useOptionSetsFromIndexedDB = (queryKey: Array<string | number>, optionSetIds: ?Set<string>, queryOptions?: UseQueryOptions<>): { | ||
optionSets: ?Array<CachedOptionSet>, | ||
loading: boolean, | ||
error: any, | ||
isLoading: boolean, | ||
isError: boolean, | ||
} => { | ||
const storageController = getUserStorageController(); | ||
const { enabled = !!optionSetIds } = queryOptions ?? {}; | ||
|
||
const getOptionSets = useCallback(requestedIds => | ||
storageController.getAll( | ||
const { data, isLoading, isError } = useIndexedDBQuery( | ||
['optionSets', ...queryKey], | ||
() => storageController.getAll( | ||
userStores.OPTION_SETS, { | ||
predicate: optionSet => requestedIds.has(optionSet.id), | ||
// $FlowIgnore - the enabled prop guarantees that optionSetIds will be defined | ||
predicate: optionSet => optionSetIds.has(optionSet.id), | ||
}, | ||
), [storageController]); | ||
|
||
const { loading, data, error } = useQueryStyleEvaluation(getOptionSets, optionSetIds); | ||
), { | ||
enabled, | ||
}, | ||
); | ||
|
||
return { | ||
optionSets: data, | ||
loading, | ||
error, | ||
isLoading, | ||
isError, | ||
}; | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/utils/reactQueryHelpers/reactQueryHelpers.const.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
// @flow | ||
|
||
export const ReactQueryAppNamespace = 'capture'; | ||
export const IndexedDBNamespace = 'indexedDB'; |