Skip to content

Commit

Permalink
(refactor) add removeTrailingSlash helper and update breadcrumbs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mdewey committed Dec 27, 2024
1 parent c3f13bb commit 0d01c71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/applications/mhv-medical-records/components/MrBreadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { Link, useHistory, useLocation, useParams } from 'react-router-dom';
import { Breadcrumbs, Paths } from '../util/constants';
import { setBreadcrumbs } from '../actions/breadcrumbs';
import { clearPageNumber, setPageNumber } from '../actions/pageTracker';
import { handleDataDogAction } from '../util/helpers';
import { handleDataDogAction, removeTrialingSlash } from '../util/helpers';

const MrBreadcrumbs = () => {
const dispatch = useDispatch();
const location = useLocation();
const history = useHistory();

const crumbsList = useSelector(state => state.mr.breadcrumbs.crumbsList);
const pageNumber = useSelector(state => state.mr.pageTracker.pageNumber);
const phase0p5Flag = useSelector(
Expand Down Expand Up @@ -58,18 +59,16 @@ const MrBreadcrumbs = () => {
if (pageNumber) {
backToPageNumCrumb = {
...Breadcrumbs[feature],
href: `${Breadcrumbs[feature].href.slice(
0,
-1,
href: `${removeTrialingSlash(
Breadcrumbs[feature].href,
)}?page=${pageNumber}`,
};
dispatch(setBreadcrumbs([backToPageNumCrumb, detailCrumb]));
} else if (urlVitalsDate) {
const backToVitalsDateCrumb = {
...Breadcrumbs[feature],
href: `${Breadcrumbs[feature].href.slice(
0,
-1,
href: `${removeTrialingSlash(
Breadcrumbs[feature].href,
)}?timeFrame=${urlVitalsDate}`,
};
dispatch(setBreadcrumbs([backToVitalsDateCrumb, detailCrumb]));
Expand All @@ -80,7 +79,14 @@ const MrBreadcrumbs = () => {
dispatch(setBreadcrumbs([Breadcrumbs[feature]]));
}
},
[dispatch, locationBasePath, locationChildPath, textContent, pageNumber],
[
dispatch,
locationBasePath,
locationChildPath,
textContent,
pageNumber,
urlVitalsDate,
],
);

const handleRouteChange = ({ detail }) => {
Expand Down
10 changes: 10 additions & 0 deletions src/applications/mhv-medical-records/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,13 @@ export const formatDateInLocalTimezone = date => {
export const formatUserDob = userProfile => {
return userProfile?.dob ? formatDateLong(userProfile.dob) : 'Not found';
};

/**
* Removes the trailing slash from a path
*
* @param {string} path path to remove trailing slash from
* @returns {string} path without trailing slash
*/
export const removeTrialingSlash = path => {
return path.replace(/\/$/, '');
};

0 comments on commit 0d01c71

Please sign in to comment.