Skip to content

Commit

Permalink
MHV-64240: Bugs found regarding filter work (#33120)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmenshutin-bylight authored Nov 20, 2024
1 parent 5c88da0 commit 886f956
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import {
VaRadio,
Expand All @@ -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);
Expand All @@ -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,
);
}
}
Expand All @@ -51,6 +61,7 @@ const MedicationsListFilter = props => {
bordered="true"
id="filter"
data-testid="rx-filter"
ref={ref}
uswds
>
<span slot="icon">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/applications/mhv-medications/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 886f956

Please sign in to comment.