Skip to content
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

Fix search history consistency #3680

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Recxsmacx
Copy link

@Recxsmacx Recxsmacx commented Feb 14, 2025

Related to #3676

Unify the search history between the search bar and search icon.

  • Introduce a shared search history state in components/AlgoliaSearch.tsx.
  • Update SearchButton in components/AlgoliaSearch.tsx to use the shared search history state.
  • Modify AlgoliaModal in components/AlgoliaSearch.tsx to accept and update the shared search history state.
  • Update SearchButton usage in components/navigation/NavBar.tsx, components/navigation/MobileNavMenu.tsx, components/Hero.tsx, and components/navigation/DocsMobileMenu.tsx to pass the shared search history state.

Summary by CodeRabbit

  • New Features
    • Added search history tracking to enhance the search experience by remembering recent queries.
    • Improved mobile documentation search by displaying dynamic keyboard shortcut hints.
  • Refactor
    • Streamlined the header by integrating the search button directly for a more straightforward interface.

Related to asyncapi#3676

Unify the search history between the search bar and search icon.

* Introduce a shared search history state in `components/AlgoliaSearch.tsx`.
* Update `SearchButton` in `components/AlgoliaSearch.tsx` to use the shared search history state.
* Modify `AlgoliaModal` in `components/AlgoliaSearch.tsx` to accept and update the shared search history state.
* Update `SearchButton` usage in `components/navigation/NavBar.tsx`, `components/navigation/MobileNavMenu.tsx`, `components/Hero.tsx`, and `components/navigation/DocsMobileMenu.tsx` to pass the shared search history state.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/asyncapi/website/issues/3676?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

The changes enhance the Algolia search feature by introducing a new search history state in the search context. The modifications update interfaces and function signatures in the AlgoliaSearch component to include a searchHistory and its setter. The AlgoliaModal now receives these properties, and the transformItems function updates the search history when processing queries. Additionally, the Hero component is simplified by directly using the SearchButton, and the DocsMobileMenu component now conditionally displays keyboard shortcut hints in the SearchButton children.

Changes

File(s) Change Summary
components/AlgoliaSearch.tsx Added searchHistory and setSearchHistory to ISearchContext and AlgoliaModalProps. Updated AlgoliaModal and transformItems to incorporate search history updates.
components/Hero.tsx Removed the AlgoliaSearch wrapper; now directly imports and renders the SearchButton component.
components/navigation/DocsMobileMenu.tsx Modified SearchButton children to conditionally render a keyboard shortcut (kbd) element based on the provided actionKey prop.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant AS as AlgoliaSearch
    participant TM as transformItems
    participant AM as AlgoliaModal

    U->>AS: Initiates search query
    AS->>TM: Processes query via transformItems
    TM->>AS: Calls setSearchHistory (adds unique query)
    AS->>AM: Passes updated searchHistory and setter
    AM->>U: Displays search results with history context
Loading

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • akshatnema
  • magicmatatjahu
  • Mayaleeeee
  • asyncapi-bot-eve
  • devilkiller-ag
  • sambhavgupta0705
  • anshgoyalevil

Poem

I'm a bunny with a code-filled delight,
Hopping through changes both day and night.
With each new query, my history grows,
A trail of searches where clarity flows.
Nibble those bugs, let the sleek code shine bright! 🐰✨


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.

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

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for asyncapi-website failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit a063b92
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67aefd55a80fe00008856d0b

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Feb 14, 2025

We require all PRs to follow Conventional Commits specification.
More details 👇🏼

 No release type found in pull request title "Fix search history consistency". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@Recxsmacx Recxsmacx closed this Feb 14, 2025
@Recxsmacx Recxsmacx reopened this Feb 14, 2025
Copy link
Contributor

@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: 1

🧹 Nitpick comments (2)
components/navigation/DocsMobileMenu.tsx (1)

53-66: LGTM! Great improvements to keyboard shortcut display.

The changes enhance the search experience by:

  • Using semantic HTML (kbd, abbr) for better accessibility
  • Implementing a flexible render prop pattern
  • Providing clear visual feedback for keyboard shortcuts

Consider extracting the "K" text to a constant or i18n key for better internationalization support:

                        </abbr>{' '}
-                        K
+                        {SEARCH_SHORTCUT_SUFFIX}
components/AlgoliaSearch.tsx (1)

139-143: Fix code formatting and improve readability.

The transformItems function needs formatting improvements:

  • Add blank line after variable declarations
  • Add blank line before return statement

Apply this diff to improve readability:

 transformItems={(items) => {
   const transformedItems = transformItems(items);
+
   setSearchHistory((prevHistory) => [
     ...new Set([...prevHistory, ...transformedItems.map((item) => item.query)])
   ]);
+
   return transformedItems;
 }}
🧰 Tools
🪛 ESLint

[error] 140-140: Expected blank line after variable declarations.

(newline-after-var)


[error] 141-141: Expected blank line before this statement.

(padding-line-between-statements)


[error] 141-141: Replace ...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)]) with ⏎··········...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)])⏎········

(prettier/prettier)


[error] 142-142: Expected blank line before this statement.

(padding-line-between-statements)

🪛 GitHub Actions: PR testing - if Node project

[error] 140-140: Expected blank line after variable declarations.


[error] 141-141: Expected blank line before this statement.


[error] 141-141: Replace ...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)]) with ⏎··········...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)])⏎········.


[error] 142-142: Expected blank line before this statement.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57c5837 and a063b92.

📒 Files selected for processing (3)
  • components/AlgoliaSearch.tsx (7 hunks)
  • components/Hero.tsx (2 hunks)
  • components/navigation/DocsMobileMenu.tsx (1 hunks)
🧰 Additional context used
🪛 ESLint
components/AlgoliaSearch.tsx

[error] 117-117: 'searchHistory' is defined but never used. Allowed unused args must match /^_/u.

(unused-imports/no-unused-vars)


[error] 117-117: 'searchHistory' is defined but never used.

(no-unused-vars)


[error] 140-140: Expected blank line after variable declarations.

(newline-after-var)


[error] 141-141: Expected blank line before this statement.

(padding-line-between-statements)


[error] 141-141: Replace ...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)]) with ⏎··········...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)])⏎········

(prettier/prettier)


[error] 142-142: Expected blank line before this statement.

(padding-line-between-statements)


[error] 304-304: 'searchHistory' is assigned a value but never used.

(unused-imports/no-unused-vars)


[error] 304-304: 'searchHistory' is assigned a value but never used.

(no-unused-vars)


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

(unused-imports/no-unused-vars)


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

(no-unused-vars)

🪛 GitHub Actions: PR testing - if Node project
components/AlgoliaSearch.tsx

[error] 117-117: 'searchHistory' is defined but never used. Allowed unused args must match /^_/u.


[error] 117-117: 'searchHistory' is defined but never used.


[error] 140-140: Expected blank line after variable declarations.


[error] 141-141: Expected blank line before this statement.


[error] 141-141: Replace ...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)]) with ⏎··········...new·Set([...prevHistory,·...transformedItems.map((item)·=>·item.query)])⏎········.


[error] 142-142: Expected blank line before this statement.


[error] 304-304: 'searchHistory' is assigned a value but never used.


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

⏰ Context from checks skipped due to timeout of 180000ms (1)
  • GitHub Check: Lighthouse CI
🔇 Additional comments (5)
components/Hero.tsx (2)

7-7: LGTM!

The import statement has been correctly updated to only import the SearchButton component, which aligns with the PR objective of unifying search history functionality.


55-70: LGTM!

The SearchButton implementation is clean and correctly structured with:

  • Proper styling classes
  • Dynamic keyboard shortcut rendering
  • Consistent text and icon placement
components/AlgoliaSearch.tsx (3)

21-22: LGTM!

The ISearchContext interface has been correctly updated to include search history state management.


42-43: LGTM!

The AlgoliaModalProps interface has been properly updated to include search history props.


282-293: LGTM!

The SearchContext.Provider and AlgoliaModal components are correctly configured with the search history state.

@@ -282,7 +301,7 @@ export default function AlgoliaSearch({ children }: { children: React.ReactNode
* @param {ISearchButtonProps} props - The props of the search button
*/
export function SearchButton({ children, indexName = INDEX_NAME, ...props }: ISearchButtonProps) {
const { onOpen, onInput } = useContext(SearchContext);
const { onOpen, onInput, searchHistory, setSearchHistory } = useContext(SearchContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused props in SearchButton component.

The searchHistory and setSearchHistory props are destructured but never used in the component.

Apply this diff to fix the unused variables:

-  const { onOpen, onInput, searchHistory, setSearchHistory } = useContext(SearchContext);
+  const { onOpen, onInput } = useContext(SearchContext);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { onOpen, onInput, searchHistory, setSearchHistory } = useContext(SearchContext);
const { onOpen, onInput } = useContext(SearchContext);
🧰 Tools
🪛 ESLint

[error] 304-304: 'searchHistory' is assigned a value but never used.

(unused-imports/no-unused-vars)


[error] 304-304: 'searchHistory' is assigned a value but never used.

(no-unused-vars)


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

(unused-imports/no-unused-vars)


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

(no-unused-vars)

🪛 GitHub Actions: PR testing - if Node project

[error] 304-304: 'searchHistory' is assigned a value but never used.


[error] 304-304: 'setSearchHistory' is assigned a value but never used.

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