Repository navigation
[AI] Make BALANCE_OF available in formula reports - #8591
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for actualbudget-website ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthrough
ChangesBALANCE_OF query support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant FormulaCard
participant useFormulaExecution
participant CustomFunctionsPlugin
participant TransactionsQuery
FormulaCard->>useFormulaExecution: formula and simpleAccounts
useFormulaExecution->>CustomFunctionsPlugin: evaluate BALANCE_OF(accountKey)
CustomFunctionsPlugin->>useFormulaExecution: record account key and use prefetched balance
useFormulaExecution->>TransactionsQuery: sum transaction amounts
TransactionsQuery-->>useFormulaExecution: account balance
useFormulaExecution-->>FormulaCard: formatted formula result
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/desktop-client/src/hooks/useFormulaExecution.test.ts (1)
273-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that name lookup resolves to the account ID.
This test accepts the mock’s constant response even if the emitted query filters on
"Checking"instead of"acc1". Inspect the captured payload as the ID test does.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/desktop-client/src/hooks/useFormulaExecution.test.ts` around lines 273 - 283, Update the test using useFormulaExecution for exact-name account resolution to inspect the captured query payload, following the existing account-ID test pattern. Assert that the emitted lookup filters by the resolved account ID "acc1", while preserving the existing result assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/desktop-client/src/components/formula/formulaCatalog.ts`:
- Around line 1007-1008: Update the description passed to t() in formulaCatalog
so the cents unit applies only to rule-formula balances, while explicitly
stating that report/query formula balances use money/display units. Preserve the
existing guidance about cutoff behavior and account matching.
In `@packages/docs/docs/experimental/formulas.md`:
- Line 102: Update the ISREF entry in the formula catalog table to list only
“Query” under supported modes, removing “Rules” while preserving the existing
description, example, and other metadata.
---
Nitpick comments:
In `@packages/desktop-client/src/hooks/useFormulaExecution.test.ts`:
- Around line 273-283: Update the test using useFormulaExecution for exact-name
account resolution to inspect the captured query payload, following the existing
account-ID test pattern. Assert that the emitted lookup filters by the resolved
account ID "acc1", while preserving the existing result assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cffe214a-2906-468b-bd43-d5bddf41ae6f
📒 Files selected for processing (10)
packages/desktop-client/src/components/formula/formulaCatalog.test.tspackages/desktop-client/src/components/formula/formulaCatalog.tspackages/desktop-client/src/components/reports/reports/Formula.tsxpackages/desktop-client/src/components/reports/reports/FormulaCard.tsxpackages/desktop-client/src/hooks/useFormulaExecution.test.tspackages/desktop-client/src/hooks/useFormulaExecution.tspackages/docs/docs/experimental/formulas.mdpackages/loot-core/src/server/rules/customFunctions.test.tspackages/loot-core/src/shared/formulas/customFunctions.tsupcoming-release-notes/balance-of-in-formula-cards.md
|
Is it possible to add account name autocomplete? |
Probably, there already is category autocomplete, but I would rather that is its own PR. |
Resolves conflicts with #8591, which added a fifth `accounts` argument to `useFormulaExecution` for BALANCE_OF support. - Give `accounts` the same treatment as `queries`/`namedExpressions`: key the effect on its serialized contents and read the live array through a ref, so a caller passing a fresh array each render can't restart the execution loop. - Keep both new test suites (BALANCE_OF and execution stability), and extend the stability test to pass a fresh accounts array too. - Replace `const { data: accounts = [] } = useAccounts()` in FormulaCard with a nullish coalesce onto a module-level constant. The destructuring default was re-triggering the same React Compiler bailout this PR removed from the props, which would have left the component unmemoized again. Co-Authored-By: Claude Opus 5 <[email protected]>
…albudget#8591) with home-loan example
* [AI] Make BALANCE_OF available in query/report formulas * [AI] Address CodeRabbit review comments on BALANCE_OF PR
Description
Make the
balance_offunction work in the formula reportMade by Claude
Related issue(s)
Testing
Checklist
Bundle Stats
View detailed bundle stats
desktop-client
Total
Changeset
src/components/reports/reports/FormulaCard.tsxsrc/hooks/useFormulaExecution.tssrc/components/reports/reports/Formula.tsxhome/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.tssrc/components/formula/formulaCatalog.tslocale/en.jsonView detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
Smaller
No assets were smaller
Unchanged
loot-core
Total
Changeset
home/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.tsView detailed bundle breakdown
Added
Removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
No assets were unchanged
api
Total
Changeset
home/runner/work/actual/actual/packages/loot-core/src/shared/formulas/customFunctions.tsView detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
Smaller
No assets were smaller
Unchanged
cli
Total
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
crdt
Total
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