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] Fix and Improve Total Value Filter on Accounting Screen #8759

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

samuelmbabhazi
Copy link
Contributor

@samuelmbabhazi samuelmbabhazi commented Feb 4, 2025

PR

Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.


Summary by CodeRabbit

  • New Features

    • Introduced a new range-based filter on the Invoices Received page enabling users to filter invoices by specifying minimum and maximum total values.
    • Enhanced invoice pagination to support detailed range filtering for more precise invoice retrieval.
  • Refactor

    • Updated the filtering logic throughout the invoice management system to seamlessly integrate the new range-based search functionality.

@samuelmbabhazi samuelmbabhazi self-assigned this Feb 4, 2025
Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

This PR replaces a single value input filter with a range filter for the totalValue column on the invoices page. A new RangeFilterComponent is introduced and integrated into the smart table settings, with modifications to the filtering logic to accept a range object (min and max). The backend has been updated in the invoice service’s pagination method to process these range filters, while the invoice controller has been adjusted by removing a decorator. Additionally, associated module exports and declarations have been updated to include the new component.

Changes

File(s) Change Summary
apps/gauzy/src/app/pages/invoices/invoices-received/invoices-received.component.ts Replaced InputFilterComponent with RangeFilterComponent and updated the filter function to accept an object with min and max properties.
packages/core/src/lib/invoice/invoice.controller.ts
packages/core/src/lib/invoice/invoice.service.ts
Removed the @UseValidationPipe({ transform: true }) decorator from the pagination method (controller) and enhanced the pagination logic (service) to support range-based totalValue filtering using Between, MoreThanOrEqual, and LessThanOrEqual conditions.
packages/ui-core/shared/src/lib/table-filters/index.ts
packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts
packages/ui-core/shared/src/lib/table-filters/table-filters.module.ts
Added a new RangeFilterComponent export, updated its module declaration, and repositioned export statements to integrate the range filter into the table filters module.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RFilter as RangeFilterComponent
    participant InvComp as InvoicesReceivedComponent
    participant InvService as InvoiceService
    participant DB as Database

    User->>RFilter: Enter min/max values
    RFilter->>InvComp: Emit updated range filter event
    InvComp->>InvService: Call pagination with range filter {min, max}
    InvService->>DB: Query invoices with range conditions
    DB-->>InvService: Return filtered invoices
    InvService-->>InvComp: Send filtered results
    InvComp-->>User: Render updated invoice list
Loading

Possibly related issues

Suggested reviewers

  • rahul-rocket

Poem

I'm a rabbit in the code, hopping with delight,
With range filters in place, everything's looking right.
Min and max values, side by side they play,
Filtering invoices in a clever new way.
A carrot crunch for each bug set free,
CodeRabbit cheers – now jump with me!
🥕🐇 Happy filtering!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

nx-cloud bot commented Feb 4, 2025

View your CI Pipeline Execution ↗ for commit 9529748.

Command Status Duration Result
nx build api -c=production --prod ✅ Succeeded 1m 9s View ↗
nx build desktop-ui-lib --configuration=develop... ✅ Succeeded 30s View ↗
nx build desktop-ui-lib --configuration=production ✅ Succeeded 29s View ↗
nx build plugin-integration-wakatime ✅ Succeeded 4s View ↗
nx build desktop-lib ✅ Succeeded <1s View ↗
nx build desktop-window ✅ Succeeded <1s View ↗
nx build desktop-core ✅ Succeeded <1s View ↗
nx build plugin-videos ✅ Succeeded 5s View ↗
Additional runs (51) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-06 09:41:58 UTC

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 (5)
packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts (3)

48-48: Remove empty lifecycle hook.

The ngOnChanges method is empty and unused. Remove it to improve code maintainability.

-  ngOnChanges(changes: SimpleChanges) {}

29-31: Remove unnecessary constructor.

The constructor only calls super() and doesn't perform any other initialization.

-  constructor() {
-    super();
-  }
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-31: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)


10-19: Enhance template accessibility.

Add ARIA labels and role attributes to improve accessibility.

   <div class="d-flex">
     <input
       [formControl]="rangeControl.controls.min"
       class="form-control me-2"
       placeholder="Min"
       type="number"
+      aria-label="Minimum value"
     />
-    <span>-</span>
+    <span aria-hidden="true">-</span>
     <input
       [formControl]="rangeControl.controls.max"
       class="form-control"
       placeholder="Max"
       type="number"
+      aria-label="Maximum value"
     />
   </div>
packages/core/src/lib/invoice/invoice.service.ts (1)

304-314: Add type safety and validation for range values.

While the implementation is correct, consider these improvements:

  1. Add type safety for the filter parameters
  2. Validate that min is not greater than max when both are provided
-      if ('totalValue' in where) {
-        const { min, max } = where.totalValue;
+      if ('totalValue' in where && where.totalValue) {
+        const { min, max } = where.totalValue as { min?: number; max?: number };
+
+        if (min !== undefined && max !== undefined && min > max) {
+          throw new BadRequestException('Minimum value cannot be greater than maximum value');
+        }

         if (min !== undefined && max !== undefined) {
           filter.where.totalValue = Between(min, max);
         } else if (min !== undefined) {
           filter.where.totalValue = MoreThanOrEqual(min);
         } else if (max !== undefined) {
           filter.where.totalValue = LessThanOrEqual(max);
         }
       }
apps/gauzy/src/app/pages/invoices/invoices-received/invoices-received.component.ts (1)

389-396: Add type safety and validation to the range filter.

While the range filter implementation is good, it could benefit from additional type safety and validation.

Consider applying these improvements:

-filterFunction: (range) => {
-  const { min, max } = range;
-  this.setFilter({
-    field: 'totalValue',
-    search: { min, max }
-  });
+filterFunction: (range: { min?: number; max?: number }) => {
+  const { min, max } = range;
+  // Validate range values
+  if ((min !== undefined && min < 0) || (max !== undefined && max < 0)) {
+    console.warn('Invalid range values: Values cannot be negative');
+    return;
+  }
+  if (min !== undefined && max !== undefined && min > max) {
+    console.warn('Invalid range values: Minimum value cannot be greater than maximum value');
+    return;
+  }
+  this.setFilter({
+    field: 'totalValue',
+    search: { min, max }
+  });
},
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0e05c2 and 9529748.

📒 Files selected for processing (6)
  • apps/gauzy/src/app/pages/invoices/invoices-received/invoices-received.component.ts (3 hunks)
  • packages/core/src/lib/invoice/invoice.controller.ts (0 hunks)
  • packages/core/src/lib/invoice/invoice.service.ts (2 hunks)
  • packages/ui-core/shared/src/lib/table-filters/index.ts (1 hunks)
  • packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts (1 hunks)
  • packages/ui-core/shared/src/lib/table-filters/table-filters.module.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/lib/invoice/invoice.controller.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts

[error] 29-31: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (4)
packages/ui-core/shared/src/lib/table-filters/index.ts (1)

6-7: LGTM!

The new export follows the existing pattern and maintains consistency with other exports.

packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts (1)

33-46: LGTM on subscription handling!

The subscription cleanup in ngOnDestroy is properly implemented, preventing memory leaks. The use of RxJS operators (debounceTime, distinctUntilChanged) is also a good practice for optimizing filter updates.

packages/ui-core/shared/src/lib/table-filters/table-filters.module.ts (1)

22-22: LGTM!

The RangeFilterComponent is properly imported and declared in the module.

Also applies to: 46-46

apps/gauzy/src/app/pages/invoices/invoices-received/invoices-received.component.ts (1)

36-36: LGTM!

Clean import of the RangeFilterComponent within the existing imports block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Fix and Improve Total Value Filter on Accounting Screen
1 participant