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

extend fix splits tool to report splits with mismatched amounts #3970

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

matt-fidd
Copy link
Contributor

No description provided.

Copy link

netlify bot commented Dec 12, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit eedddd4
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/675f0ef83f648b0008fe0731
😎 Deploy Preview https://deploy-preview-3970.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.

Copy link
Contributor

github-actions bot commented Dec 12, 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
10 5.53 MB → 5.53 MB (+246 B) +0.00%
Changeset
File Δ Size
src/components/settings/FixSplits.tsx 📈 +246 B (+7.52%) 3.19 kB → 3.43 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.45 MB → 3.45 MB (+246 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/TransactionList.js 102.91 kB 0%
static/js/narrow.js 83.36 kB 0%
static/js/wide.js 161.25 kB 0%
static/js/ReportRouter.js 1.58 MB 0%

Copy link
Contributor

github-actions bot commented Dec 12, 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.32 MB → 1.32 MB (+191 B) +0.01%
Changeset
File Δ Size
packages/loot-core/src/server/tools/app.ts 📈 +457 B (+20.92%) 2.13 kB → 2.58 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.32 MB → 1.32 MB (+191 B) +0.01%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@matt-fidd matt-fidd changed the title [WIP] log mismatched split amounts on repair split extend fix splits tool to report splits with mismatched amounts Dec 15, 2024
Copy link
Contributor

coderabbitai bot commented Dec 15, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/desktop-client/src/components/settings/FixSplits.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eslint-plugin".

(The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eslint-plugin@latest --save-dev

The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces enhancements to the handling and reporting of split transactions across multiple files in the desktop client and core application. The changes focus on improving the detection and reporting of issues related to split transactions.

In the loot-core package, the tools/fix-split-transactions method has been updated to include logic for identifying mismatched splits, where the sum of subtransaction amounts does not equal the parent transaction amount. The method now returns additional information, including the count of mismatched splits alongside existing counts for blank payees, cleared transactions, and deleted transactions.

Correspondingly, the FixSplits component in the desktop client has been modified to process and display this new mismatchedSplits information. The renderResults function now utilizes an array to collect and join multiple result messages, allowing for more detailed reporting of various split transaction issues. Type definitions have also been updated to reflect these changes, adding the mismatchedSplits property to the return type of the tools/fix-split-transactions method.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • MikesGlitch
  • youngcw

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d681a73 and eedddd4.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/settings/FixSplits.tsx (3 hunks)
🔇 Additional comments (5)
packages/desktop-client/src/components/settings/FixSplits.tsx (5)

18-19: LGTM: Clean type handling for results

The change from a single string to an array of strings is a good approach for handling multiple message types, and the destructuring is clean.


21-26: LGTM: Comprehensive check for repairs needed

The addition of mismatchedSplits.length === 0 completes the set of conditions for determining if repairs are needed.


51-54: LGTM: Appropriate visual feedback

Good use of theme colors to provide visual distinction between normal and error states.


81-83: LGTM: Improved layout structure

The layout changes properly implement flex layout with appropriate spacing and alignment, addressing the previous feedback about avoiding display: block.


38-44: Verify date format consistency

The message construction for mismatched splits is well-structured, but let's verify the date format consistency with other parts of the application.

✅ Verification successful

Based on the search results, I can see that dates in the codebase are consistently handled in ISO format ('YYYY-MM-DD') internally, and when displayed, they are formatted according to the user's preferred date format using utility functions. Let's verify the specific date handling in the FixSplits component and its related utilities:


Let's check how the date is being used in the FixSplits component and verify if there are any date formatting utilities being used:


Based on the comprehensive analysis of the FixSplits component and date handling in the codebase, I can now generate the final response:

Date format is consistent with codebase standards

The date handling in the mismatched splits message is correct and consistent with the codebase. The dates are received directly from the server response (tools/fix-split-transactions) and displayed in their original format without any additional formatting needed, as they are used only for informational purposes in an error message. The component correctly handles both singular and plural cases in the message construction.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for date formatting patterns in the codebase
rg -A 2 "t\.date|date:" packages/desktop-client/src/

Length of output: 35810


Script:

#!/bin/bash
# Search for date-related imports and utilities in FixSplits
rg -A 3 "import.*date|formatDate|parseDate" packages/desktop-client/src/components/settings/FixSplits.tsx

# Look for the Transaction type definition that includes the date field
ast-grep --pattern 'type Transaction = {
  $$$
  date: $_
  $$$
}'

Length of output: 938


Script:

#!/bin/bash
# Get the full content of FixSplits component to understand the date handling
cat packages/desktop-client/src/components/settings/FixSplits.tsx

# Search for date utility functions in the codebase
rg -g '!*.test.*' -g '!*.d.ts' "export.*function.*date|export.*const.*date" packages/desktop-client/src/

Length of output: 5117


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (3)
packages/loot-core/src/server/tools/app.ts (1)

60-69: Consider adding an index hint for performance.

The query fetches all parent transactions with their splits. As the dataset grows, this could become performance-intensive. Consider adding appropriate database indexes and limiting the result set if possible.

packages/desktop-client/src/components/settings/FixSplits.tsx (2)

38-42: Consider showing more transaction details.

The current implementation only shows the date for mismatched splits. Consider adding more identifying information such as the transaction amount, account, or payee to help users locate these transactions more easily.

 if (mismatchedSplits.length > 0) {
   result.push(
     `Found ${mismatchedSplits.length} split transaction${mismatchedSplits.length > 1 ? 's' : ''} with mismatched amounts:\n` +
-      mismatchedSplits.map(t => `- ${t.date}`).join('\n'),
+      mismatchedSplits.map(t => 
+        `- ${t.date} | ${t.payee || 'No payee'} | Amount: ${t.amount} (Expected: ${
+          t.subtransactions.reduce((acc, st) => acc + st.amount, 0)
+        })`
+      ).join('\n'),
   );
 }

Line range hint 45-57: Improve accessibility for screen readers.

Consider adding ARIA labels or roles to improve the screen reader experience for the results message, especially since it contains structured information about mismatched splits.

 return (
   <Paragraph
+    role="status"
+    aria-live="polite"
     style={{
       color: theme.noticeTextLight,
       marginBottom: 0,
       marginLeft: '1em',
       textAlign: 'right',
       whiteSpace: 'pre-wrap',
     }}
   >
     {result.join('\n')}
   </Paragraph>
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef95850 and 31c83d3.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/settings/FixSplits.tsx (3 hunks)
  • packages/loot-core/src/server/tools/app.ts (2 hunks)
  • packages/loot-core/src/server/tools/types/handlers.d.ts (1 hunks)
🔇 Additional comments (1)
packages/loot-core/src/server/tools/types/handlers.d.ts (1)

1-1: LGTM! Type definitions are well-structured.

The addition of mismatchedSplits: TransactionEntity[] to the return type properly extends the interface to support the new mismatched amounts reporting feature.

Also applies to: 8-8

packages/loot-core/src/server/tools/app.ts Show resolved Hide resolved
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

♻️ Duplicate comments (1)
packages/loot-core/src/server/tools/app.ts (1)

70-74: ⚠️ Potential issue

Handle floating-point arithmetic precision for monetary calculations.

When comparing monetary amounts, floating-point arithmetic can lead to precision issues. Consider using a decimal arithmetic library or rounding to a fixed precision before comparison.

 const mismatchedSplits = splitTransactions.filter(t => {
-  const subValue = t.subtransactions.reduce((acc, st) => acc + st.amount, 0);
+  const subValue = Number(t.subtransactions.reduce((acc, st) => acc + st.amount, 0).toFixed(2));
+  const parentValue = Number(t.amount.toFixed(2));
-  return subValue !== t.amount;
+  return subValue !== parentValue;
 });
🧹 Nitpick comments (1)
packages/loot-core/src/server/tools/app.ts (1)

59-68: Consider optimizing the query by selecting only required fields.

The query currently selects all fields (select('*')). For better performance, consider selecting only the fields needed for the mismatched splits check (e.g., 'id', 'amount', 'subtransactions').

 const splitTransactions = (
   await runQuery(
     q('transactions')
       .options({ splits: 'grouped' })
       .filter({
         is_parent: true,
       })
-      .select('*'),
+      .select(['id', 'amount', 'subtransactions']),
   )
 ).data;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31c83d3 and 42719f5.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3970.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • packages/loot-core/src/server/tools/app.ts (2 hunks)
  • packages/loot-core/src/server/tools/types/handlers.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/loot-core/src/server/tools/types/handlers.d.ts
🔇 Additional comments (2)
packages/loot-core/src/server/tools/app.ts (2)

2-2: LGTM!

The new imports are correctly added and necessary for the query functionality.

Also applies to: 5-5


80-80: LGTM!

The addition of mismatchedSplits to the return object aligns with the PR objective and maintains type safety.

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

🧹 Nitpick comments (1)
packages/desktop-client/src/components/settings/FixSplits.tsx (1)

Line range hint 18-72: Consider adding error boundary protection

Given that this component handles critical data repair operations, consider wrapping it in an error boundary to gracefully handle any rendering errors that might occur due to unexpected data formats or failed operations.

This would help prevent the entire UI from crashing if something goes wrong during the repair process or result rendering.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42719f5 and d681a73.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/settings/FixSplits.tsx (3 hunks)
🔇 Additional comments (5)
packages/desktop-client/src/components/settings/FixSplits.tsx (5)

18-19: LGTM: Good refactor to support multiple messages

The change from a single string to an array of strings is a clean approach that makes the message handling more maintainable and extensible.


21-27: LGTM: Comprehensive check for all error conditions

The condition properly includes the new mismatched splits check while maintaining the existing validation logic.


51-54: LGTM: Good use of theme-based error indication

The conditional styling provides clear visual feedback using consistent theme colors.


59-59: LGTM: Clean message rendering

The array join with newlines provides clear visual separation between different types of messages.


38-44: Verify the date format display

The implementation looks good, but we should verify the date format being displayed. The current code uses the raw t.date value without any formatting.

Let's check the date format in the codebase:

Consider using a consistent date formatting function if one exists in the codebase, to maintain uniformity across the application.

✅ Verification successful

Let me search for the specific date format being used in the file's context.


Let me check how the date format is handled in the server-side handler that provides these transactions.


Let me check one final thing to see how the transaction dates are stored and handled in the models.


Let me check the transaction model definition specifically.


Raw date format is appropriate in this context

The current implementation using raw t.date is actually correct because:

  1. The TransactionEntity type shows that date is stored as a string in a standardized format
  2. This is an internal diagnostic tool showing dates of transactions that need manual fixing
  3. The raw format ensures consistency with the database's stored format, which is crucial for manual investigation and fixing of problematic transactions
  4. The dates will be in ISO format (YYYY-MM-DD) as that's the standard storage format in the database, making it unambiguous for users to locate these transactions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for date formatting patterns in the codebase
rg -A 2 "\.date.*format|formatDate" 

Length of output: 8737


Script:

#!/bin/bash
# Search for date format usage in the FixSplits component and its imports
rg -l "FixSplits" | xargs rg "dateFormat|format.*date"

# Also check the specific file for any date-related imports
cat packages/desktop-client/src/components/settings/FixSplits.tsx

Length of output: 3853


Script:

#!/bin/bash
# Check the server-side handler implementation
ast-grep --pattern 'tools/fix-split-transactions'

# Also check the type definition of the transaction object
rg -A 5 "type.*Transaction" packages/loot-core/src/types/

Length of output: 3435


Script:

#!/bin/bash
# Check the transaction model definition
cat packages/loot-core/src/types/models/index.d.ts

# Also check the fix-split-transactions handler implementation
rg -A 10 "tools/fix-split-transactions" packages/loot-core/src/

Length of output: 2136


Script:

#!/bin/bash
# Check the transaction model definition
cat packages/loot-core/src/types/models/transaction.d.ts

# Also check if there's a common date format utility
rg -A 3 "export.*dateFormat" packages/loot-core/src/

Length of output: 1603

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.

1 participant