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 deleting rules considering the applied filters #4224

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

Conversation

harrydigos
Copy link

Fixes #3366

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 0664413
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67929d51ce03c90008836a21
😎 Deploy Preview https://deploy-preview-4224.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 23, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
15 6.68 MB → 6.68 MB (+81 B) +0.00%
Changeset
File Δ Size
src/components/ManageRules.tsx 📈 +318 B (+3.51%) 8.85 kB → 9.16 kB
node_modules/define-data-property/index.js 📉 -9 B (-0.39%) 2.25 kB → 2.24 kB
node_modules/call-bind/index.js 📉 -9 B (-0.84%) 1.05 kB → 1.04 kB
node_modules/has-property-descriptors/index.js 📉 -9 B (-1.55%) 582 B → 573 B
node_modules/es-define-property/index.js 📉 -210 B (-37.50%) 560 B → 350 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 4.28 MB → 4.28 MB (+81 B) +0.00%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/nl.js 58.58 kB 0%
static/js/en-GB.js 92.98 kB 0%
static/js/en.js 99.31 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/uk.js 111.19 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/pt-BR.js 103.38 kB 0%
static/js/AppliedFilters.js 10.52 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/narrow.js 84.94 kB 0%
static/js/wide.js 102.8 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Jan 23, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.33 MB 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%

@harrydigos harrydigos force-pushed the digos/delete-selected-rules branch from 10e7a8a to 79d606e Compare January 23, 2025 17:45
@harrydigos harrydigos force-pushed the digos/delete-selected-rules branch from 79d606e to f998baa Compare January 23, 2025 17:47
@harrydigos harrydigos changed the title [WIP] fix deleting rules when user has used filters fix deleting rules considering the applied filters Jan 23, 2025
Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request modifies the ManageRules.tsx component to enhance the handling of rule selection and deletion. Key changes include the introduction of the RuleEntity type to improve type safety, and the initialization of the allRules state as an array of RuleEntity objects. A new memoized variable, rulesToDelete, has been added to accurately determine which rules are eligible for deletion by intersecting selected items with filtered rules. The onDeleteSelected function has been updated to utilize this variable, improving the correctness of the deletion process. Additionally, the rendering logic for the delete button has been adjusted to reflect the count of rulesToDelete, ensuring that the button accurately indicates the number of deletable rules.

Assessment against linked issues

Objective Addressed Explanation
Fix "select all" checkbox behavior with filter [#3366]
Ensure only filtered rules are deleted when selected

Possibly related PRs

  • refactor: fill in basic types in rules.ts #3365: The changes in this PR enhance type safety in the Rule class, which is directly related to the introduction of the RuleEntity type in the main PR, as both focus on improving type definitions for rules.

Suggested labels

:sparkles: Merged

Suggested reviewers

  • MikesGlitch

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.

@harrydigos
Copy link
Author

Would you also prefer to reset the filter after the deletion is complete?

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 (1)
packages/desktop-client/src/components/ManageRules.tsx (1)

203-210: Consider removing ts-ignore and improving type safety.

While the intersection logic is correct, there are opportunities to improve the type safety:

  1. The @ts-ignore comment seems unnecessary as Set operations are well-supported in TypeScript.
  2. Consider using type parameters for the Set to avoid type assertion.
- // @ts-ignore `intersection` is fully compatible with browser versions
- selectedInst.items.intersection(
-   new Set(filteredRules.map(r => r.id)),
- ) as Set<string>
+ const filteredIds = new Set<string>(filteredRules.map(r => r.id));
+ new Set([...selectedInst.items].filter(x => filteredIds.has(x)))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f5e5d4 and 521076f.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4224.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/ManageRules.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (4)
packages/desktop-client/src/components/ManageRules.tsx (4)

21-24: LGTM! Type imports improve type safety.

The addition of explicit type imports enhances type checking and code maintainability.


116-116: LGTM! Explicit state typing.

The explicit typing of allRules as RuleEntity[] improves type safety and code clarity.


Line range hint 212-228: LGTM! Robust delete handler implementation.

The delete handler correctly:

  • Uses the filtered set of rules
  • Handles errors gracefully with user feedback
  • Cleans up selection state

354-357: LGTM! Accurate UI feedback.

The delete button correctly reflects the number of rules that can actually be deleted, considering the applied filters.

@harrydigos harrydigos changed the title fix deleting rules considering the applied filters [WIP] fix deleting rules considering the applied filters Jan 23, 2025
@harrydigos harrydigos changed the title [WIP] fix deleting rules considering the applied filters fix deleting rules considering the applied filters Jan 23, 2025
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 (1)
packages/desktop-client/src/components/ManageRules.tsx (1)

Line range hint 210-226: Consider enhancing error feedback.

The implementation correctly uses rulesToDelete and handles the deletion process well. However, the error message could be more specific about which rules failed to delete.

Consider enhancing the error message to include the names or IDs of rules that couldn't be deleted:

-      alert(
-        t('Some rules were not deleted because they are linked to schedules'),
-      );
+      alert(
+        t('The following rules could not be deleted because they are linked to schedules: ') +
+        Array.from(rulesToDelete)
+          .filter(id => /* check which rules failed */)
+          .map(id => allRules.find(r => r.id === id)?.name || id)
+          .join(', ')
+      );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 521076f and 0664413.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/ManageRules.tsx (5 hunks)
🔇 Additional comments (5)
packages/desktop-client/src/components/ManageRules.tsx (5)

21-24: LGTM! Type safety improvement.

The addition of the RuleEntity type import enhances type safety and provides better type checking for rule entities.


116-116: LGTM! Proper type annotation for state.

The explicit type annotation RuleEntity[] for allRules state ensures type safety throughout the component.


203-208: LGTM! Core fix for rule deletion.

The rulesToDelete implementation correctly ensures that only rules visible in the current filter can be deleted. The use of Set for efficient lookups and proper memoization with correct dependencies makes this a robust solution.


352-355: LGTM! Accurate delete button state.

The delete button correctly reflects the number of rules that can be deleted based on the current filter.


203-208: Verify edge cases in rule deletion.

Let's verify the robustness of the rule deletion implementation.

Also applies to: 352-355

✅ Verification successful

Rule deletion implementation is robust and handles edge cases properly

The implementation correctly handles:

  • Filtered rule selection
  • Both single and batch deletions
  • Failed deletion scenarios
  • Loading states and concurrency
  • Type safety through proper interfaces
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential edge cases in rule deletion handling

# Test 1: Check for proper cleanup of rule references
echo "Checking for proper cleanup of rule references..."
rg -l "rule\." --type ts

# Test 2: Check for proper error handling patterns
echo "Checking for consistent error handling patterns in rule deletion..."
ast-grep --pattern 'await send("rule-delete", $_)'

# Test 3: Check for proper loading state management
echo "Checking for consistent loading state management..."
ast-grep --pattern 'setLoading($_)'

Length of output: 6000


Script:

#!/bin/bash
# Check rule deletion implementation and error handling

# Look for rule deletion implementation
echo "Checking rule deletion implementation..."
rg -A 5 "rule-delete" --type ts

# Look for error handling patterns around rule deletion
echo "Checking error handling patterns..."
rg -A 5 "catch.*rule.*delete" --type ts
rg -A 5 "try.*rule.*delete" --type ts

Length of output: 3697

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]: rules' "select all" checkbox doesn't know about the filter field
1 participant