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

Identify and fix broken transfers #4216

Merged
merged 10 commits into from
Jan 23, 2025
Merged

Conversation

youngcw
Copy link
Member

@youngcw youngcw commented Jan 21, 2025

There is currently nothing in the code that automatically fixes an on budget transfer that ended up with a category. This adds that function to the "fix splits" script, and renames that script to "Repair Transactions".

Ive attached an example file that will show the "BROKEN" category label.
image

test1.zip
View the "test" account to see the broken transfer, or open the "Food" category spending

Thanks @UnderKoen for adding in the actual fix part.

@actual-github-bot actual-github-bot bot changed the title Show Broken Transfers [WIP] Show Broken Transfers Jan 21, 2025
Copy link

netlify bot commented Jan 21, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit cc88bf8
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67917dae3bb42a00088e8531
😎 Deploy Preview https://deploy-preview-4216.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 Jan 21, 2025

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
15 6.68 MB → 6.68 MB (+547 B) +0.01%
Changeset
File Δ Size
src/components/settings/RepairTransactions.tsx 🆕 +4.53 kB 0 B → 4.53 kB
node_modules/clsx/dist/clsx.js 🆕 +509 B 0 B → 509 B
node_modules/clsx/dist/clsx.js?commonjs-module 🆕 +27 B 0 B → 27 B
src/components/settings/index.tsx 📈 +9 B (+0.12%) 7.39 kB → 7.4 kB
src/components/transactions/TransactionsTable.jsx 📈 +38 B (+0.05%) 67.5 kB → 67.54 kB
node_modules/react-grid-layout/build/ReactGridLayout.js 📉 -1 B (-0.00%) 24.96 kB → 24.96 kB
node_modules/react-grid-layout/build/GridItem.js 📉 -1 B (-0.00%) 21.49 kB → 21.49 kB
node_modules/react-grid-layout/build/components/WidthProvider.js 📉 -1 B (-0.02%) 5.22 kB → 5.22 kB
src/components/settings/FixSplits.tsx 🔥 -4.14 kB (-100%) 4.14 kB → 0 B
node_modules/clsx/dist/clsx.mjs 🔥 -368 B (-100%) 368 B → 0 B
node_modules/clsx/dist/clsx.mjs?commonjs-proxy 🔥 -64 B (-100%) 64 B → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

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

Smaller

Asset File Size % Changed
static/js/ReportRouter.js 1.59 MB → 1.59 MB (-67 B) -0.00%

Unchanged

Asset File Size % Changed
static/js/nl.js 60.77 kB 0%
static/js/en.js 99.08 kB 0%
static/js/pt-BR.js 105.58 kB 0%
static/js/en-GB.js 95 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/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/uk.js 114.36 kB 0%
static/js/narrow.js 84.62 kB 0%
static/js/wide.js 101.36 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/AppliedFilters.js 10.52 kB 0%

Copy link
Contributor

github-actions bot commented Jan 21, 2025

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.33 MB → 1.33 MB (+425 B) +0.03%
Changeset
File Δ Size
packages/loot-core/src/server/tools/app.ts 📈 +693 B (+26.23%) 2.58 kB → 3.26 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.33 MB → 1.33 MB (+425 B) +0.03%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@youngcw
Copy link
Member Author

youngcw commented Jan 21, 2025

🎉 That seems to work! We should probably rename that button to be something more generic than about splits, and add a comment that transfers will get fixed.

@UnderKoen
Copy link
Member

Should we make the needs repair text clickable to directly fix it?

@youngcw
Copy link
Member Author

youngcw commented Jan 21, 2025

Should we make the needs repair text clickable to directly fix it?

If you can, then yes please!

@youngcw youngcw changed the title [WIP] Show Broken Transfers Identify and fix broken transfers Jan 21, 2025
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces changes to the transaction repair functionality across multiple files in the desktop client and server tools. The primary modifications include renaming the FixSplits function to RepairTransactions, updating the handling of budget transfer transactions, and adding a new feature to identify and fix transfers with incorrect categories. A new property numTransfersFixed is introduced to track the number of transfers repaired. The changes span the user interface components, including the settings and transactions table, and extend to the server-side tools for transaction repair. The modifications improve the clarity and functionality of the transaction repair process, particularly focusing on budget transfers and their categorization.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • matt-fidd

📜 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 3f4d4a6 and f6c17ea.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/settings/RepairTransactions.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/settings/RepairTransactions.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: compare

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 (5)
packages/loot-core/src/server/tools/app.ts (1)

77-85: Add NULL check for transfer_id in SQL query.

The query should handle cases where transfer_id is NULL to avoid potential issues.

 SELECT t1.id
 FROM v_transactions_internal t1
        JOIN accounts a1 ON t1.account = a1.id
-       JOIN v_transactions_internal t2 ON t1.transfer_id = t2.id
+       JOIN v_transactions_internal t2 ON t1.transfer_id = t2.id AND t1.transfer_id IS NOT NULL
        JOIN accounts a2 ON t2.account = a2.id
 WHERE a1.offbudget = a2.offbudget
   AND t1.category IS NOT NULL
packages/desktop-client/src/components/settings/RepairTransactions.tsx (2)

157-158: Fix typo in description text.

The word "erroniously" is misspelled.

-            Check if you have any budget transfers that erroniously contain a
+            Check if you have any budget transfers that erroneously contain a

62-64: Improve the fixed transfers message.

The message could be more descriptive about what was fixed.

-          t('Fixed {{count}} transfers.', {
+          t('Fixed {{count}} off-budget transfers by removing incorrect categories.', {
packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2)

1445-1447: LGTM! The changes effectively identify broken transfers.

The modification correctly implements the PR's objective by displaying 'Needs Repair' when a budget transfer incorrectly has a category assigned, helping users identify broken transfers that need attention.

Consider adding a comment explaining this logic for future maintainers:

                : isBudgetTransfer
+                  // For budget transfers, display 'Needs Repair' if a category is incorrectly assigned
+                  // otherwise display 'Transfer' as expected
                  ? categoryId != null
                    ? 'Needs Repair'
                    : 'Transfer'

1445-1447: Consider making the 'Needs Repair' text actionable.

Based on the PR discussion, particularly UnderKoen's suggestion, consider making the 'Needs Repair' text clickable to help users directly fix the broken transfers. This would improve the user experience by providing a clear path to resolution.

Example implementation approach:

                : isBudgetTransfer
                  ? categoryId != null
-                    ? 'Needs Repair'
+                    ? <Button
+                        variant="bare"
+                        style={{
+                          color: theme.errorText,
+                          textDecoration: 'underline',
+                          cursor: 'pointer'
+                        }}
+                        onPress={() => onRepairTransfer(transaction.id)}
+                      >
+                        Needs Repair
+                      </Button>
                    : 'Transfer'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7791b74 and 3f4d4a6.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4216.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/desktop-client/src/components/settings/RepairTransactions.tsx (5 hunks)
  • packages/desktop-client/src/components/settings/index.tsx (2 hunks)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx (1 hunks)
  • packages/loot-core/src/server/tools/app.ts (1 hunks)
  • packages/loot-core/src/server/tools/types/handlers.d.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: compare
🔇 Additional comments (3)
packages/loot-core/src/server/tools/types/handlers.d.ts (1)

8-8: LGTM!

The type definition for numTransfersFixed is correctly added to track the number of fixed transfers.

packages/desktop-client/src/components/settings/index.tsx (1)

34-34: LGTM!

The component import is correctly updated to use the renamed RepairTransactions component.

packages/desktop-client/src/components/transactions/TransactionsTable.jsx (1)

1445-1447: Strengthen the null check for better error handling.

The current check categoryId != null could be made more explicit to handle all edge cases properly.

Consider this more robust implementation:

                : isBudgetTransfer
-                  ? categoryId != null
+                  ? categoryId !== null && categoryId !== undefined
                    ? 'Needs Repair'
                    : 'Transfer'

Let's verify if there are any instances where categoryId might be undefined:

Comment on lines +87 to +93
await runMutator(async () => {
const updated = brokenTransfers.map(row => ({
id: row.id,
category: null,
}));
await batchUpdateTransactions({ updated });
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for failed updates.

The update operation should include error handling to ensure all transfers are properly fixed.

 await runMutator(async () => {
+  try {
     const updated = brokenTransfers.map(row => ({
       id: row.id,
       category: null,
     }));
-    await batchUpdateTransactions({ updated });
+    const results = await batchUpdateTransactions({ updated });
+    if (results.length !== updated.length) {
+      throw new Error('Not all transfers were updated successfully');
+    }
+  } catch (error) {
+    console.error('Failed to update transfers:', error);
+    throw error;
+  }
 });

Committable suggestion skipped: line range outside the PR's diff.

@matt-fidd
Copy link
Contributor

Nice!

@youngcw
Copy link
Member Author

youngcw commented Jan 23, 2025

@UnderKoen Im going to merge this now. Feel free to make another PR that makes the error text clickable.

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.

3 participants