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

Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) #3732

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

Conversation

lelemm
Copy link
Contributor

@lelemm lelemm commented Oct 24, 2024

Fix #2932

@actual-github-bot actual-github-bot bot changed the title Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) [WIP] Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) Oct 24, 2024
Copy link

netlify bot commented Oct 24, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 3ced57f
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/671a987a435ce3000873a474
😎 Deploy Preview https://deploy-preview-3732.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 Oct 24, 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.32 MB → 5.32 MB (+275 B) +0.00%
Changeset
File Δ Size
src/components/util/AmountInput.tsx 📈 +365 B (+9.98%) 3.57 kB → 3.93 kB
src/components/schedules/ScheduleDetails.jsx 📉 -90 B (-0.29%) 30.46 kB → 30.38 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.33 MB → 3.33 MB (+275 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.57 kB 0%
static/js/AppliedFilters.js 21.3 kB 0%
static/js/wide.js 232.16 kB 0%
static/js/ReportRouter.js 1.5 MB 0%

Copy link
Contributor

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

@lelemm lelemm changed the title [WIP] Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) Fix #2932: Schedule reset amount to ten (10) when amount is zero (0) Oct 24, 2024
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

The pull request introduces changes to two components: ScheduleDetails and AmountInput. In ScheduleDetails.jsx, the default value for the amount field in the state management logic has been modified from -1000 to 0. This change affects how new schedules are initialized. Additionally, the updateScheduleConditions function now includes validation checks for the amount field. The handling of the amountOp field remains unchanged, and error handling for the date and amount fields continues to function as expected.

In AmountInput.tsx, several modifications enhance the component's functionality. A new state variable, symbol, tracks the sign of the amount. The logic for determining the sign has been refactored, and the onSwitch function has been updated to toggle the symbol state. The getAmount and fireUpdate functions have been simplified to improve clarity. The rendering logic for the button's aria-label and icons has also been adjusted to reflect the current symbol state.

Assessment against linked issues

Objective Addressed Explanation
Fix the bug where the schedule resets the amount to 10 when it is 0 (#2932)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1b19f98 and 3ced57f.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/util/AmountInput.tsx (5 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/util/AmountInput.tsx (1)
Learnt from: lelemm
PR: actualbudget/actual#3732
File: packages/desktop-client/src/components/util/AmountInput.tsx:102-108
Timestamp: 2024-10-24T18:57:16.406Z
Learning: In `packages/desktop-client/src/components/util/AmountInput.tsx`, zero amounts are handled in the `onSwitch` function, so zero amounts are intentionally ignored in the `fireUpdate` function.
🔇 Additional comments (6)
packages/desktop-client/src/components/util/AmountInput.tsx (6)

58-60: LGTM: Proper symbol initialization logic.

The initialization logic correctly handles all cases including zero amounts, using the zeroSign prop to determine the initial symbol state when the amount is zero.


78-82: LGTM: Correct zero amount handling in onSwitch.

The special handling of zero amounts in onSwitch is intentional and correctly implements the toggle behavior without affecting non-zero amounts.


85-87: LGTM: Clean getAmount implementation.

The refactored getAmount function cleanly handles sign based on the symbol state, making the logic more maintainable.


98-104: LGTM: Correct symbol update logic.

The fireUpdate function correctly updates the symbol based on amount sign, intentionally omitting zero amount handling as this is managed in onSwitch.


124-124: LGTM: Proper UI and accessibility updates.

The UI changes correctly reflect the symbol state while maintaining accessibility through appropriate aria-labels and icons.

Also applies to: 129-134


78-82: Verify integration with schedule functionality.

While the implementation looks correct, let's verify that this component properly integrates with the schedule functionality to prevent the amount reset issue.

Also applies to: 98-104

✅ Verification successful

Based on the search results, I can see that the AmountInput component is used in the schedule functionality through ScheduleDetails.jsx, where it's used both directly and through its BetweenAmountInput variant. The implementation in AmountInput.tsx shows that the zero amount handling and sign switching logic is properly contained within the component and works consistently across all its usages.

The implementation correctly handles schedule integration

The changes to AmountInput.tsx are safe and properly integrate with schedule functionality because:

  • The sign switching logic for zero amounts is self-contained within the component
  • The component maintains consistent behavior across all its usages, including schedules
  • The schedule-related test confirms amount handling works as expected
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for schedule-related components that use AmountInput
rg -l "AmountInput.*schedule" --type tsx --type jsx

# Search for tests related to schedule amounts
rg -l "test.*schedule.*amount" --type test

Length of output: 155


Script:

#!/bin/bash
# Search for AmountInput usage in all files
rg "AmountInput" -A 5 -B 5

# Search for schedule-related test files
fd ".*\.(test|spec)\.(ts|tsx|js|jsx)$" | xargs rg "schedule.*amount"

# Search for schedule-related components
rg "schedule.*amount" --type ts --type tsx --type js --type jsx

Length of output: 34152


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6af0dba and 1b19f98.

⛔ Files ignored due to path filters (4)
  • packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png is excluded by !**/*.png
  • upcoming-release-notes/3732.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • packages/desktop-client/src/components/schedules/ScheduleDetails.jsx (1 hunks)
  • packages/desktop-client/src/components/util/AmountInput.tsx (5 hunks)
🔇 Additional comments (6)
packages/desktop-client/src/components/util/AmountInput.tsx (4)

113-114: LGTM: Proper state synchronization on blur.

The blur handling correctly uses the new sign-aware amount calculation.


89-91: Verify handling of undefined/null values.

The amount calculation looks correct, but we should verify edge case handling.

Let's check for proper null/undefined handling:

#!/bin/bash
# Search for tests covering AmountInput edge cases
rg -A 5 "test.*AmountInput.*undefined|test.*AmountInput.*null" --type typescript --type typescript-react

128-128: LGTM: Proper UI feedback and accessibility.

The UI changes correctly reflect the current symbol state and maintain accessibility.

Let's verify accessibility attributes:

#!/bin/bash
# Search for accessibility-related tests
rg -l "aria-label.*AmountInput" --type typescript --type typescript-react

Also applies to: 133-137, 148-149


58-60: LGTM: Proper zero amount sign handling implemented.

The new symbol state correctly handles sign preservation for zero amounts, which is essential for fixing the schedule amount reset issue.

Let's verify the component's integration with ScheduleDetails:

✅ Verification successful

Based on the comprehensive analysis of the codebase, I can now provide the final response:

The new symbol state implementation is correct and properly integrated.

The changes to AmountInput are well-integrated with the scheduling system:

  • The component is used in ScheduleDetails for handling scheduled amounts
  • The sign handling aligns with the schedule amount validation logic
  • The zero amount handling with zeroSign prop is properly respected in the schedule context

The implementation correctly preserves the sign for zero amounts, which directly addresses the bug where scheduled amounts were being reset to 10 when the amount is zero.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for AmountInput usage in ScheduleDetails
rg -l "AmountInput.*ScheduleDetails" --type typescript --type typescript-react

Length of output: 226


Script:

#!/bin/bash
# Search for AmountInput usage in the codebase
rg "AmountInput" --type tsx -A 5 -B 5

Length of output: 65


Script:

#!/bin/bash
# Search for AmountInput usage in the codebase
rg "AmountInput" -A 5 -B 5

Length of output: 33885


Script:

#!/bin/bash
# Search for ScheduleDetails usage and implementation
rg "ScheduleDetails" -A 5 -B 5

Length of output: 3078


Script:

#!/bin/bash
# Search for schedule amount handling in ScheduleDetails
rg "amount" -A 5 -B 5 packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

Length of output: 5544

packages/desktop-client/src/components/schedules/ScheduleDetails.jsx (2)

Line range hint 449-486: Verify amount handling in save logic.

The save logic processes the amount field but doesn't explicitly handle zero values. Consider adding a test case to verify that zero amounts are preserved during save operations.

Let's examine the save logic in the codebase:


105-105: Verify if changing default amount to 0 fully fixes the reset issue.

While changing the default amount from -1000 to 0 is a step in the right direction, we need to verify if this change alone prevents the schedule from resetting to 10 when the amount is zero. The bug description specifically mentions a reset to 10, but this change only modifies the initial default value.

Let's search for potential reset logic or hardcoded values:

✅ Verification successful

Let me analyze the results and generate additional verification scripts to understand the amount handling better:

The previous results show the usage of schedule._amount but we need to understand how it's validated and processed, especially during updates. These new scripts will help us verify if there's any logic that could cause the amount to reset to 10.


Let me search for one more critical piece - the state updates and reducer logic in ScheduleDetails that might affect the amount:

This will help us understand how the amount state is managed and if there's any logic that could cause it to reset to 10 during state updates or form submission.


Let me search for one final piece - the reducer implementation and initial state setup:

This will help us understand how the amount state is initialized and updated through the reducer, which is crucial for understanding if there's any logic that could cause the amount to reset to 10.


Based on the analysis of the code and shell script results, I can now provide a final response:

The change from -1000 to 0 as default amount is correct and sufficient.

The investigation reveals:

  1. The amount handling is done through controlled state management with proper validation
  2. The value 10 doesn't appear in any amount-related logic in schedule components
  3. The schedule._amount is properly handled in multiple places:
    • Initial state from the schedule object
    • State updates through reducer's set-field action
    • Form submission preserving the amount value
  4. The bug was likely caused by the default -1000 being considered invalid, leading to a fallback value. Setting it to 0 is a valid default that won't trigger unwanted resets.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential reset logic or hardcoded values in schedule-related files

# Test 1: Look for files containing both "schedule" and "amount" in their names
echo "=== Schedule & Amount Related Files ==="
fd -t f -i "schedule.*amount|amount.*schedule"

# Test 2: Search for occurrences of the number 10 in schedule-related files
echo -e "\n=== Occurrences of '10' in Schedule Files ==="
rg -C 3 "\b10\b" -g "*schedule*"

# Test 3: Search for amount reset logic in schedule-related files
echo -e "\n=== Amount Reset Logic in Schedule Files ==="
rg -C 3 "amount.*=.*(?:10|0)" -g "*schedule*"

# Test 4: Search for schedule amount handling in the codebase
echo -e "\n=== Schedule Amount Handling ==="
ast-grep --pattern 'schedule._amount'

Length of output: 17360


Script:

#!/bin/bash
# Search for amount validation and processing logic

# Look for amount validation in schedule-related files
echo "=== Amount Validation Logic ==="
rg -C 5 "amount.*valid|valid.*amount" -g "*schedule*"

# Look for amount operations and conditions
echo -e "\n=== Amount Operations ==="
ast-grep --pattern '{ op: $_, field: "amount", value: $_ }'

# Look for getScheduledAmount implementation
echo -e "\n=== getScheduledAmount Implementation ==="
rg -C 5 "function getScheduledAmount"

# Look for amount state updates in ScheduleDetails
echo -e "\n=== Amount State Updates in ScheduleDetails ==="
rg -C 5 "amount.*state" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

Length of output: 1971


Script:

#!/bin/bash
# Search for state management in ScheduleDetails

# Look for reducer and state updates
echo "=== State Management in ScheduleDetails ==="
rg -C 10 "function reducer|type: '.*'" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

# Look for amount initialization
echo -e "\n=== Amount Initialization ==="
rg -C 5 "initialState|useState.*amount" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

# Look for form submission handling
echo -e "\n=== Form Submission Logic ==="
rg -C 10 "onSubmit|handleSubmit" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

Length of output: 12443


Script:

#!/bin/bash
# Search for reducer implementation and initial state

# Look for reducer function and initial state
echo "=== Reducer Implementation ==="
rg -A 20 "function reducer" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

# Look for amount-related state updates in reducer
echo -e "\n=== Amount State Updates in Reducer ==="
rg -B 5 -A 10 "case '.*':" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

# Look for initial state declaration
echo -e "\n=== Initial State Declaration ==="
rg -B 2 -A 10 "const initialState = {" packages/desktop-client/src/components/schedules/ScheduleDetails.jsx

Length of output: 4526

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@youngcw
Copy link
Member

youngcw commented Oct 25, 2024

Functionally this seem good. I still need to go through the code though. Thanks for making a better fix then my simple fix

@lelemm
Copy link
Contributor Author

lelemm commented Oct 25, 2024

No problem. I'm with some spare time at work. Helping cleaning up the issue log ;)

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.

[Bug]: Schedule reset amount to ten (10) when amount is zero (0)
2 participants