Skip to content

Comments

[WEB-2758] Fix intake status count#5990

Merged
pushya22 merged 2 commits intopreviewfrom
fix-intake-status-count
Nov 13, 2024
Merged

[WEB-2758] Fix intake status count#5990
pushya22 merged 2 commits intopreviewfrom
fix-intake-status-count

Conversation

@gakshita
Copy link
Collaborator

@gakshita gakshita commented Nov 12, 2024

Summary

This PR fixes the total count in intake header based on the status filters

[WEB-2758]

Summary by CodeRabbit

  • New Features

    • Improved filtering of inbox issues by adjusting the status handling in the inbox query.
  • Bug Fixes

    • Resolved potential issues with the inclusion of snoozed status in inbox issue filtering.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The pull request modifies the ProjectInboxStore class in the web/core/store/inbox/project-inbox.store.ts file. The primary change is in the fetchInboxIssues method, where the handling of the status variable is updated. Instead of combining the existing inboxFilters?.status with EInboxIssueStatus.SNOOZED, the new implementation directly assigns this.inboxFilters?.status to status. This change affects the query parameters sent to the inboxIssueService.list method, altering the filtering of inbox issues based on status.

Changes

File Path Change Summary
web/core/store/inbox/project-inbox.store.ts Modified fetchInboxIssues method to directly assign this.inboxFilters?.status to status, removing EInboxIssueStatus.SNOOZED.

Possibly related PRs

  • [WEB-1671] fix: expired snooze issues fixed #5270: This PR modifies the ProjectInboxStore class, enhancing the filtering logic for inbox issues based on their statuses, which is directly related to the changes made in the main PR regarding the handling of the status variable in the same class.
  • fix: intake loading #5966: This PR also involves changes to the ProjectInboxStore, specifically in the regenerateIntakeForms method, which is relevant as it pertains to the management of intake forms within the same store class.

Suggested labels

🐛bug, ⚙️backend

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham

🐰 In the inbox where issues play,
A change was made to clear the way.
No snoozed status to combine,
Just filters neat, all in a line.
Now queries flow, so swift and bright,
A hop towards clarity, a joyful sight! 🐇✨


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

🧹 Outside diff range and nitpick comments (1)
web/core/store/inbox/project-inbox.store.ts (1)

Line range hint 142-166: Consider refactoring the status filtering logic for better maintainability

The status filtering logic in the filteredInboxIssueIds getter is complex and mixes multiple concerns. Consider splitting it into smaller, more focused functions.

Here's a suggested refactor:

- get filteredInboxIssueIds() {
-   let appliedFilters =
-     this.currentTab === EInboxIssueCurrentTab.OPEN
-       ? [EInboxIssueStatus.PENDING, EInboxIssueStatus.SNOOZED]
-       : [EInboxIssueStatus.ACCEPTED, EInboxIssueStatus.DECLINED, EInboxIssueStatus.DUPLICATE];
-   appliedFilters = appliedFilters.filter((filter) => this.inboxFilters?.status?.includes(filter));
-   const currentTime = new Date().getTime();
-
-   return this.currentTab === EInboxIssueCurrentTab.OPEN
-     ? this.inboxIssueIds.filter((id) => {
-         if (appliedFilters.length == 2) return true;
-         if (appliedFilters[0] === EInboxIssueStatus.SNOOZED)
-           return (
-             this.inboxIssues[id].status === EInboxIssueStatus.SNOOZED &&
-             currentTime < new Date(this.inboxIssues[id].snoozed_till!).getTime()
-           );
-         if (appliedFilters[0] === EInboxIssueStatus.PENDING)
-           return (
-             appliedFilters.includes(this.inboxIssues[id].status) ||
-             (this.inboxIssues[id].status === EInboxIssueStatus.SNOOZED &&
-               currentTime > new Date(this.inboxIssues[id].snoozed_till!).getTime())
-           );
-       })
-     : this.inboxIssueIds.filter((id) => appliedFilters.includes(this.inboxIssues[id].status));
+ private isSnoozeExpired(snoozedTill: string): boolean {
+   return new Date().getTime() > new Date(snoozedTill).getTime();
+ }
+
+ private getDefaultStatusFilters(): EInboxIssueStatus[] {
+   return this.currentTab === EInboxIssueCurrentTab.OPEN
+     ? [EInboxIssueStatus.PENDING, EInboxIssueStatus.SNOOZED]
+     : [EInboxIssueStatus.ACCEPTED, EInboxIssueStatus.DECLINED, EInboxIssueStatus.DUPLICATE];
+ }
+
+ private filterIssueByStatus(id: string, appliedFilters: EInboxIssueStatus[]): boolean {
+   const issue = this.inboxIssues[id];
+   
+   if (this.currentTab !== EInboxIssueCurrentTab.OPEN) {
+     return appliedFilters.includes(issue.status);
+   }
+   
+   if (appliedFilters.length === 2) return true;
+   
+   if (appliedFilters[0] === EInboxIssueStatus.SNOOZED) {
+     return (
+       issue.status === EInboxIssueStatus.SNOOZED &&
+       !this.isSnoozeExpired(issue.snoozed_till!)
+     );
+   }
+   
+   if (appliedFilters[0] === EInboxIssueStatus.PENDING) {
+     return (
+       appliedFilters.includes(issue.status) ||
+       (issue.status === EInboxIssueStatus.SNOOZED &&
+         this.isSnoozeExpired(issue.snoozed_till!))
+     );
+   }
+   
+   return false;
+ }
+
+ get filteredInboxIssueIds() {
+   const defaultFilters = this.getDefaultStatusFilters();
+   const appliedFilters = defaultFilters.filter(
+     (filter) => this.inboxFilters?.status?.includes(filter)
+   );
+   
+   return this.inboxIssueIds.filter((id) =>
+     this.filterIssueByStatus(id, appliedFilters)
+   );
}

This refactor:

  1. Splits the logic into smaller, focused functions
  2. Makes the code more readable and maintainable
  3. Makes it easier to test individual pieces of logic
  4. Improves reusability of the status filtering logic
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 106710f and e2251ce.

📒 Files selected for processing (1)
  • web/core/store/inbox/project-inbox.store.ts (1 hunks)
🔇 Additional comments (1)
web/core/store/inbox/project-inbox.store.ts (1)

391-391: LGTM! This change correctly fixes the intake status count.

The modification ensures that only explicitly selected status filters are used in the API query, which will accurately reflect the status filters applied in the intake header.

Let's verify the status filtering logic:

✅ Verification successful

Based on the results from the shell scripts, I can now generate the final response as we have sufficient evidence about the status filtering implementation:

The status filtering change is correct and safe.

The search results confirm that:

  • The status filtering logic in filteredInboxIssueIds properly handles both PENDING and SNOOZED states with appropriate time-based conditions
  • The direct use of inboxFilters?.status in the API query is consistent with the UI filter implementation in inbox-filter components
  • No other parts of the codebase combine status with SNOOZED in a way that would be affected by this change
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the status filtering implementation across the codebase
# Expected results: No instances of combining status with SNOOZED outside of filteredInboxIssueIds

# Check for any other instances where status might be combined with SNOOZED
rg -A 5 "status.*SNOOZED" --type ts

# Check the complete status filtering implementation
ast-grep --pattern 'status = $status' --type ts

Length of output: 2000


Script:

#!/bin/bash
# Let's try a different pattern to check status assignments and filtering logic

# Check for status filtering in the inbox store
rg -A 10 "inboxFilters\?\.status" --type ts

# Check for status-related filtering logic
ast-grep --pattern 'status: $status'

# Check for any direct status assignments
ast-grep --pattern 'status = $_'

Length of output: 8258

@pushya22 pushya22 merged commit 8c3189e into preview Nov 13, 2024
@pushya22 pushya22 deleted the fix-intake-status-count branch November 13, 2024 10:08
@coderabbitai coderabbitai bot mentioned this pull request Dec 11, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants