Skip to content

A local-first personal finance app

:bug: fix link-schedule option in transaction table (#1250)

Matiss Janis Aboltinsede51872e2a7
diff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.js
index 33ac8cc956..ab0105a217 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 7b3427153c..64a08d7929 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 a8fc7ea7d9..f370d90d53 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 f472495991..44cf69c6d9 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 989f2ac5ff..001ef57094 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 0000000000..90fca92bb6
--- /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 0000000000..bf59b80de7
--- /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