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) migrated NetWorth component to TS #3576

Merged
merged 2 commits into from
Oct 6, 2024

Conversation

MatissJanis
Copy link
Member

No description provided.

@actual-github-bot actual-github-bot bot changed the title ♻️ (typescript) migrated NetWorth component to TS [WIP] ♻️ (typescript) migrated NetWorth component to TS Oct 5, 2024
Copy link
Contributor

coderabbitai bot commented Oct 5, 2024

Walkthrough

The changes involve significant updates to the NetWorthGraph and NetWorth components in the desktop client. The NetWorthGraph component's graphData type has been redefined to include a more detailed structure, and the compact property has been made optional. In the NetWorth component, type safety has been enhanced through the introduction of specific prop types and the updating of function signatures, ensuring better handling of widget data and state management.

Changes

File Change Summary
packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx Updated NetWorthGraphProps type for graphData, added hasNegative, start, and end properties, made compact optional. Updated CustomTooltip props to align with new graphData structure.
packages/desktop-client/src/components/reports/reports/NetWorth.tsx Enhanced type safety by defining NetWorthInnerProps, updated method signatures for NetWorthInner and onChangeDates, and modified widget saving logic. Simplified rendering of NetWorthGraph by removing unnecessary props.

Suggested labels

::sparkles: Merged

Suggested reviewers

  • carkom

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

netlify bot commented Oct 5, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 112f8db
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/670121e85b356a0008be7223
😎 Deploy Preview https://deploy-preview-3576.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

@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 (4)
packages/desktop-client/src/components/reports/reports/NetWorth.tsx (2)

37-39: LGTM: Improved type safety for useWidget hook

The addition of the NetWorthWidget generic type to the useWidget hook enhances type safety. The use of the nullish coalescing operator for the widget ID is also a good practice.

Consider using a default empty string as the second argument to useWidget instead of relying on the nullish coalescing operator:

const { data: widget, isLoading } = useWidget<NetWorthWidget>(
  params.id,
  ''
);

This would make the intent clearer and potentially simplify the code.


67-70: LGTM: Improved state typing

The explicit typing of the allMonths state improves type safety and clarity. The structure is well-defined, and allowing null as a possible value is appropriate for initialization.

Consider using a type alias for the month object to improve readability and reusability:

type Month = {
  name: string;
  pretty: string;
};

const [allMonths, setAllMonths] = useState<Month[] | null>(null);

This would make the code more maintainable if you need to use this structure elsewhere in the application.

packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx (2)

Line range hint 53-56: Specify the type of 'tick' in 'tickFormatter' function

The tickFormatter function's parameter tick is not explicitly typed. Adding a type annotation enhances type safety and code clarity.

Apply this change:

- const tickFormatter = tick => {
+ const tickFormatter = (tick: number) => {

Line range hint 66-75: Align 'PayloadItem' types with 'graphData' for consistency

In the PayloadItem type, properties like assets, debt, networth, and change are typed as number | string, whereas in graphData, they are typed as string. For consistency, consider aligning these types.

Update the PayloadItem type:

 type PayloadItem = {
   payload: {
     date: string;
-    assets: number | string;
-    debt: number | string;
-    networth: number | string;
-    change: number | string;
+    assets: string;
+    debt: string;
+    networth: string;
+    change: string;
   };
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a28fb93 and 112f8db.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3576.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx (1 hunks)
  • packages/desktop-client/src/components/reports/reports/NetWorth.tsx (4 hunks)
🔇 Additional comments (6)
packages/desktop-client/src/components/reports/reports/NetWorth.tsx (5)

13-13: LGTM: Proper type imports added

The addition of type imports from a centralized location is a good practice in TypeScript. This will help maintain consistency and make it easier to manage types across the application.


49-51: LGTM: Clear and appropriate prop type definition

The NetWorthInnerProps type is well-defined and correctly makes the widget property optional. This improves the type safety of the NetWorthInner component and makes its interface clear to other developers.


53-53: LGTM: Function signature updated with proper typing

The NetWorthInner function now correctly uses the NetWorthInnerProps type, which improves type safety and makes the component's interface clear. This is a good use of TypeScript features.


113-113: LGTM: Function parameters properly typed

The onChangeDates function now has explicit parameter types, which improves type safety and makes the function's interface clear. The use of TimeFrame['mode'] for the mode parameter ensures that only valid mode values can be passed, which is a good practice.


120-123: LGTM: Improved error handling

The addition of a null check for the widget object before saving improves error handling and prevents potential runtime errors. The error message is clear and descriptive.

However, please verify if this null check is necessary. If the widget is guaranteed to be defined at this point in the code (e.g., due to earlier checks or the component's logic), this check might be redundant. Consider removing it if it's not needed, or add a comment explaining why it's necessary if it is.

To help verify this, you can run the following script to check for other occurrences of widget null checks in this file:

If there are no other occurrences, it might indicate that this check is indeed necessary. If there are other occurrences, compare them to understand the flow and determine if this check is redundant.

✅ Verification successful

Verified: Necessary widget null check confirmed

The null check for the widget object is necessary as it is the only instance in the file ensuring that widget is defined before saving. This prevents potential runtime errors by providing clear and descriptive error handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other widget null checks in the file

rg --type typescript 'if\s*\(\s*!widget\s*\)' packages/desktop-client/src/components/reports/reports/NetWorth.tsx

Length of output: 150


Script:

#!/bin/bash
# Description: Check for other widget null checks in the file without specifying a type

rg 'if\s*\(\s*!widget\s*\)' packages/desktop-client/src/components/reports/reports/NetWorth.tsx

Length of output: 116

packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx (1)

47-47: Verify that making 'compact' optional does not affect existing usages

By changing compact from required to optional with a default value of false, ensure that all existing usages of NetWorthGraph in the codebase are compatible with this change and that it doesn't introduce any unintended side effects.

Run the following script to verify all usages of NetWorthGraph:

✅ Verification successful

Verified: Making compact optional with a default value of false does not adversely affect existing usages of NetWorthGraph. All current implementations are compatible with this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of NetWorthGraph and check for 'compact' prop usage.

# Test: Search for component usages and inspect 'compact' prop assignments.
rg --type tsx -A 5 '<NetWorthGraph' | rg 'compact='

Length of output: 79


Script:

#!/bin/bash
# Description: Find all usages of NetWorthGraph and check for 'compact' prop usage.

# Search for .tsx files containing <NetWorthGraph and inspect 'compact' prop assignments.
rg '<NetWorthGraph' --glob '*.tsx' -A 5 | rg 'compact='

Length of output: 154


Script:

#!/bin/bash
# Description: Find all usages of NetWorthGraph without the 'compact' prop.

# Search for <NetWorthGraph in .tsx files and exclude those with 'compact='
rg '<NetWorthGraph' --glob '*.tsx' | grep -v 'compact='

Length of output: 243

@MatissJanis MatissJanis changed the title [WIP] ♻️ (typescript) migrated NetWorth component to TS ♻️ (typescript) migrated NetWorth component to TS Oct 5, 2024
Copy link
Contributor

github-actions bot commented Oct 5, 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
9 5.3 MB → 5.3 MB (-787 B) -0.01%
Changeset
File Δ Size
src/components/reports/reports/NetWorth.tsx 🆕 +5.73 kB 0 B → 5.73 kB
src/components/reports/graphs/NetWorthGraph.tsx 📈 +8 B (+0.14%) 5.6 kB → 5.6 kB
src/components/transactions/TransactionsTable.jsx 📉 -500 B (-0.76%) 63.83 kB → 63.34 kB
src/components/common/Button2.tsx 📉 -158 B (-3.01%) 5.12 kB → 4.97 kB
src/components/reports/reports/NetWorth.jsx 🔥 -5.87 kB (-100%) 5.87 kB → 0 B
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/wide.js 225.75 kB → 225.26 kB (-500 B) -0.22%
static/js/index.js 3.32 MB → 3.32 MB (-158 B) -0.00%
static/js/ReportRouter.js 1.5 MB → 1.5 MB (-129 B) -0.01%

Unchanged

Asset File Size % Changed
static/js/usePreviewTransactions.js 1.64 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/BackgroundImage.js 122.29 kB 0%
static/js/AppliedFilters.js 20.96 kB 0%
static/js/narrow.js 82.55 kB 0%

Copy link
Contributor

github-actions bot commented Oct 5, 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.19 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.19 MB 0%

@MatissJanis MatissJanis merged commit 38c5f89 into master Oct 6, 2024
20 checks passed
@MatissJanis MatissJanis deleted the matiss/networth-card branch October 6, 2024 19:09
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