Skip to content

fix: pressist search state inbox #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025

Conversation

abdou6666
Copy link
Contributor

@abdou6666 abdou6666 commented Apr 2, 2025

Motivation

This PR ensures persistence of the search state in the inbox.

Fixes #782

Type of change:

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have performed a self-review of my own code

Summary by CodeRabbit

  • New Features

    • Enhanced conversation navigation now preserves your search context and URL parameters when switching views.
    • The search input experience is improved with dynamic synchronization to reflect the current URL state, offering a more intuitive interaction.
  • Chores

    • Updated system information to reflect the current year.

Copy link

coderabbitai bot commented Apr 4, 2025

Walkthrough

The changes update the routing and search functionality within the inbox. In the conversation component, the route navigation now uses an object with a pathname and a query—where the query is extracted using a new utility function. The search feature has been enhanced by modifying the useSearch hook to initialize and synchronize its state with the URL’s query parameters. Additionally, the Inbox component now consumes the updated hook, and a copyright year update has been introduced.

Changes

File/s Change Summary
frontend/.../inbox/components/ConversationsList.tsx Modified the onClick handler to invoke push with an object containing a pathname and a query (obtained via extractQueryParamsUrl).
frontend/.../inbox/index.tsx, frontend/.../hooks/useSearch.tsx Enhanced search functionality by integrating a searchText state that is initialized from and synchronized with the router’s query parameter; updated the hook’s onSearch to update state and URL; updated copyright information.
frontend/.../utils/URL.ts Added a new function extractQueryParamsUrl which uses the qs library to parse and stringify query parameters from a full URL; includes a comment noting a potential future refactor into a hook.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant S as Search Component
    participant H as useSearch Hook
    participant R as Router

    U->>S: Enter search text
    S->>H: Trigger onSearch event
    H->>H: Update searchText state
    H->>R: Debounced update of query parameters
    R-->>H: Reflect updated search query
    Note over H: useEffect syncs searchText with URL
Loading
sequenceDiagram
    participant U as User
    participant C as Conversation Component
    participant Q as extractQueryParamsUrl
    participant R as Router

    U->>C: Click on conversation
    C->>Q: Extract query parameters from current URL
    Q-->>C: Return query string
    C->>R: Call push({ pathname, query })
Loading

Assessment against linked issues

Objective Addressed Explanation
[#782] URL persist search query text from the inbox page

Poem

I'm a bouncy rabbit with a coding flair,
Hopping through routes with a careful care,
Extracting queries and syncing the state,
My inbox now knows its search text fate,
With hops and bytes, I celebrate this update! 🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 7368194 and 9700a08.

📒 Files selected for processing (1)
  • frontend/src/utils/URL.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/utils/URL.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: API-Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Frontend Tests

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 (1)
frontend/src/utils/URL.ts (1)

63-70: Consider handling invalid or malformed URLs.
If fullUrl is invalid, new URL(fullUrl) will throw. You might want to wrap this in a try-catch block to gracefully handle that scenario, especially if the function is used in contexts where fullUrl might be unknown or user-provided.

 export const extractQueryParamsUrl = (fullUrl: string): string => {
-  const extractedQueryParams = qs.parse(new URL(fullUrl).search, {
-    ignoreQueryPrefix: true,
-  });
-  return qs.stringify(extractedQueryParams);
+  try {
+    const extractedQueryParams = qs.parse(new URL(fullUrl).search, {
+      ignoreQueryPrefix: true,
+    });
+    return qs.stringify(extractedQueryParams);
+  } catch (error) {
+    // handle or log error, returning empty string or fallback
+    return "";
+  }
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd709ff and 7368194.

📒 Files selected for processing (4)
  • frontend/src/components/inbox/components/ConversationsList.tsx (2 hunks)
  • frontend/src/components/inbox/index.tsx (3 hunks)
  • frontend/src/hooks/useSearch.tsx (3 hunks)
  • frontend/src/utils/URL.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
frontend/src/components/inbox/components/ConversationsList.tsx (1)
frontend/src/utils/URL.ts (1)
  • extractQueryParamsUrl (64-70)
frontend/src/components/inbox/index.tsx (1)
frontend/src/hooks/useSearch.tsx (1)
  • useSearch (55-109)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Frontend Tests
  • GitHub Check: API-Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (10)
frontend/src/utils/URL.ts (1)

9-9: Good use of the qs library.
The import is straightforward and helps parse query strings reliably.

frontend/src/components/inbox/components/ConversationsList.tsx (2)

23-23: Import statement aligns well with usage.
No issues with the newly imported extractQueryParamsUrl function. This helps keep the query parsing logic centralized.


67-71:

❓ Verification inconclusive

Watch out for potential SSR contexts.
Using window.location.href may not work in server-side rendering contexts. If this component ever needs to render on the server, consider router.asPath or storing the query string in a more SSR-friendly manner.

Would you like to confirm if this code runs exclusively in the browser? If needed, we can investigate references to this component’s usage by searching the codebase:

If you discover it is server-rendered, you may need to insert guards or use Next.js router properties.


🏁 Script executed:

#!/bin/bash
# Searching for usage of SubscribersList component
fd SubscribersList.tsx --exec rg 'SubscribersList'

Length of output: 50


Manual Verification Required: Confirm Client-Only Usage for Query Extraction

The code in
frontend/src/components/inbox/components/ConversationsList.tsx (lines 67–71) currently uses window.location.href for extracting query parameters. However, our attempt to locate references to the corresponding subscriber component (via searching for “SubscribersList”) returned no output, which leaves some uncertainty about whether this code is strictly executed on the client side.

  • Action Needed: Please manually verify that ConversationsList (or any related components) is exclusively used in browser contexts.
  • If SSR Usage Is Possible: Consider replacing window.location.href with an SSR-safe alternative like router.asPath or introducing a safeguard to ensure the code executes only in the browser.
frontend/src/components/inbox/index.tsx (3)

2-2: License year updated.
No code concerns here.


29-29: Addition of searchText is consistent.
The extended destructuring from useSearch aligns with the usage pattern for controlling the search state.


51-51: Binding value={searchText} ensures the search box reflects the URL state.
This is a good enhancement for synchronizing the UI with query parameters.

frontend/src/hooks/useSearch.tsx (4)

2-2: License year update only.
No functional impact or concerns.


10-11: New imports are relevant to the router-based search feature.
These additions are appropriate for handling side effects and user input.


55-87: Enhanced synchronization with router query.
Initializing and syncing searchText with router.query.search is a solid approach, ensuring the UI remains in sync with the URL. The debounced updateQueryParams function helps prevent excessive router updates, which is beneficial for performance.


96-96: Returning searchText aids controlled components.
Exposing searchText makes the search logic reusable and consistent throughout the consumer components.

Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub left a comment

Choose a reason for hiding this comment

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

LGTM 🚀
image

@yassinedorbozgithub
Copy link
Collaborator

@coderabbitai Open a follow-up GitHub issue to address the flickering search results in the inbox page

Copy link

coderabbitai bot commented Apr 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@yassinedorbozgithub I've created a follow-up GitHub issue to address the flickering search results in the inbox page. The issue includes:

  • A description of the flickering problem
  • Context linking it to PR fix: pressist search state inbox #873 (this PR)
  • Expected behavior for smooth search results rendering
  • References to related PRs/issues
  • Assigned to you for tracking

Let me know if you'd like me to modify the issue with any additional details.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue about flickering search results in the inbox page
gh issue create \
  --title "Fix: Flickering search results in the inbox page" \
  --body "## Description

When searching in the inbox page, the search results flicker or momentarily disappear/reappear during the search process. This creates a poor user experience when filtering conversations.

## Context

This issue was identified as a follow-up to PR #873 (https://github.com/Hexastack/Hexabot/pull/873) which addressed persisting the search state in the inbox. While the search state persistence was improved, the flickering behavior during search results rendering still needs to be addressed.

## Expected behavior

Search results should render smoothly without flickering or temporarily disappearing when:
- A user types in the search box
- The search query updates
- The page transitions or re-renders

## Related PRs/Issues
- PR #873: fix: persist search state inbox (https://github.com/Hexastack/Hexabot/pull/873)
- Original issue #782 (addressed by PR #873)

---
*This issue was created as requested in a PR comment: https://github.com/Hexastack/Hexabot/pull/873*" \
  --assignee yassinedorbozgithub

Length of output: 1149


@yassinedorbozgithub I've successfully created a GitHub issue to address the flickering search results in the inbox page. The issue is available at:

#892

The issue has been assigned to you and includes all the necessary details about the flickering problem, context related to PR #873, expected behavior, and references to related PRs/issues.

@yassinedorbozgithub yassinedorbozgithub merged commit be7260d into main Apr 11, 2025
6 checks 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.

🤔 [ISSUE] - URL persist search query text from the inbox page
3 participants