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) ported TransactionsTable.test to TS #4108

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

MatissJanis
Copy link
Member

No description provided.

@actual-github-bot actual-github-bot bot changed the title ♻️ (typescript) ported TransactionsTable.test to TS [WIP] ♻️ (typescript) ported TransactionsTable.test to TS Jan 7, 2025
Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 33fabe6
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/677ee49f2feba70008840dc4
😎 Deploy Preview https://deploy-preview-4108.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 7, 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
10 5.66 MB → 5.66 MB (-47 B) -0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/shared/transactions.ts 📈 +6 B (+0.07%) 8.25 kB → 8.26 kB
package.json 📉 -53 B (-1.74%) 2.97 kB → 2.92 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
static/js/index.js 3.73 MB → 3.73 MB (-47 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 10.24 kB 0%
static/js/narrow.js 84.22 kB 0%
static/js/wide.js 104.78 kB 0%
static/js/ReportRouter.js 1.58 MB 0%

Copy link
Contributor

github-actions bot commented Jan 7, 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 (+6 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/shared/transactions.ts 📈 +15 B (+0.14%) 10.23 kB → 10.24 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 (+6 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@MatissJanis MatissJanis changed the title [WIP] ♻️ (typescript) ported TransactionsTable.test to TS ♻️ (typescript) ported TransactionsTable.test to TS Jan 7, 2025
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces several modifications across multiple packages in the project, focusing primarily on type safety improvements, testing enhancements, and minor structural changes. Key changes include adding a global function __resetWorld() in the desktop client, removing Jest dependencies, updating type definitions for transactions and entities, and refining function signatures in various modules. The modifications span across desktop-client, loot-core, and project-level configuration files, with a strong emphasis on TypeScript type annotations and improving the robustness of the codebase.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • joel-jeremy

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5d591f and 1ed938d.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/4108.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (12)
  • packages/desktop-client/globals.d.ts (1 hunks)
  • packages/desktop-client/package.json (0 hunks)
  • packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx (21 hunks)
  • packages/desktop-client/src/hooks/useSplitsExpanded.tsx (1 hunks)
  • packages/loot-core/src/client/query-helpers.test.ts (1 hunks)
  • packages/loot-core/src/mocks/index.ts (5 hunks)
  • packages/loot-core/src/platform/client/fetch/index.d.ts (2 hunks)
  • packages/loot-core/src/server/accounts/rules.test.ts (0 hunks)
  • packages/loot-core/src/server/spreadsheet/spreadsheet.test.ts (2 hunks)
  • packages/loot-core/src/shared/transactions.ts (7 hunks)
  • packages/loot-core/src/types/models/transaction.d.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/desktop-client/package.json
  • packages/loot-core/src/server/accounts/rules.test.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx

[error] 240-240: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (22)
packages/loot-core/src/shared/transactions.ts (8)

24-25: Good use of as const for type safety

Using as const for type and version ensures they are treated as literal types, enhancing type safety.


30-30: Update GenericTransactionEntity type aligns with interface removal

Updating GenericTransactionEntity to TransactionEntity reflects the removal of TransactionEntityWithError.


157-160: Function signature updated to reflect type changes

Updating the function parameter and return types to TransactionEntity is consistent with the type changes.


283-284: Repeated use of the satisfies operator—ensure TypeScript version compatibility

As mentioned earlier, verify that the project's TypeScript version supports the satisfies operator.


314-315: Repeated use of the satisfies operator—ensure TypeScript version compatibility

This is another occurrence of the satisfies operator. Please ensure TypeScript 4.9 or higher is used.

Also applies to: 320-320


340-340: Repeated use of the satisfies operator—ensure TypeScript version compatibility

Again, confirm that the TypeScript version in the project supports the satisfies operator.


129-132: Ensure TypeScript version supports the satisfies operator

The use of the satisfies operator requires TypeScript 4.9 or higher. Please verify that the project is using a compatible TypeScript version to avoid compilation issues.

Run the following script to check the TypeScript version specified in package.json files:

✅ Verification successful

TypeScript version is compatible with the satisfies operator

The project uses TypeScript 5.5.4 across all packages, which fully supports the satisfies operator (introduced in TypeScript 4.9).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the TypeScript version used in the project.
# Expected: TypeScript version 4.9.0 or higher.

rg '"typescript"\s*:\s*"[^\"]+"' package.json packages/*/package.json

Length of output: 367


Script:

#!/bin/bash
# Search for TypeScript version in package.json files
rg -U '"typescript":\s*"[^"]+"|"typescript":\s*"[^"]+"' package.json packages/*/package.json

# Find and show content of tsconfig.json files
fd tsconfig.json --exec cat {}

Length of output: 2053


84-87: Ensure consistent handling of the error property when undefined

The error property is now assigned undefined when there is no error. Please verify that all consumers of TransactionEntity.error handle undefined appropriately and that the change from null to undefined doesn't introduce any issues.

Run the following script to check for comparisons against null:

✅ Verification successful

The change from null to undefined is safe to proceed

All existing consumers of TransactionEntity.error already handle the property safely:

  • Uses optional chaining (?.) for property access
  • Tests use toBeFalsy()/toBeTruthy() which work with both values
  • TypeScript interface properly declares error as optional
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for places where 'transaction.error' is compared to 'null'.
# Expected: No occurrences of 'transaction.error === null' or 'transaction.error !== null'

rg "transaction\.error\s*===\s*null|transaction\.error\s*!==\s*null"

Length of output: 70


Script:

#!/bin/bash
# Search for all usages of transaction.error and type definitions
echo "=== Searching for transaction.error usages ==="
rg "transaction\.error" -A 2

echo -e "\n=== Searching for TransactionEntity type definition ==="
ast-grep --pattern 'type TransactionEntity = {
  $$$
}'

echo -e "\n=== Searching for interface TransactionEntity ==="
ast-grep --pattern 'interface TransactionEntity {
  $$$
}'

Length of output: 4457

packages/desktop-client/globals.d.ts (1)

12-14: Verify the necessity of adding __resetWorld() to the global scope

Please verify that adding __resetWorld() to the global scope is necessary and does not introduce conflicts. If this function is intended for testing purposes, ensure that it is scoped appropriately.

Run the following script to find usages of __resetWorld() in the codebase:

✅ Verification successful

Global scope for __resetWorld() is appropriate for its test utility purpose

The function is correctly implemented as a global test utility:

  • Serves as a Redux store reset mechanism between tests
  • Automatically called in the global afterEach hook
  • Only used in test files (setupTests.js and *.test.tsx)
  • Follows testing best practices for cleanup utilities
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of '__resetWorld()' in the codebase.
# Expected: Usages are limited to test files or appropriate contexts.

rg '__resetWorld\(\)'

Length of output: 264


Script:

#!/bin/bash
# Check the implementation and context in setupTests.js
cat packages/desktop-client/src/setupTests.js

Length of output: 586

packages/loot-core/src/types/models/transaction.d.ts (1)

29-33: Addition of error property enhances transaction error handling

The optional error property in TransactionEntity allows for improved handling of split transaction errors.

packages/desktop-client/src/hooks/useSplitsExpanded.tsx (1)

87-87: LGTM! Good improvement to the API.

Making initialMode optional with a sensible default value improves the component's usability while maintaining backward compatibility.

packages/loot-core/src/mocks/index.ts (3)

16-51: Well-structured type improvements for account generation.

The addition of explicit types and the separation of offline vs. connected account logic improves code clarity and type safety.


68-72: Good type safety improvements for category-related functions.

The addition of explicit parameter types and return types enhances the reliability of these mock generators.

Also applies to: 83-86, 95-97


110-112: Type-safe transaction generation with required fields.

Using Pick to enforce required fields is a good practice. The account field requirement prevents potential runtime errors.

Also applies to: 126-130

packages/loot-core/src/server/spreadsheet/spreadsheet.test.ts (1)

13-13: Good test simplification.

Removing the unused payeeId parameter simplifies the test setup without losing any test coverage.

Also applies to: 128-129

packages/loot-core/src/client/query-helpers.test.ts (1)

125-127: Good modernization of async patterns.

Converting the server initialization to use an async function improves code consistency and makes the asynchronous nature of the operation more explicit.

packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx (4)

24-30: LGTM! Clean type imports.

The imported types from loot-core/types/models are well-organized and properly scoped.


51-65: LGTM! Well-typed payees array.

The payees array is properly typed as PayeeEntity[] with all required properties.


118-130: LGTM! Well-defined props interface.

The LiveTransactionTableProps type is comprehensive and properly documents all required and optional props.


182-184: Address the ts-expect-error comment.

The comment indicates that TransactionTable needs to be migrated to TypeScript.

Let's check the status of the component:

✅ Verification successful

The @ts-expect-error comment is valid and should be kept

The comment accurately reflects the current state of the codebase, where TransactionsTable is still a .jsx file that needs to be migrated to TypeScript. The error suppression is temporary and will be resolved once the migration is complete.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if TransactionTable is already being worked on
fd -e tsx -e ts "TransactionTable.tsx"

Length of output: 38


Script:

#!/bin/bash
# Find TransactionTable component with any extension
fd "TransactionTable" --type f

# Search for TypeScript migration related comments
rg -i "typescript|ts-expect|todo.*typescript" --type js --type jsx --type ts --type tsx

Length of output: 148


Script:

#!/bin/bash
# List files in the transactions directory
ls -la packages/desktop-client/src/components/transactions/

# Search for TransactionTable definition and related comments
rg "TransactionTable" packages/desktop-client/src/components/transactions/ -A 2

Length of output: 6101

packages/loot-core/src/platform/client/fetch/index.d.ts (2)

2-2: LGTM! Clean type import.

The CategoryGroupEntity type import is properly scoped.


42-49: LGTM! Well-typed server initialization.

The initServer function signature now provides proper type safety with well-defined handlers interface.

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

🧹 Nitpick comments (1)
packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx (1)

293-293: Consider improving type safety by handling null cases.

Several functions use non-null assertions (!) which bypass TypeScript's null checks. Consider handling these cases explicitly:

  • Line 293: field.querySelector(subSelector)!
  • Line 308: field.querySelector(subSelector)!
  • Lines 327-331: Multiple non-null assertions

Example safer implementation:

-return field.querySelector(subSelector)!;
+const element = field.querySelector(subSelector);
+if (!element) {
+  throw new Error(`Element with selector "${subSelector}" not found`);
+}
+return element;

Also applies to: 308-308, 327-331

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ed938d and 33fabe6.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • packages/desktop-client/package.json (0 hunks)
  • packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx (21 hunks)
  • packages/desktop-client/src/hooks/useSplitsExpanded.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/desktop-client/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/hooks/useSplitsExpanded.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx

[error] 240-240: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: typecheck
  • GitHub Check: build (macos-latest)
  • GitHub Check: test
  • GitHub Check: api
  • GitHub Check: build (windows-latest)
  • GitHub Check: web
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: Analyze
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: lint
  • GitHub Check: crdt
  • GitHub Check: compare
🔇 Additional comments (5)
packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx (5)

23-29: Well-structured type imports!

Good use of the type keyword for importing type definitions, which helps with tree-shaking and keeps the runtime bundle size optimal.


239-241: Fix performance issue in categories reduction.

The spread operator in the reducer's accumulator causes O(n²) time complexity.

🧰 Tools
🪛 Biome (1.9.4)

[error] 240-240: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


118-130: Well-defined props interface!

The LiveTransactionTableProps interface is comprehensive and properly typed, making the component's API clear and type-safe.


Line range hint 405-425: Excellent test coverage with proper type handling!

The test cases thoroughly verify transaction table functionality while properly handling optional chaining for nullable fields (e.g., acct?.name, p?.name, category?.name).


183-183: Remove @ts-expect-error comment.

The comment indicates that this will be auto-patched once TransactionTable is moved to TS. Let's track this technical debt.

Let's check if the TransactionTable component has been converted to TypeScript:

@MatissJanis MatissJanis merged commit b92fa70 into master Jan 14, 2025
20 checks passed
@MatissJanis MatissJanis deleted the matiss/typescript-trans-test branch January 14, 2025 18:33
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