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

Use a toggle on mobile transaction's Cleared flag #3622

Merged
merged 7 commits into from
Oct 13, 2024

Conversation

joel-jeremy
Copy link
Contributor

No description provided.

@actual-github-bot actual-github-bot bot changed the title Use a toggle on mobile transaction's Cleared flag [WIP] Use a toggle on mobile transaction's Cleared flag Oct 10, 2024
Copy link

netlify bot commented Oct 10, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 8e66005
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/670ae9651ffd410008e819fe
😎 Deploy Preview https://deploy-preview-3622.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] Use a toggle on mobile transaction's Cleared flag Use a toggle on mobile transaction's Cleared flag Oct 10, 2024
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces several modifications across multiple components within the desktop client application. The Toggle component has been updated with reordered import statements, and the ToggleProps type has been modified to replace the checked property with isOn, while adding new optional properties isDisabled and className. The onToggle function now accepts a boolean argument indicating the toggle state. In MobileForms.tsx, the BooleanField has been replaced with a new ToggleField that utilizes the Toggle component for rendering. The TransactionEdit.jsx component also replaces the BooleanField with the Toggle component and includes optimizations using useCallback for several functions to enhance performance. Additionally, the Menu component has been adjusted to improve the layout of toggle items, and new constants for checkbox styling have been added in various theme files. These changes collectively enhance the usability and styling of the components involved.

Possibly related PRs

Suggested labels

#sparkles: Merged

Suggested reviewers

  • MatissJanis

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

github-actions bot commented Oct 10, 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.33 MB → 5.33 MB (-151 B) -0.00%
Changeset
File Δ Size
src/components/common/Toggle.tsx 📈 +231 B (+14.96%) 1.51 kB → 1.73 kB
src/style/themes/development.ts 📈 +140 B (+1.80%) 7.59 kB → 7.72 kB
src/style/themes/dark.ts 📈 +96 B (+1.22%) 7.66 kB → 7.75 kB
src/style/themes/midnight.ts 📈 +92 B (+1.22%) 7.36 kB → 7.45 kB
src/style/themes/light.ts 📈 +96 B (+1.21%) 7.72 kB → 7.81 kB
src/components/mobile/transactions/TransactionEdit.jsx 📈 +66 B (+0.19%) 34.09 kB → 34.16 kB
src/components/common/Menu.tsx 📉 -44 B (-0.76%) 5.67 kB → 5.63 kB
src/components/mobile/MobileForms.tsx 📉 -828 B (-24.60%) 3.29 kB → 2.48 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.34 MB → 3.34 MB (-151 B) -0.00%

Unchanged

Asset File Size % Changed
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/AppliedFilters.js 21.31 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/wide.js 243.06 kB 0%
static/js/ReportRouter.js 1.51 MB 0%

Copy link
Contributor

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

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 (9)
packages/desktop-client/src/components/common/Toggle.tsx (3)

12-14: Approved: Enhanced ToggleProps with new properties.

The addition of disabled and className props, along with the updated onToggle signature, improves the component's flexibility and usability. These changes align well with common React patterns.

Consider adding JSDoc comments for these new props to improve documentation:

/** Whether the toggle is disabled */
disabled?: boolean;
/** Callback function when the toggle state changes */
onToggle?: (on: boolean) => void;
/** Additional CSS class names */
className?: string;

41-42: Approved: Enhanced label element with data attributes and theme-based styling.

The addition of data attributes (data-toggle-container and data-on) and the use of theme variables for background color are good improvements. These changes enhance testability and maintain consistent styling.

Consider extracting the background color logic to a separate variable for improved readability:

const backgroundColor = checked
  ? theme.checkboxToggleBackgroundSelected
  : theme.checkboxToggleBackground;

Then use this variable in the style object:

background: backgroundColor,

Also applies to: 53-55


60-61: Approved: Improved span element with data attributes and conditional styling.

The addition of data attributes (data-toggle and data-on) and the conditional background color based on the disabled state are good improvements. These changes enhance testability and provide better visual feedback.

Consider extracting the background color logic to a separate variable for improved readability:

const toggleBackground = disabled ? theme.checkboxToggleDisabled : '#fff';

Then use this variable in the style object:

background: toggleBackground,

Also applies to: 64-64, 73-73

packages/desktop-client/src/components/common/Menu.tsx (1)

Line range hint 210-232: Improved toggle item layout and accessibility

The changes to the toggle item rendering enhance both the layout and accessibility:

  1. The new View component with flexbox properties (flexDirection, flex, justifyContent, alignItems) improves the alignment and spacing of the toggle item elements.
  2. Wrapping the text in a label element and associating it with the toggle input using the htmlFor attribute enhances accessibility.
  3. The onToggle function now uses a boolean callback, which is more idiomatic for toggle components.

However, there are a couple of points to consider:

  1. The removal of the onColor prop from the Toggle component might affect its visual representation. Ensure that the toggle still has appropriate styling for its active state.
  2. The marginLeft: 5 on the Toggle component seems arbitrary. Consider using a design system variable or a more flexible spacing approach.

Consider the following improvements:

  1. Replace the hardcoded marginLeft: 5 with a design system spacing variable.
  2. Verify that the Toggle component still has appropriate styling for its active state after removing the onColor prop.
packages/desktop-client/src/style/themes/development.ts (1)

178-180: LGTM! Consider grouping toggle-related constants.

The new constants for checkbox toggle styling are well-named and use appropriate colors from the existing palette. They align with the PR objective of adding a toggle functionality.

For improved organization, consider grouping all toggle-related constants together. You could move the new constants right after the existing checkbox constants (around line 177) for better readability and maintenance.

packages/desktop-client/src/style/themes/light.ts (1)

181-182: Summary: New checkbox toggle constants added

The additions of checkboxToggleBackgroundSelected and checkboxToggleDisabled are appropriate and consistent with the existing theme structure. These changes support the implementation of a toggle for the Cleared flag on mobile transactions.

Suggestions for next steps:

  1. Ensure these constants are added to all other theme files (dark, development, midnight) for consistency.
  2. Consider adding a brief comment explaining the usage of these constants in the relevant UI components.
  3. Update the PR description with more details about the implementation and the rationale behind these changes.

To maintain consistency and improve maintainability, consider creating a shared interface for theme files. This would help ensure that all required constants are present in each theme file and make it easier to add new themes in the future.

packages/desktop-client/src/style/themes/midnight.ts (2)

180-182: LGTM! Consider grouping related constants.

The new constants checkboxToggleBackgroundSelected and checkboxToggleDisabled are well-named and use appropriate colors from the colorPalette. They enhance the styling options for checkbox toggles, providing distinct visual cues for selected and disabled states.

For improved readability and maintainability, consider grouping all checkbox-related constants together. You could move the existing checkboxToggleBackground constant (if it's defined elsewhere in this file) next to these new constants.

Here's a suggested grouping:

export const checkboxToggleBackground = colorPalette.gray400;
export const checkboxToggleBackgroundSelected = colorPalette.purple300;
export const checkboxToggleDisabled = colorPalette.gray700;

This grouping will make it easier for developers to find and modify all checkbox toggle-related styles in one place.


Line range hint 1-182: Summary: Enhancing checkbox toggle styling in the midnight theme

The changes to this file are part of a larger effort to improve the styling of checkbox toggles across the application. The new constants checkboxToggleBackgroundSelected and checkboxToggleDisabled provide additional styling options for selected and disabled states of checkbox toggles.

These additions enhance the visual feedback for users interacting with checkbox toggles in the midnight theme, improving overall user experience and accessibility. The chosen colors align well with the existing color scheme, maintaining consistency with the midnight theme's dark and purple-accented aesthetic.

To further improve the theme system:

  1. Consider creating a separate file for checkbox-related styles if they become more complex in the future.
  2. Ensure that these new styles are applied consistently across all components that use checkbox toggles.
  3. Document the purpose and usage of these new constants in a central theme guide or style documentation to help other developers understand and correctly use these new styling options.
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (1)

Line range hint 1077-1110: Rename unmounted flag to isMounted for better readability

Using isMounted initialized to true and setting it to false upon unmount enhances clarity when checking the component's mount status. It makes the conditionals more intuitive.

Apply this diff to rename the flag:

-        let unmounted = false;
+        let isMounted = true;

         async function fetchTransaction() {
           // ...
-          if (!unmounted) {
+          if (isMounted) {
             // Update state
           }
         }

         // ...

         return () => {
-          unmounted = true;
+          isMounted = false;
         };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 23de23b and f765146.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3622.md is excluded by !**/*.md
📒 Files selected for processing (7)
  • packages/desktop-client/src/components/common/Menu.tsx (2 hunks)
  • packages/desktop-client/src/components/common/Toggle.tsx (4 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (6 hunks)
  • packages/desktop-client/src/style/themes/dark.ts (1 hunks)
  • packages/desktop-client/src/style/themes/development.ts (1 hunks)
  • packages/desktop-client/src/style/themes/light.ts (1 hunks)
  • packages/desktop-client/src/style/themes/midnight.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/style/themes/light.ts (2)
Learnt from: psybers
PR: actualbudget/actual#3298
File: packages/desktop-client/src/style/themes/light.ts:212-214
Timestamp: 2024-09-20T03:54:11.640Z
Learning: The tooltip styling constants `tooltipText`, `tooltipBackground`, and `tooltipBorder` have been added to all theme files, including `dark.ts`, `development.ts`, and `midnight.ts`.
Learnt from: psybers
PR: actualbudget/actual#3298
File: packages/desktop-client/src/style/themes/light.ts:212-214
Timestamp: 2024-10-08T15:46:15.739Z
Learning: The tooltip styling constants `tooltipText`, `tooltipBackground`, and `tooltipBorder` have been added to all theme files, including `dark.ts`, `development.ts`, and `midnight.ts`.
🔇 Additional comments (10)
packages/desktop-client/src/components/common/Toggle.tsx (5)

5-5: LGTM: Import order change.

The reordering of imports doesn't affect functionality and may align with coding standards.


21-21: LGTM: Updated props destructuring.

The destructuring of disabled and className props is consistent with the ToggleProps type updates and allows for their use within the component.

Also applies to: 23-23


31-32: LGTM: Improved input element functionality.

The addition of the disabled attribute and the updated onChange handler improves the component's functionality and accessibility. The onToggle callback now provides more useful information to the parent component.


Line range hint 1-84: Overall improvements to the Toggle component

The changes made to this file have significantly enhanced the Toggle component:

  1. Added new props (disabled and className) for improved flexibility.
  2. Updated the onToggle callback to provide more information.
  3. Improved accessibility with the disabled attribute.
  4. Enhanced styling options with theme variables and data attributes.
  5. Improved maintainability and testability.

These changes align well with React best practices and should improve the overall quality of the codebase.


27-27: Approved: Replaced div with View component.

The replacement of the outer div with a View component and the addition of the className prop improves the component's flexibility. This change allows for better customization from parent components.

Could you provide more information about the View component? Let's verify its implementation:

Also applies to: 82-82

✅ Verification successful

Further Verification Needed: Unable to locate the View component definition.

To better understand the View component, let's perform a broader search to identify its definition or import.


Further Verification Needed: rg command failed to recognize the 'typescript' file type.

Let's adjust the search to use specific file extensions and try again.


Verified: Replacement of div with View component is correct.

The View component is properly defined and serves as a flexible wrapper around a div, ensuring enhanced customization and ref forwarding. Replacing the div with View in Toggle.tsx aligns with our component architecture and maintains functionality.

  • Confirmed the definition of View in packages/desktop-client/src/components/common/View.tsx.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the View component definition
ast-grep --lang typescript --pattern $'export const View = $_'

Length of output: 63


Script:

#!/bin/bash
# Search for any export or import of the View component
rg --type typescript 'export\s+(const|function|class)\s+View\b' || rg --type typescript 'import\s+\{\s*View\s*\}'

Length of output: 184


Script:

#!/bin/bash
# Search for any export or import of the View component using TypeScript file extensions
rg 'export\s+(const|function|class)\s+View\b' --glob '*.ts' --glob '*.tsx' || rg 'import\s+\{\s*View\s*\}' --glob '*.ts' --glob '*.tsx'

Length of output: 207

packages/desktop-client/src/style/themes/dark.ts (2)

Line range hint 1-180: Summary of changes to the dark theme

The additions to this file enhance the dark theme by introducing two new checkbox toggle states:

  1. checkboxToggleBackgroundSelected: For the selected state of a checkbox toggle.
  2. checkboxToggleDisabled: For the disabled state of a checkbox toggle.

These changes are consistent with the existing theme and follow the established naming conventions. They provide more granular control over checkbox toggle appearances, which aligns with the PR objective of using a toggle for the Cleared flag on mobile transactions.

The changes look good and are ready for integration, pending verification of their usage in the components.


179-180: New checkbox toggle styles added

The new exports checkboxToggleBackgroundSelected and checkboxToggleDisabled have been added to support additional states for checkbox toggles. These additions enhance the theme's flexibility for checkbox styling.

A few observations:

  1. The selected state uses purple300, which is consistent with other selected states in the theme (e.g., checkboxBackgroundSelected).
  2. The disabled state uses gray400, which is appropriate for indicating a non-interactive state.

These additions look good and are consistent with the existing theme. However, to ensure proper integration:

Let's verify if these new exports are used correctly in the codebase:

This will help us confirm that the new exports are being utilized as intended in the components.

✅ Verification successful

Checkbox Toggle Styles Integration Verified

The new exports checkboxToggleBackgroundSelected and checkboxToggleDisabled are correctly defined in the theme files and properly utilized within Toggle.tsx. No issues detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the new exports
echo "Searching for checkboxToggleBackgroundSelected usage:"
rg "checkboxToggleBackgroundSelected" --type ts --type tsx

echo "\nSearching for checkboxToggleDisabled usage:"
rg "checkboxToggleDisabled" --type ts --type tsx

Length of output: 381


Script:

#!/bin/bash
# Search for usage of the new exports in .ts and .tsx files
echo "Searching for checkboxToggleBackgroundSelected usage:"
rg "checkboxToggleBackgroundSelected" --glob "*.ts" --glob "*.tsx"

echo "\nSearching for checkboxToggleDisabled usage:"
rg "checkboxToggleDisabled" --glob "*.ts" --glob "*.tsx"

Length of output: 1524

packages/desktop-client/src/style/themes/light.ts (2)

182-182: LGTM! Verify consistency across theme files.

The addition of checkboxToggleDisabled is consistent with the existing theme structure and naming conventions. It appropriately uses a color from the colorPalette.

To ensure consistency across all theme files, please run the following script:

✅ Verification successful

Action Required: Retry consistency check with corrected file type.

The previous script failed due to an unrecognized file type. Please use the updated script below to verify the presence of checkboxToggleDisabled in all TypeScript theme files:


Consistency Verified Across All Theme Files

The checkboxToggleDisabled constant is present in all theme files with appropriate color assignments:

  • packages/desktop-client/src/style/themes/midnight.ts
  • packages/desktop-client/src/style/themes/development.ts
  • packages/desktop-client/src/style/themes/dark.ts
  • packages/desktop-client/src/style/themes/light.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if checkboxToggleDisabled is present in all theme files

# Test: Search for checkboxToggleDisabled in all theme files
rg --type typescript 'export const checkboxToggleDisabled' packages/desktop-client/src/style/themes/

Length of output: 137


Script:

# 
#!/bin/bash
# Description: Check if checkboxToggleDisabled is present in all theme files

# Test: Search for checkboxToggleDisabled in all `.ts` theme files
rg --type-add 'ts:*.ts' --type ts 'export const checkboxToggleDisabled' packages/desktop-client/src/style/themes/

Length of output: 563


181-181: LGTM! Verify consistency across theme files.

The addition of checkboxToggleBackgroundSelected is consistent with the existing theme structure and naming conventions. It appropriately uses a color from the colorPalette.

To ensure consistency across all theme files, please run the following script:

✅ Verification successful

The previous script failed due to an unrecognized file type. Please use the corrected script below to verify consistency across theme files:


The previous script failed due to unrecognized ts and tsx file types. Please use the corrected script below to verify consistency across theme files:


Verification Complete: Consistency Across Theme Files Confirmed

The checkboxToggleBackgroundSelected constant is present and appropriately defined in all theme files:

  • packages/desktop-client/src/style/themes/midnight.ts
  • packages/desktop-client/src/style/themes/development.ts
  • packages/desktop-client/src/style/themes/dark.ts
  • packages/desktop-client/src/style/themes/light.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if checkboxToggleBackgroundSelected is present in all theme files

# Test: Search for checkboxToggleBackgroundSelected in all theme files
rg --type typescript 'export const checkboxToggleBackgroundSelected' packages/desktop-client/src/style/themes/

Length of output: 147


Script:

# Description: Check if checkboxToggleBackgroundSelected is present in all theme files

# Test: Search for checkboxToggleBackgroundSelected in all TypeScript theme files
rg --type ts --type tsx 'export const checkboxToggleBackgroundSelected' packages/desktop-client/src/style/themes/

Length of output: 143


Script:

#!/bin/bash
# Description: Check if checkboxToggleBackgroundSelected is present in all TypeScript theme files

# Test: Search for checkboxToggleBackgroundSelected in all .ts and .tsx files within the specified directory
rg 'export const checkboxToggleBackgroundSelected' packages/desktop-client/src/style/themes/ --glob '*.ts' --glob '*.tsx'

Length of output: 615

packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (1)

1125-1179: ⚠️ Potential issue

Include all dependencies in the useCallback dependency array

In the onUpdate function, you're using onClearActiveEdit, which should be included in the dependency array of the useCallback hook. Omitting dependencies can lead to stale closures and unexpected behavior.

Apply this diff to include onClearActiveEdit in the dependency array:

       [dateFormat, transactions],
+      [dateFormat, transactions, onClearActiveEdit],

Likely invalid or redundant comment.

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

🧹 Outside diff range and nitpick comments (7)
packages/desktop-client/src/components/common/Toggle.tsx (4)

11-14: LGTM! Consider adding JSDoc comments.

The changes to ToggleProps improve the component's flexibility and clarity. The new properties and updated function signature enhance the component's usability.

Consider adding JSDoc comments to describe each property, especially the new ones. This would improve the component's documentation and make it easier for other developers to use. For example:

type ToggleProps = {
  /** Unique identifier for the toggle */
  id: string;
  /** Whether the toggle is on or off */
  isOn: boolean;
  /** Whether the toggle is disabled */
  isDisabled?: boolean;
  /** Callback function called when the toggle state changes */
  onToggle?: (isOn: boolean) => void;
  /** Additional CSS class names */
  className?: string;
  /** Custom styles */
  style?: CSSProperties;
};

20-23: Consider maintaining consistent prop names.

The prop destructuring aligns with the ToggleProps changes, which is good. However, renaming isDisabled to disabled in the destructuring might lead to confusion.

For consistency and clarity, consider using the same names in the destructuring as in the ToggleProps definition:

export const Toggle = ({
  id,
  isOn,
  isDisabled,
  onToggle,
  className,
  style,
}: ToggleProps) => {
  // ...
}

This maintains consistency between the prop definition and usage, making the code easier to understand and maintain.


27-32: LGTM! Consider using optional chaining for onToggle.

The changes improve the component's functionality and align with the updated prop types. Using View instead of div, adding the disabled attribute, and updating the onChange handler are all positive improvements.

Consider using optional chaining for the onToggle call to make it more concise:

onChange={e => onToggle?.(e.target.checked)}

This achieves the same result but is slightly more readable.


60-73: LGTM! Consider removing unnecessary content property.

The changes to the span element, including the addition of data attributes and the conditional background color, are good improvements. They enhance the component's flexibility and visual feedback.

The empty string content property on line 64 appears to be unnecessary. Consider removing it:

- content: ' ',

This property doesn't affect the element's appearance or behavior and can be safely removed to keep the code cleaner.

packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (3)

964-977: Improved transaction status display with toggle functionality

The addition of conditional rendering for "Reconciled" and "Cleared" statuses in the Footer component enhances the user interface. The use of a Toggle component for the "Cleared" status allows for easy updating of this field.

Consider adding a tooltip or brief explanation for users to understand the difference between "Reconciled" and "Cleared" statuses, as this might not be immediately clear to all users.


1113-1167: Enhanced onUpdate function with improved handling of rules and split transactions

The refactored onUpdate function now includes more robust handling of transaction updates, especially for split transactions and rule-based updates. This is a good improvement in functionality.

However, the increased complexity of this function might make it harder to maintain in the future. Consider breaking down this function into smaller, more focused functions to improve readability and maintainability. For example, you could extract the rule-running logic and the subtransaction updating logic into separate helper functions.

Also, consider adding comments to explain the purpose of complex logic blocks, especially around the handling of subtransactions and rule updates.


Line range hint 1-1252: Consider refactoring for improved maintainability

This file is quite large and contains multiple components and complex logic. While it's functional, it could benefit from some refactoring to improve maintainability. Consider breaking it down into smaller, more focused components and files. This would make the code easier to understand, test, and maintain in the long run.

For example, you could:

  1. Move the ChildTransactionEdit component into its own file.
  2. Extract the complex logic in the onUpdate function into a custom hook or utility function.
  3. Consider using the React Context API for sharing state and callbacks between deeply nested components instead of prop drilling.

These changes would significantly improve the overall structure and maintainability of the code.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f765146 and f6818c6.

⛔ Files ignored due to path filters (9)
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-4-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-5-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-6-chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • packages/desktop-client/src/components/common/Menu.tsx (2 hunks)
  • packages/desktop-client/src/components/common/Toggle.tsx (4 hunks)
  • packages/desktop-client/src/components/mobile/MobileForms.tsx (3 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/common/Menu.tsx
🧰 Additional context used
🪛 GitHub Check: lint
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx

[warning] 19-19:
'css' is defined but never used. Allowed unused vars must match /^(_|React)/u

🔇 Additional comments (9)
packages/desktop-client/src/components/common/Toggle.tsx (3)

Line range hint 41-55: LGTM! Good use of data attributes and theme values.

The addition of data attributes to the label element and the use of theme values for background colors are positive changes. These improvements enhance the component's flexibility for styling and testing, while also ensuring consistency with the overall theme.

The use of data-toggle-container and data-on attributes provides useful hooks for styling or testing. The background color logic using theme.checkboxToggleBackgroundSelected and theme.checkboxToggleBackground ensures consistency with the application's theme.


82-82: LGTM! Consistent use of View component.

The change of the closing tag to </View> is correct and consistent with the earlier modification of the opening tag.

This change ensures that the Toggle component is properly wrapped with the View component, maintaining consistency throughout the component structure.


5-7: LGTM! Verify View component usage.

The import changes look good. The View component is now imported, which is used later in the component implementation.

Let's verify the usage of the View component:

✅ Verification successful

Verified! The View component is correctly imported and utilized within the Toggle.tsx component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of View component in Toggle.tsx

# Test: Search for View usage in Toggle.tsx
rg --type typescript 'View' packages/desktop-client/src/components/common/Toggle.tsx

Length of output: 119


Script:

#!/bin/bash
# Description: Verify the usage of View component in Toggle.tsx

# Test: Search for View usage in Toggle.tsx with correct file types
rg --type ts --type tsx 'View' packages/desktop-client/src/components/common/Toggle.tsx

Length of output: 115


Script:

#!/bin/bash
# Description: Verify the usage of View component in Toggle.tsx using grep

# Test: Search for 'View' usage in Toggle.tsx
grep 'View' packages/desktop-client/src/components/common/Toggle.tsx

Length of output: 158

packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (2)

61-61: New import added for Toggle component

The Toggle component has been imported from the common components. This is good as it suggests a move towards using a standardized UI component for toggle functionality.


971-974: Consistent use of ToggleField for "Cleared" status

The implementation of the ToggleField component for the "Cleared" status in the TransactionEditInner component is consistent with the changes in the Footer. This provides a unified way of handling the "Cleared" status throughout the component, improving the overall user experience and code consistency.

packages/desktop-client/src/components/mobile/MobileForms.tsx (4)

2-2: Approved: Added necessary type import

The addition of ComponentPropsWithoutRef is appropriate for typing the new component without ref forwarding.


14-14: Approved: Importing the Toggle component

Importing the Toggle component is necessary for the implementation of ToggleField.


136-136: Approved: Defining ToggleFieldProps

Using ComponentPropsWithoutRef<typeof Toggle> to define ToggleFieldProps ensures proper typing based on the Toggle component's props.


153-167: Approved: Customizing Toggle component styles

The use of css from Glamor to customize the styles of the Toggle component ensures consistent styling across the application.

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/TransactionEdit.jsx (1)

963-975: LGTM: Implementation of toggle for Cleared and Reconciled flags

The changes successfully implement a toggle for the "Cleared" flag and display a disabled toggle for the "Reconciled" flag. This is consistent with the PR objective of adding a toggle for the "Cleared" flag on mobile transactions.

A minor suggestion for consistency:

Consider using the same casing for the id prop in both Toggle components:

- <Toggle id="Reconciled" isOn isDisabled />
+ <Toggle id="reconciled" isOn isDisabled />

This makes it consistent with the "cleared" id used in the ToggleField component.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f6818c6 and 52ec641.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (5 hunks)
🧰 Additional context used
🔇 Additional comments (2)
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (2)

60-60: LGTM: New Toggle component import

The addition of the Toggle component import is consistent with the implementation of the toggle functionality for the "Cleared" flag in the component.


Line range hint 1064-1243: LGTM: Improvements in TransactionEditUnconnected component

The changes in the TransactionEditUnconnected component bring several improvements:

  1. Addition of a cleanup mechanism for the async fetchTransaction function (lines 1064-1097) to prevent state updates on unmounted components.
  2. Implementation of useCallback hooks for onUpdate, onSave, onDelete, onAddSplit, and onSplit functions (lines 1112-1243).

These changes help prevent memory leaks and improve performance through memoization. The code is now more robust and efficient.

@joel-jeremy joel-jeremy force-pushed the mobile-transaction-edit-cleared-toggle branch from 52ec641 to 0e42e61 Compare October 10, 2024 04:06
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 (2)
packages/desktop-client/src/components/mobile/MobileForms.tsx (2)

147-167: LGTM: Toggle component usage is correct, with a minor suggestion for improvement.

The Toggle component is used correctly with all necessary props passed. The custom styling using the css function is well-implemented and consistent with the project's styling approach.

Consider extracting the custom styles into a separate constant for improved readability:

const toggleStyles = css({
  '& [data-toggle-container]': {
    width: 50,
    height: 24,
  },
  '& [data-toggle]': {
    width: 20,
    height: 20,
  },
});

// Then in the component:
className={String(css([toggleStyles, className]))}

This change would make the component's render function cleaner and easier to read.


136-167: LGTM: Overall implementation of ToggleField is well-done.

The refactoring from BooleanField to ToggleField using the Toggle component is a good improvement. It likely enhances the user experience on mobile devices and maintains consistency with the rest of the application. The implementation adheres to React and TypeScript best practices.

Consider adding a brief JSDoc comment to the ToggleField component to describe its purpose and usage. This would be helpful for other developers working on the project.

Example:

/**
 * ToggleField component for rendering a toggle input in mobile forms.
 * It wraps the Toggle component with additional styling and mobile-specific behavior.
 */
export function ToggleField({ ... }: ToggleFieldProps) {
  // ...
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 52ec641 and 0e42e61.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/common/Toggle.tsx (3 hunks)
  • packages/desktop-client/src/components/mobile/MobileForms.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/common/Toggle.tsx
🧰 Additional context used
🔇 Additional comments (3)
packages/desktop-client/src/components/mobile/MobileForms.tsx (3)

14-14: LGTM: Import statement added correctly.

The Toggle component import is appropriately placed with other component imports, which is consistent with the file's structure.


136-136: LGTM: Type definition for ToggleFieldProps is well-defined.

The ToggleFieldProps type correctly extends the props from the Toggle component using ComponentPropsWithoutRef. This approach ensures type consistency and promotes reusability.


138-145: LGTM: ToggleField function declaration and props destructuring are well-implemented.

The ToggleField function correctly destructures the necessary props from ToggleFieldProps. The isDisabled prop with a default value of false addresses the past review comment about consistent naming, which is a good improvement.

Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Personally I preferred the purple branding color. Apart from that everything else LGTM

Before:
Screenshot 2024-10-10 at 19 50 00

After:
Screenshot 2024-10-10 at 19 49 57

@MatissJanis MatissJanis self-assigned this Oct 10, 2024
@MatissJanis
Copy link
Member

LGTM. Just vrt failing

@joel-jeremy joel-jeremy force-pushed the mobile-transaction-edit-cleared-toggle branch from 821d741 to 8e66005 Compare October 12, 2024 21:25
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/common/Toggle.tsx (3)

11-14: Approved: ToggleProps type definition improved

The changes to the ToggleProps type definition enhance the API of the Toggle component:

  1. Renaming checked to isOn improves clarity.
  2. Adding isDisabled and className properties increases flexibility.
  3. Updating onToggle to accept a boolean parameter allows for more explicit state management.

These changes are well-thought-out and improve the component's usability.

Consider adding JSDoc comments to describe the purpose of each prop, especially the new ones, to improve code documentation.


41-58: Approved: Label element styling and attributes improved

The changes to the label element enhance its functionality and styling:

  1. Addition of data-toggle-container and data-on attributes improves testability and allows for more specific styling.
  2. Use of theme variables for background colors improves consistency and maintainability.
  3. Conditional background color based on isOn state provides better visual feedback.

These changes significantly improve the component's flexibility and user experience.

Consider extracting the CSS object into a separate constant or using a CSS-in-JS solution like styled-components for better organization and reusability.


62-85: Approved: Span element styling and attributes enhanced

The changes to the span element (toggle knob) significantly improve its functionality and appearance:

  1. Addition of data-toggle and data-on attributes enhances testability and allows for more specific styling.
  2. Conditional background color based on isDisabled state provides better visual feedback.
  3. Additional styling for the "on" state improves the toggle's appearance and user experience.

These changes result in a more robust and visually appealing toggle component.

Consider extracting the CSS objects into separate constants or using a CSS-in-JS solution like styled-components. This would improve code organization and potentially allow for easier theming and customization.

packages/desktop-client/src/components/mobile/MobileForms.tsx (1)

147-167: LGTM: Toggle component usage is correct with appropriate styling.

The Toggle component is used correctly with all necessary props passed down. The custom styling applied through className is appropriate for adjusting the toggle size. The use of the css function allows for dynamic styling based on the passed className prop.

Consider extracting the custom styles object into a separate constant for improved readability:

const toggleStyles = {
  '& [data-toggle-container]': {
    width: 50,
    height: 24,
  },
  '& [data-toggle]': {
    width: 20,
    height: 20,
  },
};

// Then use it in the component:
className={String(css([toggleStyles, className]))}

This change would make the component more readable and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d443d12 and 8e66005.

⛔ Files ignored due to path filters (10)
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-from-accounts-id-page-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-4-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-5-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/transactions.mobile.test.js-snapshots/Mobile-Transactions-creates-a-transaction-via-footer-button-6-chromium-linux.png is excluded by !**/*.png
  • upcoming-release-notes/3622.md is excluded by !**/*.md
📒 Files selected for processing (8)
  • packages/desktop-client/src/components/common/Menu.tsx (2 hunks)
  • packages/desktop-client/src/components/common/Toggle.tsx (2 hunks)
  • packages/desktop-client/src/components/mobile/MobileForms.tsx (3 hunks)
  • packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (5 hunks)
  • packages/desktop-client/src/style/themes/dark.ts (1 hunks)
  • packages/desktop-client/src/style/themes/development.ts (1 hunks)
  • packages/desktop-client/src/style/themes/light.ts (1 hunks)
  • packages/desktop-client/src/style/themes/midnight.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/desktop-client/src/components/common/Menu.tsx
  • packages/desktop-client/src/style/themes/dark.ts
  • packages/desktop-client/src/style/themes/development.ts
  • packages/desktop-client/src/style/themes/light.ts
  • packages/desktop-client/src/style/themes/midnight.ts
🧰 Additional context used
🔇 Additional comments (10)
packages/desktop-client/src/components/common/Toggle.tsx (4)

5-7: LGTM: Import statements reorganized and updated

The import statements have been reorganized and updated appropriately. The addition of the View import suggests an improvement in the component's structure.


20-23: LGTM: Component props destructuring updated

The changes in the component props destructuring align well with the updates made to the ToggleProps type. The addition of a default value for isDisabled is a good practice, ensuring the component behaves predictably when the prop is not explicitly set.


88-88: LGTM: Closing View component tag added

The addition of the closing View component tag is consistent with the earlier changes and completes the component structure correctly.


27-32: Approved: Component structure and behavior improved

The changes in the component's return statement enhance its structure and behavior:

  1. Replacing div with View component (likely for consistency or added functionality).
  2. Renaming checked to isOn in the input element.
  3. Adding the disabled attribute to the input element.
  4. Updating the onChange handler to pass the checked state to onToggle.

These changes align well with the updated props and improve the component's functionality.

Could you please clarify the purpose of using the View component instead of a div? Is this a custom component that adds specific functionality or styling?

packages/desktop-client/src/components/mobile/MobileForms.tsx (4)

14-14: LGTM: Import statement added correctly.

The Toggle component import is appropriately placed with other component imports, which is consistent with the file's structure.


136-136: LGTM: Type definition for ToggleFieldProps is well-defined.

The ToggleFieldProps type correctly extends ComponentPropsWithoutRef<typeof Toggle>, allowing the ToggleField component to inherit all props from the Toggle component. This approach follows React best practices for type definitions.


138-145: LGTM: ToggleField function declaration and props destructuring are correct.

The ToggleField function is properly declared as a React functional component. The props destructuring is done correctly, and the isDisabled prop has a default value of false. The naming of isDisabled is consistent with the previous review comment suggestion, which improves code clarity.


138-169: LGTM: ToggleField implementation is clean and follows best practices.

The ToggleField component is well-implemented as a wrapper around the Toggle component. It provides a consistent interface for using toggles in mobile forms, following React best practices. The component is flexible, allowing for custom styling and behavior through props, which enhances its reusability across the application.

packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx (2)

Line range hint 1064-1097: Improved error handling with cleanup mechanism

The addition of the cleanup mechanism in the useEffect hook is a good practice. It prevents potential memory leaks and race conditions by ensuring that state updates don't occur if the component unmounts before the asynchronous operation completes.


960-975: Improved UI with Toggle component for transaction status

The replacement of BooleanField with the Toggle component for "Cleared" and "Reconciled" statuses is a good improvement. It enhances the user interface and provides a more intuitive way for users to interact with these boolean fields. The implementation correctly handles the different states, using a disabled Toggle for reconciled transactions and an interactive ToggleField for cleared status.

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