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) Refactoring the mobile TransactionListWithBalance component into typescript. #4061

Merged

Conversation

leoltl
Copy link
Contributor

@leoltl leoltl commented Dec 31, 2024

1st OSS PR, so apologies if there are stuff that I am missing. 😄

Refactoring the mobile TransactionListWithBalance component into typescript.

re #1483.

@actual-github-bot actual-github-bot bot changed the title ♻️ (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. [WIP] ♻️ (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. Dec 31, 2024
Copy link

netlify bot commented Dec 31, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 3a4802d
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/677766912be41c00089ec624
😎 Deploy Preview https://deploy-preview-4061.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 Dec 31, 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.64 MB → 5.64 MB (+540 B) +0.01%
Changeset
File Δ Size
src/components/mobile/transactions/TransactionListWithBalances.tsx 🆕 +5.79 kB 0 B → 5.79 kB
home/runner/work/actual/actual/packages/loot-core/src/client/queries.ts 📈 +130 B (+1.75%) 7.27 kB → 7.4 kB
src/components/mobile/transactions/TransactionListWithBalances.jsx 🔥 -5.39 kB (-100%) 5.39 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.71 MB → 3.71 MB (+540 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/resize-observer.js 18.37 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/AppliedFilters.js 10.24 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 83.36 kB 0%
static/js/wide.js 104.11 kB 0%
static/js/ReportRouter.js 1.58 MB 0%

Copy link
Contributor

github-actions bot commented Dec 31, 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.33 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.33 MB 0%

>,
) => {
return <CellValue {...props} />;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the pattern found in budget/envelope/EnvelopeBudgetCompontns.tsx and budget/tracking/TrackingBudgetCompontns.tsx

</View>
<PullToRefresh
isPullable={!!onRefresh}
onRefresh={async () => onRefresh?.()}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this props accept an async function

@leoltl leoltl changed the title [WIP] ♻️ (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. ♻️ (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. Dec 31, 2024
Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

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/transactions/TransactionListWithBalances.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.

Walkthrough

The pull request involves the removal of the TransactionListWithBalances.jsx file and its replacement with a new TypeScript implementation, TransactionListWithBalances.tsx. This change introduces a React component that displays a transaction list alongside balances, incorporating state management and search functionality. Additionally, the changes expand the Spreadsheets type in the spreadsheet index to include a new category property with various fields. The queries file is updated to enhance category handling and improve type safety for certain functions. Overall, the modifications focus on refactoring components for better type support and functionality.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • matt-fidd

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

🧹 Nitpick comments (6)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (5)

25-69: Accessibility nitpick for TransactionSearchInput
Consider adding an aria-label or aria-describedby attribute to improve screen reader accessibility, particularly if the placeholder is omitted or not descriptive.

 <InputWithContent
+  aria-label={placeholder}
   ...
 />

71-93: Complex union types
The TransactionListWithBalancesProps type comprehensively covers multiple union types for different balance queries. Consider extracting separate smaller types or using discriminated unions to simplify future maintenance.


95-107: Handling isLoading
It might be beneficial to render a loading indicator (e.g., a spinner) when isLoading is true, improving user experience during data fetches.


157-168: Optional naming improvement
TransactionListBalanceCellValue is descriptive but somewhat lengthy. If commonly used, consider a shorter alias or internal variable to boost readability in repeated usage.


180-249: Duplicate patterns in BalanceWithCleared
Cleared and uncleared sections have similar layout code. A shared internal helper could reduce duplication and centralize style transformations.

 function BalanceWithCleared({...}) {
-  // Repeats code for cleared & uncleared
+  // Possible approach: factor out repeated code for each balance section into a sub-component or method
 }
packages/desktop-client/src/components/spreadsheet/index.ts (1)

18-26: Consistent naming in category
All fields are named consistently with the existing structure. A minor suggestion is to confirm that 'uncategorized-amount' and 'uncategorized-balance' align with other naming conventions (e.g., 'offbudget-accounts-balance'). If everything is uniform across the codebase, it’s good to keep it as is.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da613ab and 242cbc2.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4061.md is excluded by !**/*.md
📒 Files selected for processing (4)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx (0 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (1 hunks)
  • packages/desktop-client/src/components/spreadsheet/index.ts (1 hunks)
  • packages/loot-core/src/client/queries.ts (5 hunks)
💤 Files with no reviewable changes (1)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.jsx
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (2)
Learnt from: matt-fidd
PR: actualbudget/actual#3472
File: packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx:375-383
Timestamp: 2024-11-10T16:45:25.627Z
Learning: Styles in the codebase are generally defined inline within components to match existing conventions and maintain readability. Extracting styles into constants may diverge from the codebase conventions.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-11-10T16:45:25.627Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.
🔇 Additional comments (11)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (6)

1-3: Imports look good
No immediate issues are found with the import statements or the usage of typed imports from React.


4-6: Imports from queries
This import style is consistent with the rest of the codebase. Nothing to change.


7-16: Imports for hooks, icons, and styling
Everything appears organized; the codebase’s inline styling convention is respected.


20-23: Type referencing with TransactionListWithBalancesProps['onSearch']
Using a prop reference to ensure consistent function signatures is a solid approach.


110-153: Inline styles and layout
Inline styles are consistent with the established convention in this project (per retrieved learnings). However, consider factoring out repeated style objects (e.g., flex containers) into local constants if usage grows across the file.


252-278: Overall design of Balance
The code correctly handles negative amounts by coloring them as error text and otherwise highlighting them. This approach is clear and user-friendly.

packages/loot-core/src/client/queries.ts (5)

28-28: Introduction of categoryParametrizedField
This is a clean solution to generate fields for category-related bindings.


183-191: categoryBalance usage
The approach for filtering transactions by category and month is straightforward and type-safe.


Line range hint 199-208: categoryBalanceCleared
Identical structure to categoryBalance but for cleared transactions. Nothing problematic here.


Line range hint 216-225: categoryBalanceUncleared
Same reliable pattern, focusing on uncleared transactions.


239-243: Generic uncategorizedBalance
Making this function generic with <SheetName extends SheetNames> is a neat enhancement, ensuring it integrates consistently with the rest of the code.

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

🧹 Nitpick comments (4)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (4)

54-57: Consider implementing debounce for search functionality

The search callback is triggered on every keystroke, which might cause performance issues with frequent API calls. Consider implementing debouncing to limit the rate of search requests.

+import { debounce } from 'lodash';
+
 function TransactionSearchInput({
   placeholder,
   onSearch,
 }: TransactionSearchInputProps) {
   const [text, setText] = useState('');
+  const debouncedSearch = React.useMemo(
+    () => debounce((searchText: string) => onSearch(searchText), 300),
+    [onSearch]
+  );
+
+  React.useEffect(() => {
+    return () => {
+      debouncedSearch.cancel();
+    };
+  }, [debouncedSearch]);

   return (
     // ... rest of the component
     <InputWithContent
       value={text}
       onChangeValue={text => {
         setText(text);
-        onSearch(text);
+        debouncedSearch(text);
       }}

141-141: Simplify async callback and improve type safety

The async arrow function with optional chaining can be simplified while maintaining type safety.

-          onRefresh={async () => onRefresh?.()}
+          onRefresh={onRefresh}

156-167: Simplify generic type constraints

The generic type constraint and component props type could be simplified while maintaining type safety.

-const TransactionListBalanceCellValue = <
-  FieldName extends SheetFields<'account'> | SheetFields<'category'>,
->(
-  props: ComponentProps<
-    typeof CellValue<
-      FieldName extends SheetFields<'account'> ? 'account' : 'category',
-      FieldName
-    >
-  >,
-) => {
+type ValidSheetName = 'account' | 'category';
+type ValidFieldName = SheetFields<ValidSheetName>;
+
+const TransactionListBalanceCellValue = <T extends ValidFieldName>(
+  props: ComponentProps<typeof CellValue<ValidSheetName, T>>,
+) => {
   return <CellValue {...props} />;
 };

124-133: Consider extracting balance display logic

The conditional rendering of balance components could be extracted into a separate component to improve maintainability and reusability.

Consider creating a BalanceDisplay component that encapsulates the logic for choosing between BalanceWithCleared and Balance components. This would make the main component cleaner and the balance display logic more maintainable.

type BalanceDisplayProps = {
  balance: TransactionListWithBalancesProps['balance'];
  balanceCleared?: TransactionListWithBalancesProps['balanceCleared'];
  balanceUncleared?: TransactionListWithBalancesProps['balanceUncleared'];
};

function BalanceDisplay({ balance, balanceCleared, balanceUncleared }: BalanceDisplayProps) {
  return balanceCleared && balanceUncleared ? (
    <BalanceWithCleared
      balance={balance}
      balanceCleared={balanceCleared}
      balanceUncleared={balanceUncleared}
    />
  ) : (
    <Balance balance={balance} />
  );
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 242cbc2 and 3a4802d.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/mobile/transactions/TransactionListWithBalances.tsx (2)
Learnt from: matt-fidd
PR: actualbudget/actual#3472
File: packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx:375-383
Timestamp: 2024-11-10T16:45:25.627Z
Learning: Styles in the codebase are generally defined inline within components to match existing conventions and maintain readability. Extracting styles into constants may diverge from the codebase conventions.
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-11-10T16:45:25.627Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.

@leoltl leoltl changed the title ♻️ (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. (typescript) Refactoring the mobile TransactionListWithBalance component into typescript. Jan 3, 2025
Copy link
Contributor

@joel-jeremy joel-jeremy left a comment

Choose a reason for hiding this comment

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

LGTM!

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