Skip to content

fix(chat): clear selection after resolving selected conversation (EVO-1053)#53

Merged
marcelogorutuba merged 1 commit into
developfrom
fix/EVO-1053
May 14, 2026
Merged

fix(chat): clear selection after resolving selected conversation (EVO-1053)#53
marcelogorutuba merged 1 commit into
developfrom
fix/EVO-1053

Conversation

@marcelogorutuba
Copy link
Copy Markdown
Member

@marcelogorutuba marcelogorutuba commented May 11, 2026

Summary

When the operator resolves the currently-selected conversation, the frontend now clears the selection and navigates back to /conversations, allowing the active filter to naturally exclude the resolved item from the list.

Root Cause

handleMarkAsResolved in Chat.tsx was updating conversation status without clearing the router selection, so the resolved conversation stayed pinned in the list regardless of the active filter.

Changes

  • After a successful resolve, checks if the resolved conversation is the one currently open in the URL (conversationId from useParams)
  • If so: clears context selection, sets mobile view to list, and navigates to /conversations (same flow as handleCloseConversation)
  • Resolving a non-selected conversation (sidebar quick action) is unaffected

Validation

  • pnpm exec tsc -b --noEmit — passed
  • pnpm exec eslint src/pages/Customer/Chat/Chat.tsx — passed

Linked Issue

  • EVO-1053

Summary by Sourcery

Ensure the chat view deselects and navigates away from a conversation when that conversation is resolved.

Bug Fixes:

  • Clear the currently selected conversation and return to the conversations list when resolving the active conversation so it no longer appears pinned despite filters.

Enhancements:

  • Align the post-resolve navigation and mobile view behavior with the existing close-conversation flow for a more consistent UX.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 11, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates Chat conversation resolution handling so that resolving the currently selected conversation clears the selection and navigates back to the conversations list, aligning behavior with closing a conversation and ensuring filters naturally hide resolved items.

Sequence diagram for resolving a selected conversation in Chat

sequenceDiagram
  actor Operator
  participant Chat
  participant ConversationHandlers
  participant Conversations
  participant Router

  Operator->>Chat: handleMarkAsResolved(conversation)
  Chat->>ConversationHandlers: handleMarkAsResolved(conversation, reloadCurrentFilters)
  ConversationHandlers-->>Chat: resolve_completed
  alt [isCurrentlySelected or selectedConversationId equals resolvedId]
    Chat->>Conversations: selectConversation(null)
    Chat->>Chat: setMobileView(list)
    Chat->>Chat: setIsContactSidebarOpen(false)
    Chat->>Router: navigate(/conversations, replace=true)
  end
Loading

File-Level Changes

Change Details Files
Update handleMarkAsResolved to detect when the resolved conversation is currently selected and then clear selection and navigate back to the conversations list.
  • Compute a stable resolved conversation ID string from uuid or id.
  • Determine if the resolved conversation matches the conversationId from the route parameters.
  • After resolving, if the resolved conversation is currently selected or matches the selectedConversationId in state, mark navigation as manual, clear the selected conversation, switch mobile view to list, close the contact sidebar, and navigate to /conversations with replace semantics, then reset the manual navigation flag with a short timeout.
  • Extend the handleMarkAsResolved useCallback dependency array to include routing, selection, and layout-related dependencies.
src/pages/Customer/Chat/Chat.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The handleMarkAsResolved logic for determining the resolved conversation (resolvedId, isCurrentlySelected, and the selectedConversationId comparison) duplicates string coercion and id/uuid checks; consider centralizing this into a small helper or reusing resolvedId to make the selection matching logic easier to follow and less error-prone.
  • The navigation/cleanup sequence inside handleMarkAsResolved duplicates the flow in handleCloseConversation; extracting this into a shared helper would reduce duplication and ensure both paths stay behaviorally aligned if you tweak the close behavior later.
  • The setTimeout with a hard-coded 100 delay for resetting isManualNavigationRef is a bit of a magic number; consider documenting why this value is sufficient or deriving it from a shared constant so future maintainers understand the timing requirement.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `handleMarkAsResolved` logic for determining the resolved conversation (`resolvedId`, `isCurrentlySelected`, and the `selectedConversationId` comparison) duplicates string coercion and id/uuid checks; consider centralizing this into a small helper or reusing `resolvedId` to make the selection matching logic easier to follow and less error-prone.
- The navigation/cleanup sequence inside `handleMarkAsResolved` duplicates the flow in `handleCloseConversation`; extracting this into a shared helper would reduce duplication and ensure both paths stay behaviorally aligned if you tweak the close behavior later.
- The `setTimeout` with a hard-coded `100` delay for resetting `isManualNavigationRef` is a bit of a magic number; consider documenting why this value is sufficient or deriving it from a shared constant so future maintainers understand the timing requirement.

## Individual Comments

### Comment 1
<location path="src/pages/Customer/Chat/Chat.tsx" line_range="392-393" />
<code_context>
+        conversations.selectConversation(null);
+        setMobileView('list');
+        setIsContactSidebarOpen(false);
+        navigate('/conversations', { replace: true });
+        setTimeout(() => {
+          isManualNavigationRef.current = false;
+        }, 100);
</code_context>
<issue_to_address>
**issue (bug_risk):** Using a fixed 100ms timeout to reset `isManualNavigationRef` may be brittle and race-prone.

This relies on navigation completing within 100ms, which can easily be wrong on slow devices or under load, and may also clear the flag sooner than needed on fast paths. Where possible, reset `isManualNavigationRef` based on a concrete event (e.g., route-change callback or an effect tied to the relevant state) rather than a fixed delay.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/pages/Customer/Chat/Chat.tsx Outdated
Comment on lines +392 to +393
navigate('/conversations', { replace: true });
setTimeout(() => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Using a fixed 100ms timeout to reset isManualNavigationRef may be brittle and race-prone.

This relies on navigation completing within 100ms, which can easily be wrong on slow devices or under load, and may also clear the flag sooner than needed on fast paths. Where possible, reset isManualNavigationRef based on a concrete event (e.g., route-change callback or an effect tied to the relevant state) rather than a fixed delay.

…ction, and tests (EVO-1053)

- Re-throw in useConversationHandlers.handleMarkAsResolved so callers can gate navigation on success
- Remove stale conversationId closure; use live selectedConversationId after await (H1+M1)
- Extract clearSelectionAndGoToList helper; used in handleMarkAsResolved, confirmDeleteConversation, handleCloseConversation (L2+L3)
- Await selectConversation(null) inside helper (L2)
- Add Vitest tests: hook re-throw behavior + Chat component selected/non-selected/error scenarios (M2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marcelogorutuba marcelogorutuba merged commit f99864e into develop May 14, 2026
1 check passed
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.

1 participant