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

Convert mobile Accounts.jsx to tsx #3862

Merged
merged 3 commits into from
Nov 22, 2024
Merged

Conversation

joel-jeremy
Copy link
Contributor

No description provided.

@actual-github-bot actual-github-bot bot changed the title Convert mobile Accounts.jsx to TS [WIP] Convert mobile Accounts.jsx to TS Nov 20, 2024
Copy link

netlify bot commented Nov 20, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 359cfe5
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/673e68f58d6776000985fc21
😎 Deploy Preview https://deploy-preview-3862.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.

@joel-jeremy joel-jeremy changed the title [WIP] Convert mobile Accounts.jsx to TS Convert mobile Accounts.jsx to TS Nov 20, 2024
@joel-jeremy joel-jeremy changed the title Convert mobile Accounts.jsx to TS Convert mobile Accounts.jsx to tsx Nov 20, 2024
Copy link
Contributor

github-actions bot commented Nov 20, 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.42 MB → 5.42 MB (+187 B) +0.00%
Changeset
File Δ Size
src/components/mobile/accounts/Accounts.tsx 🆕 +7.4 kB 0 B → 7.4 kB
home/runner/work/actual/actual/packages/loot-core/src/client/reducers/queries.ts 📉 -29 B (-0.94%) 3 kB → 2.97 kB
src/components/mobile/accounts/Accounts.jsx 🔥 -7.19 kB (-100%) 7.19 kB → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/narrow.js 82.72 kB → 82.93 kB (+216 B) +0.26%

Smaller

Asset File Size % Changed
static/js/index.js 3.44 MB → 3.44 MB (-29 B) -0.00%

Unchanged

Asset File Size % Changed
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/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/AppliedFilters.js 21.32 kB 0%
static/js/wide.js 241.19 kB 0%
static/js/ReportRouter.js 1.49 MB 0%

Copy link
Contributor

github-actions bot commented Nov 20, 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 0%

Changeset

No files were changed

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

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

This pull request introduces significant type adjustments across several components in the codebase, specifically focusing on transaction identifiers and state management. In the Account.tsx component, the AccountInternalProps type has been modified to change newTransactions and matchedTransactions from string[] to Array<TransactionEntity['id']>, enhancing type safety. The methods isNew and isMatched have also been updated to accept parameters of type TransactionEntity['id'].

In Accounts.tsx, new types have been defined for better structure, including AccountCardProps and AccountListProps, while existing functions have been refactored to utilize useCallback for improved performance. The queries.ts file has seen the removal of the earliestTransaction property from the initialState, and updates in queries.d.ts have aligned various properties with the new transaction and account identifier types. These changes collectively aim to enhance type specificity and clarity in state management.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • youngcw
  • MikesGlitch

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/mobile/accounts/Accounts.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.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8149817 and 359cfe5.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/mobile/accounts/Accounts.tsx (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/mobile/accounts/Accounts.tsx

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

🧹 Outside diff range and nitpick comments (4)
packages/desktop-client/src/components/mobile/accounts/Accounts.tsx (3)

Line range hint 115-131: Address TODO comment about bankId type safety

The current implementation uses a runtime check 'bankId' in account which suggests bankId should be part of the AccountEntity type. This could lead to type safety issues.

Consider:

  1. Adding bankId to the AccountEntity type if it's a valid property
  2. Creating a union type if bankId is only valid for certain account types
  3. Using a type guard if the property is truly optional

Example:

type AccountEntity = {
  // ... existing properties
  bankId?: string; // If optional
} | {
  // ... existing properties
  bankId: string; // If required for certain account types
}
🧰 Tools
🪛 GitHub Check: lint

[warning] 115-115:
Replace /*·TODO:·Should·bankId·be·part·of·the·AccountEntity·type?·*/·'bankId'·in with ⏎············/*·TODO:·Should·bankId·be·part·of·the·AccountEntity·type?·*/·'bankId'·in⏎·············


[warning] 116-116:
Insert ··


[warning] 117-117:
Insert ··


[warning] 118-118:
Insert ··


Line range hint 174-194: Consider memoizing filtered accounts

The account filtering operations (budgetedAccounts and offbudgetAccounts) are performed on every render. Consider memoizing these values for better performance.

const budgetedAccounts = useMemo(
  () => accounts.filter(account => account.offbudget === 0),
  [accounts]
);
const offbudgetAccounts = useMemo(
  () => accounts.filter(account => account.offbudget === 1),
  [accounts]
);

1-1: Solid TypeScript conversion with room for type refinement

The TypeScript conversion is well-executed with proper type definitions and generic constraints. However, consider the following architectural improvements:

  1. Document the relationship between AccountEntity and bank-related properties
  2. Consider creating a dedicated type for bank-connected accounts
  3. Add JSDoc comments for complex type definitions and generic constraints

Would you like assistance in implementing any of these improvements?

packages/desktop-client/src/components/accounts/Account.tsx (1)

Line range hint 1-1: Consider removing @ts-strict-ignore

The @ts-strict-ignore directive disables strict TypeScript checks. Consider addressing any remaining type issues and removing this directive to maintain full type safety throughout the file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0696c81 and 8149817.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3862.md is excluded by !**/*.md
📒 Files selected for processing (4)
  • packages/desktop-client/src/components/accounts/Account.tsx (2 hunks)
  • packages/desktop-client/src/components/mobile/accounts/Accounts.tsx (9 hunks)
  • packages/loot-core/src/client/reducers/queries.ts (0 hunks)
  • packages/loot-core/src/client/state-types/queries.d.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/loot-core/src/client/reducers/queries.ts
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/mobile/accounts/Accounts.tsx (1)
Learnt from: joel-jeremy
PR: actualbudget/actual#3685
File: packages/desktop-client/src/components/accounts/Account.tsx:655-665
Timestamp: 2024-11-10T16:45:31.225Z
Learning: The Account component in 'packages/desktop-client/src/components/accounts/Account.tsx' is being rewritten in a separate PR.
🪛 GitHub Check: lint
packages/desktop-client/src/components/mobile/accounts/Accounts.tsx

[warning] 115-115:
Replace /*·TODO:·Should·bankId·be·part·of·the·AccountEntity·type?·*/·'bankId'·in with ⏎············/*·TODO:·Should·bankId·be·part·of·the·AccountEntity·type?·*/·'bankId'·in⏎·············

🔇 Additional comments (9)
packages/loot-core/src/client/state-types/queries.d.ts (4)

2-2: LGTM! Good use of type-only imports.

The import statement follows TypeScript best practices by using the type keyword for type-only imports.


22-24: LGTM! Consistent type improvements.

The action type properly mirrors the state type changes, maintaining type safety while preserving the optional nature of the properties.


6-9: Great type safety improvements!

The changes from generic string[] to specific entity ID types (Array<TransactionEntity['id']> and Array<AccountEntity['id']>) and from unknown to TransactionEntity improve type safety and maintainability.

Let's verify that all consumers of these state properties have been updated accordingly:

✅ Verification successful

Based on the search results, I can now generate the final response since I have enough information to verify the type changes in queries.d.ts:

Type changes are safe and properly integrated across the codebase

The type changes in queries.d.ts are well integrated:

  • The QueriesState type is properly imported and used in the reducers (packages/loot-core/src/client/reducers/queries.ts)
  • The state properties are correctly accessed with their new types throughout the codebase
  • The lastTransaction property is properly handled as TransactionEntity | null in components like TransactionsTable and TransactionEdit
  • The ID arrays (newTransactions, matchedTransactions, updatedAccounts) are used consistently with their entity ID types
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct access to these properties to ensure type compatibility
rg -t typescript -t javascript "state\.(newTransactions|matchedTransactions|lastTransaction|updatedAccounts)"

Length of output: 146


Script:

#!/bin/bash
# Search for direct access to these properties without file type restrictions
rg "state\.(newTransactions|matchedTransactions|lastTransaction|updatedAccounts)"

Length of output: 1021


Script:

#!/bin/bash
# Let's check for lastTransaction usage and also look for any imports or usage of these types
rg "lastTransaction|QueriesState|TransactionEntity|AccountEntity" -A 2

Length of output: 77069


34-34: Type safety improvement looks good.

The change from unknown to TransactionEntity removes type ambiguity and aligns with the state type changes.

Let's verify that all action creators have been updated to provide the correct type:

✅ Verification successful

Based on the gathered information, I can now generate the final response:

Type change is safe and correctly implemented

The change from unknown to TransactionEntity in SetLastTransactionAction type is safe as the only usage of setLastTransaction action creator in packages/loot-core/src/client/actions/account.ts already expects a transaction object, and its only invocation in packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx passes a properly typed transaction object from the newly created transactions array.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SET_LAST_TRANSACTION action creators
rg -t typescript -t javascript "SET_LAST_TRANSACTION.*transaction:"

Length of output: 104


Script:

#!/bin/bash
# Search for SET_LAST_TRANSACTION action creators with ripgrep
# Note: Using broader pattern and multiple searches to ensure we don't miss anything
rg "SET_LAST_TRANSACTION" 

# Also search for any file that might contain transaction-related actions
fd -e ts -e js -e tsx -e jsx | xargs rg "setLastTransaction|SET_LAST_TRANSACTION"

Length of output: 1258


Script:

#!/bin/bash
# Let's check the implementation of setLastTransaction action creator
ast-grep --pattern 'function setLastTransaction($_) { $$$ }'

# Also check the actual transaction type being passed in the component
cat packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx

Length of output: 36636


Script:

#!/bin/bash
# Let's check the implementation of setLastTransaction in account actions
cat packages/loot-core/src/client/actions/account.ts

Length of output: 8391

packages/desktop-client/src/components/mobile/accounts/Accounts.tsx (3)

Line range hint 1-31: Well-structured type definitions and imports!

The TypeScript conversion introduces proper type definitions and generic type parameters, enhancing type safety. The AccountHeaderProps type is particularly well-designed with its generic constraint to sheet fields.


Line range hint 33-72: Clean and type-safe AccountHeader implementation!

The component makes good use of generics and properly types all props. The implementation is clean and follows React best practices.


276-289: Well-implemented event handlers with proper memoization!

The event handlers are properly typed and memoized using useCallback. The implementation follows React best practices and maintains type safety.

packages/desktop-client/src/components/accounts/Account.tsx (2)

269-270: LGTM! Type safety improvement

The change from string[] to Array<TransactionEntity['id']> enhances type safety by explicitly linking transaction IDs to the TransactionEntity type.


873-877: LGTM! Consistent type safety

The parameter type changes in isNew and isMatched methods maintain type safety by consistently using TransactionEntity['id'] throughout the component.

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