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

Add ability to provide defaults for and skip updating cleared status in API #4129

Merged
merged 6 commits into from
Jan 15, 2025

Conversation

NikxDa
Copy link
Contributor

@NikxDa NikxDa commented Jan 11, 2025

  • Add ability to provide default for cleared field
  • Add ability to skip updating cleared field

Motivation

The reason for these changes is explained in NikxDa/actual-moneymoney#20.
Basically, there is currently no way for an API import to leave the cleared status as set by the user, and neither is there a way to import transactions with the status defaulting to false. This addresses both issues, enabling importing and updating transactions without modifying their cleared status (a request I have so far received twice in the importer repo above).

- Add ability to provide default for cleared field
- Add ability to skip updating cleared field
Copy link

netlify bot commented Jan 11, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit bf3a2ac
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/678797d33672310008d83e32
😎 Deploy Preview https://deploy-preview-4129.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 11, 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
13 6.02 MB → 6.02 MB (+237 B) +0.00%
Changeset
File Δ Size
node_modules/es-define-property/index.js 📈 +210 B (+60.00%) 350 B → 560 B
node_modules/has-property-descriptors/index.js 📈 +9 B (+1.57%) 573 B → 582 B
node_modules/call-bind/index.js 📈 +9 B (+0.85%) 1.04 kB → 1.05 kB
node_modules/define-data-property/index.js 📈 +9 B (+0.39%) 2.24 kB → 2.25 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.78 MB → 3.78 MB (+237 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/BackgroundImage.js 122.29 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/AppliedFilters.js 10.21 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/en-GB.js 96.92 kB 0%
static/js/en.js 96.91 kB 0%
static/js/narrow.js 84.3 kB 0%
static/js/wide.js 106.04 kB 0%
static/js/uk.js 120.47 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Jan 11, 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 (+10 B) +0.00%
Changeset
File Δ Size
packages/api/methods.ts 📈 +138 B (+0.95%) 14.17 kB → 14.31 kB
packages/loot-core/src/server/main.ts 📈 +28 B (+0.04%) 69.32 kB → 69.34 kB
packages/loot-core/src/server/accounts/sync.ts 📉 -1 B (-0.00%) 26.19 kB → 26.19 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 (+10 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@NikxDa NikxDa marked this pull request as ready for review January 11, 2025 01:51
Copy link
Contributor

coderabbitai bot commented Jan 11, 2025

Walkthrough

This pull request introduces a new ImportTransactionsOpts interface and modifies several functions across multiple files to support an optional defaultCleared parameter for transaction imports. The changes span the API methods, server-side transaction synchronization, and type definitions. The primary modification allows more flexible handling of transaction clearing status during import, with a default value of true. The updates are implemented consistently across packages/api/methods.ts, packages/loot-core/src/server/accounts/sync.ts, packages/loot-core/src/server/main.ts, and type definition files to ensure comprehensive support for the new import options.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • matt-fidd
  • jfdoming
  • MikesGlitch

Finishing Touches

  • 📝 CodeRabbit is generating docstrings... (♻️ Check again to generate again)

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: 0

🧹 Nitpick comments (1)
packages/loot-core/src/server/main.ts (1)

1259-1259: Consider adding JSDoc documentation for the new parameter.

The implementation correctly uses optional chaining to handle the new parameter. To improve maintainability, consider adding JSDoc documentation to describe the purpose and expected values of the defaultCleared option.

Example documentation:

/**
 * @param opts.defaultCleared - Optional parameter to specify the default cleared status for imported transactions
 */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da13dfa and 736172d.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4129.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/api/methods.ts (1 hunks)
  • packages/loot-core/src/server/accounts/sync.ts (3 hunks)
  • packages/loot-core/src/server/main.ts (2 hunks)
  • packages/loot-core/src/types/api-handlers.d.ts (2 hunks)
  • packages/loot-core/src/types/server-handlers.d.ts (2 hunks)
🔇 Additional comments (11)
packages/api/methods.ts (2)

88-90: LGTM! Clean interface design.

The ImportTransactionsOpts interface is well-defined and follows TypeScript best practices.


92-102: LGTM! Good backward compatibility.

The function signature change maintains backward compatibility by providing a default value for opts. The implementation correctly passes the options to the API endpoint.

packages/loot-core/src/types/api-handlers.d.ts (2)

1-1: LGTM! Proper import.

The import statement is correctly placed and imports the new interface from the API package.


85-85: LGTM! Consistent type usage.

The method signature is properly updated to use the imported ImportTransactionsOpts type.

packages/loot-core/src/types/server-handlers.d.ts (1)

244-244: LGTM! Consistent type propagation.

The server handler interface is properly updated to use the imported ImportTransactionsOpts type.

packages/loot-core/src/server/accounts/sync.ts (3)

396-396: LGTM! Good backward compatibility.

The new defaultCleared parameter maintains backward compatibility with its default value of true.


440-440: LGTM! Proper preservation of existing values.

The update logic correctly preserves the existing cleared status when not explicitly set in the incoming transaction.


472-472: LGTM! Consistent default handling.

The new transaction creation logic consistently applies the defaultCleared value when no explicit cleared status is provided.

packages/loot-core/src/server/main.ts (3)

1245-1245: LGTM: Optional parameter addition aligns with PR objectives.

The addition of the optional opts parameter to the transactions-import handler function provides a clean way to extend the API's functionality without breaking existing clients.


Line range hint 1245-1272: LGTM: Error handling remains robust with the new parameter.

The existing error handling structure adequately covers the new parameter:

  • TransactionError catching remains appropriate
  • Type safety is maintained through TypeScript
  • The underlying reconcileTransactions function handles parameter validation

Line range hint 1245-1259: Well-structured implementation of the new feature.

The changes effectively implement the ability to control transaction cleared status during imports while maintaining backward compatibility. The implementation is:

  • Minimal and focused
  • Non-breaking for existing clients
  • Type-safe through TypeScript

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Looks good, two nits just to improve readability

packages/loot-core/src/server/accounts/sync.ts Outdated Show resolved Hide resolved
@@ -468,7 +469,7 @@ export async function reconcileTransactions(
...newTrans,
id: uuidv4(),
category: trans.category || null,
cleared: trans.cleared != null ? trans.cleared : true,
cleared: trans.cleared != null ? trans.cleared : defaultCleared,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cleared: trans.cleared != null ? trans.cleared : defaultCleared,
cleared: trans.cleared ?? defaultCleared,

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

🧹 Nitpick comments (1)
packages/loot-core/src/server/accounts/sync.ts (1)

Line range hint 751-751: Align cleared status handling in addTransactions.

For consistency, consider updating the cleared status handling in addTransactions to match the new pattern:

-      cleared: trans.cleared != null ? trans.cleared : true,
+      cleared: trans.cleared ?? true,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 736172d and bd0347f.

📒 Files selected for processing (1)
  • packages/loot-core/src/server/accounts/sync.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze
  • GitHub Check: Wait for Netlify build to finish
🔇 Additional comments (3)
packages/loot-core/src/server/accounts/sync.ts (3)

396-396: LGTM! Parameter addition maintains backward compatibility.

The new defaultCleared parameter with a default value of true is well-named and maintains backward compatibility with existing callers.


440-440: LGTM! Preserves existing cleared status.

Using the nullish coalescing operator to preserve the existing cleared status when not explicitly set is the correct approach.


Line range hint 472-478: Verify cleared status propagation in split transactions.

The cleared status is correctly set using the defaultCleared parameter. However, we should verify that this status is properly propagated to child transactions in the makeSplitTransaction function.

Let's verify the split transaction handling:

✅ Verification successful

Cleared status is properly propagated to split transactions

The implementation correctly propagates the cleared status from parent to child transactions through the spread operator in the makeChild function. The defaultCleared value set on the parent transaction is automatically inherited by all child transactions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if makeSplitTransaction preserves cleared status for child transactions
ast-grep --pattern 'function makeSplitTransaction($parent, $subtransactions) {
  $$$
  return [$parent, $$$];
}'

Length of output: 114


Script:

#!/bin/bash
# Try different approaches to find makeSplitTransaction implementation
# 1. Use ripgrep to find any occurrence with context
rg "makeSplitTransaction" -A 10 -B 2

# 2. Try ast-grep with a more flexible pattern
ast-grep --pattern 'makeSplitTransaction = $_'

# 3. Look for any function containing "Split" as a fallback
rg "function.*Split.*Transaction" -A 10

Length of output: 17890


Script:

#!/bin/bash
# Search for makeChildTransaction implementation
rg "makeChildTransaction" -A 5 -B 2

# Also try with ast-grep to catch any variable declarations
ast-grep --pattern 'makeChildTransaction = $_'

Length of output: 4212


Script:

#!/bin/bash
# Search for makeChild function implementation in shared transactions
rg "makeChild = |function makeChild" -A 10 shared/transactions

# Also try with ast-grep as fallback
ast-grep --pattern 'function makeChild($_) {
  $$$
}'

Length of output: 180


Script:

#!/bin/bash
# Search for makeChild implementation with correct path
rg "export (function makeChild|const makeChild)" -A 10 packages/loot-core/src/shared/transactions.ts

# Also search for any occurrence of makeChild
rg "makeChild" -B 2 -A 10 packages/loot-core/src/shared/transactions.ts

Length of output: 1772

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Caution

An unexpected error occurred while opening a pull request: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

@matt-fidd matt-fidd merged commit aa529a2 into actualbudget:master Jan 15, 2025
20 checks passed
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.

2 participants