Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2703 - Fixes inaccurate running balance when hiding reconciled transactions #3603

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

wysinder
Copy link
Contributor

@wysinder wysinder commented Oct 8, 2024

Fixes #2703 to show an account's running balance accurately when hiding its reconciled transactions. This addresses the use case of wanting to hide reconciled transactions (to keep them off of mind) and still showing the account's running balance.

Implementation notes:

  • This fix changes updateQuery to not filter out reconciled transactions, but defers the filtering downstream to TransactionsTable instead (which now takes the showReconciled prop accordingly).
  • This allows us to call calculateBalances on the full set of account transactions. Previously, calculateBalances would be executed on only the rendered transactions, which meant the calculation would not reflect the account's actual balance.
  • This does not break the existing behaviour that hides running balances when searching, filtering, or sorting (canCalculateBalance is respected).

Preview build screenshots:

Show running balance + Show reconciled transactions:
image

[PREVIOUS TO THIS FIX] Show running balance + Hide reconciled transactions (inaccurate running balance):
image

[WITH THIS FIX] Show running balance + Hide reconciled transactions (running balance is now accurate):
image

Show running balance + Hide reconciled transactions + Reconciled transaction in between two other transactions (shows accurate running balance on that day):
image

Copy link

netlify bot commented Oct 8, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 64b8d87
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/670532af0bfee40007693cb9
😎 Deploy Preview https://deploy-preview-3603.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@wysinder wysinder marked this pull request as draft October 8, 2024 03:35
Copy link
Contributor

github-actions bot commented Oct 8, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 5.31 MB → 5.31 MB (+339 B) +0.01%
Changeset
File Δ Size
src/components/transactions/TransactionList.jsx 📈 +36 B (+0.74%) 4.74 kB → 4.78 kB
src/components/transactions/TransactionsTable.jsx 📈 +210 B (+0.32%) 63.34 kB → 63.55 kB
src/components/accounts/Account.tsx 📈 +93 B (+0.21%) 43.46 kB → 43.55 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/wide.js 224.55 kB → 224.88 kB (+339 B) +0.15%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/AppliedFilters.js 20.96 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/ReportRouter.js 1.51 MB 0%
static/js/index.js 3.33 MB 0%

Copy link
Contributor

github-actions bot commented Oct 8, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.19 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.19 MB 0%

Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request introduces significant updates to the Account.tsx and TransactionsTable.jsx components. In Account.tsx, the logic for filtering reconciled transactions within the AccountInternal class has been refined to consider user settings regarding balance visibility. This adjustment affects the updateQuery method, ensuring reconciled transactions are filtered based on whether balances are shown or can be calculated. The TransactionsTable.jsx component now includes a new variable, transactionsToRender, which is computed using the useMemo hook to determine which transactions to display based on the showReconciled prop. This change replaces direct references to props.transactions with transactionsToRender, ensuring accurate rendering of transactions according to user preferences. Additionally, several method signatures in AccountInternalProps have been updated to reflect these changes, enhancing the clarity and maintainability of the code.

Assessment against linked issues

Objective Addressed Explanation
Filter reconciled transactions based on user settings (2703)
Ensure correct balance display when reconciled transactions are hidden (2703)

Possibly related PRs

  • fix creating rule from transaction #3539: The changes in this PR involve modifications to the Account.tsx component, specifically in the onCreateRule method, which is relevant to the transaction handling logic also modified in the main PR's Account.tsx.

Suggested labels

:sparkles: Merged, :white_check_mark: Approved

Suggested reviewers

  • matt-fidd
  • joel-jeremy

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
packages/desktop-client/src/components/transactions/TransactionList.jsx (1)

208-209: LGTM: showReconciled prop passed to TransactionTable.

The showReconciled prop is correctly passed down to the TransactionTable component. Its placement is logical and consistent with the component's structure.

For consistency, consider aligning the showReconciled prop with showBalances on the previous line:

-      showBalances={showBalances}
-
-      showReconciled={showReconciled}
+      showBalances={showBalances}
+      showReconciled={showReconciled}
packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2)

1814-1814: Improve readability by reformatting the conditional operator

The current formatting of the conditional operator in the useMemo hook can be hard to read. Reformatting it enhances clarity and adheres to the project's coding standards.

Apply this diff to reformat the code:

       const transactionsToRender = useMemo(
-        () => props.showReconciled ? props.transactions : props.transactions.filter(t => !t.reconciled),
+        () =>
+          props.showReconciled
+            ? props.transactions
+            : props.transactions.filter(t => !t.reconciled),
         [props.transactions, props.showReconciled]
       );
🧰 Tools
🪛 GitHub Check: lint

[warning] 1814-1814:
Replace ·props.showReconciled·?·props.transactions with ⏎······props.showReconciled⏎········?·props.transactions⏎·······


1815-1815: Add a trailing comma to the dependency array for consistency

According to the style guidelines, adding a trailing comma in multi-line arrays and objects improves diff readability and maintains consistency.

Apply this diff to add the trailing comma:

         [props.transactions, props.showReconciled]
+        ,
🧰 Tools
🪛 GitHub Check: lint

[warning] 1815-1815:
Insert ,

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bdeb194 and 28dc971.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/accounts/Account.tsx (2 hunks)
  • packages/desktop-client/src/components/transactions/TransactionList.jsx (2 hunks)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2 hunks)
🧰 Additional context used
🪛 GitHub Check: lint
packages/desktop-client/src/components/accounts/Account.tsx

[warning] 491-491:
Replace !this.state.showReconciled·&&·(!this.state.showBalances·||·!this.canCalculateBalance()) with ⏎······!this.state.showReconciled·&&⏎······(!this.state.showBalances·||·!this.canCalculateBalance())⏎····

packages/desktop-client/src/components/transactions/TransactionsTable.jsx

[warning] 1814-1814:
Replace ·props.showReconciled·?·props.transactions with ⏎······props.showReconciled⏎········?·props.transactions⏎·······


[warning] 1815-1815:
Insert ,

🔇 Additional comments (3)
packages/desktop-client/src/components/transactions/TransactionList.jsx (2)

71-71: LGTM: New prop showReconciled added.

The addition of the showReconciled prop is consistent with the component's existing structure and naming conventions. It's well-placed among similar props and its purpose is clear from the name.


71-71: Overall changes look good, consider additional steps.

The introduction of the showReconciled prop is well-implemented and consistent with the PR objectives. However, to ensure completeness:

  1. Verify that the TransactionTable component correctly utilizes the showReconciled prop.
  2. Update unit tests to cover the new functionality.
  3. Update component documentation to reflect the new prop.

To verify the usage of showReconciled in the TransactionTable component, run:

Also applies to: 208-209

✅ Verification successful

showReconciled Prop Usage Verified Successfully

The showReconciled prop is correctly implemented and utilized within the TransactionList.jsx and TransactionsTable.jsx components. No issues were found related to its usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the usage of showReconciled prop in TransactionTable
rg --type javascript 'showReconciled.*TransactionTable' packages/desktop-client/src/components/transactions/

Length of output: 145


Script:

#!/bin/bash
# Search for the usage of showReconciled prop in TransactionTable with the correct file type
rg --type js 'showReconciled.*TransactionTable' packages/desktop-client/src/components/transactions/

Length of output: 102


Script:

#!/bin/bash
# Search for all usages of showReconciled across the codebase
rg --type js --type jsx 'showReconciled' .

Length of output: 70


Script:

#!/bin/bash
# Search for all usages of showReconciled across the entire codebase without specifying file types
rg 'showReconciled' .

Length of output: 2214

packages/desktop-client/src/components/accounts/Account.tsx (1)

1750-1750: Prop 'showReconciled' correctly passed to TransactionList component

The showReconciled prop is appropriately passed to the TransactionList component, ensuring that the component reflects the updated logic for displaying reconciled transactions.

@wysinder wysinder changed the title [WIP] Fixes #2703 - Show accurate balances when hiding reconciled transactions. [WIP] Fixes #2703 - Fixes inaccurate running balance when hiding reconciled transactions Oct 8, 2024
@wysinder wysinder marked this pull request as ready for review October 8, 2024 13:40
@actual-github-bot actual-github-bot bot changed the title [WIP] Fixes #2703 - Fixes inaccurate running balance when hiding reconciled transactions Fixes #2703 - Fixes inaccurate running balance when hiding reconciled transactions Oct 8, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2)

1994-1994: Good update to use filtered transactions in renderRow

The change to use transactionsToRender instead of props.transactions in the renderRow function is correct and necessary to complete the implementation of the reconciled transaction filtering feature.

For consistency, consider updating other occurrences of props.transactions within this component to use transactionsToRender where appropriate.


Review Additional Instances of props.transactions

The initial change to use transactionsToRender in the renderRow function is correctly implemented. However, multiple other instances of props.transactions exist in TransactionsTable.jsx that may require review:

  • Lines 1816-1818:
    ? props.transactions
    : props.transactions.filter(t => !t.reconciled),
    [props.transactions, props.showReconciled],
  • Lines 1859-1861:
    ? props.transactionsByParent[trans.id]
    const emptyChildTransactions = props.transactionsByParent[
  • Line 1867:
    allTransactions={props.transactions}
  • Lines 1975-1976:
    props.transactions?.length > 0
    ? props.balances?.[props.transactions[0]?.id]?.balance
  • Lines 2036-2082:
    const index = props.transactions.findIndex(
    result = props.transactions.filter((t, idx) => {
    result = props.transactions.filter(t => {
    }, [props.transactions, splitsExpanded]);
    return props.transactions.reduce((acc, trans) => {
    }, [props.transactions]);
  • Lines 2092-2137:
    props.transactions.map(t => {
    }, [props.transactions, props.payees, props.accounts]);
    transactions: props.transactions,
  • Line 2186:
    }, [newTransactions, props.transactions]);

Please review each of these instances to determine if they should utilize transactionsToRender instead of props.transactions to maintain consistency with the new filtering logic.

🔗 Analysis chain

Line range hint 1812-1994: Consider reviewing other uses of props.transactions

While the change to use transactionsToRender in the renderRow function is correct, there are several other occurrences of props.transactions in this file. It would be beneficial to review each of these instances to determine if they should also be updated to use transactionsToRender.

For example:

  • Line 1821: const trans = item; (This is correct as is, since it's using the filtered transactionsToRender)
  • Line 1885: props.transactions.reduce((acc, trans) => {
  • Line 1902: props.transactions.map(t => {

Please carefully consider each usage to ensure consistency with the new filtering logic while maintaining the intended functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all occurrences of props.transactions in the file
echo "Occurrences of props.transactions:"
rg --line-number 'props\.transactions' packages/desktop-client/src/components/transactions/TransactionsTable.jsx

echo "\nOccurrences of transactionsToRender:"
rg --line-number 'transactionsToRender' packages/desktop-client/src/components/transactions/TransactionsTable.jsx

Length of output: 654


Script:

#!/bin/bash
# Corrected script to find all occurrences of props.transactions and transactionsToRender in the specified file

echo "Occurrences of props.transactions:"
rg --line-number 'props\.transactions' packages/desktop-client/src/components/transactions/TransactionsTable.jsx

echo "\nOccurrences of transactionsToRender:"
rg --line-number 'transactionsToRender' packages/desktop-client/src/components/transactions/TransactionsTable.jsx

Length of output: 1439

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 28dc971 and 64b8d87.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3603.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • packages/desktop-client/src/components/accounts/Account.tsx (2 hunks)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/accounts/Account.tsx
🧰 Additional context used
🔇 Additional comments (2)
packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2)

1812-1819: Excellent implementation of reconciled transaction filtering!

The introduction of transactionsToRender using useMemo is a great approach to conditionally render transactions based on their reconciled status. This change directly addresses the PR objective of fixing the inaccurate running balance issue when hiding reconciled transactions. The use of useMemo also ensures that the filtering only occurs when necessary, which is good for performance.


Line range hint 1812-2024: Overall good implementation, suggest comprehensive testing

The changes introduced in this file effectively implement the feature to filter out reconciled transactions when showReconciled is false. This directly addresses the PR objective of fixing the inaccurate running balance issue when hiding reconciled transactions. The use of useMemo for transactionsToRender is a good choice for performance optimization.

However, to ensure the changes are fully effective and don't introduce any unintended side effects, I recommend:

  1. Comprehensive testing of the new functionality, especially edge cases involving reconciled transactions.
  2. Verifying that the running balance calculation is now accurate when reconciled transactions are hidden.
  3. Ensuring that toggling the showReconciled prop correctly updates the displayed transactions and associated balances.
  4. Checking that other features dependent on transaction data (like sorting, filtering, etc.) still work correctly with the new implementation.
#!/bin/bash
# This script can't run tests directly, but it can check for the presence of relevant test files

echo "Checking for relevant test files:"
fd --type file --extension test.js --extension test.jsx --extension spec.js --extension spec.jsx | rg -i "transaction|reconcil"

echo "\nChecking for reconciled transaction logic in test files:"
rg --type js "reconciled.*transaction" -g "*test*"

Copy link
Member

@youngcw youngcw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for taking care of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Hide reconciled transactions - wrong balance shown
2 participants