-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MHV-56686 handle first time data refresh (#29004)
* MHV-56686 Added a retry-API function at the action level * MHV-56686 Added SET_INITIAL_FHIR_LOAD * MHV-56686 Handle displaying the records section in one place * MHV-56686 Modify action creators to use the new API retry function * MHV-56686 Removed old unit test * MHV-56686 Unused imports * MHV-56686 Added a spinner for initial FHIR data load * MHV-56686 Added the special case for vitals * MHV-56686 Reduce width of spinner * MHV-56686 Added more unit tests * MHV-56686 Fixed allergies no-records display * MHV-56686 Changed the API-retry time to 2 minutes
- Loading branch information
Showing
22 changed files
with
384 additions
and
317 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Actions } from '../util/actionTypes'; | ||
|
||
const defaultRetryInterval = 2000; | ||
const defaultEndTimeOffset = 120000; | ||
|
||
/** | ||
* Helper function to create a delay | ||
*/ | ||
const delay = ms => { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
}; | ||
|
||
/** | ||
* Recursive function that will continue polling the provided API endpoint if it sends a 202 response. | ||
* The backend returns a 202 if the patient record has not yet been created. | ||
* | ||
* @param {Function} dispatch the dispatch function | ||
* @param {Function} getList the API function to poll | ||
* @param {number} retryInterval how often to poll, e.g. 2000 for every two seconds | ||
* @param {number} endTimeParam when to stop polling and return an error (milliseconds since epoch) | ||
* @returns the response from the API function once it returns a 200 response | ||
*/ | ||
export const getListWithRetry = async ( | ||
dispatch, | ||
getList, | ||
retryInterval = defaultRetryInterval, | ||
endTimeParam = null, | ||
) => { | ||
const endTime = | ||
endTimeParam === null ? Date.now() + defaultEndTimeOffset : endTimeParam; | ||
|
||
if (Date.now() >= endTime) { | ||
throw new Error('Timed out while waiting for response'); | ||
} | ||
|
||
const response = await getList(); | ||
if (response?.status === 202) { | ||
dispatch({ type: Actions.Refresh.SET_INITIAL_FHIR_LOAD }); | ||
if (Date.now() < endTime) { | ||
await delay(retryInterval); | ||
return getListWithRetry(dispatch, getList, retryInterval, endTime); | ||
} | ||
} | ||
return response; | ||
}; |
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
57 changes: 57 additions & 0 deletions
57
src/applications/mhv/medical-records/components/shared/RecordListSection.jsx
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,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AccessTroubleAlertBox from './AccessTroubleAlertBox'; | ||
import NoRecordsMessage from './NoRecordsMessage'; | ||
|
||
const RecordListSection = ({ | ||
children, | ||
accessAlert, | ||
accessAlertType, | ||
recordCount, | ||
recordType, | ||
listCurrentAsOf, | ||
initialFhirLoad, | ||
}) => { | ||
if (accessAlert) { | ||
return <AccessTroubleAlertBox alertType={accessAlertType} />; | ||
} | ||
if (initialFhirLoad && !listCurrentAsOf) { | ||
return ( | ||
<div className="vads-u-margin-y--8"> | ||
<va-loading-indicator | ||
class="hydrated initial-fhir-load" | ||
message="We're loading your records for the first time. This can take up to 2 minutes. Stay on this page until your records load." | ||
setFocus | ||
data-testid="initial-fhir-loading-indicator" | ||
/> | ||
</div> | ||
); | ||
} | ||
if (recordCount === 0) { | ||
return <NoRecordsMessage type={recordType} />; | ||
} | ||
if (recordCount) { | ||
return children; | ||
} | ||
return ( | ||
<div className="vads-u-margin-y--8"> | ||
<va-loading-indicator | ||
message="We’re loading your records. This could take up to a minute." | ||
setFocus | ||
data-testid="loading-indicator" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RecordListSection; | ||
|
||
RecordListSection.propTypes = { | ||
accessAlert: PropTypes.bool, | ||
accessAlertType: PropTypes.string, | ||
children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), | ||
initialFhirLoad: PropTypes.bool, | ||
listCurrentAsOf: PropTypes.string, | ||
recordCount: PropTypes.number, | ||
recordType: PropTypes.string, | ||
}; |
Oops, something went wrong.