Skip to content

Commit

Permalink
AKR:OTR:VKT:YKI:SHARED(Frontend) OPHAKRKEH-515 jest migration test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Jan 4, 2024
1 parent fdb2e6d commit d83ae6f
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 317 deletions.
15 changes: 4 additions & 11 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"react-dom": "^18.2.0",
"react-i18next": "^13.3.1",
"react-redux": "^8.1.3",
"react-router-dom": "6.18.0",
"react-router-dom": "6.13.0",
"redux-saga": "^1.2.3"
},
"devDependencies": {
Expand Down Expand Up @@ -110,14 +110,7 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"@availableBiggerUpdates": [
"loader-utils",
"@mui/x-date-pickers",
"i18next",
"i18next-browser-languagedetector",
"react-router-dom",
"prettier + eslint-plugin-prettier",
"stylelint + configs",
"typescript"
]
"@comments": {
"react-router-dom": "Do not update past 6.13.0 until useBlocker is fixed, see https://github.com/remix-run/react-router/issues/11155"
}
}
2 changes: 1 addition & 1 deletion frontend/packages/akr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"akr:tslint": "yarn g:tsc --pretty --noEmit"
},
"dependencies": {
"shared": "npm:@opetushallitus/[email protected].31"
"shared": "npm:@opetushallitus/[email protected].32"
}
}
2 changes: 1 addition & 1 deletion frontend/packages/otr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"otr:tslint": "yarn g:tsc --pretty --noEmit"
},
"dependencies": {
"shared": "npm:@opetushallitus/[email protected].31"
"shared": "npm:@opetushallitus/[email protected].32"
}
}
2 changes: 1 addition & 1 deletion frontend/packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opetushallitus/kieli-ja-kaantajatutkinnot.shared",
"version": "1.9.31",
"version": "1.9.32",
"description": "Shared Frontend Package",
"exports": {
"./components": "./src/components/index.tsx",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { History } from 'history';
import { useContext, useLayoutEffect } from 'react';
import { UNSAFE_NavigationContext } from 'react-router-dom';
import { useLayoutEffect } from 'react';
import { useLocation } from 'react-router-dom';

export const ScrollToTop = () => {
// FIXME: UNSAFE_NavigationContext is no longer allowed in react router 6
/*
const navigator = useContext(UNSAFE_NavigationContext).navigator as History;
const location = useLocation();

useLayoutEffect(() => {
const unlisten = navigator.listen(({ action }) => {
if (action !== 'POP') {
window.scrollTo({ left: 0, top: 0 });
}
});
window.scrollTo({ left: 0, top: 0 });
}, [location]);

return unlisten;
}, [navigator]);
*/
return null;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Blocker, Transition } from 'history';
import { useCallback, useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router';

import { useBlocker } from './useBlocker';

export const useCallbackPrompt = (when: boolean, baseUrl?: string) => {

/*
const navigate = useNavigate();
const location = useLocation();
const [showPrompt, setShowPrompt] = useState(false);
Expand Down Expand Up @@ -65,6 +63,6 @@ export const useCallbackPrompt = (when: boolean, baseUrl?: string) => {
}, [isNavigationConfirmed, blockedTransition, navigate, isWithinBaseUrl]);
useBlocker(handleBlockedNavigation, when, baseUrl);

*/
return { showPrompt, confirmNavigation, cancelNavigation };
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { useEffect, useCallback } from 'react';
import { flushSync } from "react-dom";

import { useCallbackPrompt } from './useCallbackPrompt';
import { unstable_useBlocker as useBlocker } from 'react-router-dom';

export const useNavigationProtection = (
when: boolean,
Expand All @@ -10,14 +11,26 @@ export const useNavigationProtection = (
) => void,
baseUrl?: string
) => {
const { showPrompt, confirmNavigation, cancelNavigation } = useCallbackPrompt(
when,
baseUrl
);

const shouldBlock =
({ currentLocation, nextLocation, historyAction }) =>
when &&
!nextLocation.pathname.includes(baseUrl) &&
currentLocation.pathname !== nextLocation.pathname;

const blocker = useBlocker(shouldBlock);

const confirmNavigation = useCallback(() => {
blocker.proceed();
}, [blocker]);

const cancelNavigation = useCallback(() => {
blocker.reset();
}, [blocker]);

useEffect(() => {
if (showPrompt) {
if (blocker.state === "blocked") {
showConfirmationDialog(confirmNavigation, cancelNavigation);
}
}, [showPrompt, confirmNavigation, cancelNavigation, showConfirmationDialog]);
}, [blocker, confirmNavigation, cancelNavigation, showConfirmationDialog]);
};
2 changes: 1 addition & 1 deletion frontend/packages/vkt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"dependencies": {
"reduxjs-toolkit-persist": "^7.2.1",
"shared": "npm:@opetushallitus/[email protected].31"
"shared": "npm:@opetushallitus/[email protected].32"
}
}
Loading

0 comments on commit d83ae6f

Please sign in to comment.