Skip to content

Commit

Permalink
MAT-7667: Let layout only listen to top level and details click
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Nov 13, 2024
1 parent 1d1f2b0 commit fe549bf
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/router/RouteChangeHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ const RouteChangePrompt = () => {
};
}, []);

const isTopLevel = ({ pathname }) => {
const singleRoutePattern = /^\/[^\/]+\/?$/;
const detailsClickPattern = /^\/measures\/[a-f0-9]{24}\/edit\/details\/$/;
// should return true if path matches singleRoutePattern or detailsClickPattern
return (
singleRoutePattern.test(pathname) || detailsClickPattern.test(pathname)
);
};
const blocker = useBlocker(({ currentLocation, nextLocation }) => {
if (
!routeHandlerState?.canTravel &&
currentLocation.pathname !== nextLocation.pathname
) {
setDialogOpen(true);
return true;
if (isTopLevel(nextLocation)) {
if (
!routeHandlerState?.canTravel &&
currentLocation.pathname !== nextLocation.pathname
) {
setDialogOpen(true);
return true;
}
setDialogOpen(false);
return false;
}
setDialogOpen(false);
return false;
});

const onContinue = () => {
Expand Down

0 comments on commit fe549bf

Please sign in to comment.