Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(sales): Added stageChanged date range fixed enddate bug and fixed infinite loading totalcount - #8294

#8294
Merged
munkhsaikhan merged 2 commits into
mainerxes/erxes:mainfrom
feature/deals-filters-and-counterxes/erxes:feature/deals-filters-and-countCopy head branch name to clipboard
Jun 24, 2026
Merged

feat(sales): Added stageChanged date range fixed enddate bug and fixed infinite loading totalcount#8294
munkhsaikhan merged 2 commits into
mainerxes/erxes:mainfrom
feature/deals-filters-and-counterxes/erxes:feature/deals-filters-and-countCopy head branch name to clipboard

Conversation

@Zolb646

@Zolb646 Zolb646 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features
    • Added Close date and Stage changed date as new deal date filters, replacing the previous End date option.
  • Bug Fixes
    • Improved deal count accuracy and synchronization across board views, including more consistent handling of total counts as data loads and subscriptions update.
  • Refactor
    • Updated deal query filter parameters to support the new close/stage-changed date ranges end-to-end.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @Zolb646, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c5923bd-1f5c-4fd8-8f67-931d233b3917

📥 Commits

Reviewing files that changed from the base of the PR and between bc943aa and 6c12ad7.

📒 Files selected for processing (4)
  • frontend/plugins/sales_ui/src/modules/deals/boards/components/DealsBoardColumn.tsx
  • frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx
  • frontend/plugins/sales_ui/src/modules/deals/graphql/queries/DealsQueries.ts
  • frontend/plugins/sales_ui/src/modules/deals/utils/queryVariables.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/plugins/sales_ui/src/modules/deals/utils/queryVariables.ts
  • frontend/plugins/sales_ui/src/modules/deals/boards/components/DealsBoardColumn.tsx
  • frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx

📝 Walkthrough

Walkthrough

The PR replaces the single "End date" sales filter with two dedicated date filters—"Close date" and "Stage changed"—wiring them through the type, constants, query variable parsing, and all UI layers. It also introduces Jotai-backed deal count tracking: per-column counts are written by DealsBoardColumn into dealCountByBoardAtom, aggregated by DealsBoard into dealTotalCountAtom, and independently managed by useDeals for the list view.

Changes

New Close Date and Stage Changed Date Filters

Layer / File(s) Summary
Type, constants, query variables, and GraphQL definitions
actionBar/types/actionBarTypes.ts, actionBar/constants/Filters.ts, utils/queryVariables.ts, graphql/queries/DealsQueries.ts
SalesFilterState adds four optional nullable date fields; ActionBarFilters replaces startDateEndDate with closeDateStartDate and stageChangedStartDate entries; DATE_RANGE_MAP and DATE_UPPER_BOUND_KEYS are extended to parse the new date keys into ISO bounds; GraphQL commonParams and commonParamDefs are updated with variable definitions for stage changed, start date, and close date ranges.
SalesFilter UI wiring
actionBar/components/SalesFilter.tsx
useMultiQueryState is extended with the four new keys; Filter.View entries, SalesFilterBar items, command list entries, and Filter.DateView components are all updated to replace "End date" with "Close date" and "Stage changed" controls; bar layout is repositioned.

Jotai Deal Count Tracking

Layer / File(s) Summary
Per-column count writes in DealsBoardColumn
boards/components/DealsBoardColumn.tsx
Imports dealCountByBoardAtom and useSetAtom; clears the column's entry on query variable change; writes totalCount or deals.length after loading; deletes the entry on unmount.
Board-level aggregation in DealsBoard
boards/components/DealsBoard.tsx
Reads dealCountByBoardAtom, sums per-column counts into dealTotalCountAtom (null when loading or counts are incomplete), resets atom on unmount, and expands the board-reset effect's dependency array.
List view total count in useDeals
cards/hooks/useDeals.tsx
Adds dealsViewAtom and dealTotalCountAtom wiring; decrements totalCount on subscription remove events; writes dealTotalCountAtom from query count or deals.length in list view, with null resets on loading and cleanup.

Possibly Related PRs

  • erxes/erxes#7814: Modifies the same queryVariables.ts file, updating DATE_RANGE_MAP/DATE_UPPER_BOUND_KEYS for existing created*/startDate* fields—the same mechanism this PR extends for closeDate*/stageChanged*.
  • erxes/erxes#7847: Adds backend generateFilter support for closeDate range queries using $gte/$lte, directly corresponding to the closeDateStartDate/closeDateEndDate fields wired in this PR.
  • erxes/erxes#7961: Fixes Filter.DateView query state clearing behavior—directly relevant to the new Filter.DateView instances added for close date and stage changed date in this PR.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop hop, the dates have changed today,
Close date and stage changed lead the way!
Old "End date" gone, two new fields appear,
Jotai counts the deals far and near.
The board totals up each column's score —
This bunny's filter dance adds so much more! 🗓️

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title mentions adding stageChanged date range and fixing bugs, but is grammatically awkward and lacks clarity about the main changes (added closeDate filter, fixed subscription logic, and deal count management via Jotai atoms). Consider revising to: 'feat(sales): Add stageChanged and closeDate filters, fix subscription totalCount updates, and manage deal counts with Jotai' for better clarity and completeness.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/deals-filters-and-count

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx (1)

147-160: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

totalCount can drift from the actual list during subscription updates.

totalCount is adjusted only by action, even when updatedList did not change (duplicate add / missing remove), and arithmetic can run on an undefined prior count. This can produce incorrect totals (including negative/invalid values).

Proposed fix
         return {
           ...prev,
           deals: {
             ...prev.deals,
             list: updatedList,
             pageInfo: prev.deals.pageInfo,
-            totalCount:
-              action === 'add'
-                ? prev.deals.totalCount + 1
-                : action === 'remove'
-                ? prev.deals.totalCount - 1
-                : prev.deals.totalCount,
+            totalCount: Math.max(
+              0,
+              (prev.deals.totalCount ?? currentList.length) +
+                (updatedList.length - currentList.length),
+            ),
           },
         };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx` around
lines 147 - 160, The totalCount calculation in the state updater function uses
arithmetic based on the action type, which can cause drift from the actual list
size when there are duplicate operations or when prior count is undefined.
Instead of incrementing or decrementing totalCount based on the action, replace
the conditional arithmetic logic with a direct assignment that sets totalCount
to the length of updatedList. This ensures the count always reflects the actual
size of the list being managed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/plugins/sales_ui/src/modules/deals/utils/queryVariables.ts`:
- Around line 19-24: The DATE_UPPER_BOUND_KEYS set contains an incorrect key
name mismatch. On line 23, the entry is `stateChangedEndDate`, but the actual
filter state and query keys use `stageChangedEndDate` (note the difference:
"stage" vs "state"). This mismatch causes resolveParam to not recognize the
upper-bound key when it should, leading to incorrect variable key forwarding to
the backend. In the DATE_UPPER_BOUND_KEYS set definition, change the
`stateChangedEndDate` entry to `stageChangedEndDate` to match the actual filter
state keys used throughout the application.

---

Outside diff comments:
In `@frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx`:
- Around line 147-160: The totalCount calculation in the state updater function
uses arithmetic based on the action type, which can cause drift from the actual
list size when there are duplicate operations or when prior count is undefined.
Instead of incrementing or decrementing totalCount based on the action, replace
the conditional arithmetic logic with a direct assignment that sets totalCount
to the length of updatedList. This ensures the count always reflects the actual
size of the list being managed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6746e762-77e1-432a-840b-2512702c97eb

📥 Commits

Reviewing files that changed from the base of the PR and between 41bf465 and bc943aa.

📒 Files selected for processing (7)
  • frontend/plugins/sales_ui/src/modules/deals/actionBar/components/SalesFilter.tsx
  • frontend/plugins/sales_ui/src/modules/deals/actionBar/constants/Filters.ts
  • frontend/plugins/sales_ui/src/modules/deals/actionBar/types/actionBarTypes.ts
  • frontend/plugins/sales_ui/src/modules/deals/boards/components/DealsBoard.tsx
  • frontend/plugins/sales_ui/src/modules/deals/boards/components/DealsBoardColumn.tsx
  • frontend/plugins/sales_ui/src/modules/deals/cards/hooks/useDeals.tsx
  • frontend/plugins/sales_ui/src/modules/deals/utils/queryVariables.ts

Comment thread frontend/plugins/sales_ui/src/modules/deals/utils/queryVariables.ts
@Zolb646
Zolb646 force-pushed the feature/deals-filters-and-count branch from 6c12ad7 to 9bd6412 Compare June 24, 2026 06:56
@munkhsaikhan
munkhsaikhan merged commit eaac538 into main Jun 24, 2026
14 of 15 checks passed
@munkhsaikhan
munkhsaikhan deleted the feature/deals-filters-and-count branch June 24, 2026 07:13
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.