-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) O3-1594 BUG: Patient chart close button has inconsistent behavi…
…or (#1581)
- Loading branch information
Showing
7 changed files
with
366 additions
and
174 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/esm-patient-chart-app/src/visit-header/close-button.component.tsx
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,40 @@ | ||
import React from 'react'; | ||
import { HeaderGlobalAction } from '@carbon/react'; | ||
import { CloseFilled } from '@carbon/react/icons'; | ||
import { getHistory, goBackInHistory, navigate, usePatient } from '@openmrs/esm-framework'; | ||
import { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styles from './close-button.scss'; | ||
|
||
export function CloseButton() { | ||
const { t } = useTranslation(); | ||
const { patientUuid } = usePatient(); | ||
|
||
const onClosePatientChart = useCallback(() => { | ||
const history = getHistory(); | ||
// Get the last page the user was on before opening the patient chart by going backward | ||
// through the history until a URL does not include patientUuid | ||
let onCloseTarget = ''; | ||
for (let i = history.length - 1; i >= 0; i--) { | ||
if (!history[i].includes(patientUuid)) { | ||
onCloseTarget = history[i]; | ||
break; | ||
} | ||
} | ||
if (onCloseTarget) { | ||
goBackInHistory({ toUrl: onCloseTarget }); | ||
} else { | ||
navigate({ to: '${openmrsSpaBase}/home' }); | ||
} | ||
}, [patientUuid]); | ||
|
||
return ( | ||
<HeaderGlobalAction | ||
className={styles.headerGlobalBarCloseButton} | ||
aria-label={t('close', 'Close')} | ||
onClick={onClosePatientChart} | ||
> | ||
<CloseFilled size={20} /> | ||
</HeaderGlobalAction> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/esm-patient-chart-app/src/visit-header/close-button.scss
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,5 @@ | ||
@import '~@openmrs/esm-styleguide/src/vars'; | ||
|
||
.headerGlobalBarCloseButton { | ||
@include brand-02(background-color); | ||
} |
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
Oops, something went wrong.