Skip to content

Conversation

@tsl-ps2
Copy link
Collaborator

@tsl-ps2 tsl-ps2 commented Jan 10, 2025

Description

Acceptance Criteria

  • Given I am using the search bar to locate a chat room, when I type the complete name or a partial name of a chat room into the search bar, then the displayed list of chat rooms should dynamically update to show only those chat rooms whose names contain the entered text (case-insensitive match).

  • And if no matching chat rooms are found, an appropriate "No results found" message should be displayed.

  • It should filter the Chat List that is selected.

Current behavior
When I use the search bar in the Archive Chat list, is doesnt show chat rooms even tho they contain the entered text. It shows the empty state when no chat rooms were found.
This empty state persists even tho I clear the search bar.

https://www.loom.com/share/7e249f5eb0ab4814a7c3544302b1f047

Approvd
https://app.approvd.io/silverlogic/BA/stories/38023

Summary by CodeRabbit

  • New Features

    • Enhanced search functionality in chat rooms list
    • Improved search context awareness across different tabs
    • Persistent search term when switching between tabs
  • Bug Fixes

    • Resolved search input rendering issues during tab changes
    • Fixed chatroom search functionality in the latest version update (0.0.48)

@changeset-bot
Copy link

changeset-bot bot commented Jan 10, 2025

⚠️ No Changeset found

Latest commit: 7b84de8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2025

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.

packages/components/modules/messages/ChatRoomsList/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /packages/components/.eslintrc.js
Error: Cannot find module '@baseapp-frontend/config/.eslintrc.js'
Require stack:

  • /packages/components/.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/packages/components/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

Walkthrough

The pull request modifies the ChatRoomsList component to enhance its search functionality and improve chat room state management based on the selected tab. A new searchValue state variable is introduced to track the current search input, and the search handling functions are updated to include parameters that reflect the current tab state. This ensures that search results are contextually relevant and persist across tab switches. Additionally, the Searchbar component is configured to re-render appropriately when the tab changes.

Changes

File Change Summary
packages/components/modules/messages/ChatRoomsList/index.tsx - Added searchValue state variable
- Updated handleSearchChange and handleSearchClear functions to include tab-based parameters
- Modified handleChange to utilize searchValue for data refetching across tabs
- Assigned dynamic key prop to Searchbar for re-rendering based on tab changes
packages/components/CHANGELOG.md - Added new version entry ## 0.0.48
- Included patch change entry - Chatroom search fixed
packages/components/package.json - Updated version from 0.0.47 to 0.0.48

Possibly related PRs

  • BA-1882: update unread mechanism #146: The changes in the ChatRoomsList/index.tsx file involve enhancements to the chat room's message count and subscription handling, which are related to the search functionality and state management improvements in the main PR.
  • BA-1934 [FE packages] Mark Chat as Unread #158: This PR introduces functionality for marking chats as unread, which is closely related to the main PR's focus on improving chat room state handling and user interactions.
  • BA-1964: update unread badge and divider behavior #159: The modifications to the ChatRoom component regarding unread message handling align with the main PR's updates to chat room state management and search functionality.

Suggested reviewers

  • Ronan-Fernandes
  • anicioalexandre
  • pt-tsl

Poem

🐰 Searching rooms with rabbit's might,
Tabs and searches now shine bright!
Unread, archived - context clear,
Search persists without a fear.
CodeRabbit's magic takes its flight! 🔍


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39c5f43a35699657c1c8a153d622e1fc324bab41 and 7b84de8.

📒 Files selected for processing (3)
  • packages/components/CHANGELOG.md (1 hunks)
  • packages/components/modules/messages/ChatRoomsList/index.tsx (3 hunks)
  • packages/components/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/components/package.json
  • packages/components/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/modules/messages/ChatRoomsList/index.tsx

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

@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 (2)
packages/components/modules/messages/ChatRoomsList/index.tsx (2)

48-52: Consider extracting common refetch parameters.

The refetch parameters are duplicated between handleSearchChange and handleSearchClear. Consider extracting them into a helper function to improve maintainability.

+const getRefetchParams = (searchText: string) => ({
+  q: searchText,
+  unreadMessages: isInUnreadTab,
+  archived: isInArchivedTab,
+})

 const handleSearchChange: ChangeEventHandler<HTMLInputElement> = (e) => {
   const value = e.target.value || ''
   startTransition(() => {
-    refetch({
-      q: value,
-      unreadMessages: isInUnreadTab,
-      archived: isInArchivedTab,
-    })
+    refetch(getRefetchParams(value))
   })
 }

 const handleSearchClear = () => {
   startTransition(() => {
     reset()
-    refetch({
-      q: '',
-      unreadMessages: isInUnreadTab,
-      archived: isInArchivedTab,
-    })
+    refetch(getRefetchParams(''))
   })
 }

Also applies to: 59-63


168-172: Consider lifting debounce state up instead of using key prop.

While using the key prop works as a workaround for the debounce issue, it forces a complete remount of the Searchbar component on every tab change. This might impact performance and cause unnecessary re-renders.

A more robust solution would be to lift the debounce state up to the parent component or use a ref that's updated when the tab changes.

Example approach:

// Option 1: Lift debounce up
const debouncedSearch = useCallback(
  debounce((value: string, tab: ChatTabValues) => {
    refetch({
      q: value,
      unreadMessages: tab === CHAT_TAB_VALUES.unread,
      archived: tab === CHAT_TAB_VALUES.archived,
    })
  }, 300),
  []
)

// Option 2: Update ref on tab change
const searchConfigRef = useRef({ tab })
useEffect(() => {
  searchConfigRef.current = { tab }
}, [tab])
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6340985 and 39c5f43a35699657c1c8a153d622e1fc324bab41.

📒 Files selected for processing (1)
  • packages/components/modules/messages/ChatRoomsList/index.tsx (3 hunks)
🔇 Additional comments (3)
packages/components/modules/messages/ChatRoomsList/index.tsx (3)

43-43: LGTM! Good use of form state tracking.

The addition of searchValue using watch('search') is a clean way to track the search input state and enables persistence across tab changes.


Line range hint 72-76: LGTM! Good implementation of search persistence across tabs.

The inclusion of searchValue in the tab change handler ensures that search context is maintained when switching tabs, which directly addresses the reported issue.


Line range hint 43-172: Verify that these changes fix the reported search issues.

The implementation looks solid and should address the reported issues with search functionality in the Archive Chat list. Please verify:

  1. Search works correctly in all tabs (Active, Unread, Archived)
  2. Search persists when switching between tabs
  3. "No results found" state appears and clears correctly
  4. The search is case-insensitive

Let's verify the search functionality implementation:

✅ Verification successful

Search functionality implementation verified

The implementation correctly handles:

  • Search state persistence across tab switches
  • Consistent search behavior in all tabs (Active, Unread, Archived)
  • Proper loading states and transitions
  • Search clearing and reset functionality

The code structure ensures that the search value is maintained and properly synchronized during all operations, which should resolve the reported issues with search functionality in the Archive Chat list.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify search-related code implementation

# Check if the search functionality is consistently implemented across all tabs
echo "Checking search implementation consistency..."
rg -A 2 "refetch\(" packages/components/modules/messages/ChatRoomsList/

# Verify case-insensitive search implementation
echo "Checking case-sensitivity handling..."
ast-grep --pattern 'q: $value' packages/components/modules/messages/ChatRoomsList/

Length of output: 1093


Script:

#!/bin/bash
# Check GraphQL query and form state implementation

# Find GraphQL query definition
echo "Checking GraphQL query..."
rg -B 2 -A 5 "chatRooms\(" packages/components/modules/messages/ChatRoomsList/

# Check form state management
echo "Checking form state management..."
rg -B 2 "useForm|watch\(" packages/components/modules/messages/ChatRoomsList/

Length of output: 1260

@tsl-ps2 tsl-ps2 force-pushed the BA-2070-fix-chatroom-search-frontend branch from 39c5f43 to 7b84de8 Compare January 15, 2025 09:35
@sonarqubecloud
Copy link

@tsl-ps2 tsl-ps2 merged commit 1b42a21 into master Jan 15, 2025
8 of 9 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Feb 7, 2025
@nossila nossila deleted the BA-2070-fix-chatroom-search-frontend branch May 26, 2025 21:18
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.

4 participants