fix(chat): clear selection after resolving selected conversation (EVO-1053)#53
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 ChatsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
handleMarkAsResolvedlogic for determining the resolved conversation (resolvedId,isCurrentlySelected, and theselectedConversationIdcomparison) duplicates string coercion and id/uuid checks; consider centralizing this into a small helper or reusingresolvedIdto make the selection matching logic easier to follow and less error-prone. - The navigation/cleanup sequence inside
handleMarkAsResolvedduplicates the flow inhandleCloseConversation; extracting this into a shared helper would reduce duplication and ensure both paths stay behaviorally aligned if you tweak the close behavior later. - The
setTimeoutwith a hard-coded100delay for resettingisManualNavigationRefis 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| navigate('/conversations', { replace: true }); | ||
| setTimeout(() => { |
There was a problem hiding this comment.
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>
0bb3612 to
ca14dea
Compare
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
handleMarkAsResolvedinChat.tsxwas updating conversation status without clearing the router selection, so the resolved conversation stayed pinned in the list regardless of the active filter.Changes
conversationIdfromuseParams)/conversations(same flow ashandleCloseConversation)Validation
pnpm exec tsc -b --noEmit— passedpnpm exec eslint src/pages/Customer/Chat/Chat.tsx— passedLinked Issue
Summary by Sourcery
Ensure the chat view deselects and navigates away from a conversation when that conversation is resolved.
Bug Fixes:
Enhancements: