diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.js index 33ac8cc9560677280ee47b8206bc3dc1722be3b7..ab0105a217edf99ecd813dc8d133db8bbadc3151 100644 --- a/packages/desktop-client/src/components/accounts/Account.js +++ b/packages/desktop-client/src/components/accounts/Account.js @@ -7,13 +7,7 @@ import React, { useMemo, } from 'react'; import { useSelector, useDispatch } from 'react-redux'; -import { - Navigate, - useParams, - useNavigate, - useLocation, - useMatch, -} from 'react-router-dom'; +import { Navigate, useParams, useLocation, useMatch } from 'react-router-dom'; import { debounce } from 'debounce'; import { bindActionCreators } from 'redux'; @@ -59,6 +53,7 @@ import SvgRemove from '../../icons/v2/Remove'; import SearchAlternate from '../../icons/v2/SearchAlternate'; import { authorizeBank } from '../../nordigen'; import { styles, colors } from '../../style'; +import { usePushModal } from '../../util/router-tools'; import { useActiveLocation } from '../ActiveLocation'; import AnimatedRefresh from '../AnimatedRefresh'; import { @@ -494,9 +489,8 @@ function SelectedTransactionsButton({ onCreateRule, onScheduleAction, }) { + let pushModal = usePushModal(); let selectedItems = useSelectedItems(); - let navigate = useNavigate(); - let location = useLocation(); let types = useMemo(() => { let items = [...selectedItems]; @@ -608,14 +602,11 @@ function SelectedTransactionsButton({ } if (scheduleId) { - navigate(`/schedule/edit/${scheduleId}`, { - locationPtr: location, - }); + pushModal(`/schedule/edit/${scheduleId}`); } break; case 'link-schedule': - navigate(`/schedule/link`, { - locationPtr: location, + pushModal('/schedule/link', { transactionIds: [...selectedItems], }); break; @@ -2124,7 +2115,7 @@ export default function Account() { {...actionCreators} modalShowing={ state.modalShowing || - !!(activeLocation.state && activeLocation.state.locationPtr) + !!(activeLocation.state && activeLocation.state.parent) } accountId={params.id} categoryId={activeLocation?.state?.filter?.category} diff --git a/packages/desktop-client/src/global-events.js b/packages/desktop-client/src/global-events.js index 7b3427153c14ce3635fa4d59a1bfa22a36d2ae47..64a08d7929c586bb883019082dc46ffede5d6bd8 100644 --- a/packages/desktop-client/src/global-events.js +++ b/packages/desktop-client/src/global-events.js @@ -36,14 +36,9 @@ export function handleGlobalEvents(actions, store) { }); listen('schedules-offline', ({ payees }) => { - let navigate = window.__navigate; - if (navigate) { - navigate(`/schedule/posts-offline-notification`, { - state: { - locationPtr: navigate.location, - payees, - }, - }); + let pushModal = window.__pushModal; + if (pushModal) { + pushModal(`/schedule/posts-offline-notification`, { payees }); } }); diff --git a/packages/desktop-client/src/util/router-tools.tsx b/packages/desktop-client/src/util/router-tools.tsx index a8fc7ea7d9c6a107becc9946dea7efebb26be1f3..f370d90d53c292aeca6f5b83c6f26b315ea1d168 100644 --- a/packages/desktop-client/src/util/router-tools.tsx +++ b/packages/desktop-client/src/util/router-tools.tsx @@ -13,9 +13,11 @@ let VERSION = Date.now(); export function ExposeNavigate() { let navigate = useNavigate(); + let pushModal = usePushModal(); useLayoutEffect(() => { window.__navigate = navigate; - }, [navigate]); + window.__pushModal = pushModal; + }, [navigate, pushModal]); return null; } @@ -24,8 +26,10 @@ export function usePushModal() { let location = useLocation(); return useCallback( - (path: To) => - navigate(path, { state: { parent: location, _version: VERSION } }), + (path: To, stateProps: Record<string, unknown> = {}) => + navigate(path, { + state: { parent: location, _version: VERSION, ...stateProps }, + }), [navigate, location], ); } diff --git a/packages/desktop-electron/menu.js b/packages/desktop-electron/menu.js index f472495991f0f50aaa79040a98dc822f9424ae5b..44cf69c6d9c99918483ecd25986e222bd3b54405 100644 --- a/packages/desktop-electron/menu.js +++ b/packages/desktop-electron/menu.js @@ -131,9 +131,7 @@ function getMenu(isDev, createWindow) { enabled: false, click: function (menuItem, focusedWin) { focusedWin.webContents.executeJavaScript( - // TODO: fix - // '__navigate && __history.push("/schedule/discover", { locationPtr: __history.location })', - 'alert("Not implemented")', + '__pushModal && __pushModal("/schedule/discover")', ); }, }, diff --git a/packages/loot-core/typings/window.d.ts b/packages/loot-core/typings/window.d.ts index 989f2ac5ff81478b21b06dac8889e4d57147b4bd..001ef57094cabe797c513caf3176e4ca2ede9716 100644 --- a/packages/loot-core/typings/window.d.ts +++ b/packages/loot-core/typings/window.d.ts @@ -1,3 +1,5 @@ +import { usePushModal } from '../../desktop-client/src/util/router-tools'; + export {}; declare global { @@ -9,5 +11,6 @@ declare global { }; __navigate?: import('react-router').NavigateFunction; + __pushModal?: ReturnType<typeof usePushModal>; } } diff --git a/upcoming-release-notes/1250.md b/upcoming-release-notes/1250.md new file mode 100644 index 0000000000000000000000000000000000000000..90fca92bb6d706adb49fdbf39abaa958721d433b --- /dev/null +++ b/upcoming-release-notes/1250.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [MatissJanis] +--- + +Fix `link schedule` option in transaction table diff --git a/upcoming-release-notes/1256.md b/upcoming-release-notes/1256.md new file mode 100644 index 0000000000000000000000000000000000000000..bf59b80de716130000d33b53abbb9363d4b097a9 --- /dev/null +++ b/upcoming-release-notes/1256.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [j-f1] +--- + +Remove lingering references to `locationPtr` after `react-router` upgrade