actualbudget / actual

A local-first personal finance app
https://actualbudget.org
MIT License
15.62k stars 1.21k forks source link

useTransactions hook to simplify loading of transactions #3685

Closed joel-jeremy closed 1 week ago

joel-jeremy commented 1 month ago

Create a new useTransactions hook to simplify loading of transactions and preview transactions.

The mobile transactions page have been migrated to use the new hook. Will try to use it on the desktop transaction list as well if I am able to find time because it first will need to be migrated to a functional component.

Having both desktop and mobile use the same hook to load the transactions would make the behavior more consistent on both views and would be easier to maintain.

netlify[bot] commented 1 month ago

Deploy Preview for actualbudget ready!

Name Link
Latest commit b398e38865a3085410a6228b5652074ca474a776
Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/672d3a4a76e9e8000878326c
Deploy Preview https://deploy-preview-3685.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.

github-actions[bot] commented 1 month ago

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 → 9 5.34 MB → 5.35 MB (+5.74 kB) +0.10%
Changeset File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/transactions.ts` | 🆕 +4.22 kB | 0 B → 4.22 kB `node_modules/clsx/dist/clsx.mjs` | 🆕 +368 B | 0 B → 368 B `node_modules/clsx/dist/clsx.mjs?commonjs-proxy` | 🆕 +64 B | 0 B → 64 B `src/components/rules/ScheduleValue.tsx` | 📈 +423 B (+91.56%) | 462 B → 885 B `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/schedules.tsx` | 📈 +677 B (+28.15%) | 2.35 kB → 3.01 kB `home/runner/work/actual/actual/packages/loot-core/src/client/query-hooks.ts` | 📈 +168 B (+23.97%) | 701 B → 869 B `src/components/schedules/index.tsx` | 📈 +375 B (+11.36%) | 3.22 kB → 3.59 kB `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/widget.ts` | 📈 +26 B (+10.32%) | 252 B → 278 B `home/runner/work/actual/actual/packages/loot-core/src/client/query-helpers.ts` | 📈 +520 B (+8.16%) | 6.22 kB → 6.73 kB `home/runner/work/actual/actual/packages/loot-core/src/shared/query.ts` | 📈 +208 B (+7.21%) | 2.82 kB → 3.02 kB `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/dashboard.ts` | 📈 +12 B (+5.29%) | 227 B → 239 B `src/components/modals/ScheduledTransactionMenuModal.tsx` | 📈 +86 B (+3.24%) | 2.59 kB → 2.67 kB `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/reports.ts` | 📈 +40 B (+2.86%) | 1.37 kB → 1.4 kB `src/components/schedules/ScheduleLink.tsx` | 📈 +41 B (+1.11%) | 3.61 kB → 3.65 kB `node_modules/lodash/debounce.js` | 📈 +56 B (+0.92%) | 5.95 kB → 6 kB `node_modules/lodash/now.js` | 📈 +4 B (+0.79%) | 505 B → 509 B `src/components/ManageRules.tsx` | 📈 +69 B (+0.79%) | 8.53 kB → 8.59 kB `node_modules/lodash.debounce/index.js` | 📈 +68 B (+0.62%) | 10.66 kB → 10.73 kB `src/components/mobile/accounts/Accounts.jsx` | 📈 +40 B (+0.55%) | 7.15 kB → 7.18 kB `node_modules/lodash/_baseGetTag.js` | 📈 +4 B (+0.52%) | 763 B → 767 B `src/components/accounts/Account.tsx` | 📈 +213 B (+0.47%) | 44.32 kB → 44.53 kB `src/components/schedules/SchedulesTable.tsx` | 📈 +39 B (+0.32%) | 11.78 kB → 11.81 kB `src/components/schedules/ScheduleDetails.jsx` | 📈 +72 B (+0.23%) | 30.38 kB → 30.45 kB `src/components/modals/EditRuleModal.jsx` | 📈 +74 B (+0.18%) | 39.37 kB → 39.44 kB `src/components/PrivacyFilter.tsx` | 📈 +6 B (+0.18%) | 3.26 kB → 3.27 kB `src/components/transactions/TransactionsTable.jsx` | 📈 +28 B (+0.04%) | 66.33 kB → 66.36 kB `node_modules/react-grid-layout/build/components/WidthProvider.js` | 📈 +1 B (+0.02%) | 5.22 kB → 5.22 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/ReactGridLayout.js` | 📈 +1 B (+0.00%) | 24.96 kB → 24.96 kB `src/components/accounts/Balance.jsx` | 📉 -7 B (-0.13%) | 5.43 kB → 5.42 kB `home/runner/work/actual/actual/packages/loot-core/src/client/queries.ts` | 📉 -23 B (-0.31%) | 7.3 kB → 7.27 kB `src/components/mobile/transactions/TransactionList.jsx` | 📉 -100 B (-0.62%) | 15.8 kB → 15.7 kB `node_modules/lodash/_objectToString.js` | 📉 -4 B (-0.69%) | 578 B → 574 B `node_modules/lodash/isSymbol.js` | 📉 -12 B (-1.78%) | 673 B → 661 B `node_modules/lodash/_WeakMap.js` | 📉 -4 B (-2.11%) | 190 B → 186 B `src/components/mobile/accounts/AccountTransactions.tsx` | 📉 -313 B (-3.93%) | 7.78 kB → 7.48 kB `home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/filters.ts` | 📉 -45 B (-7.35%) | 612 B → 567 B `src/hooks/usePreviewTransactions.ts` | 📉 -135 B (-8.05%) | 1.64 kB → 1.5 kB `src/components/mobile/budget/CategoryTransactions.jsx` | 📉 -861 B (-22.74%) | 3.7 kB → 2.86 kB `node_modules/clsx/dist/clsx.js` | 🔥 -509 B (-100%) | 509 B → 0 B `src/hooks/useSchedules.ts` | 🔥 -88 B (-100%) | 88 B → 0 B `node_modules/clsx/dist/clsx.js?commonjs-module` | 🔥 -27 B (-100%) | 27 B → 0 B
View detailed bundle breakdown
**Added** No assets were added **Removed** Asset | File Size | % Changed ----- | --------- | --------- static/js/usePreviewTransactions.js | 1.64 kB → 0 B (-1.64 kB) | -100% **Bigger** Asset | File Size | % Changed ----- | --------- | --------- static/js/index.js | 3.35 MB → 3.37 MB (+19.37 kB) | +0.57% static/js/wide.js | 239.81 kB → 241.91 kB (+2.1 kB) | +0.88% **Smaller** Asset | File Size | % Changed ----- | --------- | --------- static/js/ReportRouter.js | 1.5 MB → 1.49 MB (-13.82 kB) | -0.90% static/js/narrow.js | 82.57 kB → 82.3 kB (-273 B) | -0.32% **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- static/js/workbox-window.prod.es5.js | 5.69 kB | 0% static/js/indexeddb-main-thread-worker-e59fee74.js | 13.5 kB | 0% static/js/BackgroundImage.js | 122.29 kB | 0% static/js/AppliedFilters.js | 21.3 kB | 0% static/js/resize-observer.js | 18.37 kB | 0%
github-actions[bot] commented 1 month ago

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.27 MB → 1.27 MB (+126 B) +0.01%
Changeset File | Δ | Size ---- | - | ---- `packages/loot-core/src/shared/query.ts` | 📈 +292 B (+8.11%) | 3.51 kB → 3.8 kB
View detailed bundle breakdown
**Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.js | 1.27 MB → 1.27 MB (+126 B) | +0.01% **Smaller** No assets were smaller **Unchanged** No assets were unchanged
coderabbitai[bot] commented 1 month ago

Walkthrough

The pull request introduces substantial changes across multiple components and files, primarily enhancing transaction management and state handling. In AccountTransactions.tsx, the useDefaultSchedulesQueryTransform hook is replaced with a useMemo call that utilizes accountSchedulesQuery, altering the schedule querying method. New hooks, namely useTransactions, usePreviewTransactions, and useTransactionsSearch, are introduced to streamline transaction fetching and searching processes. The SchedulesProvider is updated to accept a query prop instead of a transform prop, improving the query structure. Several functions are refactored to utilize useCallback, enhancing performance through memoization, and method signatures for AccountTransactions and TransactionListWithPreviews are modified to accommodate broader prop types.

In CategoryTransactions.jsx, the manual pagination system is replaced with a hook-based approach, simplifying transaction management. The makeRootQuery function is renamed to baseTransactionsQuery, and the logic for updating queries is streamlined.

The new transactions.ts file introduces the useTransactions, useTransactionsSearch, and usePreviewTransactions hooks, encapsulating logic for handling transaction data retrieval, search functionality, and error management, thereby enhancing the overall structure and readability of transaction management.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
joel-jeremy commented 4 weeks ago

I noticed there's some flickering on the schedules page now that isn't present in the previous release. To reproduce, open the devtools, and set a 20x slowdown on the "Application" tab, then switch away and back to the Schedules page (e.g. Schedules -> Payees -> Schedules). I think it would be good to at least display a spinner, and ideally fix the regression from the previous behaviour. Any ideas what might be causing this?

Nice catch! Just needed to properly handle the loading states. It should now display loading indicators instead of not rendering the entire component.

joel-jeremy commented 2 weeks ago

@maintainers I would like to get 2 or more approvals on this PR before merging