Skip to content

Commit

Permalink
React Router 6 fixes (actualbudget#1178)
Browse files Browse the repository at this point in the history
* Provide `match` prop to class components that still rely on it.
* Fixes actualbudget#1169
* Fixes an unrelated crash on Payees
  • Loading branch information
trevdor authored Jun 24, 2023
1 parent 83459b4 commit f3f2c84
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useParams,
useNavigate,
useLocation,
useMatch,
} from 'react-router-dom';

import { debounce } from 'debounce';
Expand Down Expand Up @@ -1996,10 +1997,12 @@ class AccountInternal extends PureComponent {

function AccountHack(props) {
let { dispatch: splitsExpandedDispatch } = useSplitsExpanded();
let match = useMatch(props.location.pathname);

return (
<AccountInternal
{...props}
match={match}
splitsExpandedDispatch={splitsExpandedDispatch}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function Account(props) {

useEffect(updateSearchQuery, [searchText, currentQuery, state.dateFormat]);

if (!props.accounts || !props.accounts.length || !props.match) {
if (!props.accounts || !props.accounts.length) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/components/budget/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { memo, PureComponent, useContext, useMemo } from 'react';
import { connect } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { useLocation, useMatch, useNavigate } from 'react-router-dom';

import * as actions from 'loot-core/src/client/actions';
import { useSpreadsheet } from 'loot-core/src/client/SpreadsheetProvider';
Expand Down Expand Up @@ -520,6 +520,8 @@ const RolloverBudgetSummary = memo(props => {
function BudgetWrapper(props) {
let spreadsheet = useSpreadsheet();
let titlebar = useContext(TitlebarContext);
let location = useLocation();
let match = useMatch(location.pathname);
let navigate = useNavigate();

let reportComponents = useMemo(
Expand Down Expand Up @@ -566,6 +568,7 @@ function BudgetWrapper(props) {
spreadsheet={spreadsheet}
titlebar={titlebar}
navigate={navigate}
match={match}
/>
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/payees/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export const ManagePayees = forwardRef(
style={{
marginRight: '10px',
}}
disabled={!(orphanedPayees.length > 0) && !orphanedOnly}
disabled={!(orphanedPayees?.length > 0) && !orphanedOnly}
onClick={() => {
setOrphanedOnly(!orphanedOnly);
const filterInput = document.getElementById('filter-input');
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1178.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [trevdor]
---

A couple patches for the React Router 6 upgrade.

0 comments on commit f3f2c84

Please sign in to comment.