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

♻️ (typescript) convert CategoryTransactions.jsx to .tsx #3875

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

cindywu
Copy link

@cindywu cindywu commented Nov 22, 2024

#1483

  • converts CategoryTransactions.jsx to .tsx

Copy link

netlify bot commented Nov 22, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit dc65fa2
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67415be181c6bf00087d4324
😎 Deploy Preview https://deploy-preview-3875.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.

@cindywu cindywu changed the title convert CategoryTransactions.jsx to .tsx ♻️ (typescript) convert CategoryTransactions.jsx to .tsx Nov 22, 2024
Copy link
Contributor

github-actions bot commented Nov 22, 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.46 MB → 5.46 MB (+278 B) +0.00%
Changeset
File Δ Size
src/components/mobile/budget/CategoryTransactions.tsx 🆕 +2.9 kB 0 B → 2.9 kB
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
src/components/mobile/budget/CategoryTransactions.jsx 🔥 -2.86 kB (-100%) 2.86 kB → 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 3.44 MB → 3.44 MB (+278 B) +0.01%

Smaller

No assets were smaller

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/resize-observer.js 18.37 kB 0%
static/js/useAccountPreviewTransactions.js 1.68 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/AppliedFilters.js 21.32 kB 0%
static/js/narrow.js 82.93 kB 0%
static/js/wide.js 241.19 kB 0%
static/js/ReportRouter.js 1.52 MB 0%

Copy link
Contributor

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

@cindywu cindywu marked this pull request as ready for review November 22, 2024 06:02
Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

Walkthrough

This pull request introduces several modifications to the CategoryTransactions component located in CategoryTransactions.tsx. A new type CategoryTransactionsProps has been defined, specifying that the category parameter is of type CategoryEntity and the month parameter is a string. The function signature of CategoryTransactions has been updated to use this new type for its parameters. The getCategoryMonthFilter function has been refactored to accept an object with destructured parameters, explicitly typed to include category and month. Consequently, the call to getCategoryMonthFilter within the baseTransactionsQuery has been updated to pass an object containing category and month instead of separate arguments. Additionally, the onOpenTransaction callback function's parameter has been updated to specify that it is of type TransactionEntity. Import statements have also been modified to include the new types TransactionEntity and CategoryEntity. Furthermore, the TransactionListWithBalances component has been updated to provide a default value for the onRefresh prop, allowing it to function without an explicitly passed handler.

Suggested labels

sparkles: Merged

Suggested reviewers

  • joel-jeremy
  • matt-fidd

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 (1.23.1)

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/budget/CategoryTransactions.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.


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

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx (1)

25-31: LGTM with a minor suggestion

The TypeScript interface for props is well-defined. Consider extracting the props interface for better reusability:

interface CategoryTransactionsProps {
  category: CategoryEntity;
  month: string;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebaa52 and fe47e51.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3875.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx (4 hunks)
🔇 Additional comments (4)
packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx (4)

14-14: LGTM: Clean type import

The CategoryEntity type import is properly added using the recommended type-only import syntax.


Line range hint 83-89: LGTM: Properly typed callback

The transaction parameter is correctly typed with the minimal required interface.


130-139: LGTM: Well-structured filter function

The getCategoryMonthFilter function is properly typed with a clean interface matching the component props.


Line range hint 1-139: Verify TypeScript strict mode compliance

The conversion to TypeScript looks thorough, but let's ensure strict mode compliance:

✅ Verification successful

TypeScript strict mode compliance verified

The code demonstrates proper TypeScript implementation with:

  • No unsafe any types in the component (found any usages are in test files and type definitions)
  • Type assertions are used appropriately for React component props and refs
  • The file is under strict mode influence as evidenced by its presence in the strict-enabled files list
  • Clean type inference without need for explicit type annotations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any TypeScript configuration files that might affect strict mode
fd -e json tsconfig

# Look for any 'any' type usage that might have been missed
rg -g "*.tsx?" "any[^a-zA-Z]"

# Check for type assertions that might indicate type safety issues
rg -g "*.tsx?" "as [A-Z]"

Length of output: 540


Script:

#!/bin/bash
# Check TypeScript configuration for strict mode settings
cat tsconfig.json packages/desktop-client/tsconfig.json 2>/dev/null

# Look for any 'any' type usage with correct glob pattern
rg -g '*.{ts,tsx}' "any[^a-zA-Z]"

# Check for type assertions with correct glob pattern
rg -g '*.{ts,tsx}' "as [A-Z]"

# Check if the file is under strict mode influence
rg -g '*.{ts,tsx}' -l "strict" packages/desktop-client/

Length of output: 66974

@@ -114,12 +121,19 @@ export function CategoryTransactions({ category, month }) {
onSearch={onSearch}
onLoadMore={loadMoreTransactions}
onOpenTransaction={onOpenTransaction}
onRefresh
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Fix missing onRefresh callback implementation

The onRefresh prop in CategoryTransactions.tsx is incomplete as it's missing the callback implementation. Looking at the codebase:

  1. TransactionListWithBalances component expects a callback function for onRefresh
  2. Other components like AccountTransactions properly implement it with a callback: onRefresh={onRefresh}
  3. The prop is used with PullToRefresh component which requires a callback for the pull-to-refresh functionality
-        onRefresh
+        onRefresh={() => dispatch(sync())}

This pattern is consistent with how it's implemented in AccountTransactions.tsx where it dispatches a sync action.

🔗 Analysis chain

Fix incomplete onRefresh prop

The onRefresh prop is added without a value. In React, a prop without a value is implicitly set to true. If this is a callback prop, it should be properly assigned:

-        onRefresh
+        onRefresh={handleRefresh}

Or if it's meant to be a boolean prop, explicitly set its value:

-        onRefresh
+        onRefresh={true}

Let's verify the expected type of this prop:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the TransactionListWithBalances component definition
ast-grep --pattern 'interface $_ {
  $$$
  onRefresh$_
  $$$
}'

Length of output: 65


Script:

#!/bin/bash
# Let's try a broader search for TransactionListWithBalances component and its props
rg -A 10 "TransactionListWithBalances" 

# Also search for onRefresh usage patterns
rg "onRefresh" -A 3 -B 3

Length of output: 19203

category,
month,
}: {
category: CategoryEntity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please extract to a Props type

@@ -73,7 +80,7 @@ export function CategoryTransactions({ category, month }) {
});

const onOpenTransaction = useCallback(
transaction => {
(transaction: { id: string }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a TransactionEntity

@@ -114,12 +121,19 @@ export function CategoryTransactions({ category, month }) {
onSearch={onSearch}
onLoadMore={loadMoreTransactions}
onOpenTransaction={onOpenTransaction}
onRefresh
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be nullable in TransactionListWithBalances

@cindywu
Copy link
Author

cindywu commented Nov 23, 2024

This is ready for review again!

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 (1)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (1)

Consider converting related transaction components to TypeScript

The directory contains a mix of TypeScript (.tsx) and JavaScript (.jsx) files, with 3 JSX files remaining unconverted:

  • TransactionEdit.jsx
  • TransactionList.jsx
  • TransactionListWithBalances.jsx

Since half of the transaction-related components are already in TypeScript, converting these remaining files would improve consistency and type safety across the mobile transaction components.

🔗 Analysis chain

Line range hint 1-1: Consider converting this file to TypeScript.

Since the PR's objective is TypeScript conversion and this component is closely related to CategoryTransactions, it might be worth converting this file to TypeScript as well for consistency.

Let's check if there are other components in the same directory that might need TypeScript conversion:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other JSX files in the same directory that might need TypeScript conversion

# Find all JSX files in the transactions directory
fd -e jsx . "packages/desktop-client/src/components/mobile/transactions"

# Check if there are any existing TypeScript files to understand the conversion progress
fd -e tsx . "packages/desktop-client/src/components/mobile/transactions"

Length of output: 645

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ac41690 and dc65fa2.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx (4 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
🔇 Additional comments (1)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (1)

70-70: LGTM! Good defensive programming practice.

Adding a default empty function for onRefresh is a good practice as it prevents potential null/undefined errors and makes the prop optional.

@@ -67,7 +67,7 @@ export function TransactionListWithBalances({
onSearch,
onLoadMore,
onOpenTransaction,
onRefresh,
onRefresh = () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be undefined as default because there's logic below which checks for this prop. Setting an empty function will introduce a regression.

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