diff --git a/src/applications/mhv-medications/components/MedicationsList/MedicationsListFilter.jsx b/src/applications/mhv-medications/components/MedicationsList/MedicationsListFilter.jsx index 7e2649d32688..2785fe043b84 100644 --- a/src/applications/mhv-medications/components/MedicationsList/MedicationsListFilter.jsx +++ b/src/applications/mhv-medications/components/MedicationsList/MedicationsListFilter.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useRef } from 'react'; import PropTypes from 'prop-types'; import { VaRadio, @@ -10,11 +10,20 @@ import { import { focusElement } from '@department-of-veterans-affairs/platform-utilities/ui'; import { filterOptions, + SESSION_RX_FILTER_OPEN_BY_DEFAULT, SESSION_SELECTED_FILTER_OPTION, } from '../../util/constants'; const MedicationsListFilter = props => { const { updateFilter, filterOption, setFilterOption } = props; + const ref = useRef(null); + + useEffect(() => { + if (sessionStorage.getItem(SESSION_RX_FILTER_OPEN_BY_DEFAULT)) { + ref.current.setAttribute('open', true); + sessionStorage.removeItem(SESSION_RX_FILTER_OPEN_BY_DEFAULT); + } + }, []); const handleFilterOptionChange = ({ detail }) => { setFilterOption(detail.value); @@ -30,7 +39,8 @@ const MedicationsListFilter = props => { const isOpen = target.getAttribute('open'); if (isOpen === 'false') { setFilterOption( - sessionStorage.getItem(SESSION_SELECTED_FILTER_OPTION) || null, + sessionStorage.getItem(SESSION_SELECTED_FILTER_OPTION) || + filterOptions.ALL_MEDICATIONS.url, ); } } @@ -51,6 +61,7 @@ const MedicationsListFilter = props => { bordered="true" id="filter" data-testid="rx-filter" + ref={ref} uswds > diff --git a/src/applications/mhv-medications/components/RefillPrescriptions/RefillNotification.jsx b/src/applications/mhv-medications/components/RefillPrescriptions/RefillNotification.jsx index 1661ac093bbf..40aff6f8479b 100644 --- a/src/applications/mhv-medications/components/RefillPrescriptions/RefillNotification.jsx +++ b/src/applications/mhv-medications/components/RefillPrescriptions/RefillNotification.jsx @@ -5,10 +5,7 @@ import { focusElement } from '@department-of-veterans-affairs/platform-utilities import { useSelector } from 'react-redux'; import { dataDogActionNames } from '../../util/dataDogConstants'; import { selectFilterFlag } from '../../util/selectors'; -import { - SESSION_SELECTED_FILTER_OPTION, - filterOptions, -} from '../../util/constants'; +import { SESSION_RX_FILTER_OPEN_BY_DEFAULT } from '../../util/constants'; const RefillNotification = ({ refillStatus }) => { // Selectors @@ -43,11 +40,8 @@ const RefillNotification = ({ refillStatus }) => { ); const handleGoToMedicationsListOnSuccess = () => { - if (!sessionStorage.getItem(SESSION_SELECTED_FILTER_OPTION)) { - sessionStorage.setItem( - SESSION_SELECTED_FILTER_OPTION, - Object.values(filterOptions)[0].label, - ); + if (!sessionStorage.getItem(SESSION_RX_FILTER_OPEN_BY_DEFAULT)) { + sessionStorage.setItem(SESSION_RX_FILTER_OPEN_BY_DEFAULT, true); } }; diff --git a/src/applications/mhv-medications/containers/Prescriptions.jsx b/src/applications/mhv-medications/containers/Prescriptions.jsx index b4e1f481bf25..0e9c9a31f294 100644 --- a/src/applications/mhv-medications/containers/Prescriptions.jsx +++ b/src/applications/mhv-medications/containers/Prescriptions.jsx @@ -107,7 +107,8 @@ const Prescriptions = () => { const [loadingMessage, setLoadingMessage] = useState(''); const [sortingInProgress, setSortingInProgress] = useState(false); const [filterOption, setFilterOption] = useState( - sessionStorage.getItem(SESSION_SELECTED_FILTER_OPTION) || null, + sessionStorage.getItem(SESSION_SELECTED_FILTER_OPTION) || + filterOptions.ALL_MEDICATIONS.url, ); const [pdfTxtGenerateStatus, setPdfTxtGenerateStatus] = useState({ status: PDF_TXT_GENERATE_STATUS.NotStarted, diff --git a/src/applications/mhv-medications/util/constants.js b/src/applications/mhv-medications/util/constants.js index a223d5cff1e6..fd33f8ac1c7d 100644 --- a/src/applications/mhv-medications/util/constants.js +++ b/src/applications/mhv-medications/util/constants.js @@ -205,6 +205,8 @@ export const dispStatusObj = { export const SESSION_SELECTED_SORT_OPTION = 'SESSION_SELECTED_SORT_OPTION'; export const SESSION_SELECTED_FILTER_OPTION = 'SESSION_SELECTED_FILTER_OPTION'; +export const SESSION_RX_FILTER_OPEN_BY_DEFAULT = + 'SESSION_RX_FILTER_OPEN_BY_DEFAULT'; export const SESSION_SELECTED_PAGE_NUMBER = 'SESSION_SELECTED_PAGE_NUMBER'; export const INCLUDE_IMAGE_ENDPOINT = '&include_image=true';